import { app } from 'electron'; import AutoLaunch from 'auto-launch'; import { readDesktopSettings } from '../desktop-settings'; let autoLauncher: AutoLaunch | null = null; function resolveLaunchPath(): string { // AppImage runs from a temporary mount; APPIMAGE points to the real file path. const appImagePath = process.platform === 'linux' ? String(process.env['APPIMAGE'] || '').trim() : ''; return appImagePath || process.execPath; } function getAutoLauncher(): AutoLaunch | null { if (!app.isPackaged) { return null; } if (!autoLauncher) { autoLauncher = new AutoLaunch({ name: app.getName(), path: resolveLaunchPath() }); } return autoLauncher; } async function setAutoStartEnabled(enabled: boolean): Promise { const launcher = getAutoLauncher(); if (!launcher) { return; } const currentlyEnabled = await launcher.isEnabled(); if (currentlyEnabled === enabled) { return; } if (enabled) { await launcher.enable(); return; } await launcher.disable(); } export async function synchronizeAutoStartSetting(enabled = readDesktopSettings().autoStart): Promise { try { await setAutoStartEnabled(enabled); } catch { // Auto-launch integration should never block app startup or settings saves. } }