1
1
const { app, Menu } = require ( 'electron' )
2
+ const { shortcuts, disableShortcuts } = require ( './shortcuts.js' )
2
3
const path = require ( 'path' )
3
4
const serial = require ( './serial/serial.js' ) . sharedInstance
4
5
const openAboutWindow = require ( 'about-window' ) . default
5
- const shortcuts = require ( './shortcuts.js' )
6
+
6
7
const { type } = require ( 'os' )
7
8
9
+ let appInfoWindow = null
10
+
11
+ function closeAppInfo ( win ) {
12
+ disableShortcuts ( win , false )
13
+ appInfoWindow . off ( 'close' , ( ) => closeAppInfo ( win ) )
14
+ appInfoWindow = null
15
+
16
+ }
17
+ function openAppInfo ( win ) {
18
+ if ( appInfoWindow != null ) {
19
+ appInfoWindow . show ( )
20
+ } else {
21
+ appInfoWindow = openAboutWindow ( {
22
+ icon_path : path . resolve ( __dirname , '../ui/arduino/media/about_image.png' ) ,
23
+ css_path : path . resolve ( __dirname , '../ui/arduino/views/about.css' ) ,
24
+ copyright : '© Arduino SA 2022' ,
25
+ package_json_dir : path . resolve ( __dirname , '..' ) ,
26
+ bug_report_url : "https://github.com/arduino/lab-micropython-editor/issues" ,
27
+ bug_link_text : "report an issue" ,
28
+ homepage : "https://labs.arduino.cc" ,
29
+ use_version_info : false ,
30
+ win_options : {
31
+ parent : win ,
32
+ modal : true ,
33
+ } ,
34
+ show_close_button : 'Close' ,
35
+ } )
36
+ appInfoWindow . on ( 'close' , ( ) => closeAppInfo ( win ) ) ;
37
+ disableShortcuts ( win , true )
38
+ }
39
+ }
40
+
8
41
module . exports = function registerMenu ( win , state = { } ) {
9
42
const isMac = process . platform === 'darwin'
10
43
const template = [
@@ -22,7 +55,22 @@ module.exports = function registerMenu(win, state = {}) {
22
55
{
23
56
label : 'File' ,
24
57
submenu : [
25
- isMac ? { role : 'close' } : { role : 'quit' }
58
+ { label : 'New' ,
59
+ accelerator : shortcuts . menu . NEW ,
60
+ enabled : state . view === 'editor' ,
61
+ click : ( ) => win . webContents . send ( 'shortcut-cmd' , shortcuts . global . NEW )
62
+ } ,
63
+ { label : 'Save' ,
64
+ accelerator : shortcuts . menu . SAVE ,
65
+ enabled : state . view === 'editor' ,
66
+ click : ( ) => win . webContents . send ( 'shortcut-cmd' , shortcuts . global . SAVE )
67
+ } ,
68
+ { label : 'Close tab' ,
69
+ accelerator : 'CmdOrCtrl+W' ,
70
+ enabled : state . view === 'editor' ,
71
+ click : ( ) => win . webContents . send ( 'shortcut-cmd' , shortcuts . global . CLOSE )
72
+ } ,
73
+ { role : 'quit' }
26
74
]
27
75
} ,
28
76
{
@@ -166,40 +214,14 @@ module.exports = function registerMenu(win, state = {}) {
166
214
} ,
167
215
{
168
216
label :'About Arduino Lab for MicroPython' ,
169
- click : ( ) => {
170
- openAboutWindow ( {
171
- icon_path : path . resolve ( __dirname , '../ui/arduino/media/about_image.png' ) ,
172
- css_path : path . resolve ( __dirname , '../ui/arduino/views/about.css' ) ,
173
- copyright : '© Arduino SA 2022' ,
174
- package_json_dir : path . resolve ( __dirname , '..' ) ,
175
- bug_report_url : "https://github.com/arduino/lab-micropython-editor/issues" ,
176
- bug_link_text : "report an issue" ,
177
- homepage : "https://labs.arduino.cc" ,
178
- use_version_info : false ,
179
- win_options : {
180
- parent : win ,
181
- modal : true ,
182
- } ,
183
- show_close_button : 'Close' ,
184
- } )
185
- }
217
+ click : ( ) => { openAppInfo ( win ) }
186
218
} ,
187
219
]
188
220
}
189
221
]
190
222
191
223
const menu = Menu . buildFromTemplate ( template )
192
224
193
- app . setAboutPanelOptions ( {
194
- applicationName : app . name ,
195
- applicationVersion : app . getVersion ( ) ,
196
- copyright : app . copyright ,
197
- credits : '(See "Info about this app" in the Help menu)' ,
198
- authors : [ 'Arduino' ] ,
199
- website : 'https://arduino.cc' ,
200
- iconPath : path . join ( __dirname , '../assets/image.png' ) ,
201
- } )
202
-
203
225
Menu . setApplicationMenu ( menu )
204
226
205
227
}
0 commit comments