Skip to content

Commit

Permalink
Merge pull request #230 from onyedikachi-david/fix/main-window-size-c…
Browse files Browse the repository at this point in the history
…onstraints

fix(desktop): enforce main window size constraints
  • Loading branch information
richiemcilroy authored Jan 6, 2025
2 parents ac2f956 + 3e0f399 commit 1637274
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions apps/desktop/src/routes/(window-chrome)/(main).tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
useQueryClient,
} from "@tanstack/solid-query";
import { getVersion } from "@tauri-apps/api/app";
import { getCurrentWindow } from "@tauri-apps/api/window";
import { LogicalSize } from "@tauri-apps/api/window";
import { cx } from "cva";
import {
JSX,
Expand All @@ -17,6 +19,7 @@ import {
createResource,
createSignal,
onMount,
onCleanup,
} from "solid-js";
import { createStore, produce } from "solid-js/store";
import { fetch } from "@tauri-apps/plugin-http";
Expand Down Expand Up @@ -102,6 +105,25 @@ export default function () {
}
}

// Enforce window size with multiple safeguards
const currentWindow = await getCurrentWindow();
const MAIN_WINDOW_SIZE = { width: 300, height: 360 };

// Set initial size
currentWindow.setSize(new LogicalSize(MAIN_WINDOW_SIZE.width, MAIN_WINDOW_SIZE.height));

// Check size when app regains focus
const unlistenFocus = await currentWindow.onFocusChanged(({ payload: focused }) => {
if (focused) {
currentWindow.setSize(new LogicalSize(MAIN_WINDOW_SIZE.width, MAIN_WINDOW_SIZE.height));
}
});

// Listen for resize events
const unlistenResize = await currentWindow.onResized(() => {
currentWindow.setSize(new LogicalSize(MAIN_WINDOW_SIZE.width, MAIN_WINDOW_SIZE.height));
});

setTitlebar("hideMaximize", true);
setTitlebar(
"items",
Expand All @@ -121,6 +143,11 @@ export default function () {
<ChangelogButton />
</div>
);

onCleanup(() => {
unlistenFocus();
unlistenResize();
});
});

return (
Expand Down

1 comment on commit 1637274

@vercel
Copy link

@vercel vercel bot commented on 1637274 Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.