create new window if closed when dock icon clicked

This commit is contained in:
Stephen Birarda 2015-12-23 15:54:29 -07:00
parent 25666577f4
commit 12bb2c1b7a

View file

@ -25,14 +25,53 @@ var path = require('path');
var TRAY_ICON = path.join(__dirname, '../resources/console-tray.png'); var TRAY_ICON = path.join(__dirname, '../resources/console-tray.png');
var APP_ICON = path.join(__dirname, '../resources/console.png'); var APP_ICON = path.join(__dirname, '../resources/console.png');
// Quit when all windows are closed. // Don't quit when all windows are closed, make user explicitly quit from tray
app.on('window-all-closed', function() { 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 function createNewWindow() {
if (process.platform != 'darwin') { // Create the browser window.
app.quit(); 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 // Check command line arguments to see how to find binaries
var argv = require('yargs').argv; 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 to use LESS files in place of basic CSS
require('electron-compile').init(); require('electron-compile').init();
// Create the browser window. createNewWindow();
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);
});
var logPath = path.join(app.getAppPath(), 'logs'); var logPath = path.join(app.getAppPath(), 'logs');