1
- const electron = require ( 'electron' )
2
- const BrowserWindow = electron . BrowserWindow
3
- const Menu = electron . Menu
4
- const app = electron . app
1
+ const { BrowserWindow, Menu, app, shell, dialog} = require ( 'electron' )
5
2
6
3
let template = [ {
7
4
label : 'Edit' ,
@@ -37,44 +34,42 @@ let template = [{
37
34
submenu : [ {
38
35
label : 'Reload' ,
39
36
accelerator : 'CmdOrCtrl+R' ,
40
- click : function ( item , focusedWindow ) {
37
+ click : ( item , focusedWindow ) => {
41
38
if ( focusedWindow ) {
42
39
// on reload, start fresh and close any old
43
40
// open secondary windows
44
41
if ( focusedWindow . id === 1 ) {
45
- BrowserWindow . getAllWindows ( ) . forEach ( function ( win ) {
46
- if ( win . id > 1 ) {
47
- win . close ( )
48
- }
42
+ BrowserWindow . getAllWindows ( ) . forEach ( win => {
43
+ if ( win . id > 1 ) win . close ( )
49
44
} )
50
45
}
51
46
focusedWindow . reload ( )
52
47
}
53
48
}
54
49
} , {
55
50
label : 'Toggle Full Screen' ,
56
- accelerator : ( function ( ) {
51
+ accelerator : ( ( ) => {
57
52
if ( process . platform === 'darwin' ) {
58
53
return 'Ctrl+Command+F'
59
54
} else {
60
55
return 'F11'
61
56
}
62
57
} ) ( ) ,
63
- click : function ( item , focusedWindow ) {
58
+ click : ( item , focusedWindow ) => {
64
59
if ( focusedWindow ) {
65
60
focusedWindow . setFullScreen ( ! focusedWindow . isFullScreen ( ) )
66
61
}
67
62
}
68
63
} , {
69
64
label : 'Toggle Developer Tools' ,
70
- accelerator : ( function ( ) {
65
+ accelerator : ( ( ) => {
71
66
if ( process . platform === 'darwin' ) {
72
67
return 'Alt+Command+I'
73
68
} else {
74
69
return 'Ctrl+Shift+I'
75
70
}
76
71
} ) ( ) ,
77
- click : function ( item , focusedWindow ) {
72
+ click : ( item , focusedWindow ) => {
78
73
if ( focusedWindow ) {
79
74
focusedWindow . toggleDevTools ( )
80
75
}
@@ -91,7 +86,7 @@ let template = [{
91
86
buttons : [ 'Ok' ] ,
92
87
message : 'This demo is for the Menu section, showing how to create a clickable menu item in the application menu.'
93
88
}
94
- electron . dialog . showMessageBox ( focusedWindow , options , function ( ) { } )
89
+ dialog . showMessageBox ( focusedWindow , options , function ( ) { } )
95
90
}
96
91
}
97
92
} ]
@@ -113,7 +108,7 @@ let template = [{
113
108
accelerator : 'CmdOrCtrl+Shift+T' ,
114
109
enabled : false ,
115
110
key : 'reopenMenuItem' ,
116
- click : function ( ) {
111
+ click : ( ) => {
117
112
app . emit ( 'activate' )
118
113
}
119
114
} ]
@@ -122,16 +117,16 @@ let template = [{
122
117
role : 'help' ,
123
118
submenu : [ {
124
119
label : 'Learn More' ,
125
- click : function ( ) {
126
- electron . shell . openExternal ( 'http://electron.atom.io' )
120
+ click : ( ) => {
121
+ shell . openExternal ( 'http://electron.atom.io' )
127
122
}
128
123
} ]
129
124
} ]
130
125
131
126
function addUpdateMenuItems ( items , position ) {
132
127
if ( process . mas ) return
133
128
134
- const version = electron . app . getVersion ( )
129
+ const version = app . getVersion ( )
135
130
let updateItems = [ {
136
131
label : `Version ${ version } ` ,
137
132
enabled : false
@@ -143,15 +138,15 @@ function addUpdateMenuItems (items, position) {
143
138
label : 'Check for Update' ,
144
139
visible : false ,
145
140
key : 'checkForUpdate' ,
146
- click : function ( ) {
141
+ click : ( ) => {
147
142
require ( 'electron' ) . autoUpdater . checkForUpdates ( )
148
143
}
149
144
} , {
150
145
label : 'Restart and Install Update' ,
151
146
enabled : true ,
152
147
visible : false ,
153
148
key : 'restartToUpdate' ,
154
- click : function ( ) {
149
+ click : ( ) => {
155
150
require ( 'electron' ) . autoUpdater . quitAndInstall ( )
156
151
}
157
152
} ]
@@ -164,9 +159,9 @@ function findReopenMenuItem () {
164
159
if ( ! menu ) return
165
160
166
161
let reopenMenuItem
167
- menu . items . forEach ( function ( item ) {
162
+ menu . items . forEach ( item => {
168
163
if ( item . submenu ) {
169
- item . submenu . items . forEach ( function ( item ) {
164
+ item . submenu . items . forEach ( item => {
170
165
if ( item . key === 'reopenMenuItem' ) {
171
166
reopenMenuItem = item
172
167
}
@@ -177,7 +172,7 @@ function findReopenMenuItem () {
177
172
}
178
173
179
174
if ( process . platform === 'darwin' ) {
180
- const name = electron . app . getName ( )
175
+ const name = app . getName ( )
181
176
template . unshift ( {
182
177
label : name ,
183
178
submenu : [ {
@@ -207,7 +202,7 @@ if (process.platform === 'darwin') {
207
202
} , {
208
203
label : 'Quit' ,
209
204
accelerator : 'Command+Q' ,
210
- click : function ( ) {
205
+ click : ( ) => {
211
206
app . quit ( )
212
207
}
213
208
} ]
@@ -229,17 +224,17 @@ if (process.platform === 'win32') {
229
224
addUpdateMenuItems ( helpMenu , 0 )
230
225
}
231
226
232
- app . on ( 'ready' , function ( ) {
227
+ app . on ( 'ready' , ( ) => {
233
228
const menu = Menu . buildFromTemplate ( template )
234
229
Menu . setApplicationMenu ( menu )
235
230
} )
236
231
237
- app . on ( 'browser-window-created' , function ( ) {
232
+ app . on ( 'browser-window-created' , ( ) => {
238
233
let reopenMenuItem = findReopenMenuItem ( )
239
234
if ( reopenMenuItem ) reopenMenuItem . enabled = false
240
235
} )
241
236
242
- app . on ( 'window-all-closed' , function ( ) {
237
+ app . on ( 'window-all-closed' , ( ) => {
243
238
let reopenMenuItem = findReopenMenuItem ( )
244
239
if ( reopenMenuItem ) reopenMenuItem . enabled = true
245
240
} )
0 commit comments