diff --git a/main/background.ts b/main/background.ts index dba2580a..dffc3a10 100644 --- a/main/background.ts +++ b/main/background.ts @@ -1,7 +1,8 @@ import path from 'path' -import { app, ipcMain, shell, IpcMainInvokeEvent, BrowserWindow } from 'electron' +import { app, ipcMain, shell, IpcMainInvokeEvent, BrowserWindow, Menu } from 'electron' import serve from 'electron-serve' import { createWindow } from './helpers' +import { menu } from './menu' const isProd = process.env.NODE_ENV === 'production' @@ -16,6 +17,8 @@ let main: BrowserWindow = null ;(async () => { await app.whenReady() + Menu.setApplicationMenu(menu) + const mainWindow = createWindow('main', { width: 1000, height: 600, diff --git a/main/menu.ts b/main/menu.ts new file mode 100644 index 00000000..574ab238 --- /dev/null +++ b/main/menu.ts @@ -0,0 +1,77 @@ +import { app, Menu, MenuItem, MenuItemConstructorOptions } from 'electron' + +const isDarwin = () => process.platform === 'darwin' + +const template: Array = [ + ...(isDarwin() + ? ([ + { + label: app.name, + submenu: [ + { role: 'about' }, + { type: 'separator' }, + { role: 'services' }, + { type: 'separator' }, + { role: 'hide' }, + { role: 'hideOthers' }, + { role: 'unhide' }, + { type: 'separator' }, + { role: 'quit' } + ] + } + ] as Array) + : ([] as Array)), + { + label: 'File', + submenu: [isDarwin() ? { role: 'close' } : { role: 'quit' }] + }, + { + label: 'Edit', + submenu: [ + { role: 'undo' }, + { role: 'redo' }, + { type: 'separator' }, + { role: 'cut' }, + { role: 'copy' }, + { role: 'paste' }, + ...(isDarwin() + ? ([ + { role: 'pasteAndMatchStyle' }, + { role: 'delete' }, + { role: 'selectAll' }, + { type: 'separator' }, + { + label: 'Speech', + submenu: [{ role: 'startSpeaking' }, { role: 'stopSpeaking' }] + } + ] as Array) + : ([{ role: 'delete' }, { type: 'separator' }, { role: 'selectAll' }] as Array)) + ] + }, + { + label: 'View', + submenu: [ + { role: 'reload' }, + { role: 'forceReload' }, + { role: 'toggleDevTools' }, + { type: 'separator' }, + { role: 'resetZoom' }, + { role: 'zoomIn' }, + { role: 'zoomOut' }, + { type: 'separator' }, + { role: 'togglefullscreen' } + ] + }, + { + label: 'Window', + submenu: [ + { role: 'minimize' }, + { role: 'zoom' }, + ...(isDarwin() + ? ([{ type: 'separator' }, { role: 'front' }, { type: 'separator' }, { role: 'window' }] as Array) + : ([{ role: 'close' }] as Array)) + ] + } +] + +export const menu = Menu.buildFromTemplate(template) diff --git a/renderer/next-env.d.ts b/renderer/next-env.d.ts index 4f11a03d..a4a7b3f5 100644 --- a/renderer/next-env.d.ts +++ b/renderer/next-env.d.ts @@ -2,4 +2,4 @@ /// // NOTE: This file should not be edited -// see https://nextjs.org/docs/basic-features/typescript for more information. +// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.