@@ -7,9 +7,20 @@ const AUTO_HIDE_SETTING_KEY = "autoHideMenuBar";
77
88export const shouldAutoHideMenu = ( ) => ! ! store . get ( AUTO_HIDE_SETTING_KEY ) ;
99
10- export const getMenu = ( browserWindows : Electron . BrowserWindow [ ] ) => {
11- const menuTemplate : MenuItemConstructorOptions [ ] = [
12- {
10+ type MenuKey =
11+ | 'mac'
12+ | 'file'
13+ | 'edit'
14+ | 'view'
15+ | 'window'
16+ | 'help' ;
17+
18+ export const getMenu = (
19+ browserWindows : Electron . BrowserWindow [ ] ,
20+ openNewWindow : ( ) => void
21+ ) => {
22+ const menuTemplate : { [ key in MenuKey ] ?: MenuItemConstructorOptions } = {
23+ edit : {
1324 label : '&Edit' ,
1425 submenu : [
1526 { role : 'undo' } ,
@@ -22,7 +33,7 @@ export const getMenu = (browserWindows: Electron.BrowserWindow[]) => {
2233 { role : 'delete' }
2334 ]
2435 } ,
25- {
36+ view : {
2637 label : '&View' ,
2738 submenu : [
2839 { role : 'resetZoom' } ,
@@ -38,7 +49,7 @@ export const getMenu = (browserWindows: Electron.BrowserWindow[]) => {
3849 { role : 'toggleDevTools' }
3950 ]
4051 } ,
41- {
52+ help : {
4253 label : '&Help' ,
4354 role : 'help' ,
4455 submenu : [
@@ -56,10 +67,10 @@ export const getMenu = (browserWindows: Electron.BrowserWindow[]) => {
5667 }
5768 ]
5869 }
59- ] ;
70+ } ;
6071
6172 if ( process . platform === 'darwin' ) {
62- const macMenu : MenuItemConstructorOptions = {
73+ menuTemplate . mac = {
6374 label : app . getName ( ) ,
6475 submenu : [
6576 { role : 'about' } ,
@@ -73,10 +84,25 @@ export const getMenu = (browserWindows: Electron.BrowserWindow[]) => {
7384 { role : 'quit' }
7485 ]
7586 } ;
76- menuTemplate . unshift ( macMenu ) ;
87+
88+ menuTemplate . file = {
89+ label : '&File' ,
90+ submenu : [
91+ {
92+ label : 'New Session' ,
93+ accelerator : 'CommandOrControl+Shift+N' ,
94+ click : openNewWindow
95+ } ,
96+ {
97+ role : 'close' ,
98+ accelerator : 'CommandOrControl+Shift+W' ,
99+ label : 'Close Session'
100+ }
101+ ]
102+ } ;
77103
78104 // Add to Edit menu
79- ( menuTemplate [ 1 ] . submenu as MenuItemConstructorOptions [ ] ) . push (
105+ ( menuTemplate . edit ! . submenu as MenuItemConstructorOptions [ ] ) . push (
80106 { type : 'separator' } ,
81107 {
82108 label : 'Speech' ,
@@ -87,31 +113,38 @@ export const getMenu = (browserWindows: Electron.BrowserWindow[]) => {
87113 }
88114 ) ;
89115
90- // Window menu
91- menuTemplate [ 3 ] . submenu = [
92- { role : 'close' } ,
93- { role : 'minimize' } ,
94- { role : 'zoom' } ,
95- { type : 'separator' } ,
96- { role : 'front' }
97- ] ;
116+ // Mac apps usually have a 'window' menu
117+ menuTemplate . window = {
118+ label : '&Window' ,
119+ submenu : [
120+ { role : 'minimize' } ,
121+ { role : 'zoom' } ,
122+ { type : 'separator' } ,
123+ { role : 'front' }
124+ ]
125+ } ;
98126 } else {
99- menuTemplate . unshift ( {
127+ menuTemplate . file = {
100128 label : '&File' ,
101129 submenu : [
130+ {
131+ label : 'New Session' ,
132+ accelerator : 'CommandOrControl+Shift+N' ,
133+ click : openNewWindow
134+ } ,
102135 {
103136 // This should close the Window, but look like Quit. End behaviour is that every
104- // Window _acts_ like a separate process, but is really a separate window.
137+ // Window _acts_ like a separate process, but is really just a separate window.
105138 // (This lets us easily share a single server instance)
106139 role : 'close' ,
107140 label : 'Quit' ,
108141 accelerator : 'CommandOrControl+Q'
109142 }
110143 ]
111- } ) ;
144+ } ;
112145
113146 // On Windows & Linux, it's possible to autohide the menu bar:
114- ( menuTemplate [ 2 ] . submenu as MenuItemConstructorOptions [ ] ) . push ( {
147+ ( menuTemplate . view ! . submenu as MenuItemConstructorOptions [ ] ) . push ( {
115148 type : 'checkbox' ,
116149 label : 'Autohide Menu Bar' ,
117150 sublabel : 'Reveal with Alt' ,
@@ -127,5 +160,12 @@ export const getMenu = (browserWindows: Electron.BrowserWindow[]) => {
127160 } )
128161 }
129162
130- return Menu . buildFromTemplate ( menuTemplate ) ;
163+ return Menu . buildFromTemplate ( [
164+ menuTemplate . mac ,
165+ menuTemplate . file ,
166+ menuTemplate . edit ,
167+ menuTemplate . view ,
168+ menuTemplate . window ,
169+ menuTemplate . help
170+ ] . filter ( Boolean ) as MenuItemConstructorOptions [ ] ) ;
131171}
0 commit comments