diff --git a/packages/ui/src/main/flow/OPEN_SETTING_WINDOW/app-menu.ts b/packages/ui/src/main/flow/OPEN_SETTING_WINDOW/app-menu.ts new file mode 100644 index 0000000..881f5f4 --- /dev/null +++ b/packages/ui/src/main/flow/OPEN_SETTING_WINDOW/app-menu.ts @@ -0,0 +1,27 @@ +import { app, Menu, MenuItemConstructorOptions, MenuItem } from 'electron' + +const isMac = process.platform === 'darwin' + +const template: (MenuItemConstructorOptions | MenuItem)[] = [ + // { role: 'appMenu' } + ...(isMac + ? [ + { + label: app.name, + submenu: [ + { role: 'about' }, + { type: 'separator' }, + { role: 'services' }, + { type: 'separator' }, + { role: 'hide' }, + { role: 'hideOthers' }, + { role: 'unhide' }, + { type: 'separator' }, + { role: 'quit' } + ] + } + ] + : []) +] +const menu = Menu.buildFromTemplate(template) +Menu.setApplicationMenu(menu) diff --git a/packages/ui/src/main/flow/OPEN_SETTING_WINDOW.ts b/packages/ui/src/main/flow/OPEN_SETTING_WINDOW/index.ts similarity index 73% rename from packages/ui/src/main/flow/OPEN_SETTING_WINDOW.ts rename to packages/ui/src/main/flow/OPEN_SETTING_WINDOW/index.ts index 3ac0bee..fcdc4cc 100644 --- a/packages/ui/src/main/flow/OPEN_SETTING_WINDOW.ts +++ b/packages/ui/src/main/flow/OPEN_SETTING_WINDOW/index.ts @@ -1,7 +1,7 @@ -import { app, BrowserWindow, ipcMain } from 'electron' +import { app, BrowserWindow, ipcMain, globalShortcut } from 'electron' import { electronApp, optimizer } from '@electron-toolkit/utils' -import { createMainWindow } from '../window/mainWindow' - +import { createMainWindow } from '../../window/mainWindow' +import './app-menu' export function openSettingWindow() { // TODO: singleton lock; how can we check if there is another process should run as singleton with arguments? if (!app.requestSingleInstanceLock()) { @@ -9,10 +9,12 @@ export function openSettingWindow() { app.exit(0) } + const whenReadyPromise = app.whenReady() + // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. - app.whenReady().then(() => { + whenReadyPromise.then(() => { // Set app user model id for windows electronApp.setAppUserModelId('com.electron') @@ -44,4 +46,16 @@ export function openSettingWindow() { // In this file you can include the rest of your app"s specific main process // code. You can also put them in separate files and require them here. + + // short cut + whenReadyPromise.then(() => { + // Register a 'Command+Option+Shift+/' shortcut listener. + globalShortcut.register('Command+Option+Shift+/', () => { + console.log('Command+Option+Shift+/ is pressed') + app.exit(0) + }) + app.once('quit', () => { + globalShortcut.unregister('Command+Option+Shift+/') + }) + }) } diff --git a/packages/ui/src/main/index.ts b/packages/ui/src/main/index.ts index 942bd62..370409c 100644 --- a/packages/ui/src/main/index.ts +++ b/packages/ui/src/main/index.ts @@ -31,7 +31,7 @@ const runMode = process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE break } default: { - const { openSettingWindow } = await import('./flow/OPEN_SETTING_WINDOW') + const { openSettingWindow } = await import('./flow/OPEN_SETTING_WINDOW/index') openSettingWindow() break }