From 61caa9090122cd3ce63c84fa25e600273beec87c Mon Sep 17 00:00:00 2001 From: DC Date: Fri, 9 Sep 2016 18:10:47 -0700 Subject: [PATCH] Auto launch: don't open a terminal on MacOS --- package.json | 2 +- src/main/startup.js | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 70548b0d..d7ad3117 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "dependencies": { "airplayer": "^2.0.0", "application-config": "^1.0.0", - "auto-launch": "^4.0.0", + "auto-launch": "^4.0.1", "bitfield": "^1.0.2", "chromecasts": "^1.8.0", "create-torrent": "^3.24.5", diff --git a/src/main/startup.js b/src/main/startup.js index 135dc9f6..443c69c8 100644 --- a/src/main/startup.js +++ b/src/main/startup.js @@ -5,23 +5,32 @@ module.exports = { const config = require('../config') const AutoLaunch = require('auto-launch') +const { app } = require('electron') + +// On Mac, work around a bug in auto-launch where it opens a Terminal window +// See https://github.com/Teamwork/node-auto-launch/issues/28#issuecomment-222194437 +const appPath = process.platform === 'darwin' + ? app.getPath('exe').replace(/\.app\/Content.*/, '.app') + : undefined // Use the default const appLauncher = new AutoLaunch({ name: config.APP_NAME, + path: appPath, isHidden: true }) function install () { - return appLauncher.isEnabled() - .then(enabled => { - if (enabled) return - return appLauncher.enable() - }) + return appLauncher + .isEnabled() + .then(enabled => { + if (!enabled) return appLauncher.enable() + }) } function uninstall () { - return appLauncher.isEnabled() - .then(enabled => { - if (enabled) return appLauncher.disable() - }) + return appLauncher + .isEnabled() + .then(enabled => { + if (enabled) return appLauncher.disable() + }) }