From 34bba092fc7bfa828339d445385144535066b03b Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 3 Nov 2017 16:15:48 +0100 Subject: fix(macOS): Fix launch Franz on start override --- src/stores/AppStore.js | 67 ++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index f608a689e..d8ef66a92 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -2,19 +2,23 @@ import { remote, ipcRenderer, shell } from 'electron'; import { action, observable } from 'mobx'; import moment from 'moment'; import key from 'keymaster'; -import path from 'path'; +// import path from 'path'; import idleTimer from '@paulcbetts/system-idle-time'; +import AutoLaunch from 'auto-launch'; import Store from './lib/Store'; import Request from './lib/Request'; import { CHECK_INTERVAL } from '../config'; -import { isMac, isLinux } from '../environment'; +import { isMac } from '../environment'; import locales from '../i18n/translations'; import { gaEvent } from '../lib/analytics'; import Miner from '../lib/Miner'; const { app, powerMonitor } = remote; const defaultLocale = 'en-US'; +const autoLauncher = new AutoLaunch({ + name: 'Franz', +}); export default class AppStore extends Store { updateStatusTypes = { @@ -41,7 +45,7 @@ export default class AppStore extends Store { miner = null; @observable minerHashrate = 0.0; - constructor(...args: any) { + constructor(...args) { super(...args); // Register action handlers @@ -157,28 +161,17 @@ export default class AppStore extends Store { ipcRenderer.send('updateAppIndicator', { indicator }); } - @action _launchOnStartup({ enable, openInBackground }) { + @action _launchOnStartup({ enable }) { this.autoLaunchOnStart = enable; - let settings = { - openAtLogin: enable, - }; - - // For Windows - if (process.platform === 'win32') { - settings = Object.assign({ - openAsHidden: openInBackground, - path: app.getPath('exe'), - args: [ - '--processStart', `"${path.basename(app.getPath('exe'))}"`, - ], - }, settings); - - if (openInBackground) { - settings.args.push( - '--process-start-args', '"--hidden"', - ); + try { + if (enable) { + autoLauncher.enable(); + } else { + autoLauncher.disable(); } + } catch (err) { + console.warn(err); } gaEvent('App', enable ? 'enable autostart' : 'disable autostart'); @@ -287,31 +280,19 @@ export default class AppStore extends Store { } async _autoStart() { - if (!isLinux) { - this._checkAutoStart(); - - // we need to wait until the settings request is resolved - await this.stores.settings.allSettingsRequest; + this.autoLaunchOnStart = await this._checkAutoStart(); - // We don't set autostart on first launch for macOS as disabling - // the option is currently broken - // https://github.com/meetfranz/franz/issues/17 - // https://github.com/electron/electron/issues/10880 - if (process.platform === 'darwin') return; + // we need to wait until the settings request is resolved + await this.stores.settings.allSettingsRequest; - if (!this.stores.settings.all.appStarts) { - this.actions.app.launchOnStartup({ - enable: true, - }); - } + if (!this.stores.settings.all.appStarts) { + this.actions.app.launchOnStartup({ + enable: true, + }); } } - _checkAutoStart() { - const loginItem = app.getLoginItemSettings({ - path: app.getPath('exe'), - }); - - this.autoLaunchOnStart = loginItem.openAtLogin; + async _checkAutoStart() { + return autoLauncher.isEnabled() || false; } } -- cgit v1.2.3-70-g09d2