Skip to content

Commit 7f11dff

Browse files
committed
fix(Services): Restore services after 10 minutes system suspension
1 parent e17b623 commit 7f11dff

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/stores/AppStore.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ import { sleep } from '../helpers/async-helpers';
2727

2828
const debug = require('debug')('Franz:AppStore');
2929

30-
const { app, systemPreferences, screen } = remote;
30+
const {
31+
app, systemPreferences, screen, powerMonitor,
32+
} = remote;
3133

3234
const mainWindow = remote.getCurrentWindow();
3335

@@ -55,6 +57,8 @@ export default class AppStore extends Store {
5557

5658
@observable isOnline = navigator.onLine;
5759

60+
@observable timeSuspensionStart;
61+
5862
@observable timeOfflineStart;
5963

6064
@observable updateStatus = null;
@@ -180,6 +184,27 @@ export default class AppStore extends Store {
180184
gaPage(pathname);
181185
});
182186

187+
powerMonitor.on('suspend', () => {
188+
debug('System suspended starting timer');
189+
190+
this.timeSuspensionStart = moment();
191+
});
192+
193+
powerMonitor.on('resume', () => {
194+
debug('System resumed, last suspended on', this.timeSuspensionStart.toString());
195+
196+
if (this.timeSuspensionStart.add(10, 'm').isBefore(moment())) {
197+
debug('Reloading services, user info and features');
198+
199+
this.actions.service.reloadAll();
200+
201+
this.stores.user.getUserInfoRequest.invalidate({ immediately: true });
202+
this.stores.features.featuresRequest.invalidate({ immediately: true });
203+
204+
statsEvent('resumed-app');
205+
}
206+
});
207+
183208
statsEvent('app-start');
184209
}
185210

0 commit comments

Comments
 (0)