diff --git a/cli/cli.js b/cli/cli.js index 9a1599a..aa6fee9 100755 --- a/cli/cli.js +++ b/cli/cli.js @@ -685,6 +685,11 @@ function startServer(latestVersion) { const { clearScreen } = require("./src/cli/utils/display"); clearScreen(); + // Kill current tray FIRST so the new bgProcess can register a fresh + // NSStatusItem on macOS without conflicting with the orphan binary + try { require("./src/cli/tray/tray").killTray(); } catch (e) { } + await new Promise(r => setTimeout(r, 300)); + // Enable auto startup on OS boot try { const { enableAutoStart } = require("./src/cli/tray/autostart"); diff --git a/cli/package.json b/cli/package.json index f063dbd..fa279e1 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,6 +1,6 @@ { "name": "9router", - "version": "0.4.44", + "version": "0.4.45", "description": "9Router CLI - Start and manage 9Router server", "bin": { "9router": "./cli.js" diff --git a/cli/src/cli/tray/tray.js b/cli/src/cli/tray/tray.js index 1c8602a..acf74ac 100644 --- a/cli/src/cli/tray/tray.js +++ b/cli/src/cli/tray/tray.js @@ -255,10 +255,19 @@ function killTray() { if (instance) { try { if (wasWin) instance.kill(); - // systray2.kill(true) defaults to calling process.exit(0) which aborts - // the rest of cleanup (server SIGKILL, MITM/tunnel cleanup). Pass false - // so callers stay in control of process exit. - else instance.kill(false); + else { + // systray2.kill(false) closes IPC but leaves the Go tray binary + // subprocess running, which keeps an orphan NSStatusItem on macOS + // and blocks a freshly spawned tray (e.g. hide-to-tray bgProcess) + // from registering. Kill the child PID directly first. + try { + const proc = instance._process || (typeof instance.process === "function" ? instance.process() : null); + if (proc && proc.pid) { + process.kill(proc.pid, "SIGKILL"); + } + } catch (e) {} + instance.kill(false); + } } catch (e) {} } } diff --git a/package.json b/package.json index fe3cf6e..6512f95 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "9router-app", - "version": "0.4.44", + "version": "0.4.45", "description": "9Router web dashboard", "private": true, "scripts": {