| 
									
										
										
										
											2024-08-22 20:13:30 +02:00
										 |  |  | import { app, BaseWindow, BrowserWindow, session, webContents, WebContents, MenuItemConstructorOptions } from 'electron/main'; | 
					
						
							| 
									
										
										
										
											2016-06-22 15:21:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | const isMac = process.platform === 'darwin'; | 
					
						
							|  |  |  | const isWindows = process.platform === 'win32'; | 
					
						
							|  |  |  | const isLinux = process.platform === 'linux'; | 
					
						
							| 
									
										
										
										
											2019-01-10 14:32:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  | type RoleId = 'about' | 'close' | 'copy' | 'cut' | 'delete' | 'forcereload' | 'front' | 'help' | 'hide' | 'hideothers' | 'minimize' | | 
					
						
							| 
									
										
										
										
											2022-01-06 13:41:28 -05:00
										 |  |  |   'paste' | 'pasteandmatchstyle' | 'quit' | 'redo' | 'reload' | 'resetzoom' | 'selectall' | 'services' | 'recentdocuments' | 'clearrecentdocuments' | | 
					
						
							|  |  |  |   'showsubstitutions' | 'togglesmartquotes' | 'togglesmartdashes' | 'toggletextreplacement' | 'startspeaking' | 'stopspeaking' | | 
					
						
							| 
									
										
										
										
											2020-11-12 00:29:18 +09:00
										 |  |  |   'toggledevtools' | 'togglefullscreen' | 'undo' | 'unhide' | 'window' | 'zoom' | 'zoomin' | 'zoomout' | 'togglespellchecker' | | 
					
						
							|  |  |  |   'appmenu' | 'filemenu' | 'editmenu' | 'viewmenu' | 'windowmenu' | 'sharemenu' | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  | interface Role { | 
					
						
							|  |  |  |   label: string; | 
					
						
							|  |  |  |   accelerator?: string; | 
					
						
							| 
									
										
										
										
											2020-11-12 00:29:18 +09:00
										 |  |  |   checked?: boolean; | 
					
						
							| 
									
										
										
										
											2024-08-22 20:13:30 +02:00
										 |  |  |   windowMethod?: ((window: BaseWindow) => void); | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |   webContentsMethod?: ((webContents: WebContents) => void); | 
					
						
							|  |  |  |   appMethod?: () => void; | 
					
						
							|  |  |  |   registerAccelerator?: boolean; | 
					
						
							|  |  |  |   nonNativeMacOSRole?: boolean; | 
					
						
							|  |  |  |   submenu?: MenuItemConstructorOptions[]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const roleList: Record<RoleId, Role> = { | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |   about: { | 
					
						
							|  |  |  |     get label () { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       return isLinux ? 'About' : `About ${app.name}`; | 
					
						
							| 
									
										
										
										
											2020-05-21 15:38:26 -07:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2023-04-07 03:50:24 +09:00
										 |  |  |     ...((isWindows || isLinux) && { appMethod: () => app.showAboutPanel() }) | 
					
						
							| 
									
										
										
										
											2016-06-22 10:29:49 -07:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |   close: { | 
					
						
							| 
									
										
										
										
											2019-01-10 14:32:03 +01:00
										 |  |  |     label: isMac ? 'Close Window' : 'Close', | 
					
						
							| 
									
										
										
										
											2016-06-22 15:26:17 -07:00
										 |  |  |     accelerator: 'CommandOrControl+W', | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     windowMethod: w => w.close() | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |   }, | 
					
						
							|  |  |  |   copy: { | 
					
						
							|  |  |  |     label: 'Copy', | 
					
						
							| 
									
										
										
										
											2016-06-22 15:26:17 -07:00
										 |  |  |     accelerator: 'CommandOrControl+C', | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     webContentsMethod: wc => wc.copy(), | 
					
						
							| 
									
										
										
										
											2018-11-26 19:43:55 +01:00
										 |  |  |     registerAccelerator: false | 
					
						
							| 
									
										
										
										
											2016-06-22 10:29:49 -07:00
										 |  |  |   }, | 
					
						
							|  |  |  |   cut: { | 
					
						
							|  |  |  |     label: 'Cut', | 
					
						
							| 
									
										
										
										
											2016-06-22 15:26:17 -07:00
										 |  |  |     accelerator: 'CommandOrControl+X', | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     webContentsMethod: wc => wc.cut(), | 
					
						
							| 
									
										
										
										
											2018-11-26 19:43:55 +01:00
										 |  |  |     registerAccelerator: false | 
					
						
							| 
									
										
										
										
											2016-06-22 10:29:49 -07:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |   delete: { | 
					
						
							|  |  |  |     label: 'Delete', | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     webContentsMethod: wc => wc.delete() | 
					
						
							| 
									
										
										
										
											2016-06-22 10:29:49 -07:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2017-02-02 11:18:35 -08:00
										 |  |  |   forcereload: { | 
					
						
							|  |  |  |     label: 'Force Reload', | 
					
						
							|  |  |  |     accelerator: 'Shift+CmdOrCtrl+R', | 
					
						
							|  |  |  |     nonNativeMacOSRole: true, | 
					
						
							| 
									
										
										
										
											2024-08-22 20:13:30 +02:00
										 |  |  |     windowMethod: (window: BaseWindow) => { | 
					
						
							|  |  |  |       if (window instanceof BrowserWindow) { | 
					
						
							|  |  |  |         window.webContents.reloadIgnoringCache(); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-02-02 11:18:35 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |   front: { | 
					
						
							|  |  |  |     label: 'Bring All to Front' | 
					
						
							| 
									
										
										
										
											2016-06-22 10:29:49 -07:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |   help: { | 
					
						
							|  |  |  |     label: 'Help' | 
					
						
							| 
									
										
										
										
											2016-06-22 10:29:49 -07:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |   hide: { | 
					
						
							|  |  |  |     get label () { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       return `Hide ${app.name}`; | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |     }, | 
					
						
							|  |  |  |     accelerator: 'Command+H' | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   hideothers: { | 
					
						
							|  |  |  |     label: 'Hide Others', | 
					
						
							|  |  |  |     accelerator: 'Command+Alt+H' | 
					
						
							| 
									
										
										
										
											2016-06-22 10:29:49 -07:00
										 |  |  |   }, | 
					
						
							|  |  |  |   minimize: { | 
					
						
							|  |  |  |     label: 'Minimize', | 
					
						
							| 
									
										
										
										
											2016-06-22 15:26:17 -07:00
										 |  |  |     accelerator: 'CommandOrControl+M', | 
					
						
							| 
									
										
										
										
											2025-04-22 04:58:30 -04:00
										 |  |  |     windowMethod: w => { | 
					
						
							|  |  |  |       if (w.minimizable) w.minimize(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-22 10:29:49 -07:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |   paste: { | 
					
						
							|  |  |  |     label: 'Paste', | 
					
						
							| 
									
										
										
										
											2016-06-22 15:26:17 -07:00
										 |  |  |     accelerator: 'CommandOrControl+V', | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     webContentsMethod: wc => wc.paste(), | 
					
						
							| 
									
										
										
										
											2018-11-26 19:43:55 +01:00
										 |  |  |     registerAccelerator: false | 
					
						
							| 
									
										
										
										
											2016-06-22 10:29:49 -07:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |   pasteandmatchstyle: { | 
					
						
							|  |  |  |     label: 'Paste and Match Style', | 
					
						
							| 
									
										
										
										
											2020-06-17 23:13:46 +02:00
										 |  |  |     accelerator: isMac ? 'Cmd+Option+Shift+V' : 'Shift+CommandOrControl+V', | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     webContentsMethod: wc => wc.pasteAndMatchStyle(), | 
					
						
							| 
									
										
										
										
											2018-11-26 19:43:55 +01:00
										 |  |  |     registerAccelerator: false | 
					
						
							| 
									
										
										
										
											2016-06-22 10:29:49 -07:00
										 |  |  |   }, | 
					
						
							|  |  |  |   quit: { | 
					
						
							|  |  |  |     get label () { | 
					
						
							| 
									
										
										
										
											2016-06-22 15:26:17 -07:00
										 |  |  |       switch (process.platform) { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |         case 'darwin': return `Quit ${app.name}`; | 
					
						
							|  |  |  |         case 'win32': return 'Exit'; | 
					
						
							|  |  |  |         default: return 'Quit'; | 
					
						
							| 
									
										
										
										
											2016-06-22 15:26:17 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-06-22 10:29:49 -07:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2019-07-16 12:54:18 -07:00
										 |  |  |     accelerator: isWindows ? undefined : 'CommandOrControl+Q', | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     appMethod: () => app.quit() | 
					
						
							| 
									
										
										
										
											2016-06-22 10:29:49 -07:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |   redo: { | 
					
						
							|  |  |  |     label: 'Redo', | 
					
						
							| 
									
										
										
										
											2019-01-10 14:32:03 +01:00
										 |  |  |     accelerator: isWindows ? 'Control+Y' : 'Shift+CommandOrControl+Z', | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     webContentsMethod: wc => wc.redo() | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-11-15 10:49:51 -08:00
										 |  |  |   reload: { | 
					
						
							|  |  |  |     label: 'Reload', | 
					
						
							|  |  |  |     accelerator: 'CmdOrCtrl+R', | 
					
						
							| 
									
										
										
										
											2017-02-02 11:18:35 -08:00
										 |  |  |     nonNativeMacOSRole: true, | 
					
						
							| 
									
										
										
										
											2024-08-22 20:13:30 +02:00
										 |  |  |     windowMethod: (w: BaseWindow) => { | 
					
						
							|  |  |  |       if (w instanceof BrowserWindow) { | 
					
						
							|  |  |  |         w.reload(); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-11-15 10:49:51 -08:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-08-08 10:09:45 -07:00
										 |  |  |   resetzoom: { | 
					
						
							|  |  |  |     label: 'Actual Size', | 
					
						
							|  |  |  |     accelerator: 'CommandOrControl+0', | 
					
						
							| 
									
										
										
										
											2017-02-02 11:18:35 -08:00
										 |  |  |     nonNativeMacOSRole: true, | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     webContentsMethod: (webContents: WebContents) => { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       webContents.zoomLevel = 0; | 
					
						
							| 
									
										
										
										
											2016-08-08 10:09:45 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |   selectall: { | 
					
						
							|  |  |  |     label: 'Select All', | 
					
						
							| 
									
										
										
										
											2016-06-22 15:26:17 -07:00
										 |  |  |     accelerator: 'CommandOrControl+A', | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     webContentsMethod: wc => wc.selectAll() | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |   }, | 
					
						
							|  |  |  |   services: { | 
					
						
							|  |  |  |     label: 'Services' | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2017-11-20 16:31:21 -08:00
										 |  |  |   recentdocuments: { | 
					
						
							| 
									
										
										
										
											2017-11-20 16:15:43 -08:00
										 |  |  |     label: 'Open Recent' | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2017-11-20 16:31:21 -08:00
										 |  |  |   clearrecentdocuments: { | 
					
						
							| 
									
										
										
										
											2017-11-20 16:15:43 -08:00
										 |  |  |     label: 'Clear Menu' | 
					
						
							| 
									
										
										
										
											2017-11-18 21:52:52 -08:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2022-01-06 13:41:28 -05:00
										 |  |  |   showsubstitutions: { | 
					
						
							|  |  |  |     label: 'Show Substitutions' | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   togglesmartquotes: { | 
					
						
							|  |  |  |     label: 'Smart Quotes' | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   togglesmartdashes: { | 
					
						
							|  |  |  |     label: 'Smart Dashes' | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   toggletextreplacement: { | 
					
						
							|  |  |  |     label: 'Text Replacement' | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-08-08 00:02:32 +02:00
										 |  |  |   startspeaking: { | 
					
						
							|  |  |  |     label: 'Start Speaking' | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   stopspeaking: { | 
					
						
							|  |  |  |     label: 'Stop Speaking' | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-11-15 10:52:03 -08:00
										 |  |  |   toggledevtools: { | 
					
						
							|  |  |  |     label: 'Toggle Developer Tools', | 
					
						
							| 
									
										
										
										
											2019-01-10 14:32:03 +01:00
										 |  |  |     accelerator: isMac ? 'Alt+Command+I' : 'Ctrl+Shift+I', | 
					
						
							| 
									
										
										
										
											2017-02-02 11:18:35 -08:00
										 |  |  |     nonNativeMacOSRole: true, | 
					
						
							| 
									
										
										
										
											2021-08-01 18:58:28 -07:00
										 |  |  |     webContentsMethod: wc => { | 
					
						
							|  |  |  |       const bw = wc.getOwnerBrowserWindow(); | 
					
						
							|  |  |  |       if (bw) bw.webContents.toggleDevTools(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-11-15 10:52:03 -08:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-06-22 10:29:49 -07:00
										 |  |  |   togglefullscreen: { | 
					
						
							|  |  |  |     label: 'Toggle Full Screen', | 
					
						
							| 
									
										
										
										
											2019-01-10 14:32:03 +01:00
										 |  |  |     accelerator: isMac ? 'Control+Command+F' : 'F11', | 
					
						
							| 
									
										
										
										
											2024-08-22 20:13:30 +02:00
										 |  |  |     windowMethod: (window: BaseWindow) => { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       window.setFullScreen(!window.isFullScreen()); | 
					
						
							| 
									
										
										
										
											2016-06-22 13:48:26 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-22 10:47:25 -07:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |   undo: { | 
					
						
							|  |  |  |     label: 'Undo', | 
					
						
							| 
									
										
										
										
											2016-06-22 15:26:17 -07:00
										 |  |  |     accelerator: 'CommandOrControl+Z', | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     webContentsMethod: wc => wc.undo() | 
					
						
							| 
									
										
										
										
											2016-06-22 13:15:20 -07:00
										 |  |  |   }, | 
					
						
							|  |  |  |   unhide: { | 
					
						
							|  |  |  |     label: 'Show All' | 
					
						
							| 
									
										
										
										
											2016-06-22 10:47:25 -07:00
										 |  |  |   }, | 
					
						
							|  |  |  |   window: { | 
					
						
							|  |  |  |     label: 'Window' | 
					
						
							| 
									
										
										
										
											2016-06-22 13:09:39 -07:00
										 |  |  |   }, | 
					
						
							|  |  |  |   zoom: { | 
					
						
							|  |  |  |     label: 'Zoom' | 
					
						
							| 
									
										
										
										
											2016-08-08 10:09:45 -07:00
										 |  |  |   }, | 
					
						
							|  |  |  |   zoomin: { | 
					
						
							|  |  |  |     label: 'Zoom In', | 
					
						
							|  |  |  |     accelerator: 'CommandOrControl+Plus', | 
					
						
							| 
									
										
										
										
											2017-02-02 11:18:35 -08:00
										 |  |  |     nonNativeMacOSRole: true, | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     webContentsMethod: (webContents: WebContents) => { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       webContents.zoomLevel += 0.5; | 
					
						
							| 
									
										
										
										
											2016-08-08 10:09:45 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   zoomout: { | 
					
						
							|  |  |  |     label: 'Zoom Out', | 
					
						
							|  |  |  |     accelerator: 'CommandOrControl+-', | 
					
						
							| 
									
										
										
										
											2017-02-02 11:18:35 -08:00
										 |  |  |     nonNativeMacOSRole: true, | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     webContentsMethod: (webContents: WebContents) => { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       webContents.zoomLevel -= 0.5; | 
					
						
							| 
									
										
										
										
											2016-08-08 10:09:45 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-03-09 16:01:33 +01:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-11-12 00:29:18 +09:00
										 |  |  |   togglespellchecker: { | 
					
						
							|  |  |  |     label: 'Check Spelling While Typing', | 
					
						
							|  |  |  |     get checked () { | 
					
						
							|  |  |  |       const wc = webContents.getFocusedWebContents(); | 
					
						
							|  |  |  |       const ses = wc ? wc.session : session.defaultSession; | 
					
						
							|  |  |  |       return ses.spellCheckerEnabled; | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     nonNativeMacOSRole: true, | 
					
						
							|  |  |  |     webContentsMethod: (wc: WebContents) => { | 
					
						
							|  |  |  |       const ses = wc ? wc.session : session.defaultSession; | 
					
						
							|  |  |  |       ses.spellCheckerEnabled = !ses.spellCheckerEnabled; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2019-01-10 14:32:03 +01:00
										 |  |  |   // App submenu should be used for Mac only
 | 
					
						
							|  |  |  |   appmenu: { | 
					
						
							|  |  |  |     get label () { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       return app.name; | 
					
						
							| 
									
										
										
										
											2019-01-10 14:32:03 +01:00
										 |  |  |     }, | 
					
						
							|  |  |  |     submenu: [ | 
					
						
							|  |  |  |       { role: 'about' }, | 
					
						
							|  |  |  |       { type: 'separator' }, | 
					
						
							|  |  |  |       { role: 'services' }, | 
					
						
							|  |  |  |       { type: 'separator' }, | 
					
						
							|  |  |  |       { role: 'hide' }, | 
					
						
							| 
									
										
										
										
											2019-07-31 14:13:56 -07:00
										 |  |  |       { role: 'hideOthers' }, | 
					
						
							| 
									
										
										
										
											2019-01-10 14:32:03 +01:00
										 |  |  |       { role: 'unhide' }, | 
					
						
							|  |  |  |       { type: 'separator' }, | 
					
						
							|  |  |  |       { role: 'quit' } | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   // File submenu
 | 
					
						
							|  |  |  |   filemenu: { | 
					
						
							|  |  |  |     label: 'File', | 
					
						
							|  |  |  |     submenu: [ | 
					
						
							|  |  |  |       isMac ? { role: 'close' } : { role: 'quit' } | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   // Edit submenu
 | 
					
						
							| 
									
										
										
										
											2017-12-28 13:22:39 +08:00
										 |  |  |   editmenu: { | 
					
						
							| 
									
										
										
										
											2017-03-09 16:01:33 +01:00
										 |  |  |     label: 'Edit', | 
					
						
							|  |  |  |     submenu: [ | 
					
						
							| 
									
										
										
										
											2019-01-10 14:32:03 +01:00
										 |  |  |       { role: 'undo' }, | 
					
						
							|  |  |  |       { role: 'redo' }, | 
					
						
							|  |  |  |       { type: 'separator' }, | 
					
						
							|  |  |  |       { role: 'cut' }, | 
					
						
							|  |  |  |       { role: 'copy' }, | 
					
						
							|  |  |  |       { role: 'paste' }, | 
					
						
							| 
									
										
										
										
											2024-09-26 00:12:11 -07:00
										 |  |  |       ...(isMac | 
					
						
							|  |  |  |         ? [ | 
					
						
							|  |  |  |           { role: 'pasteAndMatchStyle' }, | 
					
						
							|  |  |  |           { role: 'delete' }, | 
					
						
							|  |  |  |           { role: 'selectAll' }, | 
					
						
							|  |  |  |           { type: 'separator' }, | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             label: 'Substitutions', | 
					
						
							|  |  |  |             submenu: [ | 
					
						
							|  |  |  |               { role: 'showSubstitutions' }, | 
					
						
							|  |  |  |               { type: 'separator' }, | 
					
						
							|  |  |  |               { role: 'toggleSmartQuotes' }, | 
					
						
							|  |  |  |               { role: 'toggleSmartDashes' }, | 
					
						
							|  |  |  |               { role: 'toggleTextReplacement' } | 
					
						
							|  |  |  |             ] | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             label: 'Speech', | 
					
						
							|  |  |  |             submenu: [ | 
					
						
							|  |  |  |               { role: 'startSpeaking' }, | 
					
						
							|  |  |  |               { role: 'stopSpeaking' } | 
					
						
							|  |  |  |             ] | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         ] as MenuItemConstructorOptions[] | 
					
						
							|  |  |  |         : [ | 
					
						
							|  |  |  |           { role: 'delete' }, | 
					
						
							|  |  |  |           { type: 'separator' }, | 
					
						
							|  |  |  |           { role: 'selectAll' } | 
					
						
							|  |  |  |         ] as MenuItemConstructorOptions[]) | 
					
						
							| 
									
										
										
										
											2017-03-09 16:01:33 +01:00
										 |  |  |     ] | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2019-01-10 14:32:03 +01:00
										 |  |  |   // View submenu
 | 
					
						
							|  |  |  |   viewmenu: { | 
					
						
							|  |  |  |     label: 'View', | 
					
						
							|  |  |  |     submenu: [ | 
					
						
							|  |  |  |       { role: 'reload' }, | 
					
						
							| 
									
										
										
										
											2019-07-31 14:13:56 -07:00
										 |  |  |       { role: 'forceReload' }, | 
					
						
							|  |  |  |       { role: 'toggleDevTools' }, | 
					
						
							| 
									
										
										
										
											2019-01-10 14:32:03 +01:00
										 |  |  |       { type: 'separator' }, | 
					
						
							| 
									
										
										
										
											2019-07-31 14:13:56 -07:00
										 |  |  |       { role: 'resetZoom' }, | 
					
						
							|  |  |  |       { role: 'zoomIn' }, | 
					
						
							|  |  |  |       { role: 'zoomOut' }, | 
					
						
							| 
									
										
										
										
											2019-01-10 14:32:03 +01:00
										 |  |  |       { type: 'separator' }, | 
					
						
							|  |  |  |       { role: 'togglefullscreen' } | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   // Window submenu
 | 
					
						
							| 
									
										
										
										
											2017-12-28 13:22:39 +08:00
										 |  |  |   windowmenu: { | 
					
						
							| 
									
										
										
										
											2017-03-09 16:01:33 +01:00
										 |  |  |     label: 'Window', | 
					
						
							|  |  |  |     submenu: [ | 
					
						
							| 
									
										
										
										
											2019-01-10 14:32:03 +01:00
										 |  |  |       { role: 'minimize' }, | 
					
						
							|  |  |  |       { role: 'zoom' }, | 
					
						
							| 
									
										
										
										
											2024-09-26 00:12:11 -07:00
										 |  |  |       ...(isMac | 
					
						
							|  |  |  |         ? [ | 
					
						
							|  |  |  |           { type: 'separator' }, | 
					
						
							|  |  |  |           { role: 'front' } | 
					
						
							|  |  |  |         ] as MenuItemConstructorOptions[] | 
					
						
							|  |  |  |         : [ | 
					
						
							|  |  |  |           { role: 'close' } | 
					
						
							|  |  |  |         ] as MenuItemConstructorOptions[]) | 
					
						
							| 
									
										
										
										
											2017-03-09 16:01:33 +01:00
										 |  |  |     ] | 
					
						
							| 
									
										
										
										
											2020-10-20 10:33:06 +09:00
										 |  |  |   }, | 
					
						
							|  |  |  |   // Share submenu
 | 
					
						
							|  |  |  |   sharemenu: { | 
					
						
							|  |  |  |     label: 'Share', | 
					
						
							|  |  |  |     submenu: [] | 
					
						
							| 
									
										
										
										
											2016-06-22 10:29:49 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-06-22 10:45:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 02:45:08 +02:00
										 |  |  | const hasRole = (role: keyof typeof roleList) => { | 
					
						
							| 
									
										
										
										
											2023-06-27 22:57:33 +02:00
										 |  |  |   return Object.hasOwn(roleList, role); | 
					
						
							| 
									
										
										
										
											2020-10-10 02:45:08 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  | const canExecuteRole = (role: keyof typeof roleList) => { | 
					
						
							| 
									
										
										
										
											2020-10-10 02:45:08 +02:00
										 |  |  |   if (!hasRole(role)) return false; | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |   if (!isMac) return true; | 
					
						
							| 
									
										
										
										
											2018-02-23 08:53:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-02 11:18:35 -08:00
										 |  |  |   // macOS handles all roles natively except for a few
 | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |   return roleList[role].nonNativeMacOSRole; | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-08-08 10:09:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 00:29:18 +09:00
										 |  |  | export function getDefaultType (role: RoleId) { | 
					
						
							|  |  |  |   if (shouldOverrideCheckStatus(role)) return 'checkbox'; | 
					
						
							|  |  |  |   return 'normal'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  | export function getDefaultLabel (role: RoleId) { | 
					
						
							| 
									
										
										
										
											2020-10-10 02:45:08 +02:00
										 |  |  |   return hasRole(role) ? roleList[role].label : ''; | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-06-22 10:45:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 00:29:18 +09:00
										 |  |  | export function getCheckStatus (role: RoleId) { | 
					
						
							|  |  |  |   if (hasRole(role)) return roleList[role].checked; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function shouldOverrideCheckStatus (role: RoleId) { | 
					
						
							| 
									
										
										
										
											2023-06-27 22:57:33 +02:00
										 |  |  |   return hasRole(role) && Object.hasOwn(roleList[role], 'checked'); | 
					
						
							| 
									
										
										
										
											2020-11-12 00:29:18 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  | export function getDefaultAccelerator (role: RoleId) { | 
					
						
							| 
									
										
										
										
											2020-10-10 02:45:08 +02:00
										 |  |  |   if (hasRole(role)) return roleList[role].accelerator; | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-06-22 13:48:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  | export function shouldRegisterAccelerator (role: RoleId) { | 
					
						
							| 
									
										
										
										
											2020-10-10 02:45:08 +02:00
										 |  |  |   const hasRoleRegister = hasRole(role) && roleList[role].registerAccelerator !== undefined; | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |   return hasRoleRegister ? roleList[role].registerAccelerator : true; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-11-26 19:43:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  | export function getDefaultSubmenu (role: RoleId) { | 
					
						
							| 
									
										
										
										
											2020-10-10 02:45:08 +02:00
										 |  |  |   if (!hasRole(role)) return; | 
					
						
							| 
									
										
										
										
											2017-03-09 16:01:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |   let { submenu } = roleList[role]; | 
					
						
							| 
									
										
										
										
											2017-03-09 16:01:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-29 12:27:59 -07:00
										 |  |  |   // remove null items from within the submenu
 | 
					
						
							|  |  |  |   if (Array.isArray(submenu)) { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     submenu = submenu.filter((item) => item != null); | 
					
						
							| 
									
										
										
										
											2017-03-09 16:01:33 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-03-29 12:27:59 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |   return submenu; | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-09 16:01:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-22 20:13:30 +02:00
										 |  |  | export function execute (role: RoleId, focusedWindow: BaseWindow, focusedWebContents: WebContents) { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |   if (!canExecuteRole(role)) return false; | 
					
						
							| 
									
										
										
										
											2016-06-22 13:48:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |   const { appMethod, webContentsMethod, windowMethod } = roleList[role]; | 
					
						
							| 
									
										
										
										
											2016-06-22 13:48:26 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (appMethod) { | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     appMethod(); | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2016-06-22 13:48:26 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 14:14:32 -07:00
										 |  |  |   if (windowMethod && focusedWindow != null) { | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     windowMethod(focusedWindow); | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2016-06-22 14:14:32 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-13 12:18:44 -07:00
										 |  |  |   if (webContentsMethod && focusedWebContents != null) { | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  |     webContentsMethod(focusedWebContents); | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2016-06-22 13:48:26 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2020-07-06 13:24:54 -07:00
										 |  |  | } |