diff options
Diffstat (limited to 'src/stores/AppStore.js')
-rw-r--r-- | src/stores/AppStore.js | 82 |
1 files changed, 27 insertions, 55 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 7dbef985d..d8ef66a92 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js | |||
@@ -2,19 +2,23 @@ import { remote, ipcRenderer, shell } from 'electron'; | |||
2 | import { action, observable } from 'mobx'; | 2 | import { action, observable } from 'mobx'; |
3 | import moment from 'moment'; | 3 | import moment from 'moment'; |
4 | import key from 'keymaster'; | 4 | import key from 'keymaster'; |
5 | import path from 'path'; | 5 | // import path from 'path'; |
6 | import idleTimer from '@paulcbetts/system-idle-time'; | 6 | import idleTimer from '@paulcbetts/system-idle-time'; |
7 | import AutoLaunch from 'auto-launch'; | ||
7 | 8 | ||
8 | import Store from './lib/Store'; | 9 | import Store from './lib/Store'; |
9 | import Request from './lib/Request'; | 10 | import Request from './lib/Request'; |
10 | import { CHECK_INTERVAL } from '../config'; | 11 | import { CHECK_INTERVAL } from '../config'; |
11 | import { isMac, isLinux } from '../environment'; | 12 | import { isMac } from '../environment'; |
12 | import locales from '../i18n/translations'; | 13 | import locales from '../i18n/translations'; |
13 | import { gaEvent } from '../lib/analytics'; | 14 | import { gaEvent } from '../lib/analytics'; |
14 | import Miner from '../lib/Miner'; | 15 | import Miner from '../lib/Miner'; |
15 | 16 | ||
16 | const { app, getCurrentWindow, powerMonitor } = remote; | 17 | const { app, powerMonitor } = remote; |
17 | const defaultLocale = 'en-US'; | 18 | const defaultLocale = 'en-US'; |
19 | const autoLauncher = new AutoLaunch({ | ||
20 | name: 'Franz', | ||
21 | }); | ||
18 | 22 | ||
19 | export default class AppStore extends Store { | 23 | export 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 |
@@ -112,24 +116,15 @@ export default class AppStore extends Store { | |||
112 | setTimeout(window.location.reload, 5000); | 116 | setTimeout(window.location.reload, 5000); |
113 | }); | 117 | }); |
114 | 118 | ||
115 | // Open Dev Tools (even in production mode) | ||
116 | key('⌘+ctrl+shift+alt+i, ctrl+shift+alt+i', () => { | ||
117 | getCurrentWindow().toggleDevTools(); | ||
118 | }); | ||
119 | |||
120 | key('⌘+ctrl+shift+alt+pageup, ctrl+shift+alt+pageup', () => { | ||
121 | this.actions.service.openDevToolsForActiveService(); | ||
122 | }); | ||
123 | |||
124 | // Set active the next service | 119 | // Set active the next service |
125 | key( | 120 | key( |
126 | '⌘+pagedown, ctrl+pagedown, ⌘+shift+tab, ctrl+shift+tab', () => { | 121 | '⌘+pagedown, ctrl+pagedown, ⌘+tab, ctrl+tab', () => { |
127 | this.actions.service.setActiveNext(); | 122 | this.actions.service.setActiveNext(); |
128 | }); | 123 | }); |
129 | 124 | ||
130 | // Set active the prev service | 125 | // Set active the prev service |
131 | key( | 126 | key( |
132 | '⌘+pageup, ctrl+pageup, ⌘+tab, ctrl+tab', () => { | 127 | '⌘+pageup, ctrl+pageup, ⌘+shift+tab, ctrl+shift+tab', () => { |
133 | this.actions.service.setActivePrev(); | 128 | this.actions.service.setActivePrev(); |
134 | }); | 129 | }); |
135 | 130 | ||
@@ -166,28 +161,17 @@ export default class AppStore extends Store { | |||
166 | ipcRenderer.send('updateAppIndicator', { indicator }); | 161 | ipcRenderer.send('updateAppIndicator', { indicator }); |
167 | } | 162 | } |
168 | 163 | ||
169 | @action _launchOnStartup({ enable, openInBackground }) { | 164 | @action _launchOnStartup({ enable }) { |
170 | this.autoLaunchOnStart = enable; | 165 | this.autoLaunchOnStart = enable; |
171 | 166 | ||
172 | let settings = { | 167 | try { |
173 | openAtLogin: enable, | 168 | if (enable) { |
174 | }; | 169 | autoLauncher.enable(); |
175 | 170 | } else { | |
176 | // For Windows | 171 | autoLauncher.disable(); |
177 | if (process.platform === 'win32') { | ||
178 | settings = Object.assign({ | ||
179 | openAsHidden: openInBackground, | ||
180 | path: app.getPath('exe'), | ||
181 | args: [ | ||
182 | '--processStart', `"${path.basename(app.getPath('exe'))}"`, | ||
183 | ], | ||
184 | }, settings); | ||
185 | |||
186 | if (openInBackground) { | ||
187 | settings.args.push( | ||
188 | '--process-start-args', '"--hidden"', | ||
189 | ); | ||
190 | } | 172 | } |
173 | } catch (err) { | ||
174 | console.warn(err); | ||
191 | } | 175 | } |
192 | 176 | ||
193 | gaEvent('App', enable ? 'enable autostart' : 'disable autostart'); | 177 | gaEvent('App', enable ? 'enable autostart' : 'disable autostart'); |
@@ -296,31 +280,19 @@ export default class AppStore extends Store { | |||
296 | } | 280 | } |
297 | 281 | ||
298 | async _autoStart() { | 282 | async _autoStart() { |
299 | if (!isLinux) { | 283 | this.autoLaunchOnStart = await this._checkAutoStart(); |
300 | this._checkAutoStart(); | ||
301 | |||
302 | // we need to wait until the settings request is resolved | ||
303 | await this.stores.settings.allSettingsRequest; | ||
304 | 284 | ||
305 | // We don't set autostart on first launch for macOS as disabling | 285 | // we need to wait until the settings request is resolved |
306 | // the option is currently broken | 286 | await this.stores.settings.allSettingsRequest; |
307 | // https://github.com/meetfranz/franz/issues/17 | ||
308 | // https://github.com/electron/electron/issues/10880 | ||
309 | if (process.platform === 'darwin') return; | ||
310 | 287 | ||
311 | if (!this.stores.settings.all.appStarts) { | 288 | if (!this.stores.settings.all.appStarts) { |
312 | this.actions.app.launchOnStartup({ | 289 | this.actions.app.launchOnStartup({ |
313 | enable: true, | 290 | enable: true, |
314 | }); | 291 | }); |
315 | } | ||
316 | } | 292 | } |
317 | } | 293 | } |
318 | 294 | ||
319 | _checkAutoStart() { | 295 | async _checkAutoStart() { |
320 | const loginItem = app.getLoginItemSettings({ | 296 | return autoLauncher.isEnabled() || false; |
321 | path: app.getPath('exe'), | ||
322 | }); | ||
323 | |||
324 | this.autoLaunchOnStart = loginItem.openAtLogin; | ||
325 | } | 297 | } |
326 | } | 298 | } |