From a79ae11aa1bd72043f526bf61aa6ff0b0da76d50 Mon Sep 17 00:00:00 2001 From: Xubin Ren <52506698+Re-bin@users.noreply.github.com> Date: Sat, 6 Jun 2026 01:04:12 +0800 Subject: [PATCH] fix(desktop): hide window instead of closing on macos --- desktop/src/main.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/desktop/src/main.ts b/desktop/src/main.ts index 0d3030523..8ace493c9 100644 --- a/desktop/src/main.ts +++ b/desktop/src/main.ts @@ -40,6 +40,7 @@ type HostRuntime = { let runtime: HostRuntime | null = null; let mainWindow: BrowserWindow | null = null; let crashRestartAttempts = 0; +let isQuitting = false; const hostSockets = new Map(); const APP_PROTOCOL = "nanobot-app:"; const APP_HOST = "app"; @@ -614,6 +615,11 @@ function createWindow(): BrowserWindow { win.once("ready-to-show", () => win.show()); win.on("focus", clearDesktopNotificationBadge); + win.on("close", (event) => { + if (process.platform !== "darwin" || isQuitting) return; + event.preventDefault(); + win.hide(); + }); win.webContents.setWindowOpenHandler(({ url }) => { openExternalIfSafe(url); return { action: "deny" }; @@ -749,6 +755,11 @@ app.whenReady().then(async () => { await loadAppWindow(mainWindow); app.on("activate", () => { + if (mainWindow && !mainWindow.isDestroyed()) { + if (!mainWindow.isVisible()) mainWindow.show(); + mainWindow.focus(); + return; + } if (BrowserWindow.getAllWindows().length === 0) { mainWindow = createWindow(); void loadAppWindow(mainWindow); @@ -764,6 +775,7 @@ app.on("window-all-closed", () => { }); app.on("before-quit", () => { + isQuitting = true; if (runtime) runtime.status = "stopped"; if (runtime?.gateway.exitCode === null) { runtime.gateway.kill("SIGTERM");