mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-07-19 19:52:41 +08:00
replace default app menu
This commit is contained in:
27
packages/ui/src/main/flow/OPEN_SETTING_WINDOW/app-menu.ts
Normal file
27
packages/ui/src/main/flow/OPEN_SETTING_WINDOW/app-menu.ts
Normal file
@@ -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)
|
||||
@@ -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+/')
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user