Skip to content

Commit

Permalink
fix(App): Fix service reload after waking machine up
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Dec 24, 2017
1 parent b0ac4fc commit 531531e
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/stores/AppStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 531531e

Please sign in to comment.