@@ -4,7 +4,7 @@ const {exec} = require('child_process');
44const fs = require ( 'fs' ) ;
55const extend = require ( 'extend' ) ;
66const { argv} = require ( 'yargs' ) ;
7- const { app, Menu, Tray} = require ( 'electron' ) ; // eslint-disable-line import/no-extraneous-dependencies
7+ const { app, dialog , Menu, Tray} = require ( 'electron' ) ; // eslint-disable-line import/no-extraneous-dependencies
88
99// Our modules
1010const jupyter = require ( './jupyter' ) ;
@@ -69,19 +69,37 @@ app.on('ready', () => {
6969 app . dock . hide ( ) ;
7070 }
7171
72- // settings from global config
73- const { jupyterCommand, jupyterPort, openBrowserOnStartup} = globalConfig ;
74-
7572 // Setup macOS tray menu
7673 tray = new Tray ( `${ __dirname } /assets/tray@2x.png` ) ;
7774 const contextMenu = Menu . buildFromTemplate ( [
78- { label : 'Running on localhost:' + jupyterPort , enabled : false } ,
75+ { label : 'Running on localhost:' + globalConfig . jupyterPort , enabled : false } ,
7976 { label : 'Open Jupyter Notebook' , accelerator : 'Command+O' , click : ( ) => {
8077 openBrowser ( [ ] ) ;
8178 } } ,
79+ {
80+ type : 'separator'
81+ } ,
82+ { label : 'New Notebook' , accelerator : 'Command+N' , click : ( ) => {
83+ dialog . showSaveDialog ( {
84+ title : 'New Notebook' ,
85+ defaultPath : resolve ( homedir ( ) , 'Untitled.ipynb' )
86+ } , filepath => {
87+ const defaultNotebook = {
88+ cells : [ ] ,
89+ metadata : { } ,
90+ nbformat : 4 ,
91+ nbformat_minor : 0 // eslint-disable-line camelcase
92+ } ;
93+ fs . writeFileSync ( filepath , JSON . stringify ( defaultNotebook , null , ' ' ) ) ;
94+ openBrowser ( [ filepath ] ) ;
95+ } ) ;
96+ } } ,
8297 { label : 'Preferences...' , accelerator : 'Command+,' , click : ( ) => {
8398 exec ( `open ${ userConfigPath } ` ) ;
8499 } } ,
100+ {
101+ type : 'separator'
102+ } ,
85103 { label : 'Quit Juno' , role : 'quit' , accelerator : 'Command+Q' }
86104 ] ) ;
87105 tray . setToolTip ( 'Juno is enabled' ) ;
@@ -92,8 +110,8 @@ app.on('ready', () => {
92110 notebooksToOpen = [ ] ;
93111
94112 // Launch or pick up jupyter daemon and get PID
95- jupyterPID = jupyter . getJupyterProcess ( jupyterCommand , jupyterPort ) ;
96- if ( notebooks . length > 0 || openBrowserOnStartup ) {
113+ jupyterPID = jupyter . getJupyterProcess ( globalConfig . jupyterCommand , globalConfig . jupyterPort ) ;
114+ if ( notebooks . length > 0 || globalConfig . openBrowserOnStartup ) {
97115 openBrowser ( notebooks ) ;
98116 }
99117} ) ;
0 commit comments