From 3bf697d1a9aba739b6954c8469223f51093497cc Mon Sep 17 00:00:00 2001 From: Jespercal Date: Fri, 13 Feb 2026 06:16:53 +0100 Subject: [PATCH 1/2] feat: persist and restore window size and position (#74) Finished up saving and restoring of window position and size Signed-off-by: Jespercal --- src/config.d.ts | 4 ++++ src/native/config.ts | 28 ++++++++++++++++------------ src/native/window.ts | 16 ++++++++++++++++ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/config.d.ts b/src/config.d.ts index d7a89db..d5f0cde 100644 --- a/src/config.d.ts +++ b/src/config.d.ts @@ -6,6 +6,10 @@ declare type DesktopConfig = { hardwareAcceleration: boolean; discordRpc: boolean; windowState: { + x: number; + y: number; + width: number; + height: number; isMaximised: boolean; }; }; diff --git a/src/native/config.ts b/src/native/config.ts index 7021be3..35fb0ab 100644 --- a/src/native/config.ts +++ b/src/native/config.ts @@ -28,18 +28,18 @@ const schema = { windowState: { type: "object", properties: { - // x: { - // type: 'number' - // } as JSONSchema.Number, - // y: { - // type: 'number' - // } as JSONSchema.Number, - // width: { - // type: 'number' - // } as JSONSchema.Number, - // height: { - // type: 'number' - // } as JSONSchema.Number, + x: { + type: 'number' + } as JSONSchema.Number, + y: { + type: 'number' + } as JSONSchema.Number, + width: { + type: 'number' + } as JSONSchema.Number, + height: { + type: 'number' + } as JSONSchema.Number, isMaximised: { type: "boolean", } as JSONSchema.Boolean, @@ -57,6 +57,10 @@ const store = new Store({ hardwareAcceleration: true, discordRpc: true, windowState: { + x: 0, + y: 0, + width: 0, + height: 0, isMaximised: false, }, } as DesktopConfig, diff --git a/src/native/window.ts b/src/native/window.ts index 571e504..450124e 100644 --- a/src/native/window.ts +++ b/src/native/window.ts @@ -62,6 +62,16 @@ export function createMainWindow() { mainWindow.maximize(); } + // restore last position if it was moved previously + if(config.windowState.x > 0 || config.windowState.y > 0) { + mainWindow.setPosition(config.windowState.x ?? 0, config.windowState.y ?? 0); + } + + // restore last size if it was resized previously + if(config.windowState.width > 0 && config.windowState.height > 0) { + mainWindow.setSize(config.windowState.width ?? 1280, config.windowState.height ?? 720); + } + // load the entrypoint mainWindow.loadURL(BUILD_URL.toString()); @@ -80,12 +90,18 @@ export function createMainWindow() { // keep track of window state function generateState() { config.windowState = { + x: mainWindow.getPosition()[0], + y: mainWindow.getPosition()[1], + width: mainWindow.getSize()[0], + height: mainWindow.getSize()[1], isMaximised: mainWindow.isMaximized(), }; } mainWindow.on("maximize", generateState); mainWindow.on("unmaximize", generateState); + mainWindow.on("moved", generateState); + mainWindow.on("resized", generateState); // rebind zoom controls to be more sensible mainWindow.webContents.on("before-input-event", (event, input) => { From 127d1430a9c630e0429c9cc50d57ee316a63ebe5 Mon Sep 17 00:00:00 2001 From: Mihai <45673304+mihaicm93@users.noreply.github.com> Date: Fri, 13 Feb 2026 06:25:05 +0100 Subject: [PATCH 2/2] fix: App Autostart (#68) Signed-off-by: Mihai Co-authored-by: Mihai --- src/native/autoLaunch.ts | 28 ++++++++++++++++------------ src/world/config.ts | 5 ++--- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/native/autoLaunch.ts b/src/native/autoLaunch.ts index 5e60c39..5c52141 100644 --- a/src/native/autoLaunch.ts +++ b/src/native/autoLaunch.ts @@ -8,16 +8,20 @@ export const autoLaunch = new AutoLaunch({ name: "Stoat", }); -ipcMain.on("isAutostart?", () => - autoLaunch - .isEnabled() - .then((enabled) => mainWindow.webContents.send("isAutostart", enabled)), -); - -ipcMain.on("setAutostart", (_event, state: boolean) => { - if (state) { - autoLaunch.enable(); - } else { - autoLaunch.disable(); - } +ipcMain.handle("getAutostart", async () => { + const enabled = await autoLaunch.isEnabled(); + return enabled; +}); + +ipcMain.handle("setAutostart", async (_event, state: boolean) => { + if (state) { + await autoLaunch.enable(); + console.log("Received new configuration autoStart: true"); + } else { + await autoLaunch.disable(); + console.log("Received new configuration autoStart: false"); + } + + const enabled = await autoLaunch.isEnabled(); + return enabled; }); diff --git a/src/world/config.ts b/src/world/config.ts index 8d0a202..c5ee059 100644 --- a/src/world/config.ts +++ b/src/world/config.ts @@ -8,10 +8,9 @@ contextBridge.exposeInMainWorld("desktopConfig", { get: () => config, set: (config: DesktopConfig) => ipcRenderer.send("config", config), getAutostart() { - ipcRenderer.send("isAutostart?"); - return new Promise((resolve) => ipcRenderer.once("isAutostart", resolve)); + return ipcRenderer.invoke("getAutostart") as Promise; }, setAutostart(value: boolean) { - ipcRenderer.send("setAutostart", value); + return ipcRenderer.invoke("setAutostart", value) as Promise; }, });