Skip to content

Commit

Permalink
Electron-26 (Auto Launch for Mac) (#109)
Browse files Browse the repository at this point in the history
* Electron-19 - Updated AutoLauncher path to make it work properly in mac

* Electron-26 - Implemented auto launch for mac

* Electron-26 - Added comments
  • Loading branch information
KiranNiranjan authored and Lynn committed May 31, 2017
1 parent 307b60d commit 8e8b394
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
4 changes: 2 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
44 changes: 34 additions & 10 deletions js/menus/menuTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = [
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8e8b394

Please sign in to comment.