- Fix duplicate tray icon on macOS when hiding to tray
- Fix tray not showing in background mode on macOS
- Fix hide to tray broken on Windows/Linux
- Fix Shutdown button in web UI not working
This commit is contained in:
decolua
2026-05-16 14:06:56 +07:00
parent 30ff4e3fb0
commit 593c788c75
6 changed files with 43 additions and 16 deletions
+30 -11
View File
@@ -694,29 +694,48 @@ function startServer(latestVersion) {
await startTerminalUI(port);
// Loop continues, show menu again
} else if (choice === "hide") {
// Hide to tray: keep the CURRENT process alive (it already owns a
// macOS GUI session so NSStatusItem works). Spawning a detached child
// puts it outside the login session → systray silently fails on macOS.
const { clearScreen } = require("./src/cli/utils/display");
clearScreen();
// Survive terminal close — SIGHUP is sent when the launching shell exits
process.removeAllListeners("SIGHUP");
process.on("SIGHUP", () => {});
// Enable auto startup on OS boot
try {
const { enableAutoStart } = require("./src/cli/tray/autostart");
enableAutoStart(__filename);
} catch (e) { }
console.log(`\n🔔 9Router is running in tray (PID: ${process.pid})`);
if (process.platform === "darwin") {
// macOS: keep current process alive — spawning a detached child puts
// it outside the login session so NSStatusItem silently fails.
process.removeAllListeners("SIGHUP");
process.on("SIGHUP", () => {});
console.log(`\n⏳ Switching to tray mode... (icon already visible in menu bar)`);
console.log(`🔔 9Router is running in tray (PID: ${process.pid})`);
console.log(` Server: http://${displayHost}:${port}`);
console.log(`\n💡 You can close this terminal. Right-click tray icon to quit.\n`);
// Tray already init'd at startup — just keep event loop alive.
return;
}
// Windows/Linux: spawn detached bgProcess (systray works fine in child)
console.log(`\n⏳ Starting background process... (tray icon will appear in ~3s)`);
const bgProcess = spawn(process.execPath, [__filename, "--tray", "--skip-update", "-p", port.toString()], {
detached: true,
stdio: "ignore",
windowsHide: true,
env: { ...process.env }
});
bgProcess.unref();
console.log(`🔔 9Router is now running in background (PID: ${bgProcess.pid})`);
console.log(` Server: http://${displayHost}:${port}`);
console.log(`\n💡 You can close this terminal. Right-click tray icon to quit.\n`);
// Tray icon already running (initTrayIcon was called above at startup).
// Nothing more to do — event loop keeps process alive via tray + server.
return;
// cleanup() kills server so bgProcess can claim the port fresh
cleanup();
process.exit(0);
} else if (choice === "exit") {
isShuttingDown = true;
console.log("\nExiting...");
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "9router",
"version": "0.4.49",
"version": "0.4.50",
"description": "9Router CLI - Start and manage 9Router server",
"bin": {
"9router": "./cli.js"