aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores')
-rw-r--r--src/stores/AppStore.js61
-rw-r--r--src/stores/ServicesStore.js13
-rw-r--r--src/stores/SettingsStore.js26
-rw-r--r--src/stores/UserStore.js20
4 files changed, 43 insertions, 77 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';
3import moment from 'moment'; 3import moment from 'moment';
4import key from 'keymaster'; 4import key from 'keymaster';
5import { getDoNotDisturb } from '@meetfranz/electron-notification-state'; 5import { getDoNotDisturb } from '@meetfranz/electron-notification-state';
6import idleTimer from '@paulcbetts/system-idle-time';
7import AutoLaunch from 'auto-launch'; 6import AutoLaunch from 'auto-launch';
8import prettyBytes from 'pretty-bytes'; 7import prettyBytes from 'pretty-bytes';
9 8
10import Store from './lib/Store'; 9import Store from './lib/Store';
11import Request from './lib/Request'; 10import Request from './lib/Request';
12import { CHECK_INTERVAL, DEFAULT_APP_SETTINGS } from '../config'; 11import { CHECK_INTERVAL, DEFAULT_APP_SETTINGS } from '../config';
13import { isMac } from '../environment'; 12import { isMac, isLinux, isWindows } from '../environment';
14import locales from '../i18n/translations'; 13import locales from '../i18n/translations';
15import { gaEvent } from '../lib/analytics'; 14import { gaEvent } from '../lib/analytics';
16import Miner from '../lib/Miner';
17 15
18import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; 16import { 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
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js
index 7300a76c8..c38d0d9ee 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -187,13 +187,13 @@ export default class ServicesStore extends Store {
187 187
188 // patch custom icon deletion 188 // patch custom icon deletion
189 if (data.customIcon === 'delete') { 189 if (data.customIcon === 'delete') {
190 data.iconUrl = ''; 190 newData.iconUrl = '';
191 data.hasCustomUploadedIcon = false; 191 newData.hasCustomUploadedIcon = false;
192 } 192 }
193 193
194 // patch custom icon url 194 // patch custom icon url
195 if (data.customIconUrl) { 195 if (data.customIconUrl) {
196 data.iconUrl = data.customIconUrl; 196 newData.iconUrl = data.customIconUrl;
197 } 197 }
198 198
199 Object.assign(result.find(c => c.id === serviceId), newData); 199 Object.assign(result.find(c => c.id === serviceId), newData);
@@ -536,7 +536,6 @@ export default class ServicesStore extends Store {
536 536
537 // We can't just block this earlier, otherwise the mobx reaction won't be aware of the vars to watch in some cases 537 // We can't just block this earlier, otherwise the mobx reaction won't be aware of the vars to watch in some cases
538 if (showMessageBadgesEvenWhenMuted) { 538 if (showMessageBadgesEvenWhenMuted) {
539 console.log('set badge', unreadDirectMessageCount, unreadIndirectMessageCount);
540 this.actions.app.setBadge({ 539 this.actions.app.setBadge({
541 unreadDirectMessageCount, 540 unreadDirectMessageCount,
542 unreadIndirectMessageCount, 541 unreadIndirectMessageCount,
@@ -589,12 +588,16 @@ export default class ServicesStore extends Store {
589 const delay = 1000; 588 const delay = 1000;
590 589
591 if (service) { 590 if (service) {
591 if (service.timer !== null) {
592 clearTimeout(service.timer);
593 }
594
592 const loop = () => { 595 const loop = () => {
593 if (!service.webview) return; 596 if (!service.webview) return;
594 597
595 service.webview.send('poll'); 598 service.webview.send('poll');
596 599
597 setTimeout(loop, delay); 600 service.timer = setTimeout(loop, delay);
598 }; 601 };
599 602
600 loop(); 603 loop();
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js
index da99a720f..b7d803398 100644
--- a/src/stores/SettingsStore.js
+++ b/src/stores/SettingsStore.js
@@ -1,17 +1,12 @@
1import { ipcRenderer } from 'electron'; 1import { ipcRenderer } from 'electron';
2import { action, computed, observable, extendObservable } from 'mobx'; 2import { action, computed } from 'mobx';
3import localStorage from 'mobx-localstorage';
3 4
4import Store from './lib/Store'; 5import Store from './lib/Store';
5import Request from './lib/Request';
6import CachedRequest from './lib/CachedRequest';
7import { gaEvent } from '../lib/analytics'; 6import { gaEvent } from '../lib/analytics';
8import SettingsModel from '../models/Settings'; 7import SettingsModel from '../models/Settings';
9 8
10export default class SettingsStore extends Store { 9export default class SettingsStore extends Store {
11 @observable allSettingsRequest = new CachedRequest(this.api.local, 'getSettings');
12 @observable updateSettingsRequest = new Request(this.api.local, 'updateSettings');
13 @observable removeSettingsKeyRequest = new Request(this.api.local, 'removeKey');
14
15 constructor(...args) { 10 constructor(...args) {
16 super(...args); 11 super(...args);
17 12
@@ -21,20 +16,16 @@ export default class SettingsStore extends Store {
21 } 16 }
22 17
23 setup() { 18 setup() {
24 this.allSettingsRequest.execute();
25 this._shareSettingsWithMainProcess(); 19 this._shareSettingsWithMainProcess();
26 } 20 }
27 21
28 @computed get all() { 22 @computed get all() {
29 return new SettingsModel(this.allSettingsRequest.result); 23 return new SettingsModel(localStorage.getItem('app') || {});
30 } 24 }
31 25
32 @action async _update({ settings }) { 26 @action async _update({ settings }) {
33 await this.updateSettingsRequest.execute(settings)._promise; 27 const appSettings = this.all;
34 await this.allSettingsRequest.patch((result) => { 28 localStorage.setItem('app', Object.assign(appSettings, settings));
35 if (!result) return;
36 extendObservable(result, settings);
37 });
38 29
39 // We need a little hack to wait until everything is patched 30 // We need a little hack to wait until everything is patched
40 setTimeout(() => this._shareSettingsWithMainProcess(), 0); 31 setTimeout(() => this._shareSettingsWithMainProcess(), 0);
@@ -43,8 +34,11 @@ export default class SettingsStore extends Store {
43 } 34 }
44 35
45 @action async _remove({ key }) { 36 @action async _remove({ key }) {
46 await this.removeSettingsKeyRequest.execute(key); 37 const appSettings = this.all;
47 await this.allSettingsRequest.invalidate({ immediately: true }); 38 if (Object.hasOwnProperty.call(appSettings, key)) {
39 delete appSettings[key];
40 localStorage.setItem('app', appSettings);
41 }
48 42
49 this._shareSettingsWithMainProcess(); 43 this._shareSettingsWithMainProcess();
50 } 44 }
diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js
index 09000dcdb..7dbbd955b 100644
--- a/src/stores/UserStore.js
+++ b/src/stores/UserStore.js
@@ -1,7 +1,9 @@
1import { observable, computed, action } from 'mobx'; 1import { observable, computed, action } from 'mobx';
2import moment from 'moment'; 2import moment from 'moment';
3import jwt from 'jsonwebtoken'; 3import jwt from 'jsonwebtoken';
4import localStorage from 'mobx-localstorage';
4 5
6import { isDevMode } from '../environment';
5import Store from './lib/Store'; 7import Store from './lib/Store';
6import Request from './lib/Request'; 8import Request from './lib/Request';
7import CachedRequest from './lib/CachedRequest'; 9import CachedRequest from './lib/CachedRequest';
@@ -98,7 +100,7 @@ export default class UserStore extends Store {
98 100
99 // Data 101 // Data
100 @computed get isLoggedIn() { 102 @computed get isLoggedIn() {
101 return this.authToken !== null && this.authToken !== undefined; 103 return Boolean(localStorage.getItem('authToken'));
102 } 104 }
103 105
104 // @computed get isTokenValid() { 106 // @computed get isTokenValid() {
@@ -160,13 +162,17 @@ export default class UserStore extends Store {
160 gaEvent('User', 'retrievePassword'); 162 gaEvent('User', 'retrievePassword');
161 } 163 }
162 164
163 @action _invite({ invites }) { 165 @action async _invite({ invites }) {
164 const data = invites.filter(invite => invite.email !== ''); 166 const data = invites.filter(invite => invite.email !== '');
165 167
166 this.inviteRequest.execute(data); 168 const response = await this.inviteRequest.execute(data)._promise;
167 169
168 // we do not wait for a server response before redirecting the user 170 this.actionStatus = response.status || [];
169 this.stores.router.push('/'); 171
172 // we do not wait for a server response before redirecting the user ONLY DURING SIGNUP
173 if (this.stores.router.location.pathname.includes(this.INVITE_ROUTE)) {
174 this.stores.router.push('/');
175 }
170 176
171 gaEvent('User', 'inviteUsers'); 177 gaEvent('User', 'inviteUsers');
172 } 178 }
@@ -237,7 +243,9 @@ export default class UserStore extends Store {
237 && currentRoute.includes(this.BASE_ROUTE) 243 && currentRoute.includes(this.BASE_ROUTE)
238 && (this.hasCompletedSignup 244 && (this.hasCompletedSignup
239 || this.hasCompletedSignup === null)) { 245 || this.hasCompletedSignup === null)) {
240 this.stores.router.push('/'); 246 if (!isDevMode) {
247 this.stores.router.push('/');
248 }
241 } 249 }
242 }; 250 };
243 251