feat: 隐藏窗口自带应用菜单栏,清理相关死代码
This commit is contained in:
+2
-66
@@ -95,71 +95,6 @@ ipcMain.handle('clipboard:write', (_event, text: string) => {
|
||||
return true
|
||||
})
|
||||
|
||||
function buildMenu(): void {
|
||||
const isMac = process.platform === 'darwin'
|
||||
const template: Electron.MenuItemConstructorOptions[] = [
|
||||
...(isMac
|
||||
? [
|
||||
{
|
||||
label: app.name,
|
||||
submenu: [
|
||||
{ role: 'about' as const },
|
||||
{ type: 'separator' as const },
|
||||
{ role: 'quit' as const }
|
||||
]
|
||||
}
|
||||
]
|
||||
: []),
|
||||
{
|
||||
label: '文件',
|
||||
submenu: [
|
||||
{ label: '打开文件(左侧)', accelerator: 'CmdOrCtrl+O', click: () => sendMenuCommand('open-left') },
|
||||
{ label: '打开文件(右侧)', accelerator: 'CmdOrCtrl+Alt+O', click: () => sendMenuCommand('open-right') },
|
||||
{ type: 'separator' },
|
||||
isMac ? { role: 'close' as const } : { role: 'quit' as const }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '编辑',
|
||||
submenu: [
|
||||
{ role: 'undo' as const },
|
||||
{ role: 'redo' as const },
|
||||
{ type: 'separator' as const },
|
||||
{ role: 'cut' as const },
|
||||
{ role: 'copy' as const },
|
||||
{ role: 'paste' as const },
|
||||
{ role: 'selectAll' as const }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '视图',
|
||||
submenu: [
|
||||
{ role: 'reload' as const },
|
||||
{ role: 'forceReload' as const },
|
||||
{ role: 'toggleDevTools' as const },
|
||||
{ type: 'separator' as const },
|
||||
{ role: 'resetZoom' as const },
|
||||
{ role: 'zoomIn' as const },
|
||||
{ role: 'zoomOut' as const },
|
||||
{ type: 'separator' as const },
|
||||
{ role: 'togglefullscreen' as const }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '帮助',
|
||||
submenu: [{ role: 'about' as const }]
|
||||
}
|
||||
]
|
||||
Menu.setApplicationMenu(Menu.buildFromTemplate(template))
|
||||
}
|
||||
|
||||
/** 向渲染进程广播菜单指令 */
|
||||
function sendMenuCommand(cmd: string): void {
|
||||
for (const win of BrowserWindow.getAllWindows()) {
|
||||
win.webContents.send('menu:command', cmd)
|
||||
}
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
electronApp.setAppUserModelId('com.metonateam.difflens')
|
||||
|
||||
@@ -167,7 +102,8 @@ app.whenReady().then(() => {
|
||||
optimizer.watchWindowShortcuts(window)
|
||||
})
|
||||
|
||||
buildMenu()
|
||||
// 隐藏窗口自带的应用菜单栏(功能入口由界面按钮提供)
|
||||
Menu.setApplicationMenu(null)
|
||||
createWindow()
|
||||
|
||||
app.on('activate', () => {
|
||||
|
||||
@@ -15,15 +15,7 @@ const api = {
|
||||
showInFolder: (filePath: string): Promise<boolean> =>
|
||||
ipcRenderer.invoke('file:show-in-folder', filePath),
|
||||
setClipboard: (text: string): Promise<boolean> =>
|
||||
ipcRenderer.invoke('clipboard:write', text),
|
||||
/** 订阅顶部菜单命令,返回取消订阅函数 */
|
||||
onMenuCommand: (callback: (cmd: string) => void): (() => void) => {
|
||||
const listener = (_e: unknown, cmd: string): void => callback(cmd)
|
||||
ipcRenderer.on('menu:command', listener)
|
||||
return () => {
|
||||
ipcRenderer.removeListener('menu:command', listener)
|
||||
}
|
||||
}
|
||||
ipcRenderer.invoke('clipboard:write', text)
|
||||
}
|
||||
|
||||
export type DiffLensApi = typeof api
|
||||
|
||||
@@ -86,14 +86,6 @@ export default function App(): ReactElement {
|
||||
else setPaneR(pane)
|
||||
}, [])
|
||||
|
||||
// 订阅顶层菜单命令
|
||||
useEffect(() => {
|
||||
return window.api.onMenuCommand((cmd) => {
|
||||
if (cmd === 'open-left') void openPane('left')
|
||||
else if (cmd === 'open-right') void openPane('right')
|
||||
})
|
||||
}, [openPane])
|
||||
|
||||
const diff: DiffResult = useMemo(() => {
|
||||
return computeDiff(paneL?.text ?? '', paneR?.text ?? '', options)
|
||||
}, [paneL, paneR, options])
|
||||
|
||||
Reference in New Issue
Block a user