@@ -2,13 +2,14 @@ import {
22 app ,
33 BrowserWindow ,
44 Event ,
5+ Menu ,
56 MenuItem ,
67 MenuItemConstructorOptions ,
78 shell ,
89} from 'electron'
9- import { checkForUpdates } from './updater'
10+ import { checkForUpdates , restartToUpdate , UPDATER_STATUS_MAP } from './updater'
1011
11- export const template : MenuItemConstructorOptions [ ] = [
12+ const template : MenuItemConstructorOptions [ ] = [
1213 {
1314 label : 'Edit' ,
1415 submenu : [
@@ -66,6 +67,17 @@ export const template: MenuItemConstructorOptions[] = [
6667 } ,
6768]
6869
70+ function addAboutMenuItem (
71+ items : MenuItemConstructorOptions [ ] ,
72+ position : number
73+ ) {
74+ const aboutItem : MenuItemConstructorOptions = {
75+ label : `About ${ app . getName ( ) } ` ,
76+ role : 'about' ,
77+ }
78+ items . splice . apply ( items , [ position , 0 , aboutItem ] )
79+ }
80+
6981function addUpdateMenuItems (
7082 items : MenuItemConstructorOptions [ ] ,
7183 position : number
@@ -78,7 +90,34 @@ function addUpdateMenuItems(
7890 {
7991 click : checkForUpdates ,
8092 enabled : true ,
93+ id : UPDATER_STATUS_MAP . NORMAL ,
8194 label : 'Check for Updates' ,
95+ visible : true ,
96+ } ,
97+ {
98+ enabled : false ,
99+ id : UPDATER_STATUS_MAP . CHECKING ,
100+ label : 'Checking updates...' ,
101+ visible : false ,
102+ } ,
103+ {
104+ enabled : false ,
105+ id : UPDATER_STATUS_MAP . DOWNLOADING ,
106+ label : 'Downloading updates...' ,
107+ visible : false ,
108+ } ,
109+ {
110+ enabled : false ,
111+ id : UPDATER_STATUS_MAP . ERROR ,
112+ label : 'Update Failed' ,
113+ visible : false ,
114+ } ,
115+ {
116+ click : restartToUpdate ,
117+ enabled : true ,
118+ id : UPDATER_STATUS_MAP . READY ,
119+ label : 'Restart to update' ,
120+ visible : false ,
82121 } ,
83122 ]
84123
@@ -110,14 +149,10 @@ function addPreferencesMenu(
110149}
111150
112151if ( process . platform === 'darwin' ) {
113- const name = app . getName ( )
152+ const appName = app . getName ( )
114153 template . unshift ( {
115- label : name ,
154+ label : appName ,
116155 submenu : [
117- {
118- label : `About ${ name } ` ,
119- role : 'about' ,
120- } ,
121156 {
122157 type : 'separator' ,
123158 } ,
@@ -131,7 +166,7 @@ if (process.platform === 'darwin') {
131166 } ,
132167 {
133168 accelerator : 'Command+H' ,
134- label : `Hide ${ name } ` ,
169+ label : `Hide ${ appName } ` ,
135170 role : 'hide' ,
136171 } ,
137172 {
@@ -155,15 +190,21 @@ if (process.platform === 'darwin') {
155190 } ,
156191 ] ,
157192 } )
158-
193+ addAboutMenuItem ( template [ 0 ] . submenu as MenuItemConstructorOptions [ ] , 0 )
159194 addPreferencesMenu ( template [ 0 ] . submenu as MenuItemConstructorOptions [ ] , 1 )
160195 addUpdateMenuItems ( template [ 0 ] . submenu as MenuItemConstructorOptions [ ] , 1 )
161- // addPreferencesMenu(template, template.length - 1)
162196}
163197
164198if ( process . platform === 'win32' || process . platform === 'linux' ) {
165199 const helpMenu = template [ template . length - 1 ] . submenu
166200
167- addUpdateMenuItems ( helpMenu as MenuItemConstructorOptions [ ] , 0 )
168201 addPreferencesMenu ( template , template . length - 1 )
202+ addUpdateMenuItems ( helpMenu as MenuItemConstructorOptions [ ] , 0 )
203+ // showAboutPanel not working in windows
204+ // addAboutMenuItem(helpMenu as MenuItemConstructorOptions[], 0)
205+ }
206+
207+ export function initMenu ( ) {
208+ const menu = Menu . buildFromTemplate ( template )
209+ Menu . setApplicationMenu ( menu )
169210}
0 commit comments