diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 5a6c12ee1..7e2be5e9f 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -124,15 +124,23 @@ export default class AppStore extends Store { this.stores.router.push(data.url); }); + const TIMEOUT = 5000; // Check system idle time every minute setInterval(() => { this.idleTime = idleTimer.getIdleTime(); - }, 60000); + }, TIMEOUT); // Reload all services after a healthy nap - powerMonitor.on('resume', () => { - setTimeout(window.location.reload, 5000); - }); + // Alternative solution for powerMonitor as the resume event is not fired + // More information: https://github.com/electron/electron/issues/1615 + let lastTime = (new Date()).getTime(); + setInterval(() => { + const currentTime = (new Date()).getTime(); + if (currentTime > (lastTime + TIMEOUT + 2000)) { + this._reactivateServices(); + } + lastTime = currentTime; + }, TIMEOUT); // Set active the next service key( @@ -357,6 +365,16 @@ export default class AppStore extends Store { return autoLauncher.isEnabled() || false; } + _reactivateServices(retryCount = 0) { + if (!this.isOnline) { + console.debug('reactivateServices: computer is offline, trying again in 5s, retries:', retryCount) + return setTimeout(() => this._reactivateServices(retryCount + 1), 5000); + } + + console.debug('reactivateServices: reload all services'); + this.actions.service.reloadAll(); + } + _systemDND() { const dnd = getDoNotDisturb(); if (dnd === this.stores.settings.all.isAppMuted || !this.isSystemMuteOverriden) {