diff options
Diffstat (limited to 'src/stores/AppStore.js')
-rw-r--r-- | src/stores/AppStore.js | 61 |
1 files changed, 11 insertions, 50 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index e33f50f05..162422017 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js | |||
@@ -3,17 +3,15 @@ import { action, computed, 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 { getDoNotDisturb } from '@meetfranz/electron-notification-state'; | 5 | import { getDoNotDisturb } from '@meetfranz/electron-notification-state'; |
6 | import idleTimer from '@paulcbetts/system-idle-time'; | ||
7 | import AutoLaunch from 'auto-launch'; | 6 | import AutoLaunch from 'auto-launch'; |
8 | import prettyBytes from 'pretty-bytes'; | 7 | import prettyBytes from 'pretty-bytes'; |
9 | 8 | ||
10 | import Store from './lib/Store'; | 9 | import Store from './lib/Store'; |
11 | import Request from './lib/Request'; | 10 | import Request from './lib/Request'; |
12 | import { CHECK_INTERVAL, DEFAULT_APP_SETTINGS } from '../config'; | 11 | import { CHECK_INTERVAL, DEFAULT_APP_SETTINGS } from '../config'; |
13 | import { isMac } from '../environment'; | 12 | import { isMac, isLinux, isWindows } from '../environment'; |
14 | import locales from '../i18n/translations'; | 13 | import locales from '../i18n/translations'; |
15 | import { gaEvent } from '../lib/analytics'; | 14 | import { gaEvent } from '../lib/analytics'; |
16 | import Miner from '../lib/Miner'; | ||
17 | 15 | ||
18 | import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; | 16 | import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; |
19 | 17 | ||
@@ -46,11 +44,6 @@ export default class AppStore extends Store { | |||
46 | 44 | ||
47 | @observable locale = defaultLocale; | 45 | @observable locale = defaultLocale; |
48 | 46 | ||
49 | @observable idleTime = 0; | ||
50 | |||
51 | miner = null; | ||
52 | @observable minerHashrate = 0.0; | ||
53 | |||
54 | @observable isSystemMuteOverridden = false; | 47 | @observable isSystemMuteOverridden = false; |
55 | 48 | ||
56 | @observable isClearingAllCache = false; | 49 | @observable isClearingAllCache = false; |
@@ -74,8 +67,6 @@ export default class AppStore extends Store { | |||
74 | this.registerReactions([ | 67 | this.registerReactions([ |
75 | this._offlineCheck.bind(this), | 68 | this._offlineCheck.bind(this), |
76 | this._setLocale.bind(this), | 69 | this._setLocale.bind(this), |
77 | this._handleMiner.bind(this), | ||
78 | this._handleMinerThrottle.bind(this), | ||
79 | this._muteAppHandler.bind(this), | 70 | this._muteAppHandler.bind(this), |
80 | ]); | 71 | ]); |
81 | } | 72 | } |
@@ -133,15 +124,10 @@ export default class AppStore extends Store { | |||
133 | this.stores.router.push(data.url); | 124 | this.stores.router.push(data.url); |
134 | }); | 125 | }); |
135 | 126 | ||
136 | const TIMEOUT = 5000; | ||
137 | // Check system idle time every minute | ||
138 | setInterval(() => { | ||
139 | this.idleTime = idleTimer.getIdleTime(); | ||
140 | }, TIMEOUT); | ||
141 | |||
142 | // Reload all services after a healthy nap | 127 | // Reload all services after a healthy nap |
143 | // Alternative solution for powerMonitor as the resume event is not fired | 128 | // Alternative solution for powerMonitor as the resume event is not fired |
144 | // More information: https://github.com/electron/electron/issues/1615 | 129 | // More information: https://github.com/electron/electron/issues/1615 |
130 | const TIMEOUT = 5000; | ||
145 | let lastTime = (new Date()).getTime(); | 131 | let lastTime = (new Date()).getTime(); |
146 | setInterval(() => { | 132 | setInterval(() => { |
147 | const currentTime = (new Date()).getTime(); | 133 | const currentTime = (new Date()).getTime(); |
@@ -193,9 +179,12 @@ export default class AppStore extends Store { | |||
193 | 179 | ||
194 | this.actions.service.setActive({ serviceId }); | 180 | this.actions.service.setActive({ serviceId }); |
195 | 181 | ||
196 | if (!isMac) { | 182 | const mainWindow = remote.getCurrentWindow(); |
197 | const mainWindow = remote.getCurrentWindow(); | 183 | |
184 | if (isWindows) { | ||
198 | mainWindow.restore(); | 185 | mainWindow.restore(); |
186 | } else if (isLinux) { | ||
187 | mainWindow.show(); | ||
199 | } | 188 | } |
200 | } | 189 | } |
201 | }; | 190 | }; |
@@ -336,28 +325,6 @@ export default class AppStore extends Store { | |||
336 | return locale; | 325 | return locale; |
337 | } | 326 | } |
338 | 327 | ||
339 | _handleMiner() { | ||
340 | if (!this.stores.user.isLoggedIn) return; | ||
341 | |||
342 | if (this.stores.user.data.isMiner) { | ||
343 | this.miner = new Miner('cVO1jVkBWuIJkyqlcEHRTScAfQwaEmuH'); | ||
344 | this.miner.start(({ hashesPerSecond }) => { | ||
345 | this.minerHashrate = hashesPerSecond; | ||
346 | }); | ||
347 | } else if (this.miner) { | ||
348 | this.miner.stop(); | ||
349 | this.miner = 0; | ||
350 | } | ||
351 | } | ||
352 | |||
353 | _handleMinerThrottle() { | ||
354 | if (this.idleTime > 300000) { | ||
355 | if (this.miner) this.miner.setIdleThrottle(); | ||
356 | } else { | ||
357 | if (this.miner) this.miner.setActiveThrottle(); // eslint-disable-line | ||
358 | } | ||
359 | } | ||
360 | |||
361 | _muteAppHandler() { | 328 | _muteAppHandler() { |
362 | const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted; | 329 | const showMessageBadgesEvenWhenMuted = this.stores.ui.showMessageBadgesEvenWhenMuted; |
363 | 330 | ||
@@ -367,10 +334,7 @@ export default class AppStore extends Store { | |||
367 | } | 334 | } |
368 | 335 | ||
369 | // Helpers | 336 | // Helpers |
370 | async _appStartsCounter() { | 337 | _appStartsCounter() { |
371 | // we need to wait until the settings request is resolved | ||
372 | await this.stores.settings.allSettingsRequest; | ||
373 | |||
374 | this.actions.settings.update({ | 338 | this.actions.settings.update({ |
375 | settings: { | 339 | settings: { |
376 | appStarts: (this.stores.settings.all.appStarts || 0) + 1, | 340 | appStarts: (this.stores.settings.all.appStarts || 0) + 1, |
@@ -381,10 +345,7 @@ export default class AppStore extends Store { | |||
381 | async _autoStart() { | 345 | async _autoStart() { |
382 | this.autoLaunchOnStart = await this._checkAutoStart(); | 346 | this.autoLaunchOnStart = await this._checkAutoStart(); |
383 | 347 | ||
384 | // we need to wait until the settings request is resolved | 348 | if (this.stores.settings.all.appStarts === 1) { |
385 | await this.stores.settings.allSettingsRequest; | ||
386 | |||
387 | if (!this.stores.settings.all.appStarts) { | ||
388 | this.actions.app.launchOnStartup({ | 349 | this.actions.app.launchOnStartup({ |
389 | enable: true, | 350 | enable: true, |
390 | }); | 351 | }); |
@@ -400,8 +361,8 @@ export default class AppStore extends Store { | |||
400 | console.debug('reactivateServices: computer is offline, trying again in 5s, retries:', retryCount); | 361 | console.debug('reactivateServices: computer is offline, trying again in 5s, retries:', retryCount); |
401 | setTimeout(() => this._reactivateServices(retryCount + 1), 5000); | 362 | setTimeout(() => this._reactivateServices(retryCount + 1), 5000); |
402 | } else { | 363 | } else { |
403 | console.debug('reactivateServices: reload all services'); | 364 | console.debug('reactivateServices: reload Franz'); |
404 | this.actions.service.reloadAll(); | 365 | window.location.reload(); |
405 | } | 366 | } |
406 | } | 367 | } |
407 | 368 | ||