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