Skip to content

Commit

Permalink
Resize window automatically with device size
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjadev64 committed Dec 11, 2024
1 parent 83321e1 commit 790e80a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src-tauri/capabilities/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
],
"permissions": [
"core:default",
"core:window:allow-set-min-size",
"core:window:allow-set-size",
"dialog:default",
"deep-link:default"
]
Expand Down
15 changes: 15 additions & 0 deletions src/components/DeviceSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
import { getCurrentWindow, LogicalSize } from "@tauri-apps/api/window";
export let devices: { [id: string]: DeviceInfo } = {};
export let value: string;
Expand Down Expand Up @@ -41,6 +42,20 @@
(async () => devices = await invoke("get_devices"))();
listen("devices", ({ payload }: { payload: { [id: string]: DeviceInfo } }) => devices = payload);
$: {
if (devices[value]) {
const width = (devices[value].columns * 128) + 256;
const height = (devices[value].rows * 128) + 192;
const window = getCurrentWindow();
window.setMinSize(new LogicalSize(width, height)).then(async () => {
const innerSize = await window.innerSize();
if (innerSize.width < width || innerSize.height < height) {
await window.setSize(new LogicalSize(width, height));
}
});
}
}
</script>

{#if Object.keys(devices).length > 0}
Expand Down

0 comments on commit 790e80a

Please sign in to comment.