Skip to content
Permalink
Browse files
fix(Services): Restore services after 10 minutes system suspension
  • Loading branch information
adlk committed Oct 8, 2019
1 parent e17b623 commit 7f11dff0588c975bf8dec6c98799ba7f92a5a9cc
Showing with 26 additions and 1 deletion.
  1. +26 −1 src/stores/AppStore.js
@@ -27,7 +27,9 @@ import { sleep } from '../helpers/async-helpers';

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

const { app, systemPreferences, screen } = remote;
const {
app, systemPreferences, screen, powerMonitor,
} = remote;

const mainWindow = remote.getCurrentWindow();

@@ -55,6 +57,8 @@ export default class AppStore extends Store {
@observable isOnline = navigator.onLine;
@observable timeSuspensionStart;
@observable timeOfflineStart;
@observable updateStatus = null;
@@ -180,6 +184,27 @@ export default class AppStore extends Store {
gaPage(pathname);
});
powerMonitor.on('suspend', () => {
debug('System suspended starting timer');
this.timeSuspensionStart = moment();
});
powerMonitor.on('resume', () => {
debug('System resumed, last suspended on', this.timeSuspensionStart.toString());
if (this.timeSuspensionStart.add(10, 'm').isBefore(moment())) {
debug('Reloading services, user info and features');
this.actions.service.reloadAll();
this.stores.user.getUserInfoRequest.invalidate({ immediately: true });
this.stores.features.featuresRequest.invalidate({ immediately: true });
statsEvent('resumed-app');
}
});
statsEvent('app-start');
}

0 comments on commit 7f11dff

Please sign in to comment.