The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): stop macOS launch from showing two Dock icons
brooklyn!e726b79803b0
diff --git a/apps/bootstrap-installer/src-tauri/Info.plist b/apps/bootstrap-installer/src-tauri/Info.plistindex 1df80c7b999..af71cdc824e 100644--- a/apps/bootstrap-installer/src-tauri/Info.plist+++ b/apps/bootstrap-installer/src-tauri/Info.plist@@ -2,6 +2,8 @@<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict>+ <key>LSUIElement</key>+ <true/><key>NSAudioCaptureUsageDescription</key><string>Hermes launches the desktop app, which uses audio capture for voice conversations.</string><key>NSMicrophoneUsageDescription</key>diff --git a/apps/bootstrap-installer/src-tauri/src/lib.rs b/apps/bootstrap-installer/src-tauri/src/lib.rsindex bed06b971f2..cb545df9ccb 100644--- a/apps/bootstrap-installer/src-tauri/src/lib.rs+++ b/apps/bootstrap-installer/src-tauri/src/lib.rs@@ -64,6 +64,18 @@ where.any(|a| a.as_ref() == "--reinstall" || a.as_ref() == "--repair")}+/// Whether an already-installed launch must hand off before Tauri/AppKit.+///+/// The runtime's default activation policy is Regular. Entering it registers+/// this bootstrap process as a Dock app even when Info.plist sets+/// `LSUIElement`, and the real desktop is a different bundle id, so that+/// registration is a second Hermes icon. Update, repair, and non-macOS+/// launches still build the installer UI. The installed-on-disk check is I/O+/// and stays with the caller.+pub fn handoff_before_appkit(is_macos: bool, mode: AppMode, force_setup: bool) -> bool {+ is_macos && mode == AppMode::Install && !force_setup+}+/// Process-wide install state, shared across Tauri commands.////// The bootstrap is a one-shot, single-tenant process — we only need one@@ -105,53 +117,47 @@ pub fn run() {let force_setup = force_setup_from_args(std::env::args().skip(1));tracing::info!(?mode, force_setup, "Hermes installer starting");+ // Hand off before constructing Tauri/AppKit. The setup callback is too+ // late: by then the process has already been registered as a regular+ // Dock application.+ if handoff_before_appkit(cfg!(target_os = "macos"), mode, force_setup) {+ let install_root = paths::hermes_home().join("hermes-agent");+ if bootstrap::hermes_is_installed(&install_root) {+ match bootstrap::spawn_installed_desktop(&install_root) {+ Ok(()) => {+ // Brief grace so the spawned app is registered before we+ // exit (mirrors launch_hermes_desktop).+ std::thread::sleep(std::time::Duration::from_millis(200));+ tracing::info!(+ "hermes already installed — relaunched desktop; exiting installer"+ );+ return;+ }+ Err(err) => {+ tracing::warn!(+ ?err,+ "relaunch of installed desktop failed; showing installer UI"+ );+ }+ }+ }+ }+tauri::Builder::default().plugin(tauri_plugin_dialog::init()).plugin(tauri_plugin_opener::init()).plugin(tauri_plugin_process::init()).plugin(tauri_plugin_shell::init()).manage(Arc::new(AppState::new(mode)))- .setup(move |app| {+ .setup(|app| {use tauri::Manager;- // Launcher fast path (macOS only): a bare ("Install") launch when- // Hermes is already installed should NOT show the installer or- // rebuild — it should just open the app, so the /Applications- // "Hermes" doubles as a normal launcher (first run installs, every- // later run launches instantly). The window is kept hidden until- // here via `"visible": false` so this path never flashes a window.- //- // Gated to macOS deliberately: on Windows/Linux the installer keeps- // its existing behavior (Windows users relaunch via the Start- // Menu/Desktop "Hermes" shortcuts that install.ps1 creates, and a- // reliable detached relaunch there needs the DETACHED_PROCESS +- // startup-grace handling used by launch_hermes_desktop — out of- // scope here). So this is a pure no-op on non-macOS.- //- // `--reinstall`/`--repair` opts out so a broken install can be- // repaired by re-running setup instead of launching the bad app.- if cfg!(target_os = "macos") && mode == AppMode::Install && !force_setup {- let install_root = paths::hermes_home().join("hermes-agent");- if bootstrap::hermes_is_installed(&install_root) {- match bootstrap::spawn_installed_desktop(&install_root) {- Ok(()) => {- // Brief grace so the spawned app is registered- // before we exit (mirrors launch_hermes_desktop).- std::thread::sleep(std::time::Duration::from_millis(200));- tracing::info!(- "hermes already installed — relaunched desktop; exiting installer"- );- app.handle().exit(0);- return Ok(());- }- Err(err) => {- tracing::warn!(- ?err,- "relaunch of installed desktop failed; showing installer UI"- );- }- }- }- }+ // LSUIElement keeps the launcher hand-off out of the Dock. A+ // visible installer (first run, repair, update) must still be a+ // regular foreground app. The successful fast path returned+ // before Tauri was constructed and cannot reach this callback.+ #[cfg(target_os = "macos")]+ app.set_activation_policy(tauri::ActivationPolicy::Regular);+// First run / repair install, or Update mode: reveal the UI.match app.get_webview_window("main") {Some(win) => {@@ -187,7 +193,7 @@ pub fn run() {#[cfg(test)]mod tests {- use super::{force_setup_from_args, AppMode};+ use super::{force_setup_from_args, handoff_before_appkit, AppMode};#[test]fn bare_args_are_install() {@@ -219,6 +225,21 @@ mod tests {assert!(!force_setup_from_args(["--update"]));}+ #[test]+ fn bare_macos_install_hands_off_before_appkit() {+ assert!(handoff_before_appkit(true, AppMode::Install, false));+ }++ #[test]+ fn repair_update_and_other_platforms_build_installer_ui() {+ assert!(!handoff_before_appkit(true, AppMode::Install, true));+ assert!(!handoff_before_appkit(true, AppMode::Update, false));+ assert!(!handoff_before_appkit(true, AppMode::Update, true));+ assert!(!handoff_before_appkit(false, AppMode::Install, false));+ assert!(!handoff_before_appkit(false, AppMode::Install, true));+ assert!(!handoff_before_appkit(false, AppMode::Update, false));+ }+#[test]fn force_setup_flags_do_not_affect_mode_selection() {// The repair flags must never flip Install<->Update.diff --git a/apps/desktop/electron/dock-launch-order.test.ts b/apps/desktop/electron/dock-launch-order.test.tsnew file mode 100644index 00000000000..e01939e0966--- /dev/null+++ b/apps/desktop/electron/dock-launch-order.test.ts@@ -0,0 +1,17 @@+import { describe, expect, it } from 'vitest'++import { deepLinkRegistersBeforeSingleInstanceLock, preReadyDockLaunchSteps } from './dock-launch-order'++describe('macOS Dock launch order', () => {+ it('registers the deep link before the single-instance lock', () => {+ expect(preReadyDockLaunchSteps('darwin')).toEqual(['register-deep-link', 'single-instance-lock'])+ expect(deepLinkRegistersBeforeSingleInstanceLock('darwin')).toBe(true)+ })++ it('keeps non-macOS platforms on the lock at module load, with no Dock race', () => {+ for (const platform of ['win32', 'linux', 'freebsd']) {+ expect(preReadyDockLaunchSteps(platform)).toEqual(['single-instance-lock'])+ expect(deepLinkRegistersBeforeSingleInstanceLock(platform)).toBe(false)+ }+ })+})diff --git a/apps/desktop/electron/dock-launch-order.ts b/apps/desktop/electron/dock-launch-order.tsnew file mode 100644index 00000000000..6158e618140--- /dev/null+++ b/apps/desktop/electron/dock-launch-order.ts@@ -0,0 +1,33 @@+/**+ * 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+}diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 3186ffbc0f7..2b051ade25d 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -212,6 +212,7 @@ import {type UninstallSummaryDetails} from './desktop-uninstall'import { describeDevCdpDecision, resolveDevCdpPort } from './dev-cdp'+import { preReadyDockLaunchSteps } from './dock-launch-order'import { installEmbedReferer } from './embed-referer'import { createAmbientClaimArbiter } from './event-dedupe'import { openExternalUrl as externalOpen, type ExternalOpenDeps } from './external-open'@@ -17980,6 +17981,16 @@ function registerDeepLinkProtocol() {}}+// macOS: register the deep link before the lock. Launch Services relaunches+// the app when the default protocol client changes; if the lock is already+// held, that relaunch flashes a second Dock icon and then app.exit(0)s.+// Win/Linux have no Dock and still register on ready.+const preReadyDockSteps = preReadyDockLaunchSteps(process.platform)++if (preReadyDockSteps.includes('register-deep-link')) {+ registerDeepLinkProtocol()+}+// Single-instance lock: deep links on a running app (Win/Linux) arrive as a// second-instance argv. Without the lock a second `hermes://` launch spawns a// whole new app instead of routing into the running one.@@ -18068,7 +18079,11 @@ app.whenReady().then(() => {registerMediaProtocol()installEmbedReferer()installRemoteHeaderRules()- registerDeepLinkProtocol()++ if (!preReadyDockSteps.includes('register-deep-link')) {+ registerDeepLinkProtocol()+ }+installPreviewGuestPreload()ensureWslWindowsFonts()