11const { app, Menu } = require ( 'electron' )
2+ const { shortcuts, disableShortcuts } = require ( './shortcuts.js' )
23const path = require ( 'path' )
34const serial = require ( './serial/serial.js' ) . sharedInstance
45const openAboutWindow = require ( 'about-window' ) . default
5- const shortcuts = require ( './shortcuts.js' )
6+
67const { type } = require ( 'os' )
78
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+
841module . exports = function registerMenu ( win , state = { } ) {
942 const isMac = process . platform === 'darwin'
1043 const template = [
1144 ...( isMac ? [ {
1245 label : app . name ,
1346 submenu : [
14- { role : 'about' } ,
15- { type : 'separator' } ,
1647 { type : 'separator' } ,
1748 { role : 'hide' , accelerator : 'CmdOrCtrl+Shift+H' } ,
1849 { role : 'hideOthers' } ,
@@ -24,7 +55,22 @@ module.exports = function registerMenu(win, state = {}) {
2455 {
2556 label : 'File' ,
2657 submenu : [
27- 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' }
2874 ]
2975 } ,
3076 {
@@ -167,41 +213,15 @@ module.exports = function registerMenu(win, state = {}) {
167213 }
168214 } ,
169215 {
170- label :'Info about this app' ,
171- click : ( ) => {
172- openAboutWindow ( {
173- icon_path : path . resolve ( __dirname , '../ui/arduino/media/about_image.png' ) ,
174- css_path : path . resolve ( __dirname , '../ui/arduino/views/about.css' ) ,
175- copyright : '© Arduino SA 2022' ,
176- package_json_dir : path . resolve ( __dirname , '..' ) ,
177- bug_report_url : "https://github.com/arduino/lab-micropython-editor/issues" ,
178- bug_link_text : "report an issue" ,
179- homepage : "https://labs.arduino.cc" ,
180- use_version_info : false ,
181- win_options : {
182- parent : win ,
183- modal : true ,
184- } ,
185- show_close_button : 'Close' ,
186- } )
187- }
216+ label :'About Arduino Lab for MicroPython' ,
217+ click : ( ) => { openAppInfo ( win ) }
188218 } ,
189219 ]
190220 }
191221 ]
192222
193223 const menu = Menu . buildFromTemplate ( template )
194224
195- app . setAboutPanelOptions ( {
196- applicationName : app . name ,
197- applicationVersion : app . getVersion ( ) ,
198- copyright : app . copyright ,
199- credits : '(See "Info about this app" in the Help menu)' ,
200- authors : [ 'Arduino' ] ,
201- website : 'https://arduino.cc' ,
202- iconPath : path . join ( __dirname , '../assets/image.png' ) ,
203- } )
204-
205225 Menu . setApplicationMenu ( menu )
206226
207227}
0 commit comments