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.js105
1 files changed, 64 insertions, 41 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index bbb5e6305..1d706f1ef 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -1,26 +1,38 @@
1import { ipcRenderer, shell } from 'electron'; 1import { ipcRenderer, shell } from 'electron';
2import { 2import {
3 app, screen, powerMonitor, nativeTheme, getCurrentWindow, process as remoteProcess, 3 app,
4 screen,
5 powerMonitor,
6 nativeTheme,
7 getCurrentWindow,
8 process as remoteProcess,
4} from '@electron/remote'; 9} from '@electron/remote';
5import { action, computed, observable } from 'mobx'; 10import { action, computed, observable } from 'mobx';
6import moment from 'moment'; 11import moment from 'moment';
7import AutoLaunch from 'auto-launch'; 12import AutoLaunch from 'auto-launch';
8import ms from 'ms'; 13import ms from 'ms';
9import { URL } from 'url'; 14import { URL } from 'url';
10import path from 'path';
11import { readJsonSync } from 'fs-extra'; 15import { readJsonSync } from 'fs-extra';
12 16
13import Store from './lib/Store'; 17import Store from './lib/Store';
14import Request from './lib/Request'; 18import Request from './lib/Request';
15import { CHECK_INTERVAL } from '../config'; 19import { CHECK_INTERVAL } from '../config';
16import { 20import {
17 DEFAULT_APP_SETTINGS, isMac, ferdiVersion, electronVersion, osRelease, 21 DEFAULT_APP_SETTINGS,
22 isMac,
23 ferdiVersion,
24 electronVersion,
25 osRelease,
26 userDataPath,
18} from '../environment'; 27} from '../environment';
19import locales from '../i18n/translations'; 28import locales from '../i18n/translations';
20import { onVisibilityChange } from '../helpers/visibility-helper'; 29import { onVisibilityChange } from '../helpers/visibility-helper';
21import { getLocale } from '../helpers/i18n-helpers'; 30import { getLocale } from '../helpers/i18n-helpers';
22 31
23import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; 32import {
33 getServiceIdsFromPartitions,
34 removeServicePartitionDirectory,
35} from '../helpers/service-helpers';
24import { isValidExternalURL } from '../helpers/url-helpers'; 36import { isValidExternalURL } from '../helpers/url-helpers';
25import { sleep } from '../helpers/async-helpers'; 37import { sleep } from '../helpers/async-helpers';
26 38
@@ -49,7 +61,10 @@ export default class AppStore extends Store {
49 61
50 @observable healthCheckRequest = new Request(this.api.app, 'health'); 62 @observable healthCheckRequest = new Request(this.api.app, 'health');
51 63
52 @observable getAppCacheSizeRequest = new Request(this.api.local, 'getAppCacheSize'); 64 @observable getAppCacheSizeRequest = new Request(
65 this.api.local,
66 'getAppCacheSize',
67 );
53 68
54 @observable clearAppCacheRequest = new Request(this.api.local, 'clearCache'); 69 @observable clearAppCacheRequest = new Request(this.api.local, 'clearCache');
55 70
@@ -93,7 +108,9 @@ export default class AppStore extends Store {
93 this.actions.app.openExternalUrl.listen(this._openExternalUrl.bind(this)); 108 this.actions.app.openExternalUrl.listen(this._openExternalUrl.bind(this));
94 this.actions.app.checkForUpdates.listen(this._checkForUpdates.bind(this)); 109 this.actions.app.checkForUpdates.listen(this._checkForUpdates.bind(this));
95 this.actions.app.installUpdate.listen(this._installUpdate.bind(this)); 110 this.actions.app.installUpdate.listen(this._installUpdate.bind(this));
96 this.actions.app.resetUpdateStatus.listen(this._resetUpdateStatus.bind(this)); 111 this.actions.app.resetUpdateStatus.listen(
112 this._resetUpdateStatus.bind(this),
113 );
97 this.actions.app.healthCheck.listen(this._healthCheck.bind(this)); 114 this.actions.app.healthCheck.listen(this._healthCheck.bind(this));
98 this.actions.app.muteApp.listen(this._muteApp.bind(this)); 115 this.actions.app.muteApp.listen(this._muteApp.bind(this));
99 this.actions.app.toggleMuteApp.listen(this._toggleMuteApp.bind(this)); 116 this.actions.app.toggleMuteApp.listen(this._toggleMuteApp.bind(this));
@@ -183,9 +200,7 @@ export default class AppStore extends Store {
183 // Handle deep linking (ferdi://) 200 // Handle deep linking (ferdi://)
184 ipcRenderer.on('navigateFromDeepLink', (event, data) => { 201 ipcRenderer.on('navigateFromDeepLink', (event, data) => {
185 debug('Navigate from deep link', data); 202 debug('Navigate from deep link', data);
186 let { 203 let { url } = data;
187 url,
188 } = data;
189 if (!url) return; 204 if (!url) return;
190 205
191 url = url.replace(/\/$/, ''); 206 url = url.replace(/\/$/, '');
@@ -221,7 +236,10 @@ export default class AppStore extends Store {
221 debug('System resumed, last suspended on', this.timeSuspensionStart); 236 debug('System resumed, last suspended on', this.timeSuspensionStart);
222 this.actions.service.resetLastPollTimer(); 237 this.actions.service.resetLastPollTimer();
223 238
224 if (this.timeSuspensionStart.add(10, 'm').isBefore(moment()) && this.stores.settings.app.get('reloadAfterResume')) { 239 if (
240 this.timeSuspensionStart.add(10, 'm').isBefore(moment())
241 && this.stores.settings.app.get('reloadAfterResume')
242 ) {
225 debug('Reloading services, user info and features'); 243 debug('Reloading services, user info and features');
226 244
227 setInterval(() => { 245 setInterval(() => {
@@ -266,15 +284,15 @@ export default class AppStore extends Store {
266 ferdi: { 284 ferdi: {
267 version: ferdiVersion, 285 version: ferdiVersion,
268 electron: electronVersion, 286 electron: electronVersion,
269 installedRecipes: this.stores.recipes.all.map(recipe => ({ 287 installedRecipes: this.stores.recipes.all.map((recipe) => ({
270 id: recipe.id, 288 id: recipe.id,
271 version: recipe.version, 289 version: recipe.version,
272 })), 290 })),
273 devRecipes: this.stores.recipePreviews.dev.map(recipe => ({ 291 devRecipes: this.stores.recipePreviews.dev.map((recipe) => ({
274 id: recipe.id, 292 id: recipe.id,
275 version: recipe.version, 293 version: recipe.version,
276 })), 294 })),
277 services: this.stores.services.all.map(service => ({ 295 services: this.stores.services.all.map((service) => ({
278 id: service.id, 296 id: service.id,
279 recipe: service.recipe.id, 297 recipe: service.recipe.id,
280 isAttached: service.isAttached, 298 isAttached: service.isAttached,
@@ -285,11 +303,11 @@ export default class AppStore extends Store {
285 isDarkModeEnabled: service.isDarkModeEnabled, 303 isDarkModeEnabled: service.isDarkModeEnabled,
286 })), 304 })),
287 messages: this.stores.globalError.messages, 305 messages: this.stores.globalError.messages,
288 workspaces: this.stores.workspaces.workspaces.map(workspace => ({ 306 workspaces: this.stores.workspaces.workspaces.map((workspace) => ({
289 id: workspace.id, 307 id: workspace.id,
290 services: workspace.services, 308 services: workspace.services,
291 })), 309 })),
292 windowSettings: readJsonSync(path.join(app.getPath('userData'), 'window-state.json')), 310 windowSettings: readJsonSync(userDataPath('window-state.json')),
293 settings, 311 settings,
294 features: this.stores.features.features, 312 features: this.stores.features.features,
295 user: this.stores.user.data.id, 313 user: this.stores.user.data.id,
@@ -299,10 +317,7 @@ export default class AppStore extends Store {
299 317
300 // Actions 318 // Actions
301 @action _notify({ 319 @action _notify({
302 title, 320 title, options, notificationId, serviceId = null,
303 options,
304 notificationId,
305 serviceId = null,
306 }) { 321 }) {
307 if (this.stores.settings.all.app.isAppMuted) return; 322 if (this.stores.settings.all.app.isAppMuted) return;
308 323
@@ -339,15 +354,15 @@ export default class AppStore extends Store {
339 }; 354 };
340 } 355 }
341 356
342 @action _setBadge({ 357 @action _setBadge({ unreadDirectMessageCount, unreadIndirectMessageCount }) {
343 unreadDirectMessageCount,
344 unreadIndirectMessageCount,
345 }) {
346 let indicator = unreadDirectMessageCount; 358 let indicator = unreadDirectMessageCount;
347 359
348 if (indicator === 0 && unreadIndirectMessageCount !== 0) { 360 if (indicator === 0 && unreadIndirectMessageCount !== 0) {
349 indicator = '•'; 361 indicator = '•';
350 } else if (unreadDirectMessageCount === 0 && unreadIndirectMessageCount === 0) { 362 } else if (
363 unreadDirectMessageCount === 0
364 && unreadIndirectMessageCount === 0
365 ) {
351 indicator = 0; 366 indicator = 0;
352 } else { 367 } else {
353 indicator = parseInt(indicator, 10); 368 indicator = parseInt(indicator, 10);
@@ -358,9 +373,7 @@ export default class AppStore extends Store {
358 }); 373 });
359 } 374 }
360 375
361 @action _launchOnStartup({ 376 @action _launchOnStartup({ enable }) {
362 enable,
363 }) {
364 this.autoLaunchOnStart = enable; 377 this.autoLaunchOnStart = enable;
365 378
366 try { 379 try {
@@ -376,9 +389,7 @@ export default class AppStore extends Store {
376 } 389 }
377 } 390 }
378 391
379 @action _openExternalUrl({ 392 @action _openExternalUrl({ url }) {
380 url,
381 }) {
382 const parsedUrl = new URL(url); 393 const parsedUrl = new URL(url);
383 debug('open external url', parsedUrl); 394 debug('open external url', parsedUrl);
384 395
@@ -414,10 +425,7 @@ export default class AppStore extends Store {
414 this.healthCheckRequest.execute(); 425 this.healthCheckRequest.execute();
415 } 426 }
416 427
417 @action _muteApp({ 428 @action _muteApp({ isMuted, overrideSystemMute = true }) {
418 isMuted,
419 overrideSystemMute = true,
420 }) {
421 this.isSystemMuteOverridden = overrideSystemMute; 429 this.isSystemMuteOverridden = overrideSystemMute;
422 this.actions.settings.update({ 430 this.actions.settings.update({
423 type: 'app', 431 type: 'app',
@@ -437,16 +445,24 @@ export default class AppStore extends Store {
437 this.isClearingAllCache = true; 445 this.isClearingAllCache = true;
438 const clearAppCache = this.clearAppCacheRequest.execute(); 446 const clearAppCache = this.clearAppCacheRequest.execute();
439 const allServiceIds = await getServiceIdsFromPartitions(); 447 const allServiceIds = await getServiceIdsFromPartitions();
440 const allOrphanedServiceIds = allServiceIds.filter(id => !this.stores.services.all.find(s => id.replace('service-', '') === s.id)); 448 const allOrphanedServiceIds = allServiceIds.filter(
449 (id) => !this.stores.services.all.find(
450 (s) => id.replace('service-', '') === s.id,
451 ),
452 );
441 453
442 try { 454 try {
443 await Promise.all(allOrphanedServiceIds.map(id => removeServicePartitionDirectory(id))); 455 await Promise.all(
456 allOrphanedServiceIds.map((id) => removeServicePartitionDirectory(id)),
457 );
444 } catch (ex) { 458 } catch (ex) {
445 console.log('Error while deleting service partition directory - ', ex); 459 console.log('Error while deleting service partition directory - ', ex);
446 } 460 }
447 await Promise.all(this.stores.services.all.map(s => this.actions.service.clearCache({ 461 await Promise.all(
448 serviceId: s.id, 462 this.stores.services.all.map((s) => this.actions.service.clearCache({
449 }))); 463 serviceId: s.id,
464 })),
465 );
450 466
451 await clearAppCache._promise; 467 await clearAppCache._promise;
452 468
@@ -476,7 +492,11 @@ export default class AppStore extends Store {
476 locale = this.stores.user.data.locale; 492 locale = this.stores.user.data.locale;
477 } 493 }
478 494
479 if (locale && Object.prototype.hasOwnProperty.call(locales, locale) && locale !== this.locale) { 495 if (
496 locale
497 && Object.prototype.hasOwnProperty.call(locales, locale)
498 && locale !== this.locale
499 ) {
480 this.locale = locale; 500 this.locale = locale;
481 } else if (!locale) { 501 } else if (!locale) {
482 this.locale = this._getDefaultLocale(); 502 this.locale = this._getDefaultLocale();
@@ -553,7 +573,10 @@ export default class AppStore extends Store {
553 const dnd = await ipcRenderer.invoke('get-dnd'); 573 const dnd = await ipcRenderer.invoke('get-dnd');
554 debug('Do not disturb mode is', dnd); 574 debug('Do not disturb mode is', dnd);
555 // ipcRenderer.on('autoUpdate', (event, data) => { 575 // ipcRenderer.on('autoUpdate', (event, data) => {
556 if (dnd !== this.stores.settings.all.app.isAppMuted && !this.isSystemMuteOverridden) { 576 if (
577 dnd !== this.stores.settings.all.app.isAppMuted
578 && !this.isSystemMuteOverridden
579 ) {
557 this.actions.app.muteApp({ 580 this.actions.app.muteApp({
558 isMuted: dnd, 581 isMuted: dnd,
559 overrideSystemMute: false, 582 overrideSystemMute: false,