Skip to content
Permalink
Browse files

fix(macOS): Fix launch Franz on start override

  • Loading branch information
adlk committed Nov 3, 2017
1 parent 6d6878c commit 34bba092fc7bfa828339d445385144535066b03b
Showing with 47 additions and 49 deletions.
  1. +1 −0 package.json
  2. +24 −43 src/stores/AppStore.js
  3. +22 −6 yarn.lock
@@ -27,6 +27,7 @@
"license": "Apache-2.0",
"dependencies": {
"@paulcbetts/system-idle-time": "^1.0.4",
"auto-launch": "https://github.com/meetfranz/node-auto-launch.git",
"babel-polyfill": "^6.23.0",
"babel-runtime": "^6.23.0",
"classnames": "^2.2.5",
@@ -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;
}
}
@@ -151,6 +151,10 @@ anymatch@^1.3.0:
micromatch "^2.1.5"
normalize-path "^2.0.0"

applescript@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/applescript/-/applescript-1.0.0.tgz#bb87af568cad034a4e48c4bdaf6067a3a2701317"

aproba@^1.0.3:
version "1.1.2"
resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.1.2.tgz#45c6629094de4e96f693ef7eab74ae079c240fc1"
@@ -319,6 +323,16 @@ asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"

"auto-launch@https://github.com/meetfranz/node-auto-launch.git":
version "5.0.1"
resolved "https://github.com/meetfranz/node-auto-launch.git#b90a0470467eb84435e6554ae9db1e2c6db79e61"
dependencies:
applescript "^1.0.0"
mkdirp "^0.5.1"
path-is-absolute "^1.0.0"
untildify "^3.0.2"
winreg "1.2.2"

aws-sign2@~0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.6.0.tgz#14342dd38dbcc94d0e5b87d763cd63612c0e794f"
@@ -1998,12 +2012,6 @@ electron-spellchecker@^1.2.0:
rxjs-serial-subscription "^0.1.1"
spawn-rx "^2.0.7"

electron-squirrel-startup@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/electron-squirrel-startup/-/electron-squirrel-startup-1.0.0.tgz#19b4e55933fa0ef8f556784b9c660f772546a0b8"
dependencies:
debug "^2.2.0"

electron-to-chromium@^1.3.18:
version "1.3.20"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.20.tgz#2eedd5ccbae7ddc557f68ad1fce9c172e915e4e5"
@@ -5949,6 +5957,10 @@ universalify@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7"

untildify@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/untildify/-/untildify-3.0.2.tgz#7f1f302055b3fea0f3e81dc78eb36766cb65e3f1"

unzip-response@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97"
@@ -6133,6 +6145,10 @@ window-size@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.4.tgz#f8e1aa1ee5a53ec5bf151ffa09742a6ad7697876"

winreg@1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/winreg/-/winreg-1.2.2.tgz#8509afa3b71c5bbd110a6d7c6247ec67736c598f"

word-wrap@^1.0.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"

0 comments on commit 34bba09

Please sign in to comment.
You can’t perform that action at this time.