SymphonyElectron/js/main.js

65 lines
1.7 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');
2017-03-01 18:32:21 -06:00
const { isMac } = require('./utils.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() {
getConfig().then(function(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
});
2017-03-01 18:32:21 -06:00
windowMgr.createMainWindow(url);
}).catch(function(err) {
2017-02-28 16:45:04 -06:00
let title = 'Error loading configuration';
electron.dialog.showErrorBox(title, title + ': ' + err);
});
}
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
});