diff --git a/build/background.png b/build/background.png index 70476c23..57016803 100644 Binary files a/build/background.png and b/build/background.png differ diff --git a/main.js b/main.js index bc3408bd..c00ae1bb 100644 --- a/main.js +++ b/main.js @@ -3,14 +3,27 @@ const packageJSON = require('./package.json'); const menuTemplate = require('./menuTemplate.js'); const app = electron.app -const BrowserWindow = electron.BrowserWindow +const BrowserWindow = electron.BrowserWindow; + +let willQuitApp = false; if (require('electron-squirrel-startup')) return; +if (isDevEnv()) { + // needed for development env because local server doesn't have cert + app.commandLine.appendSwitch('--ignore-certificate-errors'); +} + // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. let mainWindow; +function isDevEnv() { + var isDev = process.env.ELECTRON_DEV ? + process.env.ELECTRON_DEV.trim().toLowerCase() === "true" : false; + return isDev; +} + function createWindow () { // note: for now, turning off node integration as this is causing failure with // onelogin, jquery can not get initialized. electron's node integration @@ -24,36 +37,53 @@ function createWindow () { } }); - const menu = electron.Menu.buildFromTemplate(menuTemplate(app)); - electron.Menu.setApplicationMenu(menu) - mainWindow.loadURL(packageJSON.homepage); + const menu = electron.Menu.buildFromTemplate(menuTemplate(app)); + electron.Menu.setApplicationMenu(menu); + + mainWindow.on('close', function(e) { + if (willQuitApp) { + mainWindow = null; + return; + } + // mac should hide window when hitting x close + if (process.platform === 'darwin') { + mainWindow.hide(); + e.preventDefault(); + } + }); 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; - }) + }); } // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. -app.on('ready', createWindow) +app.on('ready', function() { + createWindow(); +}); + +app.on('before-quit', function() { + willQuitApp = true; +}); 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() + app.quit(); } }) app.on('activate', function () { - // On OS X it's common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. if (mainWindow === null) { - createWindow() + createWindow(); + } else { + mainWindow.show(); } }); diff --git a/menuTemplate.js b/menuTemplate.js index 81ee87aa..09616ad2 100644 --- a/menuTemplate.js +++ b/menuTemplate.js @@ -38,14 +38,18 @@ const template = [ label: 'Reload', accelerator: 'CmdOrCtrl+R', click (item, focusedWindow) { - if (focusedWindow) focusedWindow.reload() + if (focusedWindow) { + focusedWindow.reload(); + } } }, { label: 'Toggle Developer Tools', accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I', click (item, focusedWindow) { - if (focusedWindow) focusedWindow.webContents.toggleDevTools() + if (focusedWindow) { + focusedWindow.webContents.toggleDevTools(); + } } }, { @@ -84,14 +88,14 @@ const template = [ submenu: [ { label: 'Learn More', - click () { require('electron').shell.openExternal('http://electron.atom.io') } + click () { require('electron').shell.openExternal('https://www.symphony.com') } } ] } ]; function getTemplate(app) { - if (process.platform === 'darwin') { + if (process.platform === 'darwin' && template[0].label !== app.getName()) { template.unshift({ label: app.getName(), submenu: [ @@ -124,7 +128,7 @@ function getTemplate(app) { role: 'quit' } ] - }) + }); // Edit menu. template[1].submenu.push( { diff --git a/package.json b/package.json index 744c183e..8877f449 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,12 @@ "author": "Symphony", "main": "main.js", "scripts": { + "dev:mac": "ELECTRON_DEV=true npm run start", + "dev:win": "SET ELECTRON_DEV=true && npm run start", "start": "electron .", "dist-mac": "build --mac", - "dist-win": "build --win --x64" + "dist-win": "build --win --x64", + "dist-win-x86": "build --win --ia32" }, "build": { "appId": "symphony-electron-desktop",