From d4a000c99c5f691e213005435e2a9ce25a2ca4e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=80=E4=BA=8C?= Date: Thu, 28 Oct 2021 01:01:14 +0800 Subject: [PATCH] fix: cmd+w closed window cannot restore https://github.com/keybase/client/pull/3317/files https://github.com/maxogden/menubar/pull/101 --- src/services/windows/index.ts | 7 +++++-- src/services/workspacesView/index.ts | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/services/windows/index.ts b/src/services/windows/index.ts index d6e9f2ad..deeee59f 100644 --- a/src/services/windows/index.ts +++ b/src/services/windows/index.ts @@ -102,7 +102,6 @@ export class Window implements IWindowService { await this.setWindowMeta(windowName, meta); const existedWindowMeta = await this.getWindowMeta(windowName); - // handle existed window, bring existed window to the front and return. if (existedWindow !== undefined) { if (recreate === true || (typeof recreate === 'function' && existedWindowMeta !== undefined && recreate(existedWindowMeta))) { existedWindow.close(); @@ -520,7 +519,6 @@ export class Window implements IWindowService { minWidth: 250, }), }); - menuBar.app.commandLine.appendSwitch('disable-backgrounding-occluded-windows', 'true'); menuBar.on('after-create-window', () => { if (menuBar.window !== undefined) { @@ -530,6 +528,11 @@ export class Window implements IWindowService { view.webContents.focus(); } }); + menuBar.window.removeAllListeners('close'); + menuBar.window.on('close', (event) => { + event.preventDefault(); + menuBar.hideWindow(); + }); } }); // https://github.com/maxogden/menubar/issues/120 diff --git a/src/services/workspacesView/index.ts b/src/services/workspacesView/index.ts index 3e4d7770..b6215adf 100644 --- a/src/services/workspacesView/index.ts +++ b/src/services/workspacesView/index.ts @@ -230,13 +230,12 @@ export class WorkspaceView implements IWorkspaceViewService { } public async setActiveWorkspaceView(workspaceID: string): Promise { - const mainWindow = this.windowService.get(WindowNames.main); const oldActiveWorkspace = await this.workspaceService.getActiveWorkspace(); const newWorkspace = await this.workspaceService.get(workspaceID); if (newWorkspace === undefined) { throw new Error(`Workspace id ${workspaceID} does not exist. When setActiveWorkspaceView().`); } - if (mainWindow !== undefined && oldActiveWorkspace !== undefined) { + if (oldActiveWorkspace !== undefined) { await this.workspaceService.setActiveWorkspace(workspaceID); await this.viewService.setActiveViewForAllBrowserViews(workspaceID); // if we are switching to a new workspace, we hibernate old view, and activate new view