fix menu bug and few other bug fixes

This commit is contained in:
Lynn Neir 2016-11-08 16:32:04 -08:00
parent 932162d5df
commit cfd0811e7b
4 changed files with 53 additions and 16 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

50
main.js
View File

@ -3,14 +3,27 @@ const packageJSON = require('./package.json');
const menuTemplate = require('./menuTemplate.js'); const menuTemplate = require('./menuTemplate.js');
const app = electron.app const app = electron.app
const BrowserWindow = electron.BrowserWindow const BrowserWindow = electron.BrowserWindow;
let willQuitApp = false;
if (require('electron-squirrel-startup')) return; 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 // 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. // be closed automatically when the JavaScript object is garbage collected.
let mainWindow; let mainWindow;
function isDevEnv() {
var isDev = process.env.ELECTRON_DEV ?
process.env.ELECTRON_DEV.trim().toLowerCase() === "true" : false;
return isDev;
}
function createWindow () { function createWindow () {
// note: for now, turning off node integration as this is causing failure with // note: for now, turning off node integration as this is causing failure with
// onelogin, jquery can not get initialized. electron's node integration // 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); 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 () { mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows // Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time // in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element. // when you should delete the corresponding element.
mainWindow = null; mainWindow = null;
}) });
} }
// This method will be called when Electron has finished // This method will be called when Electron has finished
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs. // 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 () { app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar // On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q // to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') { if (process.platform !== 'darwin') {
app.quit() app.quit();
} }
}) })
app.on('activate', function () { 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) { if (mainWindow === null) {
createWindow() createWindow();
} else {
mainWindow.show();
} }
}); });

View File

@ -38,14 +38,18 @@ const template = [
label: 'Reload', label: 'Reload',
accelerator: 'CmdOrCtrl+R', accelerator: 'CmdOrCtrl+R',
click (item, focusedWindow) { click (item, focusedWindow) {
if (focusedWindow) focusedWindow.reload() if (focusedWindow) {
focusedWindow.reload();
}
} }
}, },
{ {
label: 'Toggle Developer Tools', label: 'Toggle Developer Tools',
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I', accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
click (item, focusedWindow) { click (item, focusedWindow) {
if (focusedWindow) focusedWindow.webContents.toggleDevTools() if (focusedWindow) {
focusedWindow.webContents.toggleDevTools();
}
} }
}, },
{ {
@ -84,14 +88,14 @@ const template = [
submenu: [ submenu: [
{ {
label: 'Learn More', label: 'Learn More',
click () { require('electron').shell.openExternal('http://electron.atom.io') } click () { require('electron').shell.openExternal('https://www.symphony.com') }
} }
] ]
} }
]; ];
function getTemplate(app) { function getTemplate(app) {
if (process.platform === 'darwin') { if (process.platform === 'darwin' && template[0].label !== app.getName()) {
template.unshift({ template.unshift({
label: app.getName(), label: app.getName(),
submenu: [ submenu: [
@ -124,7 +128,7 @@ function getTemplate(app) {
role: 'quit' role: 'quit'
} }
] ]
}) });
// Edit menu. // Edit menu.
template[1].submenu.push( template[1].submenu.push(
{ {

View File

@ -6,9 +6,12 @@
"author": "Symphony", "author": "Symphony",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"dev:mac": "ELECTRON_DEV=true npm run start",
"dev:win": "SET ELECTRON_DEV=true && npm run start",
"start": "electron .", "start": "electron .",
"dist-mac": "build --mac", "dist-mac": "build --mac",
"dist-win": "build --win --x64" "dist-win": "build --win --x64",
"dist-win-x86": "build --win --ia32"
}, },
"build": { "build": {
"appId": "symphony-electron-desktop", "appId": "symphony-electron-desktop",