diff --git a/console/src/main.js b/console/src/main.js index 4b09379576..d2e6d53af2 100644 --- a/console/src/main.js +++ b/console/src/main.js @@ -25,14 +25,53 @@ var path = require('path'); var TRAY_ICON = path.join(__dirname, '../resources/console-tray.png'); var APP_ICON = path.join(__dirname, '../resources/console.png'); -// Quit when all windows are closed. -app.on('window-all-closed', function() { - // On OS X it is common for applications and their menu bar - // to stay active until the user quits explicitly with Cmd + Q - if (process.platform != 'darwin') { - app.quit(); +// Don't quit when all windows are closed, make user explicitly quit from tray +app.on('window-all-closed', function() {}); + +function createNewWindow() { + // Create the browser window. + mainWindow = new BrowserWindow({ + title: "High Fidelity", + width: 970, + height: 775, + icon: APP_ICON, + resizable: false + }); + + // In debug mode, keep the menu bar, but auto-hide it so the UI still looks the same. + if (debug) { + mainWindow.setAutoHideMenuBar(true); + } else { + mainWindow.setMenu(null); } -}); + + // and load the index.html of the app. + mainWindow.loadURL('file://' + __dirname + '/index.html'); + + // Open the DevTools. + mainWindow.webContents.openDevTools(); + + // Emitted when the window is closed. + mainWindow.on('closed', function() { + // Dereference the window object, usually you would store windows + // in an array if your app supports multi windows, this is the time + // when you should delete the corresponding element. + mainWindow = null; + }); + + // When a link is clicked that has `_target="_blank"`, open it in the user's native browser + mainWindow.webContents.on('new-window', function(e, url) { + e.preventDefault(); + shell.openExternal(url); + }); +} + +// When a user clicks on dock icon, re-create the window if we don't have one +app.on('activate', function(){ + if (!mainWindow) { + createNewWindow(); + } +}) // Check command line arguments to see how to find binaries var argv = require('yargs').argv; @@ -81,41 +120,7 @@ app.on('ready', function() { // Require electron-compile to use LESS files in place of basic CSS require('electron-compile').init(); - // Create the browser window. - mainWindow = new BrowserWindow({ - title: "High Fidelity", - width: 970, - height: 775, - icon: APP_ICON, - resizable: false - }); - - // In debug mode, keep the menu bar, but auto-hide it so the UI still looks the same. - if (debug) { - mainWindow.setAutoHideMenuBar(true); - } else { - mainWindow.setMenu(null); - } - - // and load the index.html of the app. - mainWindow.loadURL('file://' + __dirname + '/index.html'); - - // Open the DevTools. - mainWindow.webContents.openDevTools(); - - // Emitted when the window is closed. - mainWindow.on('closed', function() { - // Dereference the window object, usually you would store windows - // in an array if your app supports multi windows, this is the time - // when you should delete the corresponding element. - mainWindow = null; - }); - - // When a link is clicked that has `_target="_blank"`, open it in the user's native browser - mainWindow.webContents.on('new-window', function(e, url) { - e.preventDefault(); - shell.openExternal(url); - }); + createNewWindow(); var logPath = path.join(app.getAppPath(), 'logs');