Skip to content

Commit 531531e

Browse files
committed
fix(App): Fix service reload after waking machine up
1 parent b0ac4fc commit 531531e

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/stores/AppStore.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,23 @@ export default class AppStore extends Store {
124124
this.stores.router.push(data.url);
125125
});
126126

127+
const TIMEOUT = 5000;
127128
// Check system idle time every minute
128129
setInterval(() => {
129130
this.idleTime = idleTimer.getIdleTime();
130-
}, 60000);
131+
}, TIMEOUT);
131132

132133
// Reload all services after a healthy nap
133-
powerMonitor.on('resume', () => {
134-
setTimeout(window.location.reload, 5000);
135-
});
134+
// Alternative solution for powerMonitor as the resume event is not fired
135+
// More information: https://github.com/electron/electron/issues/1615
136+
let lastTime = (new Date()).getTime();
137+
setInterval(() => {
138+
const currentTime = (new Date()).getTime();
139+
if (currentTime > (lastTime + TIMEOUT + 2000)) {
140+
this._reactivateServices();
141+
}
142+
lastTime = currentTime;
143+
}, TIMEOUT);
136144

137145
// Set active the next service
138146
key(
@@ -357,6 +365,16 @@ export default class AppStore extends Store {
357365
return autoLauncher.isEnabled() || false;
358366
}
359367

368+
_reactivateServices(retryCount = 0) {
369+
if (!this.isOnline) {
370+
console.debug('reactivateServices: computer is offline, trying again in 5s, retries:', retryCount)
371+
return setTimeout(() => this._reactivateServices(retryCount + 1), 5000);
372+
}
373+
374+
console.debug('reactivateServices: reload all services');
375+
this.actions.service.reloadAll();
376+
}
377+
360378
_systemDND() {
361379
const dnd = getDoNotDisturb();
362380
if (dnd === this.stores.settings.all.isAppMuted || !this.isSystemMuteOverriden) {

0 commit comments

Comments
 (0)