fix(desktop): pass enabled/path/args/name to setLoginItemSettings per platform
macOS: add args:[--hidden] alongside openAsHidden for defence-in-depth detection on macOS 13+. Windows: add enabled/path/args/name so re-enabling the toggle clears the StartupApproved\Run disable marker. Linux: add deterministic name:'backspace' so the .desktop filename is stable across Electron/AppImage updates.
This commit is contained in:
@@ -164,22 +164,42 @@ function saveAutoLaunchSettings(settings: AutoLaunchSettings): void {
|
|||||||
|
|
||||||
function applyLoginItemSettings(openAtLogin: boolean, startMinimized: boolean): void {
|
function applyLoginItemSettings(openAtLogin: boolean, startMinimized: boolean): void {
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
|
// macOS: pass `args` in addition to `openAsHidden` so the renderer/main can
|
||||||
|
// detect a hidden launch via `process.argv.includes('--hidden')` on macOS 13+
|
||||||
|
// where the new ServiceManagement-backed implementation may not honour
|
||||||
|
// `wasOpenedAsHidden`. Both detection paths now work (defence in depth).
|
||||||
app.setLoginItemSettings({
|
app.setLoginItemSettings({
|
||||||
openAtLogin,
|
openAtLogin,
|
||||||
openAsHidden: startMinimized,
|
openAsHidden: startMinimized,
|
||||||
|
args: startMinimized ? ['--hidden'] : [],
|
||||||
});
|
});
|
||||||
} else if (process.platform === 'win32') {
|
} else if (process.platform === 'win32') {
|
||||||
|
// Windows: `enabled` is REQUIRED to undo a Task-Manager-side disable.
|
||||||
|
// Without it, re-enabling our toggle leaves the StartupApproved\Run
|
||||||
|
// "disabled" marker in place and the user's Run entry still won't fire.
|
||||||
|
// We pass `enabled: openAtLogin` so toggling ON re-enables, toggling OFF
|
||||||
|
// removes the entry entirely (deletion supersedes the disable marker).
|
||||||
|
// `path` and `args` are passed explicitly so subsequent get() calls can
|
||||||
|
// match the right launchItems[] entry.
|
||||||
app.setLoginItemSettings({
|
app.setLoginItemSettings({
|
||||||
openAtLogin,
|
openAtLogin,
|
||||||
|
enabled: openAtLogin,
|
||||||
|
path: process.execPath,
|
||||||
args: startMinimized ? ['--hidden'] : [],
|
args: startMinimized ? ['--hidden'] : [],
|
||||||
name: 'Backspace',
|
name: 'Backspace',
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Linux: setLoginItemSettings creates a .desktop file in ~/.config/autostart/
|
// Linux: setLoginItemSettings creates ~/.config/autostart/<name>.desktop.
|
||||||
// For AppImage, the path changes on update — we pass it explicitly.
|
// - We pass an explicit `name: 'backspace'` so the filename is deterministic
|
||||||
// Electron's Linux impl doesn't support `path`/`args` in types,
|
// across deb/AppImage installs and Electron versions.
|
||||||
// but the runtime does accept them in the options object.
|
// - For AppImage, $APPIMAGE points to the (possibly newly-updated) AppImage
|
||||||
const opts: Record<string, unknown> = { openAtLogin };
|
// path; pass it as `path` so the autostart entry tracks updates.
|
||||||
|
// Electron's TypeScript types don't list `path`/`args`/`name` on Linux,
|
||||||
|
// but the runtime accepts them.
|
||||||
|
const opts: Record<string, unknown> = {
|
||||||
|
openAtLogin,
|
||||||
|
name: 'backspace',
|
||||||
|
};
|
||||||
if (process.env.APPIMAGE) {
|
if (process.env.APPIMAGE) {
|
||||||
opts.path = process.env.APPIMAGE;
|
opts.path = process.env.APPIMAGE;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user