From 5e69ea28c4636067961e157d4d6b621a03faf807 Mon Sep 17 00:00:00 2001 From: suu <46421931+0suu@users.noreply.github.com> Date: Mon, 13 Apr 2026 18:06:08 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A2=E3=83=97=E3=83=AA=E5=86=8D=E8=B5=B7?= =?UTF-8?q?=E5=8B=95=E5=BE=8C=E3=81=AB=E5=89=8D=E5=9B=9E=E3=81=AE=E3=82=A6?= =?UTF-8?q?=E3=82=A3=E3=83=B3=E3=83=89=E3=82=A6=E3=82=B5=E3=82=A4=E3=82=BA?= =?UTF-8?q?=E3=82=92=E7=B6=AD=E6=8C=81=E3=81=97=E3=81=9F=E3=81=BE=E3=81=BE?= =?UTF-8?q?=E8=B5=B7=E5=8B=95=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/main.ts | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index 4c91649..fb59650 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -19,6 +19,7 @@ interface AppSettings { nightLightSceneAssignments?: Record; lastView?: "list" | "settings" | "scenes"; confirmOnOffPressActions?: Record; + windowBounds?: { width: number; height: number; x: number; y: number }; } const schema = { @@ -49,6 +50,15 @@ const schema = { default: {}, additionalProperties: { type: "boolean" }, }, + windowBounds: { + type: "object", + properties: { + width: { type: "number" }, + height: { type: "number" }, + x: { type: "number" }, + y: { type: "number" }, + }, + }, }; // Migrate config from v1.1.0 ("app/switchbot-client-config.json") to v1.2.0. @@ -79,9 +89,13 @@ const store = new Store({ function createWindow(): BrowserWindow { + const savedBounds = store.get("windowBounds") as AppSettings["windowBounds"]; + const mainWindow = new BrowserWindow({ - width: 1000, // Increased width a bit - height: 700, // Increased height a bit + width: savedBounds?.width ?? 1000, + height: savedBounds?.height ?? 700, + x: savedBounds?.x, + y: savedBounds?.y, webPreferences: { preload: path.join(__dirname, "../preload/preload.js"), contextIsolation: true, @@ -90,6 +104,19 @@ function createWindow(): BrowserWindow { autoHideMenuBar: true, // Hide the default menu bar }); + // Save window bounds on move and resize (debounced) + let saveTimeout: ReturnType; + const saveBounds = () => { + clearTimeout(saveTimeout); + saveTimeout = setTimeout(() => { + if (!mainWindow.isDestroyed() && !mainWindow.isMinimized() && !mainWindow.isMaximized()) { + store.set("windowBounds", mainWindow.getBounds()); + } + }, 500); + }; + mainWindow.on("resize", saveBounds); + mainWindow.on("move", saveBounds); + if (process.env.NODE_ENV === "development") { mainWindow.loadURL("http://localhost:5173"); // Vite dev server URL mainWindow.webContents.openDevTools();