Electron-26 (Auto Launch for Mac) (#109)

* Electron-19 - Updated AutoLauncher path to make it work properly in mac

* Electron-26 - Implemented auto launch for mac

* Electron-26 - Added comments
This commit is contained in:
Kiran Niranjan
2017-05-31 23:08:57 +05:30
committed by Lynn
parent 307b60dd25
commit 8e8b3948da
2 changed files with 36 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ const electron = require('electron');
const { getConfigField, updateConfigField } = require('../config.js');
const AutoLaunch = require('auto-launch');
const isMac = require('../utils/misc.js').isMac;
const childProcess = require('child_process');
var minimizeOnClose = false;
var launchOnStartup = false;
@@ -14,6 +15,7 @@ var symphonyAutoLauncher = new AutoLaunch({
name: 'Symphony',
path: process.execPath,
});
let launchAgentPath = '~/Library/LaunchAgents/com.symphony.symphony-desktop.agent.plist';
const template = [
{
@@ -184,17 +186,39 @@ function getTemplate(app) {
checked: launchOnStartup,
click: function (item) {
if (item.checked){
symphonyAutoLauncher.enable()
.catch(function (err) {
let title = 'Error setting AutoLaunch configuration';
electron.dialog.showErrorBox(title, title + ': ' + err);
});
if (isMac){
// TODO: Need to change this implementation to AutoLaunch once they fix this issue ->
// https://github.com/Teamwork/node-auto-launch/issues/28
childProcess.exec(`launchctl load ${launchAgentPath}`, (err) => {
if (err){
let title = 'Error setting AutoLaunch configuration';
electron.dialog.showErrorBox(title, 'Please try reinstalling the application');
}
});
} else {
symphonyAutoLauncher.enable()
.catch(function (err) {
let title = 'Error setting AutoLaunch configuration';
electron.dialog.showErrorBox(title, title + ': ' + err);
});
}
} else {
symphonyAutoLauncher.disable()
.catch(function (err) {
let title = 'Error setting AutoLaunch configuration';
electron.dialog.showErrorBox(title, title + ': ' + err);
});
if (isMac){
// TODO: Need to change this implementation to AutoLaunch once they fix this issue ->
// https://github.com/Teamwork/node-auto-launch/issues/28
childProcess.exec(`launchctl unload ${launchAgentPath}`, (err) => {
if (err){
let title = 'Error disabling AutoLaunch configuration';
electron.dialog.showErrorBox(title, 'Please try reinstalling the application');
}
});
} else {
symphonyAutoLauncher.disable()
.catch(function (err) {
let title = 'Error setting AutoLaunch configuration';
electron.dialog.showErrorBox(title, title + ': ' + err);
});
}
}
launchOnStartup = item.checked;
updateConfigField('launchOnStartup', launchOnStartup);