code cleanup - no functional change (#95)

This commit is contained in:
Lynn 2017-05-23 20:22:07 -07:00 committed by GitHub
parent 799da09911
commit 939b59df8e

View File

@ -6,7 +6,7 @@ const nodeURL = require('url');
const squirrelStartup = require('electron-squirrel-startup'); const squirrelStartup = require('electron-squirrel-startup');
const AutoLaunch = require('auto-launch'); const AutoLaunch = require('auto-launch');
const urlParser = require('url'); const urlParser = require('url');
const {getConfigField} = require('./config.js'); const { getConfigField } = require('./config.js');
const { isDevEnv} = require('./utils/misc.js'); const { isDevEnv} = require('./utils/misc.js');
const protocolHandler = require('./protocolHandler'); const protocolHandler = require('./protocolHandler');
@ -54,17 +54,42 @@ var symphonyAutoLauncher = new AutoLaunch({
* 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', getUrlAndOpenMainWindow); app.on('ready', setupThenOpenMainWindow);
function getUrlAndOpenMainWindow() { app.on('window-all-closed', function () {
app.quit();
});
app.on('activate', function () {
if (windowMgr.isMainWindow(null)) {
setupThenOpenMainWindow();
} else {
windowMgr.showMainWindow();
}
});
// adds 'symphony' as a protocol
// in the system. plist file in macOS
// and registry keys in windows
app.setAsDefaultProtocolClient('symphony');
// This event is emitted only on macOS
// at this moment, support for windows
// is in pipeline (https://github.com/electron/electron/pull/8052)
app.on('open-url', function (event, url) {
handleProtocolAction(url);
});
function setupThenOpenMainWindow() {
processProtocolAction(process.argv); processProtocolAction(process.argv);
isAppAlreadyOpen = true; isAppAlreadyOpen = true;
// for dev env allow passing url argument
let installMode = false; let installMode = false;
// allows installer to launch app and set auto startup mode then
// immediately quit.
process.argv.some((val) => { process.argv.some((val) => {
let flag = '--install'; let flag = '--install';
@ -80,7 +105,7 @@ function getUrlAndOpenMainWindow() {
}); });
if (installMode === false) { if (installMode === false) {
openMainWindow(); getUrlAndCreateMainWindow();
} }
} }
@ -99,7 +124,8 @@ function setStartup(lStartup){
}); });
} }
function openMainWindow() { function getUrlAndCreateMainWindow() {
// for dev env allow passing url argument
if (isDevEnv) { if (isDevEnv) {
let url; let url;
process.argv.forEach((val) => { process.argv.forEach((val) => {
@ -181,27 +207,3 @@ function handleProtocolAction(uri) {
protocolHandler.processProtocolAction(uri); protocolHandler.processProtocolAction(uri);
} }
} }
app.on('window-all-closed', function () {
app.quit();
});
app.on('activate', function () {
if (windowMgr.isMainWindow(null)) {
getUrlAndOpenMainWindow();
} else {
windowMgr.showMainWindow();
}
});
// adds 'symphony' as a protocol
// in the system. plist file in macOS
// and registry keys in windows
app.setAsDefaultProtocolClient('symphony');
// This event is emitted only on macOS
// at this moment, support for windows
// is in pipeline (https://github.com/electron/electron/pull/8052)
app.on('open-url', function (event, url) {
handleProtocolAction(url);
});