aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/AppStore.js
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2019-10-08 19:35:27 +0200
committerLibravatar Stefan Malzner <stefan@adlk.io>2019-10-08 19:35:27 +0200
commit7f11dff0588c975bf8dec6c98799ba7f92a5a9cc (patch)
tree166b9b052ddf3cddcec428342bc2bf1ece9490d4 /src/stores/AppStore.js
parentUpdate CHANGELOG.md (diff)
downloadferdium-app-7f11dff0588c975bf8dec6c98799ba7f92a5a9cc.tar.gz
ferdium-app-7f11dff0588c975bf8dec6c98799ba7f92a5a9cc.tar.zst
ferdium-app-7f11dff0588c975bf8dec6c98799ba7f92a5a9cc.zip
fix(Services): Restore services after 10 minutes system suspension
Diffstat (limited to 'src/stores/AppStore.js')
-rw-r--r--src/stores/AppStore.js27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index 0398b7533..87a661b2a 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -27,7 +27,9 @@ import { sleep } from '../helpers/async-helpers';
27 27
28const debug = require('debug')('Franz:AppStore'); 28const debug = require('debug')('Franz:AppStore');
29 29
30const { app, systemPreferences, screen } = remote; 30const {
31 app, systemPreferences, screen, powerMonitor,
32} = remote;
31 33
32const mainWindow = remote.getCurrentWindow(); 34const mainWindow = remote.getCurrentWindow();
33 35
@@ -55,6 +57,8 @@ export default class AppStore extends Store {
55 57
56 @observable isOnline = navigator.onLine; 58 @observable isOnline = navigator.onLine;
57 59
60 @observable timeSuspensionStart;
61
58 @observable timeOfflineStart; 62 @observable timeOfflineStart;
59 63
60 @observable updateStatus = null; 64 @observable updateStatus = null;
@@ -180,6 +184,27 @@ export default class AppStore extends Store {
180 gaPage(pathname); 184 gaPage(pathname);
181 }); 185 });
182 186
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
183 statsEvent('app-start'); 208 statsEvent('app-start');
184 } 209 }
185 210