From 0d652a72cdf1f993479727f5276dd211f9674c00 Mon Sep 17 00:00:00 2001 From: Jannis Braun <151788261+TheZwiss@users.noreply.github.com> Date: Mon, 27 Apr 2026 12:49:00 +0200 Subject: [PATCH] fix(desktop): base set-auto-launch-settings on OS truth, not stale disk --- packages/desktop/src/main.ts | 38 ++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/packages/desktop/src/main.ts b/packages/desktop/src/main.ts index 974d6c73..ae77bf1c 100644 --- a/packages/desktop/src/main.ts +++ b/packages/desktop/src/main.ts @@ -572,21 +572,39 @@ function registerIpcHandlers(): void { }); ipcMain.handle('set-auto-launch-settings', (_event, settings: { openAtLogin?: boolean; startMinimized?: boolean }) => { - const current = loadAutoLaunchSettings(); - const osState = app.getLoginItemSettings(); + // Read current truth from the OS (not from disk) so a partial update preserves + // whatever the user (or Task Manager / System Settings) most recently set. + let currentOpenAtLogin: boolean; + let currentStartMinimized: boolean; - const newOpenAtLogin = settings.openAtLogin ?? osState.openAtLogin; - const newStartMinimized = settings.startMinimized ?? current.startMinimized; + if (process.platform === 'win32') { + const osState = app.getLoginItemSettings({ path: process.execPath }); + const ownEntry = osState.launchItems?.find( + (item) => item.name === 'Backspace' || item.path?.toLowerCase() === process.execPath.toLowerCase(), + ); + currentOpenAtLogin = osState.executableWillLaunchAtLogin ?? false; + currentStartMinimized = deriveStartMinimizedFromArgs(ownEntry?.args); + } else { + const osState = app.getLoginItemSettings(); + const saved = loadAutoLaunchSettings(); + currentOpenAtLogin = osState.openAtLogin; + currentStartMinimized = saved.startMinimized; + } - const updated: AutoLaunchSettings = { - openAtLogin: newOpenAtLogin, - startMinimized: newStartMinimized, - }; + const newOpenAtLogin = settings.openAtLogin ?? currentOpenAtLogin; + const newStartMinimized = settings.startMinimized ?? currentStartMinimized; - saveAutoLaunchSettings(updated); applyLoginItemSettings(newOpenAtLogin, newStartMinimized); - return updated; + // Persist startMinimized as a disk cache for the macOS / Linux read path. + // We also save openAtLogin for forward compatibility / debugging, but it is + // never the source of truth on read. + saveAutoLaunchSettings({ + openAtLogin: newOpenAtLogin, + startMinimized: newStartMinimized, + }); + + return { openAtLogin: newOpenAtLogin, startMinimized: newStartMinimized }; }); // Keybinds