Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electron-26 (Auto Launch for Mac) #109

Merged
merged 4 commits into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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