fix(desktop): base set-auto-launch-settings on OS truth, not stale disk

This commit is contained in:
Jannis Braun
2026-04-27 12:49:00 +02:00
parent cd00da07d8
commit 0d652a72cd
+28 -10
View File
@@ -572,21 +572,39 @@ function registerIpcHandlers(): void {
}); });
ipcMain.handle('set-auto-launch-settings', (_event, settings: { openAtLogin?: boolean; startMinimized?: boolean }) => { ipcMain.handle('set-auto-launch-settings', (_event, settings: { openAtLogin?: boolean; startMinimized?: boolean }) => {
const current = loadAutoLaunchSettings(); // Read current truth from the OS (not from disk) so a partial update preserves
const osState = app.getLoginItemSettings(); // whatever the user (or Task Manager / System Settings) most recently set.
let currentOpenAtLogin: boolean;
let currentStartMinimized: boolean;
const newOpenAtLogin = settings.openAtLogin ?? osState.openAtLogin; if (process.platform === 'win32') {
const newStartMinimized = settings.startMinimized ?? current.startMinimized; 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 = { const newOpenAtLogin = settings.openAtLogin ?? currentOpenAtLogin;
openAtLogin: newOpenAtLogin, const newStartMinimized = settings.startMinimized ?? currentStartMinimized;
startMinimized: newStartMinimized,
};
saveAutoLaunchSettings(updated);
applyLoginItemSettings(newOpenAtLogin, newStartMinimized); 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 // Keybinds