aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/AppStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/AppStore.js')
-rw-r--r--src/stores/AppStore.js69
1 files changed, 26 insertions, 43 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index f608a689e..ecfd621d3 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -2,19 +2,23 @@ import { remote, ipcRenderer, shell } from 'electron';
2import { action, observable } from 'mobx'; 2import { action, observable } from 'mobx';
3import moment from 'moment'; 3import moment from 'moment';
4import key from 'keymaster'; 4import key from 'keymaster';
5import path from 'path'; 5// import path from 'path';
6import idleTimer from '@paulcbetts/system-idle-time'; 6import idleTimer from '@paulcbetts/system-idle-time';
7import AutoLaunch from 'auto-launch';
7 8
8import Store from './lib/Store'; 9import Store from './lib/Store';
9import Request from './lib/Request'; 10import Request from './lib/Request';
10import { CHECK_INTERVAL } from '../config'; 11import { CHECK_INTERVAL } from '../config';
11import { isMac, isLinux } from '../environment'; 12import { isMac } from '../environment';
12import locales from '../i18n/translations'; 13import locales from '../i18n/translations';
13import { gaEvent } from '../lib/analytics'; 14import { gaEvent } from '../lib/analytics';
14import Miner from '../lib/Miner'; 15import Miner from '../lib/Miner';
15 16
16const { app, powerMonitor } = remote; 17const { app, powerMonitor } = remote;
17const defaultLocale = 'en-US'; 18const defaultLocale = 'en-US';
19const autoLauncher = new AutoLaunch({
20 name: 'Franz',
21});
18 22
19export default class AppStore extends Store { 23export default class AppStore extends Store {
20 updateStatusTypes = { 24 updateStatusTypes = {
@@ -41,7 +45,7 @@ export default class AppStore extends Store {
41 miner = null; 45 miner = null;
42 @observable minerHashrate = 0.0; 46 @observable minerHashrate = 0.0;
43 47
44 constructor(...args: any) { 48 constructor(...args) {
45 super(...args); 49 super(...args);
46 50
47 // Register action handlers 51 // Register action handlers
@@ -152,33 +156,24 @@ export default class AppStore extends Store {
152 indicator = '•'; 156 indicator = '•';
153 } else if (unreadDirectMessageCount === 0 && unreadIndirectMessageCount === 0) { 157 } else if (unreadDirectMessageCount === 0 && unreadIndirectMessageCount === 0) {
154 indicator = 0; 158 indicator = 0;
159 } else {
160 indicator = parseInt(indicator, 10);
155 } 161 }
156 162
157 ipcRenderer.send('updateAppIndicator', { indicator }); 163 ipcRenderer.send('updateAppIndicator', { indicator });
158 } 164 }
159 165
160 @action _launchOnStartup({ enable, openInBackground }) { 166 @action _launchOnStartup({ enable }) {
161 this.autoLaunchOnStart = enable; 167 this.autoLaunchOnStart = enable;
162 168
163 let settings = { 169 try {
164 openAtLogin: enable, 170 if (enable) {
165 }; 171 autoLauncher.enable();
166 172 } else {
167 // For Windows 173 autoLauncher.disable();
168 if (process.platform === 'win32') {
169 settings = Object.assign({
170 openAsHidden: openInBackground,
171 path: app.getPath('exe'),
172 args: [
173 '--processStart', `"${path.basename(app.getPath('exe'))}"`,
174 ],
175 }, settings);
176
177 if (openInBackground) {
178 settings.args.push(
179 '--process-start-args', '"--hidden"',
180 );
181 } 174 }
175 } catch (err) {
176 console.warn(err);
182 } 177 }
183 178
184 gaEvent('App', enable ? 'enable autostart' : 'disable autostart'); 179 gaEvent('App', enable ? 'enable autostart' : 'disable autostart');
@@ -287,31 +282,19 @@ export default class AppStore extends Store {
287 } 282 }
288 283
289 async _autoStart() { 284 async _autoStart() {
290 if (!isLinux) { 285 this.autoLaunchOnStart = await this._checkAutoStart();
291 this._checkAutoStart();
292 286
293 // we need to wait until the settings request is resolved 287 // we need to wait until the settings request is resolved
294 await this.stores.settings.allSettingsRequest; 288 await this.stores.settings.allSettingsRequest;
295
296 // We don't set autostart on first launch for macOS as disabling
297 // the option is currently broken
298 // https://github.com/meetfranz/franz/issues/17
299 // https://github.com/electron/electron/issues/10880
300 if (process.platform === 'darwin') return;
301 289
302 if (!this.stores.settings.all.appStarts) { 290 if (!this.stores.settings.all.appStarts) {
303 this.actions.app.launchOnStartup({ 291 this.actions.app.launchOnStartup({
304 enable: true, 292 enable: true,
305 }); 293 });
306 }
307 } 294 }
308 } 295 }
309 296
310 _checkAutoStart() { 297 async _checkAutoStart() {
311 const loginItem = app.getLoginItemSettings({ 298 return autoLauncher.isEnabled() || false;
312 path: app.getPath('exe'),
313 });
314
315 this.autoLaunchOnStart = loginItem.openAtLogin;
316 } 299 }
317} 300}