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, 65 insertions, 40 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index bbb5e6305..6b5ca7c9a 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -1,6 +1,11 @@
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';
@@ -14,13 +19,20 @@ import Store from './lib/Store';
14import Request from './lib/Request'; 19import Request from './lib/Request';
15import { CHECK_INTERVAL } from '../config'; 20import { CHECK_INTERVAL } from '../config';
16import { 21import {
17 DEFAULT_APP_SETTINGS, isMac, ferdiVersion, electronVersion, osRelease, 22 DEFAULT_APP_SETTINGS,
23 isMac,
24 ferdiVersion,
25 electronVersion,
26 osRelease,
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,13 @@ 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(
311 path.join(app.getPath('userData'), 'window-state.json'),
312 ),
293 settings, 313 settings,
294 features: this.stores.features.features, 314 features: this.stores.features.features,
295 user: this.stores.user.data.id, 315 user: this.stores.user.data.id,
@@ -299,10 +319,7 @@ export default class AppStore extends Store {
299 319
300 // Actions 320 // Actions
301 @action _notify({ 321 @action _notify({
302 title, 322 title, options, notificationId, serviceId = null,
303 options,
304 notificationId,
305 serviceId = null,
306 }) { 323 }) {
307 if (this.stores.settings.all.app.isAppMuted) return; 324 if (this.stores.settings.all.app.isAppMuted) return;
308 325
@@ -339,15 +356,15 @@ export default class AppStore extends Store {
339 }; 356 };
340 } 357 }
341 358
342 @action _setBadge({ 359 @action _setBadge({ unreadDirectMessageCount, unreadIndirectMessageCount }) {
343 unreadDirectMessageCount,
344 unreadIndirectMessageCount,
345 }) {
346 let indicator = unreadDirectMessageCount; 360 let indicator = unreadDirectMessageCount;
347 361
348 if (indicator === 0 && unreadIndirectMessageCount !== 0) { 362 if (indicator === 0 && unreadIndirectMessageCount !== 0) {
349 indicator = '•'; 363 indicator = '•';
350 } else if (unreadDirectMessageCount === 0 && unreadIndirectMessageCount === 0) { 364 } else if (
365 unreadDirectMessageCount === 0
366 && unreadIndirectMessageCount === 0
367 ) {
351 indicator = 0; 368 indicator = 0;
352 } else { 369 } else {
353 indicator = parseInt(indicator, 10); 370 indicator = parseInt(indicator, 10);
@@ -358,9 +375,7 @@ export default class AppStore extends Store {
358 }); 375 });
359 } 376 }
360 377
361 @action _launchOnStartup({ 378 @action _launchOnStartup({ enable }) {
362 enable,
363 }) {
364 this.autoLaunchOnStart = enable; 379 this.autoLaunchOnStart = enable;
365 380
366 try { 381 try {
@@ -376,9 +391,7 @@ export default class AppStore extends Store {
376 } 391 }
377 } 392 }
378 393
379 @action _openExternalUrl({ 394 @action _openExternalUrl({ url }) {
380 url,
381 }) {
382 const parsedUrl = new URL(url); 395 const parsedUrl = new URL(url);
383 debug('open external url', parsedUrl); 396 debug('open external url', parsedUrl);
384 397
@@ -414,10 +427,7 @@ export default class AppStore extends Store {
414 this.healthCheckRequest.execute(); 427 this.healthCheckRequest.execute();
415 } 428 }
416 429
417 @action _muteApp({ 430 @action _muteApp({ isMuted, overrideSystemMute = true }) {
418 isMuted,
419 overrideSystemMute = true,
420 }) {
421 this.isSystemMuteOverridden = overrideSystemMute; 431 this.isSystemMuteOverridden = overrideSystemMute;
422 this.actions.settings.update({ 432 this.actions.settings.update({
423 type: 'app', 433 type: 'app',
@@ -437,16 +447,24 @@ export default class AppStore extends Store {
437 this.isClearingAllCache = true; 447 this.isClearingAllCache = true;
438 const clearAppCache = this.clearAppCacheRequest.execute(); 448 const clearAppCache = this.clearAppCacheRequest.execute();
439 const allServiceIds = await getServiceIdsFromPartitions(); 449 const allServiceIds = await getServiceIdsFromPartitions();
440 const allOrphanedServiceIds = allServiceIds.filter(id => !this.stores.services.all.find(s => id.replace('service-', '') === s.id)); 450 const allOrphanedServiceIds = allServiceIds.filter(
451 (id) => !this.stores.services.all.find(
452 (s) => id.replace('service-', '') === s.id,
453 ),
454 );
441 455
442 try { 456 try {
443 await Promise.all(allOrphanedServiceIds.map(id => removeServicePartitionDirectory(id))); 457 await Promise.all(
458 allOrphanedServiceIds.map((id) => removeServicePartitionDirectory(id)),
459 );
444 } catch (ex) { 460 } catch (ex) {
445 console.log('Error while deleting service partition directory - ', ex); 461 console.log('Error while deleting service partition directory - ', ex);
446 } 462 }
447 await Promise.all(this.stores.services.all.map(s => this.actions.service.clearCache({ 463 await Promise.all(
448 serviceId: s.id, 464 this.stores.services.all.map((s) => this.actions.service.clearCache({
449 }))); 465 serviceId: s.id,
466 })),
467 );
450 468
451 await clearAppCache._promise; 469 await clearAppCache._promise;
452 470
@@ -476,7 +494,11 @@ export default class AppStore extends Store {
476 locale = this.stores.user.data.locale; 494 locale = this.stores.user.data.locale;
477 } 495 }
478 496
479 if (locale && Object.prototype.hasOwnProperty.call(locales, locale) && locale !== this.locale) { 497 if (
498 locale
499 && Object.prototype.hasOwnProperty.call(locales, locale)
500 && locale !== this.locale
501 ) {
480 this.locale = locale; 502 this.locale = locale;
481 } else if (!locale) { 503 } else if (!locale) {
482 this.locale = this._getDefaultLocale(); 504 this.locale = this._getDefaultLocale();
@@ -553,7 +575,10 @@ export default class AppStore extends Store {
553 const dnd = await ipcRenderer.invoke('get-dnd'); 575 const dnd = await ipcRenderer.invoke('get-dnd');
554 debug('Do not disturb mode is', dnd); 576 debug('Do not disturb mode is', dnd);
555 // ipcRenderer.on('autoUpdate', (event, data) => { 577 // ipcRenderer.on('autoUpdate', (event, data) => {
556 if (dnd !== this.stores.settings.all.app.isAppMuted && !this.isSystemMuteOverridden) { 578 if (
579 dnd !== this.stores.settings.all.app.isAppMuted
580 && !this.isSystemMuteOverridden
581 ) {
557 this.actions.app.muteApp({ 582 this.actions.app.muteApp({
558 isMuted: dnd, 583 isMuted: dnd,
559 overrideSystemMute: false, 584 overrideSystemMute: false,