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.js62
1 files changed, 30 insertions, 32 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index 71213774d..9c8cce679 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -8,7 +8,7 @@ import {
8 process as remoteProcess, 8 process as remoteProcess,
9} from '@electron/remote'; 9} from '@electron/remote';
10import { action, computed, observable } from 'mobx'; 10import { action, computed, observable } from 'mobx';
11import dayjs from 'dayjs'; 11import moment from 'moment';
12import AutoLaunch from 'auto-launch'; 12import AutoLaunch from 'auto-launch';
13import ms from 'ms'; 13import ms from 'ms';
14import { URL } from 'url'; 14import { URL } from 'url';
@@ -48,8 +48,7 @@ const autoLauncher = new AutoLaunch({
48 path: executablePath, 48 path: executablePath,
49}); 49});
50 50
51const CATALINA_NOTIFICATION_HACK_KEY = 51const CATALINA_NOTIFICATION_HACK_KEY = '_temp_askedForCatalinaNotificationPermissions';
52 '_temp_askedForCatalinaNotificationPermissions';
53 52
54export default class AppStore extends Store { 53export default class AppStore extends Store {
55 updateStatusTypes = { 54 updateStatusTypes = {
@@ -75,7 +74,7 @@ export default class AppStore extends Store {
75 74
76 @observable authRequestFailed = false; 75 @observable authRequestFailed = false;
77 76
78 @observable timeSuspensionStart = dayjs(); 77 @observable timeSuspensionStart = moment();
79 78
80 @observable timeOfflineStart; 79 @observable timeOfflineStart;
81 80
@@ -229,7 +228,7 @@ export default class AppStore extends Store {
229 powerMonitor.on('suspend', () => { 228 powerMonitor.on('suspend', () => {
230 debug('System suspended starting timer'); 229 debug('System suspended starting timer');
231 230
232 this.timeSuspensionStart = dayjs(); 231 this.timeSuspensionStart = moment();
233 }); 232 });
234 233
235 powerMonitor.on('resume', () => { 234 powerMonitor.on('resume', () => {
@@ -237,8 +236,8 @@ export default class AppStore extends Store {
237 this.actions.service.resetLastPollTimer(); 236 this.actions.service.resetLastPollTimer();
238 237
239 if ( 238 if (
240 this.timeSuspensionStart.add(10, 'm').isBefore(dayjs()) && 239 this.timeSuspensionStart.add(10, 'm').isBefore(moment())
241 this.stores.settings.app.get('reloadAfterResume') 240 && this.stores.settings.app.get('reloadAfterResume')
242 ) { 241 ) {
243 debug('Reloading services, user info and features'); 242 debug('Reloading services, user info and features');
244 243
@@ -284,15 +283,15 @@ export default class AppStore extends Store {
284 ferdi: { 283 ferdi: {
285 version: ferdiVersion, 284 version: ferdiVersion,
286 electron: electronVersion, 285 electron: electronVersion,
287 installedRecipes: this.stores.recipes.all.map(recipe => ({ 286 installedRecipes: this.stores.recipes.all.map((recipe) => ({
288 id: recipe.id, 287 id: recipe.id,
289 version: recipe.version, 288 version: recipe.version,
290 })), 289 })),
291 devRecipes: this.stores.recipePreviews.dev.map(recipe => ({ 290 devRecipes: this.stores.recipePreviews.dev.map((recipe) => ({
292 id: recipe.id, 291 id: recipe.id,
293 version: recipe.version, 292 version: recipe.version,
294 })), 293 })),
295 services: this.stores.services.all.map(service => ({ 294 services: this.stores.services.all.map((service) => ({
296 id: service.id, 295 id: service.id,
297 recipe: service.recipe.id, 296 recipe: service.recipe.id,
298 isAttached: service.isAttached, 297 isAttached: service.isAttached,
@@ -303,7 +302,7 @@ export default class AppStore extends Store {
303 isDarkModeEnabled: service.isDarkModeEnabled, 302 isDarkModeEnabled: service.isDarkModeEnabled,
304 })), 303 })),
305 messages: this.stores.globalError.messages, 304 messages: this.stores.globalError.messages,
306 workspaces: this.stores.workspaces.workspaces.map(workspace => ({ 305 workspaces: this.stores.workspaces.workspaces.map((workspace) => ({
307 id: workspace.id, 306 id: workspace.id,
308 services: workspace.services, 307 services: workspace.services,
309 })), 308 })),
@@ -316,7 +315,9 @@ export default class AppStore extends Store {
316 } 315 }
317 316
318 // Actions 317 // Actions
319 @action _notify({ title, options, notificationId, serviceId = null }) { 318 @action _notify({
319 title, options, notificationId, serviceId = null,
320 }) {
320 if (this.stores.settings.all.app.isAppMuted) return; 321 if (this.stores.settings.all.app.isAppMuted) return;
321 322
322 // TODO: is there a simple way to use blobs for notifications without storing them on disk? 323 // TODO: is there a simple way to use blobs for notifications without storing them on disk?
@@ -358,8 +359,8 @@ export default class AppStore extends Store {
358 if (indicator === 0 && unreadIndirectMessageCount !== 0) { 359 if (indicator === 0 && unreadIndirectMessageCount !== 0) {
359 indicator = '•'; 360 indicator = '•';
360 } else if ( 361 } else if (
361 unreadDirectMessageCount === 0 && 362 unreadDirectMessageCount === 0
362 unreadIndirectMessageCount === 0 363 && unreadIndirectMessageCount === 0
363 ) { 364 ) {
364 indicator = 0; 365 indicator = 0;
365 } else { 366 } else {
@@ -440,25 +441,22 @@ export default class AppStore extends Store {
440 const clearAppCache = this.clearAppCacheRequest.execute(); 441 const clearAppCache = this.clearAppCacheRequest.execute();
441 const allServiceIds = await getServiceIdsFromPartitions(); 442 const allServiceIds = await getServiceIdsFromPartitions();
442 const allOrphanedServiceIds = allServiceIds.filter( 443 const allOrphanedServiceIds = allServiceIds.filter(
443 id => 444 (id) => !this.stores.services.all.find(
444 !this.stores.services.all.find( 445 (s) => id.replace('service-', '') === s.id,
445 s => id.replace('service-', '') === s.id, 446 ),
446 ),
447 ); 447 );
448 448
449 try { 449 try {
450 await Promise.all( 450 await Promise.all(
451 allOrphanedServiceIds.map(id => removeServicePartitionDirectory(id)), 451 allOrphanedServiceIds.map((id) => removeServicePartitionDirectory(id)),
452 ); 452 );
453 } catch (ex) { 453 } catch (ex) {
454 console.log('Error while deleting service partition directory - ', ex); 454 console.log('Error while deleting service partition directory - ', ex);
455 } 455 }
456 await Promise.all( 456 await Promise.all(
457 this.stores.services.all.map(s => 457 this.stores.services.all.map((s) => this.actions.service.clearCache({
458 this.actions.service.clearCache({ 458 serviceId: s.id,
459 serviceId: s.id, 459 })),
460 }),
461 ),
462 ); 460 );
463 461
464 await clearAppCache._promise; 462 await clearAppCache._promise;
@@ -473,9 +471,9 @@ export default class AppStore extends Store {
473 // Reactions 471 // Reactions
474 _offlineCheck() { 472 _offlineCheck() {
475 if (!this.isOnline) { 473 if (!this.isOnline) {
476 this.timeOfflineStart = dayjs(); 474 this.timeOfflineStart = moment();
477 } else { 475 } else {
478 const deltaTime = dayjs().diff(this.timeOfflineStart); 476 const deltaTime = moment().diff(this.timeOfflineStart);
479 477
480 if (deltaTime > ms('30m')) { 478 if (deltaTime > ms('30m')) {
481 this.actions.service.reloadAll(); 479 this.actions.service.reloadAll();
@@ -490,16 +488,16 @@ export default class AppStore extends Store {
490 } 488 }
491 489
492 if ( 490 if (
493 locale && 491 locale
494 Object.prototype.hasOwnProperty.call(locales, locale) && 492 && Object.prototype.hasOwnProperty.call(locales, locale)
495 locale !== this.locale 493 && locale !== this.locale
496 ) { 494 ) {
497 this.locale = locale; 495 this.locale = locale;
498 } else if (!locale) { 496 } else if (!locale) {
499 this.locale = this._getDefaultLocale(); 497 this.locale = this._getDefaultLocale();
500 } 498 }
501 499
502 dayjs.locale(this.locale); 500 moment.locale(this.locale);
503 501
504 debug(`Set locale to "${this.locale}"`); 502 debug(`Set locale to "${this.locale}"`);
505 } 503 }
@@ -571,8 +569,8 @@ export default class AppStore extends Store {
571 debug('Do not disturb mode is', dnd); 569 debug('Do not disturb mode is', dnd);
572 // ipcRenderer.on('autoUpdate', (event, data) => { 570 // ipcRenderer.on('autoUpdate', (event, data) => {
573 if ( 571 if (
574 dnd !== this.stores.settings.all.app.isAppMuted && 572 dnd !== this.stores.settings.all.app.isAppMuted
575 !this.isSystemMuteOverridden 573 && !this.isSystemMuteOverridden
576 ) { 574 ) {
577 this.actions.app.muteApp({ 575 this.actions.app.muteApp({
578 isMuted: dnd, 576 isMuted: dnd,