-
Notifications
You must be signed in to change notification settings - Fork 1
アプリ再起動後に前回のウィンドウサイズを維持したまま起動する #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "45-\u30A2\u30D7\u30EA\u518D\u8D77\u52D5\u5F8C\u306B\u524D\u56DE\u306E\u30A6\u30A3\u30F3\u30C9\u30A6\u30B5\u30A4\u30BA\u3092\u7DAD\u6301\u3057\u305F\u307E\u307E\u8D77\u52D5\u3059\u308B"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ interface AppSettings { | |
| nightLightSceneAssignments?: Record<string, string>; | ||
| lastView?: "list" | "settings" | "scenes"; | ||
| confirmOnOffPressActions?: Record<string, boolean>; | ||
| 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<AppSettings>({ | |
|
|
||
|
|
||
| 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<typeof setTimeout>; | ||
| const saveBounds = () => { | ||
| clearTimeout(saveTimeout); | ||
| saveTimeout = setTimeout(() => { | ||
| if (!mainWindow.isDestroyed() && !mainWindow.isMinimized() && !mainWindow.isMaximized()) { | ||
| store.set("windowBounds", mainWindow.getBounds()); | ||
| } | ||
| }, 500); | ||
| }; | ||
|
Comment on lines
+109
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ウィンドウの let saveTimeout: ReturnType<typeof setTimeout>;
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(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restoring
x/yunconditionally can make the app reopen off-screen when the monitor layout changes (for example, a laptop was last used with an external display and then restarted without it). In that case Electron will honor the stale coordinates and users may see no window at startup, which is a functional regression from the previous centered default behavior.Useful? React with 👍 / 👎.