diff options
Diffstat (limited to 'src/stores/AppStore.js')
-rw-r--r-- | src/stores/AppStore.js | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 40d98cf42..c6724c20f 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js | |||
@@ -26,7 +26,9 @@ import { sleep } from '../helpers/async-helpers'; | |||
26 | 26 | ||
27 | const debug = require('debug')('Ferdi:AppStore'); | 27 | const debug = require('debug')('Ferdi:AppStore'); |
28 | 28 | ||
29 | const { app, systemPreferences, screen } = remote; | 29 | const { |
30 | app, systemPreferences, screen, powerMonitor, | ||
31 | } = remote; | ||
30 | 32 | ||
31 | const mainWindow = remote.getCurrentWindow(); | 33 | const mainWindow = remote.getCurrentWindow(); |
32 | 34 | ||
@@ -35,6 +37,8 @@ const autoLauncher = new AutoLaunch({ | |||
35 | name: 'Ferdi', | 37 | name: 'Ferdi', |
36 | }); | 38 | }); |
37 | 39 | ||
40 | const CATALINA_NOTIFICATION_HACK_KEY = '_temp_askedForCatalinaNotificationPermissions'; | ||
41 | |||
38 | export default class AppStore extends Store { | 42 | export default class AppStore extends Store { |
39 | updateStatusTypes = { | 43 | updateStatusTypes = { |
40 | CHECKING: 'CHECKING', | 44 | CHECKING: 'CHECKING', |
@@ -56,6 +60,8 @@ export default class AppStore extends Store { | |||
56 | 60 | ||
57 | @observable authRequestFailed = false; | 61 | @observable authRequestFailed = false; |
58 | 62 | ||
63 | @observable timeSuspensionStart; | ||
64 | |||
59 | @observable timeOfflineStart; | 65 | @observable timeOfflineStart; |
60 | 66 | ||
61 | @observable updateStatus = null; | 67 | @observable updateStatus = null; |
@@ -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,36 @@ 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 | }); | ||
211 | |||
212 | // macOS catalina notifications hack | ||
213 | // notifications got stuck after upgrade but forcing a notification | ||
214 | // via `new Notification` triggered the permission request | ||
215 | if (isMac && !localStorage.getItem(CATALINA_NOTIFICATION_HACK_KEY)) { | ||
216 | // eslint-disable-next-line no-new | ||
217 | new window.Notification('Welcome to Franz 5', { | ||
218 | body: 'Have a wonderful day & happy messaging.', | ||
219 | }); | ||
220 | |||
221 | localStorage.setItem(CATALINA_NOTIFICATION_HACK_KEY, true); | ||
222 | } | ||
178 | } | 223 | } |
179 | 224 | ||
180 | @computed get cacheSize() { | 225 | @computed get cacheSize() { |
@@ -383,6 +428,12 @@ export default class AppStore extends Store { | |||
383 | } | 428 | } |
384 | } | 429 | } |
385 | 430 | ||
431 | _handleLogout() { | ||
432 | if (!this.stores.user.isLoggedIn) { | ||
433 | clearInterval(this.fetchDataInterval); | ||
434 | } | ||
435 | } | ||
436 | |||
386 | // Helpers | 437 | // Helpers |
387 | _appStartsCounter() { | 438 | _appStartsCounter() { |
388 | this.actions.settings.update({ | 439 | this.actions.settings.update({ |