replace default app menu

This commit is contained in:
geekgeekrun
2024-03-28 01:51:22 +08:00
parent b3b85b1504
commit 2bf786d887
3 changed files with 46 additions and 5 deletions

View 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)

View File

@@ -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+/')
})
})
}

View File

@@ -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
}