From 4898ff4a6a7bfc83a10ddc2f32abb2da82f4819f Mon Sep 17 00:00:00 2001 From: Markus Hatvan Date: Thu, 7 Oct 2021 08:04:11 +0200 Subject: refactor: locale selection cleanup (#2031) --- src/stores/AppStore.js | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) (limited to 'src/stores') 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'; import Store from './lib/Store'; import Request from './lib/Request'; import { CHECK_INTERVAL, DEFAULT_APP_SETTINGS } from '../config'; -import { - isMac, - electronVersion, - osRelease, -} from '../environment'; -import { - ferdiVersion, - userDataPath, - ferdiLocale, -} from '../environment-remote'; +import { isMac, electronVersion, osRelease } from '../environment'; +import { ferdiVersion, userDataPath, ferdiLocale } from '../environment-remote'; import locales from '../i18n/translations'; import { getLocale } from '../helpers/i18n-helpers'; @@ -41,8 +33,6 @@ const debug = require('debug')('Ferdi:AppStore'); const mainWindow = getCurrentWindow(); -const defaultLocale = DEFAULT_APP_SETTINGS.locale; - const executablePath = isMac ? remoteProcess.execPath : process.execPath; const autoLauncher = new AutoLaunch({ name: 'Ferdi', @@ -80,9 +70,9 @@ export default class AppStore extends Store { @observable timeOfflineStart; - @observable updateStatus = null; + @observable updateStatus = ''; - @observable locale = defaultLocale; + @observable locale = ferdiLocale; @observable isSystemMuteOverridden = false; @@ -408,7 +398,7 @@ export default class AppStore extends Store { } @action _resetUpdateStatus() { - this.updateStatus = null; + this.updateStatus = ''; } @action _healthCheck() { @@ -480,23 +470,13 @@ export default class AppStore extends Store { } _setLocale() { - let locale; - if (this.stores.user.isLoggedIn) { - locale = this.stores.user.data.locale; - } - - if ( - locale && - Object.prototype.hasOwnProperty.call(locales, locale) && - locale !== this.locale - ) { - this.locale = locale; - } else if (!locale) { + if (this.stores.user.isLoggedIn && this.stores.user.data.locale) { + this.locale = this.stores.user.data.locale; + } else if (!this.locale) { this.locale = this._getDefaultLocale(); } moment.locale(this.locale); - debug(`Set locale to "${this.locale}"`); } @@ -504,7 +484,6 @@ export default class AppStore extends Store { return getLocale({ locale: ferdiLocale, locales, - defaultLocale, fallbackLocale: DEFAULT_APP_SETTINGS.fallbackLocale, }); } @@ -523,10 +502,12 @@ export default class AppStore extends Store { _handleFullScreen() { const body = document.querySelector('body'); - if (this.isFullScreen) { - body.classList.add('isFullScreen'); - } else { - body.classList.remove('isFullScreen'); + if (body) { + if (this.isFullScreen) { + body.classList.add('isFullScreen'); + } else { + body.classList.remove('isFullScreen'); + } } } -- cgit v1.2.3-54-g00ecf