diff options
author | Amine El Mouafik <412895+kytwb@users.noreply.github.com> | 2021-02-08 10:34:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-08 10:34:45 +0100 |
commit | 035002ceedf78d5ec73eabc0df7f06139939b967 (patch) | |
tree | 1c0d1e9531bae05fb65d70b9ea25baf404b74fe1 /src/stores/AppStore.js | |
parent | docs: add k0staa as a contributor (#1193) (diff) | |
download | ferdium-app-035002ceedf78d5ec73eabc0df7f06139939b967.tar.gz ferdium-app-035002ceedf78d5ec73eabc0df7f06139939b967.tar.zst ferdium-app-035002ceedf78d5ec73eabc0df7f06139939b967.zip |
Synchronize with Franz 5.6.0 (#1033)
Co-authored-by: FranzBot <i18n@meetfranz.com>
Co-authored-by: vantezzen <hello@vantezzen.io>
Co-authored-by: Makazzz <makazzzpro@live.ca>
Co-authored-by: Stefan Malzner <stefan@adlk.io>
Co-authored-by: Amine Mouafik <amine@mouafik.fr>
Diffstat (limited to 'src/stores/AppStore.js')
-rw-r--r-- | src/stores/AppStore.js | 136 |
1 files changed, 100 insertions, 36 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 153fdb2c8..869cfa9d6 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js | |||
@@ -3,7 +3,6 @@ import { | |||
3 | action, computed, observable, | 3 | action, computed, observable, |
4 | } from 'mobx'; | 4 | } from 'mobx'; |
5 | import moment from 'moment'; | 5 | import moment from 'moment'; |
6 | import { getDoNotDisturb } from '@meetfranz/electron-notification-state'; | ||
7 | import AutoLaunch from 'auto-launch'; | 6 | import AutoLaunch from 'auto-launch'; |
8 | import prettyBytes from 'pretty-bytes'; | 7 | import prettyBytes from 'pretty-bytes'; |
9 | import ms from 'ms'; | 8 | import ms from 'ms'; |
@@ -27,7 +26,10 @@ import { sleep } from '../helpers/async-helpers'; | |||
27 | const debug = require('debug')('Ferdi:AppStore'); | 26 | const debug = require('debug')('Ferdi:AppStore'); |
28 | 27 | ||
29 | const { | 28 | const { |
30 | app, nativeTheme, screen, powerMonitor, | 29 | app, |
30 | screen, | ||
31 | powerMonitor, | ||
32 | nativeTheme, | ||
31 | } = remote; | 33 | } = remote; |
32 | 34 | ||
33 | const mainWindow = remote.getCurrentWindow(); | 35 | const mainWindow = remote.getCurrentWindow(); |
@@ -63,7 +65,7 @@ export default class AppStore extends Store { | |||
63 | 65 | ||
64 | @observable authRequestFailed = false; | 66 | @observable authRequestFailed = false; |
65 | 67 | ||
66 | @observable timeSuspensionStart; | 68 | @observable timeSuspensionStart = moment(); |
67 | 69 | ||
68 | @observable timeOfflineStart; | 70 | @observable timeOfflineStart; |
69 | 71 | ||
@@ -118,11 +120,19 @@ export default class AppStore extends Store { | |||
118 | window.addEventListener('focus', this.actions.service.focusActiveService); | 120 | window.addEventListener('focus', this.actions.service.focusActiveService); |
119 | 121 | ||
120 | // Online/Offline handling | 122 | // Online/Offline handling |
121 | window.addEventListener('online', () => { this.isOnline = true; }); | 123 | window.addEventListener('online', () => { |
122 | window.addEventListener('offline', () => { this.isOnline = false; }); | 124 | this.isOnline = true; |
125 | }); | ||
126 | window.addEventListener('offline', () => { | ||
127 | this.isOnline = false; | ||
128 | }); | ||
123 | 129 | ||
124 | mainWindow.on('enter-full-screen', () => { this.isFullScreen = true; }); | 130 | mainWindow.on('enter-full-screen', () => { |
125 | mainWindow.on('leave-full-screen', () => { this.isFullScreen = false; }); | 131 | this.isFullScreen = true; |
132 | }); | ||
133 | mainWindow.on('leave-full-screen', () => { | ||
134 | this.isFullScreen = false; | ||
135 | }); | ||
126 | 136 | ||
127 | 137 | ||
128 | this.isOnline = navigator.onLine; | 138 | this.isOnline = navigator.onLine; |
@@ -137,10 +147,16 @@ export default class AppStore extends Store { | |||
137 | setInterval(() => this._systemDND(), ms('5s')); | 147 | setInterval(() => this._systemDND(), ms('5s')); |
138 | 148 | ||
139 | this.fetchDataInterval = setInterval(() => { | 149 | this.fetchDataInterval = setInterval(() => { |
140 | this.stores.user.getUserInfoRequest.invalidate({ immediately: true }); | 150 | this.stores.user.getUserInfoRequest.invalidate({ |
141 | this.stores.features.featuresRequest.invalidate({ immediately: true }); | 151 | immediately: true, |
142 | this.stores.news.latestNewsRequest.invalidate({ immediately: true }); | 152 | }); |
143 | }, ms('10m')); | 153 | this.stores.features.featuresRequest.invalidate({ |
154 | immediately: true, | ||
155 | }); | ||
156 | this.stores.news.latestNewsRequest.invalidate({ | ||
157 | immediately: true, | ||
158 | }); | ||
159 | }, ms('60m')); | ||
144 | 160 | ||
145 | // Check for updates once every 4 hours | 161 | // Check for updates once every 4 hours |
146 | setInterval(() => this._checkForUpdates(), CHECK_INTERVAL); | 162 | setInterval(() => this._checkForUpdates(), CHECK_INTERVAL); |
@@ -174,7 +190,9 @@ export default class AppStore extends Store { | |||
174 | // Handle deep linking (franz://) | 190 | // Handle deep linking (franz://) |
175 | ipcRenderer.on('navigateFromDeepLink', (event, data) => { | 191 | ipcRenderer.on('navigateFromDeepLink', (event, data) => { |
176 | debug('Navigate from deep link', data); | 192 | debug('Navigate from deep link', data); |
177 | let { url } = data; | 193 | let { |
194 | url, | ||
195 | } = data; | ||
178 | if (!url) return; | 196 | if (!url) return; |
179 | 197 | ||
180 | url = url.replace(/\/$/, ''); | 198 | url = url.replace(/\/$/, ''); |
@@ -207,13 +225,17 @@ export default class AppStore extends Store { | |||
207 | }); | 225 | }); |
208 | 226 | ||
209 | powerMonitor.on('resume', () => { | 227 | powerMonitor.on('resume', () => { |
210 | debug('System resumed, last suspended on', this.timeSuspensionStart.toString()); | 228 | debug('System resumed, last suspended on', this.timeSuspensionStart); |
229 | this.actions.service.resetLastPollTimer(); | ||
211 | 230 | ||
212 | if (this.timeSuspensionStart.add(10, 'm').isBefore(moment()) && this.stores.settings.app.get('reloadAfterResume')) { | 231 | if (this.timeSuspensionStart.add(10, 'm').isBefore(moment()) && this.stores.settings.app.get('reloadAfterResume')) { |
213 | debug('Reloading services, user info and features'); | 232 | debug('Reloading services, user info and features'); |
214 | 233 | ||
215 | setTimeout(() => { | 234 | setInterval(() => { |
216 | window.location.reload(); | 235 | debug('Reload app interval is starting'); |
236 | if (this.isOnline) { | ||
237 | window.location.reload(); | ||
238 | } | ||
217 | }, ms('2s')); | 239 | }, ms('2s')); |
218 | } | 240 | } |
219 | }); | 241 | }); |
@@ -251,8 +273,14 @@ export default class AppStore extends Store { | |||
251 | ferdi: { | 273 | ferdi: { |
252 | version: app.getVersion(), | 274 | version: app.getVersion(), |
253 | electron: process.versions.electron, | 275 | electron: process.versions.electron, |
254 | installedRecipes: this.stores.recipes.all.map(recipe => ({ id: recipe.id, version: recipe.version })), | 276 | installedRecipes: this.stores.recipes.all.map(recipe => ({ |
255 | devRecipes: this.stores.recipePreviews.dev.map(recipe => ({ id: recipe.id, version: recipe.version })), | 277 | id: recipe.id, |
278 | version: recipe.version, | ||
279 | })), | ||
280 | devRecipes: this.stores.recipePreviews.dev.map(recipe => ({ | ||
281 | id: recipe.id, | ||
282 | version: recipe.version, | ||
283 | })), | ||
256 | services: this.stores.services.all.map(service => ({ | 284 | services: this.stores.services.all.map(service => ({ |
257 | id: service.id, | 285 | id: service.id, |
258 | recipe: service.recipe.id, | 286 | recipe: service.recipe.id, |
@@ -264,7 +292,10 @@ export default class AppStore extends Store { | |||
264 | isDarkModeEnabled: service.isDarkModeEnabled, | 292 | isDarkModeEnabled: service.isDarkModeEnabled, |
265 | })), | 293 | })), |
266 | messages: this.stores.globalError.messages, | 294 | messages: this.stores.globalError.messages, |
267 | workspaces: this.stores.workspaces.workspaces.map(workspace => ({ id: workspace.id, services: workspace.services })), | 295 | workspaces: this.stores.workspaces.workspaces.map(workspace => ({ |
296 | id: workspace.id, | ||
297 | services: workspace.services, | ||
298 | })), | ||
268 | windowSettings: readJsonSync(path.join(app.getPath('userData'), 'window-state.json')), | 299 | windowSettings: readJsonSync(path.join(app.getPath('userData'), 'window-state.json')), |
269 | settings, | 300 | settings, |
270 | features: this.stores.features.features, | 301 | features: this.stores.features.features, |
@@ -275,7 +306,10 @@ export default class AppStore extends Store { | |||
275 | 306 | ||
276 | // Actions | 307 | // Actions |
277 | @action _notify({ | 308 | @action _notify({ |
278 | title, options, notificationId, serviceId = null, | 309 | title, |
310 | options, | ||
311 | notificationId, | ||
312 | serviceId = null, | ||
279 | }) { | 313 | }) { |
280 | if (this.stores.settings.all.app.isAppMuted) return; | 314 | if (this.stores.settings.all.app.isAppMuted) return; |
281 | 315 | ||
@@ -288,15 +322,17 @@ export default class AppStore extends Store { | |||
288 | 322 | ||
289 | debug('New notification', title, options); | 323 | debug('New notification', title, options); |
290 | 324 | ||
291 | notification.onclick = (e) => { | 325 | notification.onclick = () => { |
292 | if (serviceId) { | 326 | if (serviceId) { |
293 | this.actions.service.sendIPCMessage({ | 327 | this.actions.service.sendIPCMessage({ |
294 | channel: `notification-onclick:${notificationId}`, | 328 | channel: `notification-onclick:${notificationId}`, |
295 | args: e, | 329 | args: {}, |
296 | serviceId, | 330 | serviceId, |
297 | }); | 331 | }); |
298 | 332 | ||
299 | this.actions.service.setActive({ serviceId }); | 333 | this.actions.service.setActive({ |
334 | serviceId, | ||
335 | }); | ||
300 | mainWindow.show(); | 336 | mainWindow.show(); |
301 | if (app.mainWindow.isMinimized()) { | 337 | if (app.mainWindow.isMinimized()) { |
302 | mainWindow.restore(); | 338 | mainWindow.restore(); |
@@ -308,7 +344,10 @@ export default class AppStore extends Store { | |||
308 | }; | 344 | }; |
309 | } | 345 | } |
310 | 346 | ||
311 | @action _setBadge({ unreadDirectMessageCount, unreadIndirectMessageCount }) { | 347 | @action _setBadge({ |
348 | unreadDirectMessageCount, | ||
349 | unreadIndirectMessageCount, | ||
350 | }) { | ||
312 | let indicator = unreadDirectMessageCount; | 351 | let indicator = unreadDirectMessageCount; |
313 | 352 | ||
314 | if (indicator === 0 && unreadIndirectMessageCount !== 0) { | 353 | if (indicator === 0 && unreadIndirectMessageCount !== 0) { |
@@ -319,10 +358,14 @@ export default class AppStore extends Store { | |||
319 | indicator = parseInt(indicator, 10); | 358 | indicator = parseInt(indicator, 10); |
320 | } | 359 | } |
321 | 360 | ||
322 | ipcRenderer.send('updateAppIndicator', { indicator }); | 361 | ipcRenderer.send('updateAppIndicator', { |
362 | indicator, | ||
363 | }); | ||
323 | } | 364 | } |
324 | 365 | ||
325 | @action _launchOnStartup({ enable }) { | 366 | @action _launchOnStartup({ |
367 | enable, | ||
368 | }) { | ||
326 | this.autoLaunchOnStart = enable; | 369 | this.autoLaunchOnStart = enable; |
327 | 370 | ||
328 | try { | 371 | try { |
@@ -338,7 +381,9 @@ export default class AppStore extends Store { | |||
338 | } | 381 | } |
339 | } | 382 | } |
340 | 383 | ||
341 | @action _openExternalUrl({ url }) { | 384 | @action _openExternalUrl({ |
385 | url, | ||
386 | }) { | ||
342 | const parsedUrl = new URL(url); | 387 | const parsedUrl = new URL(url); |
343 | debug('open external url', parsedUrl); | 388 | debug('open external url', parsedUrl); |
344 | 389 | ||
@@ -348,14 +393,20 @@ export default class AppStore extends Store { | |||
348 | } | 393 | } |
349 | 394 | ||
350 | @action _checkForUpdates() { | 395 | @action _checkForUpdates() { |
351 | this.updateStatus = this.updateStatusTypes.CHECKING; | 396 | if (this.isOnline) { |
352 | ipcRenderer.send('autoUpdate', { action: 'check' }); | 397 | this.updateStatus = this.updateStatusTypes.CHECKING; |
398 | ipcRenderer.send('autoUpdate', { | ||
399 | action: 'check', | ||
400 | }); | ||
353 | 401 | ||
354 | this.actions.recipe.update(); | 402 | this.actions.recipe.update(); |
403 | } | ||
355 | } | 404 | } |
356 | 405 | ||
357 | @action _installUpdate() { | 406 | @action _installUpdate() { |
358 | ipcRenderer.send('autoUpdate', { action: 'install' }); | 407 | ipcRenderer.send('autoUpdate', { |
408 | action: 'install', | ||
409 | }); | ||
359 | } | 410 | } |
360 | 411 | ||
361 | @action _resetUpdateStatus() { | 412 | @action _resetUpdateStatus() { |
@@ -366,7 +417,10 @@ export default class AppStore extends Store { | |||
366 | this.healthCheckRequest.execute(); | 417 | this.healthCheckRequest.execute(); |
367 | } | 418 | } |
368 | 419 | ||
369 | @action _muteApp({ isMuted, overrideSystemMute = true }) { | 420 | @action _muteApp({ |
421 | isMuted, | ||
422 | overrideSystemMute = true, | ||
423 | }) { | ||
370 | this.isSystemMuteOverridden = overrideSystemMute; | 424 | this.isSystemMuteOverridden = overrideSystemMute; |
371 | this.actions.settings.update({ | 425 | this.actions.settings.update({ |
372 | type: 'app', | 426 | type: 'app', |
@@ -377,7 +431,9 @@ export default class AppStore extends Store { | |||
377 | } | 431 | } |
378 | 432 | ||
379 | @action _toggleMuteApp() { | 433 | @action _toggleMuteApp() { |
380 | this._muteApp({ isMuted: !this.stores.settings.all.app.isAppMuted }); | 434 | this._muteApp({ |
435 | isMuted: !this.stores.settings.all.app.isAppMuted, | ||
436 | }); | ||
381 | } | 437 | } |
382 | 438 | ||
383 | @action async _clearAllCache() { | 439 | @action async _clearAllCache() { |
@@ -391,7 +447,9 @@ export default class AppStore extends Store { | |||
391 | } catch (ex) { | 447 | } catch (ex) { |
392 | console.log('Error while deleting service partition directory - ', ex); | 448 | console.log('Error while deleting service partition directory - ', ex); |
393 | } | 449 | } |
394 | await Promise.all(this.stores.services.all.map(s => this.actions.service.clearCache({ serviceId: s.id }))); | 450 | await Promise.all(this.stores.services.all.map(s => this.actions.service.clearCache({ |
451 | serviceId: s.id, | ||
452 | }))); | ||
395 | 453 | ||
396 | await clearAppCache._promise; | 454 | await clearAppCache._promise; |
397 | 455 | ||
@@ -446,7 +504,10 @@ export default class AppStore extends Store { | |||
446 | const { showMessageBadgesEvenWhenMuted } = this.stores.ui; | 504 | const { showMessageBadgesEvenWhenMuted } = this.stores.ui; |
447 | 505 | ||
448 | if (!showMessageBadgesEvenWhenMuted) { | 506 | if (!showMessageBadgesEvenWhenMuted) { |
449 | this.actions.app.setBadge({ unreadDirectMessageCount: 0, unreadIndirectMessageCount: 0 }); | 507 | this.actions.app.setBadge({ |
508 | unreadDirectMessageCount: 0, | ||
509 | unreadIndirectMessageCount: 0, | ||
510 | }); | ||
450 | } | 511 | } |
451 | } | 512 | } |
452 | 513 | ||
@@ -491,8 +552,11 @@ export default class AppStore extends Store { | |||
491 | return autoLauncher.isEnabled() || false; | 552 | return autoLauncher.isEnabled() || false; |
492 | } | 553 | } |
493 | 554 | ||
494 | _systemDND() { | 555 | async _systemDND() { |
495 | const dnd = getDoNotDisturb(); | 556 | debug('Checking if Do Not Disturb Mode is on'); |
557 | const dnd = await ipcRenderer.invoke('get-dnd'); | ||
558 | debug('Do not disturb mode is', dnd); | ||
559 | // ipcRenderer.on('autoUpdate', (event, data) => { | ||
496 | if (dnd !== this.stores.settings.all.app.isAppMuted && !this.isSystemMuteOverridden) { | 560 | if (dnd !== this.stores.settings.all.app.isAppMuted && !this.isSystemMuteOverridden) { |
497 | this.actions.app.muteApp({ | 561 | this.actions.app.muteApp({ |
498 | isMuted: dnd, | 562 | isMuted: dnd, |