From 4813c549f67b75451f98d016c9b0cffe6046a30b Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Thu, 25 May 2017 21:08:40 +0530 Subject: [PATCH 1/3] Electron-19 - Updated AutoLauncher path to make it work properly in mac --- js/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/main.js b/js/main.js index f1b2d8fd1..6e270d6b5 100644 --- a/js/main.js +++ b/js/main.js @@ -7,7 +7,7 @@ const squirrelStartup = require('electron-squirrel-startup'); const AutoLaunch = require('auto-launch'); const urlParser = require('url'); const { getConfigField } = require('./config.js'); -const { isDevEnv} = require('./utils/misc.js'); +const { isMac, isDevEnv } = require('./utils/misc.js'); const protocolHandler = require('./protocolHandler'); // used to check if a url was opened when the app was already open @@ -46,7 +46,7 @@ if (shouldQuit) { var symphonyAutoLauncher = new AutoLaunch({ name: 'Symphony', - path: process.execPath, + path: isMac ? '/Applications/' + app.getName() + '.app' : process.execPath, }); /** From e4f645aba7578a5b3ab90ae294ecc9192bb56d64 Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Mon, 29 May 2017 15:38:19 +0530 Subject: [PATCH 2/3] Electron-26 - Implemented auto launch for mac --- js/main.js | 4 ++-- js/menus/menuTemplate.js | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/js/main.js b/js/main.js index 6e270d6b5..80d5bb037 100644 --- a/js/main.js +++ b/js/main.js @@ -46,7 +46,7 @@ if (shouldQuit) { var symphonyAutoLauncher = new AutoLaunch({ name: 'Symphony', - path: isMac ? '/Applications/' + app.getName() + '.app' : process.execPath, + path: process.execPath, }); /** @@ -93,7 +93,7 @@ function setupThenOpenMainWindow() { process.argv.some((val) => { let flag = '--install'; - if (val === flag) { + if (val === flag && !isMac) { installMode = true; getConfigField('launchOnStartup') .then(setStartup) diff --git a/js/menus/menuTemplate.js b/js/menus/menuTemplate.js index 2d8b1109e..c7acaa0a3 100644 --- a/js/menus/menuTemplate.js +++ b/js/menus/menuTemplate.js @@ -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,35 @@ 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){ + 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){ + 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); From 4e99ab37dc6b2afdca7159a717e2bcbfd290f74e Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Wed, 31 May 2017 11:55:49 +0530 Subject: [PATCH 3/3] Electron-26 - Added comments --- js/menus/menuTemplate.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/js/menus/menuTemplate.js b/js/menus/menuTemplate.js index c7acaa0a3..e6f331bd4 100644 --- a/js/menus/menuTemplate.js +++ b/js/menus/menuTemplate.js @@ -187,6 +187,8 @@ function getTemplate(app) { click: function (item) { if (item.checked){ 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'; @@ -202,6 +204,8 @@ function getTemplate(app) { } } else { 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';