Merge branch 'master' into electron-113

# Conflicts:
#	js/main.js
#	package.json
This commit is contained in:
Vishwas Shashidhar
2017-09-01 12:53:10 +05:30
50 changed files with 981 additions and 631 deletions

View File

@@ -1,12 +1,20 @@
'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, updateUserConfigWin, updateUserConfigMac } = require('./config.js');
const childProcess = require('child_process');
const path = require('path');
const AppDirectory = require('appdirectory');
const dirs = new AppDirectory('Symphony');
// Local Dependencies
const { getConfigField } = require('./config.js');
const { isMac, isDevEnv } = require('./utils/misc.js');
const protocolHandler = require('./protocolHandler');
const getCmdLineArg = require('./utils/getCmdLineArg.js');
@@ -71,10 +79,17 @@ if (isMac) {
*/
app.on('ready', setupThenOpenMainWindow);
/**
* Is triggered when all the windows are closed
* In which case we quit the app
*/
app.on('window-all-closed', function() {
app.quit();
});
/**
* Is triggered when the app is up & running
*/
app.on('activate', function() {
if (windowMgr.isMainWindow(null)) {
setupThenOpenMainWindow();
@@ -88,13 +103,19 @@ 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)
/**
* 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);
@@ -120,8 +141,8 @@ function setupThenOpenMainWindow() {
// 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
// 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))
@@ -137,6 +158,11 @@ function setupThenOpenMainWindow() {
electron.screen.on('display-removed', windowMgr.verifyDisplays);
}
/**
* Sets Symphony on startup
* @param lStartup
* @returns {Promise}
*/
function setStartup(lStartup) {
return symphonyAutoLauncher.isEnabled()
.then(function(isEnabled) {
@@ -152,10 +178,51 @@ function setStartup(lStartup) {
});
}
/**
* Method to overwrite user config on mac installer
* @returns {Promise}
*/
function updateUserConfigMac() {
return new Promise((resolve, reject) => {
let userConfigPath = dirs.userConfig() + '/';
let globalConfigPath = process.argv[2];
let userName = process.env.USER;
childProcess.exec(`rsync -r "${globalConfigPath}" "${userConfigPath}" && chown -R "${userName}" "${userConfigPath}"`, {timeout: 60000}, (err) => {
if (err) {
reject(err);
}
resolve();
});
});
}
/**
* Method to overwrite user config on windows installer
* @returns {Promise}
*/
function updateUserConfigWin() {
return new Promise((resolve, reject) => {
let userConfigPath = app.getPath('userData');
let globalConfigPath = path.join(__dirname, '..', '..', '..', 'config/Symphony.config');
childProcess.exec(`echo D|xcopy /y /e /s /c "${globalConfigPath}" "${userConfigPath}"`, {timeout: 60000}, (err) => {
if (err) {
reject(err);
}
resolve();
});
});
}
/**
* 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;
@@ -169,6 +236,10 @@ function getUrlAndCreateMainWindow() {
});
}
/**
* Creates a window
* @param urlFromConfig
*/
function createWin(urlFromConfig) {
let protocol = '';
// add https protocol if none found.
@@ -176,7 +247,7 @@ function createWin(urlFromConfig) {
if (!parsedUrl.protocol) {
protocol = 'https';
}
var url = nodeURL.format({
let url = nodeURL.format({
protocol: protocol,
slahes: true,
pathname: parsedUrl.href
@@ -198,7 +269,7 @@ function processProtocolAction(argv) {
return;
}
let protocolUri = getCmdLineArg(argv, 'symphony://');
let protocolUri = getCmdLineArg(argv, 'symphony://', false);
if (protocolUri) {
@@ -213,6 +284,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