From cd00da07d8a45ddfc0a1a64954d14e0f34ad0201 Mon Sep 17 00:00:00 2001 From: Jannis Braun <151788261+TheZwiss@users.noreply.github.com> Date: Mon, 27 Apr 2026 12:46:10 +0200 Subject: [PATCH] fix(desktop): make get-auto-launch-settings OS-authoritative on Windows --- packages/desktop/src/main.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/desktop/src/main.ts b/packages/desktop/src/main.ts index 99766b0e..974d6c73 100644 --- a/packages/desktop/src/main.ts +++ b/packages/desktop/src/main.ts @@ -15,6 +15,7 @@ import path from 'path'; import fs from 'fs'; import { startActivityDetection, stopActivityDetection, getCurrentActivity } from './activityDetector'; import { KeybindManager } from './keybindManager'; +import { deriveStartMinimizedFromArgs, parseExecPathFromDesktopFile, shouldReapplyAppImage } from './autoLaunch'; let mainWindow: BrowserWindow | null = null; const keybindManager = new KeybindManager(); @@ -544,6 +545,24 @@ function registerIpcHandlers(): void { // Auto-launch settings ipcMain.handle('get-auto-launch-settings', (): { openAtLogin: boolean; startMinimized: boolean } => { + if (process.platform === 'win32') { + // Pass path/args so getLoginItemSettings can find the matching launchItems[] entry. + // We can't know in advance whether the user's saved choice was minimized or not, + // so we query without args and inspect launchItems[] directly. Use + // executableWillLaunchAtLogin to honour Task Manager's StartupApproved state. + const osState = app.getLoginItemSettings({ path: process.execPath }); + const ownEntry = osState.launchItems?.find( + (item) => item.name === 'Backspace' || item.path?.toLowerCase() === process.execPath.toLowerCase(), + ); + return { + openAtLogin: osState.executableWillLaunchAtLogin ?? false, + startMinimized: deriveStartMinimizedFromArgs(ownEntry?.args), + }; + } + // macOS and Linux: getLoginItemSettings doesn't expose args, so startMinimized + // is disk-cached. Rationale: parsing freedesktop Exec= lines on Linux is fragile + // (quoting, escaping, third-party flags) and the out-of-band edit case is rare; + // macOS has no introspection. openAtLogin is OS-authoritative on both platforms. const saved = loadAutoLaunchSettings(); const osState = app.getLoginItemSettings(); return {