SymphonyElectron/js/main.js

84 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-02-14 19:44:15 -06:00
'use strict';
2016-11-07 14:31:39 -06:00
const electron = require('electron');
const app = electron.app;
const nodeURL = require('url');
2017-03-03 18:07:48 -06:00
const squirrelStartup = require('electron-squirrel-startup');
const getConfig = require('./getConfig.js');
const { isMac, isDevEnv } = require('./utils/misc.js');
2016-09-26 21:39:43 -05:00
2017-03-01 18:32:21 -06:00
// exit early for squirrel installer
2017-03-03 18:07:48 -06:00
if (squirrelStartup) {
2017-02-12 18:57:56 -06:00
return;
}
2016-11-07 14:31:39 -06:00
2017-03-01 18:32:21 -06:00
require('./mainApiMgr.js');
2017-02-14 19:44:15 -06:00
2017-03-01 18:32:21 -06:00
// monitor memory of main process
require('./memoryMonitor.js');
2017-02-10 20:20:09 -06:00
2017-03-01 18:32:21 -06:00
const windowMgr = require('./windowMgr.js');
2017-02-10 20:20:09 -06:00
2017-02-13 18:31:42 -06:00
/**
* 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', getUrlAndOpenMainWindow);
function getUrlAndOpenMainWindow() {
// for dev env allow passing url argument
if (isDevEnv) {
let url;
process.argv.forEach((val) => {
if (val.startsWith('--url=')) {
url = val.substr(6);
}
});
if (url) {
windowMgr.createMainWindow(url);
return;
}
}
getConfig()
.then(createWin).catch(function (err){
2017-02-28 16:45:04 -06:00
let title = 'Error loading configuration';
2017-04-03 18:50:35 -05:00
electron.dialog.showErrorBox(title, title + ': ' + err);
});
}
function createWin(config){
let protocol = '';
// add https protocol if none found.
let parsedUrl = nodeURL.parse(config.url);
if (!parsedUrl.protocol) {
protocol = 'https';
}
var url = nodeURL.format({
protocol: protocol,
slahes: true,
pathname: parsedUrl.href
});
windowMgr.createMainWindow(url);
}
2016-11-08 18:32:04 -06:00
2017-03-03 18:07:48 -06:00
app.on('window-all-closed', function() {
2017-02-12 18:57:56 -06:00
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (!isMac) {
2017-02-12 18:57:56 -06:00
app.quit();
}
});
2016-09-26 21:39:43 -05:00
2017-03-03 18:07:48 -06:00
app.on('activate', function() {
2017-03-01 18:32:21 -06:00
if (windowMgr.isMainWindow(null)) {
getUrlAndOpenMainWindow();
2017-02-12 18:57:56 -06:00
} else {
2017-03-01 18:32:21 -06:00
windowMgr.showMainWindow();
2017-02-12 18:57:56 -06:00
}
2016-11-07 14:31:39 -06:00
});