hermes-agent/apps/desktop/electron/dock-launch-order.ts
brooklyn! e726b79803 fix(desktop): stop macOS launch from showing two Dock icons
The setup launcher had no LSUIElement, and its already-installed hand-off
ran after Tauri/AppKit, whose default activation policy is Regular. That
registered the setup bundle as a second Dock app beside the real desktop.
Hand off before constructing Tauri, and restore Regular activation only
when the installer UI is actually shown.

On macOS the Electron single-instance lock also ran before deep-link
registration. setAsDefaultProtocolClient relaunches the app through Launch
Services, so the loser already had a Dock icon by the time the lock failed
and app.exit(0) ran. Register the protocol first. The lock-losing instance
still hard-exits before ready.

Fixes #73151
2026-09-25 01:01:42 -05:00

33 lines
1.3 KiB
TypeScript

/**
* Order of the two startup steps that decide whether macOS shows a second
* Dock icon.
*
* On macOS, `setAsDefaultProtocolClient` goes through Launch Services. If the
* single-instance lock has already claimed this process, that registration
* relaunches a second instance. The loser already has a Dock icon by the time
* `requestSingleInstanceLock` fails and `app.exit(0)` runs, so the deep link
* is registered before the lock.
*
* Other platforms have no Dock. They still take the lock at module load so a
* second `hermes://` launch arrives as `second-instance` argv, and they
* register the protocol on ready.
*/
export type DockLaunchStep = 'register-deep-link' | 'single-instance-lock'
export function preReadyDockLaunchSteps(platform: string): DockLaunchStep[] {
if (platform === 'darwin') {
return ['register-deep-link', 'single-instance-lock']
}
return ['single-instance-lock']
}
/** True when protocol registration is a pre-ready step that precedes the lock. */
export function deepLinkRegistersBeforeSingleInstanceLock(platform: string): boolean {
const steps = preReadyDockLaunchSteps(platform)
const registerAt = steps.indexOf('register-deep-link')
const lockAt = steps.indexOf('single-instance-lock')
return registerAt !== -1 && lockAt !== -1 && registerAt < lockAt
}