diff options
author | Markus Hatvan <markus_hatvan@aon.at> | 2021-10-07 08:04:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-07 08:04:11 +0200 |
commit | 4898ff4a6a7bfc83a10ddc2f32abb2da82f4819f (patch) | |
tree | f17e2b06ab8c8c49ff428134a433e957b26ac0c0 /src/stores | |
parent | chore: upgrade react to latest (#2030) (diff) | |
download | ferdium-app-4898ff4a6a7bfc83a10ddc2f32abb2da82f4819f.tar.gz ferdium-app-4898ff4a6a7bfc83a10ddc2f32abb2da82f4819f.tar.zst ferdium-app-4898ff4a6a7bfc83a10ddc2f32abb2da82f4819f.zip |
refactor: locale selection cleanup (#2031)
Diffstat (limited to 'src/stores')
-rw-r--r-- | src/stores/AppStore.js | 47 |
1 files changed, 14 insertions, 33 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 3d9d2b551..a86a54c6d 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js | |||
@@ -17,16 +17,8 @@ import { readJsonSync } from 'fs-extra'; | |||
17 | import Store from './lib/Store'; | 17 | import Store from './lib/Store'; |
18 | import Request from './lib/Request'; | 18 | import Request from './lib/Request'; |
19 | import { CHECK_INTERVAL, DEFAULT_APP_SETTINGS } from '../config'; | 19 | import { CHECK_INTERVAL, DEFAULT_APP_SETTINGS } from '../config'; |
20 | import { | 20 | import { isMac, electronVersion, osRelease } from '../environment'; |
21 | isMac, | 21 | import { ferdiVersion, userDataPath, ferdiLocale } from '../environment-remote'; |
22 | electronVersion, | ||
23 | osRelease, | ||
24 | } from '../environment'; | ||
25 | import { | ||
26 | ferdiVersion, | ||
27 | userDataPath, | ||
28 | ferdiLocale, | ||
29 | } from '../environment-remote'; | ||
30 | import locales from '../i18n/translations'; | 22 | import locales from '../i18n/translations'; |
31 | import { getLocale } from '../helpers/i18n-helpers'; | 23 | import { getLocale } from '../helpers/i18n-helpers'; |
32 | 24 | ||
@@ -41,8 +33,6 @@ const debug = require('debug')('Ferdi:AppStore'); | |||
41 | 33 | ||
42 | const mainWindow = getCurrentWindow(); | 34 | const mainWindow = getCurrentWindow(); |
43 | 35 | ||
44 | const defaultLocale = DEFAULT_APP_SETTINGS.locale; | ||
45 | |||
46 | const executablePath = isMac ? remoteProcess.execPath : process.execPath; | 36 | const executablePath = isMac ? remoteProcess.execPath : process.execPath; |
47 | const autoLauncher = new AutoLaunch({ | 37 | const autoLauncher = new AutoLaunch({ |
48 | name: 'Ferdi', | 38 | name: 'Ferdi', |
@@ -80,9 +70,9 @@ export default class AppStore extends Store { | |||
80 | 70 | ||
81 | @observable timeOfflineStart; | 71 | @observable timeOfflineStart; |
82 | 72 | ||
83 | @observable updateStatus = null; | 73 | @observable updateStatus = ''; |
84 | 74 | ||
85 | @observable locale = defaultLocale; | 75 | @observable locale = ferdiLocale; |
86 | 76 | ||
87 | @observable isSystemMuteOverridden = false; | 77 | @observable isSystemMuteOverridden = false; |
88 | 78 | ||
@@ -408,7 +398,7 @@ export default class AppStore extends Store { | |||
408 | } | 398 | } |
409 | 399 | ||
410 | @action _resetUpdateStatus() { | 400 | @action _resetUpdateStatus() { |
411 | this.updateStatus = null; | 401 | this.updateStatus = ''; |
412 | } | 402 | } |
413 | 403 | ||
414 | @action _healthCheck() { | 404 | @action _healthCheck() { |
@@ -480,23 +470,13 @@ export default class AppStore extends Store { | |||
480 | } | 470 | } |
481 | 471 | ||
482 | _setLocale() { | 472 | _setLocale() { |
483 | let locale; | 473 | if (this.stores.user.isLoggedIn && this.stores.user.data.locale) { |
484 | if (this.stores.user.isLoggedIn) { | 474 | this.locale = this.stores.user.data.locale; |
485 | locale = this.stores.user.data.locale; | 475 | } else if (!this.locale) { |
486 | } | ||
487 | |||
488 | if ( | ||
489 | locale && | ||
490 | Object.prototype.hasOwnProperty.call(locales, locale) && | ||
491 | locale !== this.locale | ||
492 | ) { | ||
493 | this.locale = locale; | ||
494 | } else if (!locale) { | ||
495 | this.locale = this._getDefaultLocale(); | 476 | this.locale = this._getDefaultLocale(); |
496 | } | 477 | } |
497 | 478 | ||
498 | moment.locale(this.locale); | 479 | moment.locale(this.locale); |
499 | |||
500 | debug(`Set locale to "${this.locale}"`); | 480 | debug(`Set locale to "${this.locale}"`); |
501 | } | 481 | } |
502 | 482 | ||
@@ -504,7 +484,6 @@ export default class AppStore extends Store { | |||
504 | return getLocale({ | 484 | return getLocale({ |
505 | locale: ferdiLocale, | 485 | locale: ferdiLocale, |
506 | locales, | 486 | locales, |
507 | defaultLocale, | ||
508 | fallbackLocale: DEFAULT_APP_SETTINGS.fallbackLocale, | 487 | fallbackLocale: DEFAULT_APP_SETTINGS.fallbackLocale, |
509 | }); | 488 | }); |
510 | } | 489 | } |
@@ -523,10 +502,12 @@ export default class AppStore extends Store { | |||
523 | _handleFullScreen() { | 502 | _handleFullScreen() { |
524 | const body = document.querySelector('body'); | 503 | const body = document.querySelector('body'); |
525 | 504 | ||
526 | if (this.isFullScreen) { | 505 | if (body) { |
527 | body.classList.add('isFullScreen'); | 506 | if (this.isFullScreen) { |
528 | } else { | 507 | body.classList.add('isFullScreen'); |
529 | body.classList.remove('isFullScreen'); | 508 | } else { |
509 | body.classList.remove('isFullScreen'); | ||
510 | } | ||
530 | } | 511 | } |
531 | } | 512 | } |
532 | 513 | ||