diff --git a/src/app/main.cjs b/src/app/main.cjs index bb8009f..298ebaa 100644 --- a/src/app/main.cjs +++ b/src/app/main.cjs @@ -40,12 +40,13 @@ const STATUS_TEXT_LIMIT = 80; const smokeTest = process.argv.includes('--smoke-test'); // Started by the `avenue` command for an assistant: stay in the tray, show no window. -const startedHidden = process.argv.includes('--hidden'); +// A login launch is also silent: the app waits in the tray until the person opens it. +const startedHidden = process.argv.includes('--hidden') || (process.platform === 'darwin' && app.getLoginItemSettings().wasOpenedAtLogin); app.setName('Avenue Sync'); if (smokeTest) app.setPath('userData', path.join(os.tmpdir(), `avenue-sync-smoke-${process.pid}`)); if (!smokeTest && !app.requestSingleInstanceLock()) app.exit(0); app.on('second-instance', (_event, argv) => { if (!argv.includes('--hidden')) showSettings(); }); -app.on('activate', () => showSettings()); +// No 'activate' handler: macOS activates the app for a clicked notification or an `open -g`, and that must not raise the window. The tray menu opens it. let tray; let win; @@ -485,7 +486,7 @@ app.whenReady().then(async () => { createTray(); await startApi(); syncCliCopy(app.getPath('userData')); - app.setLoginItemSettings({ openAtLogin: app.isPackaged && !smokeTest }); + app.setLoginItemSettings({ openAtLogin: app.isPackaged && !smokeTest, args: ['--hidden'] }); if (smokeTest) { log('Smoke test passed.'); setTimeout(() => app.exit(0), 500); return; } sessions.start(); void scheduler.start();