From b9b421a495876a58465710da872425a8e045dd57 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 12 Mar 2024 17:25:50 +0700 Subject: [PATCH] fix: quick app bugs (#2327) --- electron/main.ts | 20 +++++++------ electron/managers/mainWindowConfig.ts | 2 +- electron/managers/tray.ts | 36 +++++++++++++++--------- electron/managers/window.ts | 4 --- web/containers/Providers/KeyListener.tsx | 4 --- 5 files changed, 35 insertions(+), 31 deletions(-) diff --git a/electron/main.ts b/electron/main.ts index 78577ac68..b7ac0a74c 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -43,6 +43,12 @@ const gotTheLock = app.requestSingleInstanceLock() app .whenReady() + .then(() => { + if (!gotTheLock) { + app.quit() + throw new Error('Another instance of the app is already running') + } + }) .then(setupReactDevTool) .then(setupCore) .then(createUserSpace) @@ -63,22 +69,20 @@ app log(`Version: ${app.getVersion()}`) }) .then(() => { - if (!gotTheLock) { - app.quit() - } else { - app.on('second-instance', (_event, _commandLine, _workingDirectory) => { - // Someone tried to run a second instance, we should focus our window. - windowManager.showMainWindow() - }) - } app.on('activate', () => { if (!BrowserWindow.getAllWindows().length) { createMainWindow() + } else { + windowManager.showMainWindow() } }) }) .then(() => cleanLogs()) +app.on('second-instance', (_event, _commandLine, _workingDirectory) => { + windowManager.showMainWindow() +}) + app.on('ready', () => { registerGlobalShortcuts() }) diff --git a/electron/managers/mainWindowConfig.ts b/electron/managers/mainWindowConfig.ts index 184fb1c86..4f1715a94 100644 --- a/electron/managers/mainWindowConfig.ts +++ b/electron/managers/mainWindowConfig.ts @@ -5,7 +5,7 @@ export const mainWindowConfig: Electron.BrowserWindowConstructorOptions = { width: DEFAULT_WIDTH, minWidth: DEFAULT_WIDTH, height: DEFAULT_HEIGHT, - skipTaskbar: true, + skipTaskbar: false, show: true, trafficLightPosition: { x: 10, diff --git a/electron/managers/tray.ts b/electron/managers/tray.ts index 4e1c1a4ff..e7e07a0a1 100644 --- a/electron/managers/tray.ts +++ b/electron/managers/tray.ts @@ -13,20 +13,28 @@ class TrayManager { const tray = new Tray(iconPath) tray.setToolTip(app.getName()) - const contextMenu = Menu.buildFromTemplate([ - { - label: 'Open Jan', - type: 'normal', - click: () => windowManager.showMainWindow(), - }, - { - label: 'Open Quick Ask', - type: 'normal', - click: () => windowManager.showQuickAskWindow(), - }, - { label: 'Quit', type: 'normal', click: () => app.quit() }, - ]) - tray.setContextMenu(contextMenu) + tray.on('click', () => { + windowManager.showQuickAskWindow() + }) + + // Add context menu for windows only + if (process.platform === 'win32') { + const contextMenu = Menu.buildFromTemplate([ + { + label: 'Open Jan', + type: 'normal', + click: () => windowManager.showMainWindow(), + }, + { + label: 'Open Quick Ask', + type: 'normal', + click: () => windowManager.showQuickAskWindow(), + }, + { label: 'Quit', type: 'normal', click: () => app.quit() }, + ]) + + tray.setContextMenu(contextMenu) + } this.currentTray = tray } diff --git a/electron/managers/window.ts b/electron/managers/window.ts index eed80c37c..7b97f8349 100644 --- a/electron/managers/window.ts +++ b/electron/managers/window.ts @@ -73,15 +73,11 @@ class WindowManager { hideMainWindow(): void { this.mainWindow?.hide() this._mainWindowVisible = false - // Only macos - if (process.platform === 'darwin') app.dock.hide() } showMainWindow(): void { this.mainWindow?.show() this._mainWindowVisible = true - // Only macos - if (process.platform === 'darwin') app.dock.show() } hideQuickAskWindow(): void { diff --git a/web/containers/Providers/KeyListener.tsx b/web/containers/Providers/KeyListener.tsx index d832059c2..a4702783c 100644 --- a/web/containers/Providers/KeyListener.tsx +++ b/web/containers/Providers/KeyListener.tsx @@ -24,10 +24,6 @@ export default function KeyListener({ children }: Props) { useEffect(() => { const onKeyDown = (e: KeyboardEvent) => { - if (e.key === 'Escape') { - window.core?.api?.hideMainWindow() - } - const prefixKey = isMac ? e.metaKey : e.ctrlKey if (e.key === 'b' && prefixKey) {