aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/AppStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/AppStore.js')
-rw-r--r--src/stores/AppStore.js57
1 files changed, 56 insertions, 1 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index 40d98cf42..6ce79f2e2 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -26,7 +26,9 @@ import { sleep } from '../helpers/async-helpers';
26 26
27const debug = require('debug')('Ferdi:AppStore'); 27const debug = require('debug')('Ferdi:AppStore');
28 28
29const { app, systemPreferences, screen } = remote; 29const {
30 app, systemPreferences, screen, powerMonitor,
31} = remote;
30 32
31const mainWindow = remote.getCurrentWindow(); 33const mainWindow = remote.getCurrentWindow();
32 34
@@ -35,6 +37,8 @@ const autoLauncher = new AutoLaunch({
35 name: 'Ferdi', 37 name: 'Ferdi',
36}); 38});
37 39
40const CATALINA_NOTIFICATION_HACK_KEY = '_temp_askedForCatalinaNotificationPermissions';
41
38export default class AppStore extends Store { 42export default class AppStore extends Store {
39 updateStatusTypes = { 43 updateStatusTypes = {
40 CHECKING: 'CHECKING', 44 CHECKING: 'CHECKING',
@@ -55,6 +59,8 @@ export default class AppStore extends Store {
55 @observable isOnline = navigator.onLine; 59 @observable isOnline = navigator.onLine;
56 60
57 @observable authRequestFailed = false; 61 @observable authRequestFailed = false;
62
63 @observable timeSuspensionStart;
58 64
59 @observable timeOfflineStart; 65 @observable timeOfflineStart;
60 66
@@ -76,6 +82,8 @@ export default class AppStore extends Store {
76 82
77 dictionaries = []; 83 dictionaries = [];
78 84
85 fetchDataInterval = null;
86
79 constructor(...args) { 87 constructor(...args) {
80 super(...args); 88 super(...args);
81 89
@@ -97,6 +105,7 @@ export default class AppStore extends Store {
97 this._setLocale.bind(this), 105 this._setLocale.bind(this),
98 this._muteAppHandler.bind(this), 106 this._muteAppHandler.bind(this),
99 this._handleFullScreen.bind(this), 107 this._handleFullScreen.bind(this),
108 this._handleLogout.bind(this),
100 ]); 109 ]);
101 } 110 }
102 111
@@ -124,6 +133,12 @@ export default class AppStore extends Store {
124 this._systemDND(); 133 this._systemDND();
125 setInterval(() => this._systemDND(), ms('5s')); 134 setInterval(() => this._systemDND(), ms('5s'));
126 135
136 this.fetchDataInterval = setInterval(() => {
137 this.stores.user.getUserInfoRequest.invalidate({ immediately: true });
138 this.stores.features.featuresRequest.invalidate({ immediately: true });
139 this.stores.news.latestNewsRequest.invalidate({ immediately: true });
140 }, ms('10m'));
141
127 // Check for updates once every 4 hours 142 // Check for updates once every 4 hours
128 setInterval(() => this._checkForUpdates(), CHECK_INTERVAL); 143 setInterval(() => this._checkForUpdates(), CHECK_INTERVAL);
129 // Check for an update in 30s (need a delay to prevent Squirrel Installer lock file issues) 144 // Check for an update in 30s (need a delay to prevent Squirrel Installer lock file issues)
@@ -175,6 +190,40 @@ export default class AppStore extends Store {
175 190
176 debug('Window is visible/focused', isVisible); 191 debug('Window is visible/focused', isVisible);
177 }); 192 });
193
194 powerMonitor.on('suspend', () => {
195 debug('System suspended starting timer');
196
197 this.timeSuspensionStart = moment();
198 });
199
200 powerMonitor.on('resume', () => {
201 debug('System resumed, last suspended on', this.timeSuspensionStart.toString());
202
203 if (this.timeSuspensionStart.add(10, 'm').isBefore(moment())) {
204 debug('Reloading services, user info and features');
205
206 setTimeout(() => {
207 window.location.reload();
208 }, ms('2s'));
209
210 statsEvent('resumed-app');
211 }
212 });
213
214 // macOS catalina notifications hack
215 // notifications got stuck after upgrade but forcing a notification
216 // via `new Notification` triggered the permission request
217 if (isMac && !localStorage.getItem(CATALINA_NOTIFICATION_HACK_KEY)) {
218 // eslint-disable-next-line no-new
219 new window.Notification('Welcome to Franz 5', {
220 body: 'Have a wonderful day & happy messaging.',
221 });
222
223 localStorage.setItem(CATALINA_NOTIFICATION_HACK_KEY, true);
224 }
225
226 statsEvent('app-start');
178 } 227 }
179 228
180 @computed get cacheSize() { 229 @computed get cacheSize() {
@@ -383,6 +432,12 @@ export default class AppStore extends Store {
383 } 432 }
384 } 433 }
385 434
435 _handleLogout() {
436 if (!this.stores.user.isLoggedIn) {
437 clearInterval(this.fetchDataInterval);
438 }
439 }
440
386 // Helpers 441 // Helpers
387 _appStartsCounter() { 442 _appStartsCounter() {
388 this.actions.settings.update({ 443 this.actions.settings.update({