2017-02-14 17:44:15 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
2017-08-23 22:08:33 +05:30
|
|
|
// Third Party Dependencies
|
2016-11-07 12:31:39 -08:00
|
|
|
const electron = require('electron');
|
2017-02-20 10:24:46 -08:00
|
|
|
const app = electron.app;
|
2017-09-18 21:17:45 +05:30
|
|
|
const crashReporter = electron.crashReporter;
|
2017-02-20 10:24:46 -08:00
|
|
|
const nodeURL = require('url');
|
2017-12-28 17:29:27 +05:30
|
|
|
const shellPath = require('shell-path');
|
2017-03-03 16:07:48 -08:00
|
|
|
const squirrelStartup = require('electron-squirrel-startup');
|
2017-05-09 18:44:14 -03:00
|
|
|
const AutoLaunch = require('auto-launch');
|
2017-05-13 23:53:44 +05:30
|
|
|
const urlParser = require('url');
|
2018-04-19 17:56:42 +00:00
|
|
|
const nodePath = require('path');
|
|
|
|
|
const compareSemVersions = require('./utils/compareSemVersions.js');
|
2017-09-01 12:53:10 +05:30
|
|
|
|
2017-08-23 22:08:33 +05:30
|
|
|
// Local Dependencies
|
2018-04-19 17:56:42 +00:00
|
|
|
const {
|
|
|
|
|
getConfigField,
|
|
|
|
|
getGlobalConfigField,
|
|
|
|
|
readConfigFileSync,
|
|
|
|
|
updateUserConfigOnLaunch,
|
|
|
|
|
getUserConfigField
|
|
|
|
|
} = require('./config.js');
|
2017-10-17 11:39:19 +05:30
|
|
|
const {setCheckboxValues} = require('./menus/menuTemplate.js');
|
2018-01-27 16:26:49 +05:30
|
|
|
const { isMac, isDevEnv } = require('./utils/misc.js');
|
2017-05-13 23:53:44 +05:30
|
|
|
const protocolHandler = require('./protocolHandler');
|
2017-07-13 01:27:21 +05:30
|
|
|
const getCmdLineArg = require('./utils/getCmdLineArg.js');
|
2017-10-05 22:18:52 +05:30
|
|
|
const log = require('./log.js');
|
|
|
|
|
const logLevels = require('./enums/logLevels.js');
|
2017-12-28 17:29:27 +05:30
|
|
|
const { deleteIndexFolder } = require('./search/search.js');
|
2017-08-14 10:47:01 +05:30
|
|
|
|
2017-06-27 20:38:58 +05:30
|
|
|
require('electron-dl')();
|
|
|
|
|
|
2017-12-28 17:29:27 +05:30
|
|
|
//setting the env path child_process issue https://github.com/electron/electron/issues/7688
|
|
|
|
|
shellPath()
|
|
|
|
|
.then((path) => {
|
|
|
|
|
process.env.PATH = path
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
process.env.PATH = [
|
|
|
|
|
'./node_modules/.bin',
|
|
|
|
|
'/usr/local/bin',
|
|
|
|
|
process.env.PATH
|
|
|
|
|
].join(':');
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-13 23:53:44 +05:30
|
|
|
// used to check if a url was opened when the app was already open
|
|
|
|
|
let isAppAlreadyOpen = false;
|
2016-09-26 19:39:43 -07:00
|
|
|
|
2017-03-01 16:32:21 -08:00
|
|
|
// exit early for squirrel installer
|
2017-03-03 16:07:48 -08:00
|
|
|
if (squirrelStartup) {
|
2017-02-12 16:57:56 -08:00
|
|
|
return;
|
|
|
|
|
}
|
2016-11-07 12:31:39 -08:00
|
|
|
|
2017-03-01 16:32:21 -08:00
|
|
|
require('./mainApiMgr.js');
|
2017-02-14 17:44:15 -08:00
|
|
|
|
2017-03-01 16:32:21 -08:00
|
|
|
// monitor memory of main process
|
|
|
|
|
require('./memoryMonitor.js');
|
2017-02-10 18:20:09 -08:00
|
|
|
|
2017-03-01 16:32:21 -08:00
|
|
|
const windowMgr = require('./windowMgr.js');
|
2017-02-10 18:20:09 -08:00
|
|
|
|
2017-10-05 22:18:52 +05:30
|
|
|
getConfigField('url')
|
2018-07-02 17:14:30 +05:30
|
|
|
.then(initializeCrashReporter)
|
|
|
|
|
.catch(app.quit);
|
2017-10-05 22:18:52 +05:30
|
|
|
|
|
|
|
|
function initializeCrashReporter(podUrl) {
|
2017-12-28 17:29:27 +05:30
|
|
|
|
2017-10-05 22:18:52 +05:30
|
|
|
getConfigField('crashReporter')
|
2018-07-02 17:14:30 +05:30
|
|
|
.then((crashReporterConfig) => {
|
|
|
|
|
crashReporter.start({companyName: crashReporterConfig.companyName, submitURL: crashReporterConfig.submitURL, uploadToServer: crashReporterConfig.uploadToServer, extra: {'process': 'main', podUrl: podUrl}});
|
|
|
|
|
log.send(logLevels.INFO, 'initialized crash reporter on the main process!');
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
log.send(logLevels.ERROR, 'Unable to initialize crash reporter in the main process. Error is -> ' + err);
|
|
|
|
|
});
|
2017-10-05 22:18:52 +05:30
|
|
|
|
|
|
|
|
}
|
2017-09-18 21:17:45 +05:30
|
|
|
|
2017-04-28 09:00:16 -07:00
|
|
|
// only allow a single instance of app.
|
2017-05-13 23:53:44 +05:30
|
|
|
const shouldQuit = app.makeSingleInstance((argv) => {
|
2017-04-28 09:00:16 -07:00
|
|
|
// Someone tried to run a second instance, we should focus our window.
|
|
|
|
|
let mainWin = windowMgr.getMainWindow();
|
|
|
|
|
if (mainWin) {
|
2017-05-13 23:53:44 +05:30
|
|
|
isAppAlreadyOpen = true;
|
2017-04-28 09:00:16 -07:00
|
|
|
if (mainWin.isMinimized()) {
|
|
|
|
|
mainWin.restore();
|
|
|
|
|
}
|
|
|
|
|
mainWin.focus();
|
|
|
|
|
}
|
2017-05-13 23:53:44 +05:30
|
|
|
processProtocolAction(argv);
|
2017-04-28 09:00:16 -07:00
|
|
|
});
|
|
|
|
|
|
2017-11-03 11:10:51 +01:00
|
|
|
let allowMultiInstance = getCmdLineArg(process.argv, '--multiInstance', true) || isDevEnv;
|
2017-10-31 12:50:57 +01:00
|
|
|
|
|
|
|
|
// quit if another instance is already running, ignore for dev env or if app was started with multiInstance flag
|
|
|
|
|
if (!allowMultiInstance && shouldQuit) {
|
2017-04-28 09:00:16 -07:00
|
|
|
app.quit();
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 18:28:17 +05:30
|
|
|
let symphonyAutoLauncher;
|
|
|
|
|
|
|
|
|
|
if (isMac) {
|
|
|
|
|
symphonyAutoLauncher = new AutoLaunch({
|
|
|
|
|
name: 'Symphony',
|
|
|
|
|
mac: {
|
|
|
|
|
useLaunchAgent: true,
|
|
|
|
|
},
|
|
|
|
|
path: process.execPath,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
symphonyAutoLauncher = new AutoLaunch({
|
|
|
|
|
name: 'Symphony',
|
|
|
|
|
path: process.execPath,
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-05-09 18:44:14 -03:00
|
|
|
|
2017-11-10 11:00:43 +05:30
|
|
|
/**
|
|
|
|
|
* Sets chrome authentication flags in electron
|
|
|
|
|
*/
|
2017-10-26 16:53:15 +05:30
|
|
|
function setChromeFlags() {
|
2018-01-25 22:59:25 +05:30
|
|
|
|
2018-06-12 21:44:11 +05:30
|
|
|
log.send(logLevels.INFO, 'setting chrome flags!');
|
2018-01-25 22:59:25 +05:30
|
|
|
|
2017-11-10 11:00:43 +05:30
|
|
|
// Read the config parameters synchronously
|
2017-10-26 16:53:15 +05:30
|
|
|
let config = readConfigFileSync();
|
2018-01-25 22:59:25 +05:30
|
|
|
|
2017-11-10 11:00:43 +05:30
|
|
|
// If we cannot find any config, just skip setting any flags
|
2017-10-26 16:53:15 +05:30
|
|
|
if (config && config !== null && config.customFlags) {
|
2018-01-25 22:59:25 +05:30
|
|
|
|
2017-10-26 16:53:15 +05:30
|
|
|
if (config.customFlags.authServerWhitelist && config.customFlags.authServerWhitelist !== "") {
|
|
|
|
|
log.send(logLevels.INFO, 'Setting auth server whitelist flag');
|
|
|
|
|
app.commandLine.appendSwitch('auth-server-whitelist', config.customFlags.authServerWhitelist);
|
|
|
|
|
}
|
2018-01-25 22:59:25 +05:30
|
|
|
|
2017-10-26 16:53:15 +05:30
|
|
|
if (config.customFlags.authNegotiateDelegateWhitelist && config.customFlags.authNegotiateDelegateWhitelist !== "") {
|
|
|
|
|
log.send(logLevels.INFO, 'Setting auth negotiate delegate whitelist flag');
|
|
|
|
|
app.commandLine.appendSwitch('auth-negotiate-delegate-whitelist', config.customFlags.authNegotiateDelegateWhitelist);
|
|
|
|
|
}
|
2018-01-25 22:59:25 +05:30
|
|
|
|
|
|
|
|
// ELECTRON-261: Windows 10 Screensharing issues. We set chrome flags
|
|
|
|
|
// to disable gpu which fixes the black screen issue observed on
|
|
|
|
|
// multiple monitors
|
|
|
|
|
if (config.customFlags.disableGpu) {
|
2018-02-06 17:35:06 +05:30
|
|
|
log.send(logLevels.INFO, 'Setting disable gpu, gpu compositing and d3d11 flags to true');
|
2018-01-25 22:59:25 +05:30
|
|
|
app.commandLine.appendSwitch("disable-gpu", true);
|
|
|
|
|
app.commandLine.appendSwitch("disable-gpu-compositing", true);
|
|
|
|
|
app.commandLine.appendSwitch("disable-d3d11", true);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-26 16:53:15 +05:30
|
|
|
}
|
2018-06-12 21:44:11 +05:30
|
|
|
|
|
|
|
|
app.commandLine.appendSwitch("disable-background-timer-throttling", true);
|
2017-10-26 16:53:15 +05:30
|
|
|
}
|
|
|
|
|
|
2017-11-10 11:00:43 +05:30
|
|
|
// Set the chrome flags
|
2017-10-26 16:53:15 +05:30
|
|
|
setChromeFlags();
|
|
|
|
|
|
2017-02-13 16:31:42 -08: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.
|
|
|
|
|
*/
|
2018-04-19 17:56:42 +00:00
|
|
|
app.on('ready', () => {
|
|
|
|
|
checkFirstTimeLaunch()
|
|
|
|
|
.then(readConfigThenOpenMainWindow);
|
|
|
|
|
});
|
2017-02-20 10:24:46 -08:00
|
|
|
|
2017-08-24 16:18:32 +05:30
|
|
|
/**
|
|
|
|
|
* Is triggered when all the windows are closed
|
|
|
|
|
* In which case we quit the app
|
|
|
|
|
*/
|
2017-08-18 17:59:03 +05:30
|
|
|
app.on('window-all-closed', function() {
|
2018-06-13 18:09:32 +05:30
|
|
|
app.quit();
|
2017-05-23 20:22:07 -07:00
|
|
|
});
|
|
|
|
|
|
2017-08-24 16:18:32 +05:30
|
|
|
/**
|
|
|
|
|
* Is triggered when the app is up & running
|
|
|
|
|
*/
|
2017-08-18 17:59:03 +05:30
|
|
|
app.on('activate', function() {
|
2017-05-23 20:22:07 -07:00
|
|
|
if (windowMgr.isMainWindow(null)) {
|
|
|
|
|
setupThenOpenMainWindow();
|
|
|
|
|
} else {
|
|
|
|
|
windowMgr.showMainWindow();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-28 17:29:27 +05:30
|
|
|
app.on('will-quit', function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
deleteIndexFolder();
|
|
|
|
|
app.exit();
|
|
|
|
|
});
|
|
|
|
|
|
2017-05-23 20:22:07 -07:00
|
|
|
// adds 'symphony' as a protocol
|
|
|
|
|
// in the system. plist file in macOS
|
|
|
|
|
// and registry keys in windows
|
|
|
|
|
app.setAsDefaultProtocolClient('symphony');
|
|
|
|
|
|
2017-08-24 16:18:32 +05:30
|
|
|
/**
|
|
|
|
|
* This event is emitted only on macOS
|
|
|
|
|
* at this moment, support for windows
|
|
|
|
|
* is in pipeline (https://github.com/electron/electron/pull/8052)
|
|
|
|
|
*/
|
2017-08-18 17:59:03 +05:30
|
|
|
app.on('open-url', function(event, url) {
|
2017-05-23 20:22:07 -07:00
|
|
|
handleProtocolAction(url);
|
|
|
|
|
});
|
|
|
|
|
|
2017-10-17 11:39:19 +05:30
|
|
|
/**
|
|
|
|
|
* Reads the config fields that are required for the menu items
|
|
|
|
|
* then opens the main window
|
|
|
|
|
*
|
|
|
|
|
* This is a workaround for the issue where the menu template was returned
|
|
|
|
|
* even before the config data was populated
|
|
|
|
|
* https://perzoinc.atlassian.net/browse/ELECTRON-154
|
|
|
|
|
*/
|
|
|
|
|
function readConfigThenOpenMainWindow() {
|
|
|
|
|
setCheckboxValues()
|
|
|
|
|
.then(setupThenOpenMainWindow)
|
|
|
|
|
.catch(setupThenOpenMainWindow)
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-24 16:18:32 +05:30
|
|
|
/**
|
|
|
|
|
* Sets up the app (to handle various things like config changes, protocol handling etc.)
|
|
|
|
|
* and opens the main window
|
|
|
|
|
*/
|
2017-05-23 20:22:07 -07:00
|
|
|
function setupThenOpenMainWindow() {
|
2017-05-13 23:53:44 +05:30
|
|
|
|
|
|
|
|
processProtocolAction(process.argv);
|
|
|
|
|
|
|
|
|
|
isAppAlreadyOpen = true;
|
2018-04-19 17:56:42 +00:00
|
|
|
getUrlAndCreateMainWindow();
|
|
|
|
|
|
2018-05-09 10:52:31 +05:30
|
|
|
// Allows a developer to set custom user data path from command line when
|
|
|
|
|
// launching the app. Mostly used for running automation tests with
|
|
|
|
|
// multiple instances
|
|
|
|
|
let customDataArg = getCmdLineArg(process.argv, '--userDataPath=', false);
|
2018-05-09 16:41:26 +05:30
|
|
|
let customDataFolder = customDataArg && customDataArg.substring(customDataArg.indexOf('=') + 1);
|
2018-05-09 10:52:31 +05:30
|
|
|
|
|
|
|
|
if (customDataArg && customDataFolder) {
|
|
|
|
|
app.setPath('userData', customDataFolder);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-19 17:56:42 +00:00
|
|
|
// Event that fixes the remote desktop issue in Windows
|
|
|
|
|
// by repositioning the browser window
|
|
|
|
|
electron.screen.on('display-removed', windowMgr.verifyDisplays);
|
|
|
|
|
|
|
|
|
|
}
|
2017-05-13 23:53:44 +05:30
|
|
|
|
2018-04-19 17:56:42 +00:00
|
|
|
function checkFirstTimeLaunch() {
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve) => {
|
2018-01-25 22:59:25 +05:30
|
|
|
|
2018-04-19 17:56:42 +00:00
|
|
|
getUserConfigField('version')
|
|
|
|
|
.then((configVersion) => {
|
2017-07-13 01:27:21 +05:30
|
|
|
|
2018-04-19 17:56:42 +00:00
|
|
|
const appVersionString = app.getVersion().toString();
|
2017-05-31 21:39:08 -07:00
|
|
|
|
2018-04-19 17:56:42 +00:00
|
|
|
const execPath = nodePath.dirname(app.getPath('exe'));
|
|
|
|
|
const shouldUpdateUserConfig = execPath.indexOf('AppData/Local/Programs') !== -1 || isMac;
|
2017-08-08 15:20:03 +05:30
|
|
|
|
2018-04-19 17:56:42 +00:00
|
|
|
if (!(configVersion
|
|
|
|
|
&& typeof configVersion === 'string'
|
|
|
|
|
&& (compareSemVersions.check(appVersionString, configVersion) !== 1)) && shouldUpdateUserConfig) {
|
|
|
|
|
return setupFirstTimeLaunch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resolve();
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
return setupFirstTimeLaunch();
|
|
|
|
|
});
|
|
|
|
|
return resolve();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Setup and update user config
|
|
|
|
|
* on first time launch or if the latest app version
|
|
|
|
|
*
|
|
|
|
|
* @return {Promise<any>}
|
|
|
|
|
*/
|
|
|
|
|
function setupFirstTimeLaunch() {
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
|
log.send(logLevels.INFO, 'setting first time launch config');
|
|
|
|
|
getGlobalConfigField('launchOnStartup')
|
|
|
|
|
.then(setStartup)
|
|
|
|
|
.then(updateUserConfigOnLaunch)
|
|
|
|
|
.then(() => {
|
|
|
|
|
log.send(logLevels.INFO, 'first time launch config changes succeeded -> ');
|
|
|
|
|
return resolve();
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
log.send(logLevels.ERROR, 'first time launch config changes failed -> ' + err);
|
|
|
|
|
return resolve();
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-05-09 18:44:14 -03:00
|
|
|
}
|
|
|
|
|
|
2017-08-24 16:18:32 +05:30
|
|
|
/**
|
|
|
|
|
* Sets Symphony on startup
|
|
|
|
|
* @param lStartup
|
|
|
|
|
* @returns {Promise}
|
|
|
|
|
*/
|
2017-08-18 17:59:03 +05:30
|
|
|
function setStartup(lStartup) {
|
2018-05-22 13:55:47 +05:30
|
|
|
log.send(logLevels.INFO, `launch on startup parameter value is ${lStartup}`);
|
2017-11-07 13:23:31 +05:30
|
|
|
return new Promise((resolve) => {
|
2018-05-22 13:55:47 +05:30
|
|
|
let launchOnStartup = (String(lStartup) === 'true');
|
|
|
|
|
log.send(logLevels.INFO, `launchOnStartup value is ${launchOnStartup}`);
|
2017-11-07 13:23:31 +05:30
|
|
|
if (launchOnStartup) {
|
2018-05-22 13:55:47 +05:30
|
|
|
log.send(logLevels.INFO, `enabling launch on startup`);
|
2017-11-07 13:23:31 +05:30
|
|
|
symphonyAutoLauncher.enable();
|
2017-11-07 13:31:45 +05:30
|
|
|
return resolve();
|
2017-11-07 13:23:31 +05:30
|
|
|
}
|
2017-11-07 13:31:45 +05:30
|
|
|
symphonyAutoLauncher.disable();
|
2017-11-07 13:23:31 +05:30
|
|
|
return resolve();
|
|
|
|
|
});
|
2017-07-13 01:27:21 +05:30
|
|
|
}
|
|
|
|
|
|
2017-08-24 16:18:32 +05:30
|
|
|
/**
|
|
|
|
|
* Checks for the url argument, processes it
|
|
|
|
|
* and creates the main window
|
|
|
|
|
*/
|
2017-05-23 20:22:07 -07:00
|
|
|
function getUrlAndCreateMainWindow() {
|
|
|
|
|
// for dev env allow passing url argument
|
2017-03-21 09:15:18 -07:00
|
|
|
if (isDevEnv) {
|
2017-08-24 13:21:02 +05:30
|
|
|
let url = getCmdLineArg(process.argv, '--url=', false);
|
2017-03-21 09:15:18 -07:00
|
|
|
if (url) {
|
2017-05-31 21:39:08 -07:00
|
|
|
windowMgr.createMainWindow(url.substr(6));
|
2017-03-21 09:15:18 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-20 11:54:11 -07:00
|
|
|
getConfigField('url')
|
2017-08-18 17:59:03 +05:30
|
|
|
.then(createWin).catch(function(err) {
|
2018-05-10 15:06:37 +05:30
|
|
|
log.send(logLevels.ERROR, `unable to create main window -> ${err}`);
|
|
|
|
|
app.quit();
|
2017-05-09 18:44:14 -03:00
|
|
|
});
|
2017-03-22 12:10:40 -03:00
|
|
|
}
|
|
|
|
|
|
2017-08-24 16:18:32 +05:30
|
|
|
/**
|
|
|
|
|
* Creates a window
|
|
|
|
|
* @param urlFromConfig
|
|
|
|
|
*/
|
2017-05-09 18:44:14 -03:00
|
|
|
function createWin(urlFromConfig) {
|
2017-03-22 12:10:40 -03:00
|
|
|
// add https protocol if none found.
|
2017-04-20 11:54:11 -07:00
|
|
|
let parsedUrl = nodeURL.parse(urlFromConfig);
|
2017-12-30 12:49:39 +05:30
|
|
|
|
2018-03-29 15:54:42 +05:30
|
|
|
if (!parsedUrl.protocol || parsedUrl.protocol !== 'https') {
|
2017-12-30 12:49:39 +05:30
|
|
|
parsedUrl.protocol = 'https:';
|
|
|
|
|
parsedUrl.slashes = true
|
2017-03-22 12:10:40 -03:00
|
|
|
}
|
2017-12-30 12:49:39 +05:30
|
|
|
let url = nodeURL.format(parsedUrl);
|
2017-05-31 21:39:08 -07:00
|
|
|
|
2017-03-22 12:10:40 -03:00
|
|
|
windowMgr.createMainWindow(url);
|
2017-02-20 10:24:46 -08:00
|
|
|
}
|
2016-11-08 16:32:04 -08:00
|
|
|
|
2017-05-13 23:53:44 +05:30
|
|
|
/**
|
|
|
|
|
* processes protocol action for windows clients
|
|
|
|
|
* @param argv {Array} an array of command line arguments
|
|
|
|
|
*/
|
|
|
|
|
function processProtocolAction(argv) {
|
|
|
|
|
|
|
|
|
|
// In case of windows, we need to handle protocol handler
|
|
|
|
|
// manually because electron doesn't emit
|
|
|
|
|
// 'open-url' event on windows
|
|
|
|
|
if (!(process.platform === 'win32')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-24 13:21:02 +05:30
|
|
|
let protocolUri = getCmdLineArg(argv, 'symphony://', false);
|
2018-05-21 13:27:53 +05:30
|
|
|
log.send(logLevels.INFO, `Trying to process a protocol action for uri ${protocolUri}`);
|
2017-05-13 23:53:44 +05:30
|
|
|
|
|
|
|
|
if (protocolUri) {
|
|
|
|
|
const parsedURL = urlParser.parse(protocolUri);
|
|
|
|
|
if (!parsedURL.protocol || !parsedURL.slashes) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-05-21 13:27:53 +05:30
|
|
|
log.send(logLevels.INFO, `Parsing protocol url successful for ${parsedURL}`);
|
2017-05-13 23:53:44 +05:30
|
|
|
handleProtocolAction(protocolUri);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-24 16:18:32 +05:30
|
|
|
/**
|
|
|
|
|
* Handles a protocol action based on the current state of the app
|
|
|
|
|
* @param uri
|
|
|
|
|
*/
|
2017-05-13 23:53:44 +05:30
|
|
|
function handleProtocolAction(uri) {
|
|
|
|
|
if (!isAppAlreadyOpen) {
|
2018-05-21 13:27:53 +05:30
|
|
|
log.send(logLevels.INFO, `App started by protocol url ${uri}. We are caching this to be processed later!`);
|
2017-05-13 23:53:44 +05:30
|
|
|
// app is opened by the protocol url, cache the protocol url to be used later
|
|
|
|
|
protocolHandler.setProtocolUrl(uri);
|
|
|
|
|
} else {
|
2018-07-17 10:43:43 +05:30
|
|
|
// This is needed for mac OS as it brings pop-outs to foreground
|
|
|
|
|
// (if it has been previously focused) instead of main window
|
|
|
|
|
if (isMac) {
|
|
|
|
|
const mainWindow = windowMgr.getMainWindow();
|
|
|
|
|
if (mainWindow && !mainWindow.isDestroyed()) {
|
|
|
|
|
windowMgr.activate(mainWindow.winName);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-13 23:53:44 +05:30
|
|
|
// app is already open, so, just trigger the protocol action method
|
2018-05-21 13:27:53 +05:30
|
|
|
log.send(logLevels.INFO, `App opened by protocol url ${uri}`);
|
2017-05-13 23:53:44 +05:30
|
|
|
protocolHandler.processProtocolAction(uri);
|
|
|
|
|
}
|
2018-01-25 22:59:25 +05:30
|
|
|
}
|