Merge branch 'master' into electron-17

# Conflicts:
#	js/main.js
#	js/windowMgr.js
This commit is contained in:
Vishwas Shashidhar
2017-09-13 16:13:49 +05:30
60 changed files with 10908 additions and 720 deletions

View File

@@ -1,12 +1,15 @@
'use strict';
// Third Party Dependencies
const electron = require('electron');
const app = electron.app;
const nodeURL = require('url');
const squirrelStartup = require('electron-squirrel-startup');
const AutoLaunch = require('auto-launch');
const urlParser = require('url');
const { getConfigField } = require('./config.js');
// Local Dependencies
const {getConfigField, updateUserConfigWin, updateUserConfigMac} = require('./config.js');
const { isMac, isDevEnv } = require('./utils/misc.js');
const protocolHandler = require('./protocolHandler');
const getCmdLineArg = require('./utils/getCmdLineArg.js');
@@ -48,10 +51,22 @@ if (!isDevEnv && shouldQuit) {
app.quit();
}
var symphonyAutoLauncher = new AutoLaunch({
name: 'Symphony',
path: process.execPath,
});
let symphonyAutoLauncher;
if (isMac) {
symphonyAutoLauncher = new AutoLaunch({
name: 'Symphony',
mac: {
useLaunchAgent: true,
},
path: process.execPath,
});
} else {
symphonyAutoLauncher = new AutoLaunch({
name: 'Symphony',
path: process.execPath,
});
}
/**
* This method will be called when Electron has finished
@@ -60,11 +75,18 @@ var symphonyAutoLauncher = new AutoLaunch({
*/
app.on('ready', setupThenOpenMainWindow);
app.on('window-all-closed', function () {
/**
* Is triggered when all the windows are closed
* In which case we quit the app
*/
app.on('window-all-closed', function() {
app.quit();
});
app.on('activate', function () {
/**
* Is triggered when the app is up & running
*/
app.on('activate', function() {
if (windowMgr.isMainWindow(null)) {
setupThenOpenMainWindow();
} else {
@@ -77,52 +99,88 @@ app.on('activate', function () {
// 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) {
/**
* 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);
});
/**
* Sets up the app (to handle various things like config changes, protocol handling etc.)
* and opens the main window
*/
function setupThenOpenMainWindow() {
processProtocolAction(process.argv);
isAppAlreadyOpen = true;
// allows installer to launch app and set auto startup mode then
// immediately quit.
// allows installer to launch app and set appropriate global / user config params.
let hasInstallFlag = getCmdLineArg(process.argv, '--install', true);
let perUserInstall = getCmdLineArg(process.argv, '--peruser', true);
if (!isMac && hasInstallFlag) {
getConfigField('launchOnStartup')
.then(setStartup)
.then(app.quit)
.catch(app.quit);
.then(setStartup)
.then(() => updateUserConfigWin(perUserInstall))
.then(app.quit)
.catch(app.quit);
return;
}
// allows mac installer to overwrite user config
if (isMac && hasInstallFlag) {
// This value is being sent from post install script
// as the app is launched as a root user we don't get
// access to the config file
let launchOnStartup = process.argv[3];
// We wire this in via the post install script
// to get the config file path where the app is installed
let appGlobalConfigPath = process.argv[2];
setStartup(launchOnStartup)
.then(() => updateUserConfigMac(appGlobalConfigPath))
.then(app.quit)
.catch(app.quit);
return;
}
getUrlAndCreateMainWindow();
// Event that fixes the remote desktop issue in Windows
// by repositioning the browser window
electron.screen.on('display-removed', windowMgr.verifyDisplays);
}
function setStartup(lStartup){
/**
* Sets Symphony on startup
* @param lStartup
* @returns {Promise}
*/
function setStartup(lStartup) {
return symphonyAutoLauncher.isEnabled()
.then(function(isEnabled){
if (!isEnabled && lStartup) {
return symphonyAutoLauncher.enable();
}
.then(function(isEnabled) {
if (!isEnabled && lStartup) {
return symphonyAutoLauncher.enable();
}
if (isEnabled && !lStartup) {
return symphonyAutoLauncher.disable();
}
if (isEnabled && !lStartup) {
return symphonyAutoLauncher.disable();
}
return true;
});
return true;
});
}
/**
* Checks for the url argument, processes it
* and creates the main window
*/
function getUrlAndCreateMainWindow() {
// for dev env allow passing url argument
if (isDevEnv) {
let url = getCmdLineArg(process.argv, '--url=')
let url = getCmdLineArg(process.argv, '--url=', false);
if (url) {
windowMgr.createMainWindow(url.substr(6));
return;
@@ -130,12 +188,16 @@ function getUrlAndCreateMainWindow() {
}
getConfigField('url')
.then(createWin).catch(function (err) {
.then(createWin).catch(function(err) {
let title = 'Error loading configuration';
electron.dialog.showErrorBox(title, title + ': ' + err);
});
}
/**
* Creates a window
* @param urlFromConfig
*/
function createWin(urlFromConfig) {
let protocol = '';
// add https protocol if none found.
@@ -143,7 +205,7 @@ function createWin(urlFromConfig) {
if (!parsedUrl.protocol) {
protocol = 'https';
}
var url = nodeURL.format({
let url = nodeURL.format({
protocol: protocol,
slahes: true,
pathname: parsedUrl.href
@@ -179,7 +241,7 @@ function processProtocolAction(argv) {
return;
}
let protocolUri = getCmdLineArg(argv, 'symphony://');
let protocolUri = getCmdLineArg(argv, 'symphony://', false);
if (protocolUri) {
@@ -194,6 +256,10 @@ function processProtocolAction(argv) {
}
}
/**
* Handles a protocol action based on the current state of the app
* @param uri
*/
function handleProtocolAction(uri) {
if (!isAppAlreadyOpen) {
// app is opened by the protocol url, cache the protocol url to be used later