diff --git a/src/app/app.component.ts b/src/app/app.component.ts index bfe9c6c..0d9f6c4 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -17,9 +17,11 @@ export class AppComponent { ngOnInit() { this._adapter.setLocale(this.i18n.getLocale()); - if (localStorage.getItem("bstly.darkTheme") == "true") { - window.document.body.classList.add("dark-theme"); - } + try { + if (localStorage.getItem("bstly.darkTheme") == "true") { + window.document.body.classList.add("dark-theme"); + } + } catch { } } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index b840b5b..ed92ca8 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -69,7 +69,10 @@ import { JukeboxComponent } from './pages/jukebox/jukebox.compontent'; export function init_app(i18n: I18nService) { - return () => i18n.fetch().then(response => { }, error => { }); + return () => { + console.log("APP_INITIALIZER"); + i18n.fetch(); + }; } @Injectable() diff --git a/src/app/auth/auth.guard.ts b/src/app/auth/auth.guard.ts index 9e23ab5..0ba6b20 100644 --- a/src/app/auth/auth.guard.ts +++ b/src/app/auth/auth.guard.ts @@ -55,18 +55,22 @@ export class AuthenticatedGuard implements CanActivate { for (let profileField of profileFields) { if (profileField.name == "darkTheme") { darktheme = profileField.value; - } else if (profileField.name == "locale" && this.i18nService.locales.indexOf(profileField.value) != -1 && localStorage.getItem("bstly.locale") != profileField.value) { - if (this.i18nService.locale != profileField.value) { - localStorage.setItem("bstly.locale", profileField.value); - updateLocale = true; - } + } else if (profileField.name == "locale" && this.i18nService.locales.indexOf(profileField.value) != -1) { + try { + if (localStorage.getItem("bstly.locale") != profileField.value || this.i18nService.locale != profileField.value) { + localStorage.setItem("bstly.locale", profileField.value); + updateLocale = true; + } + } catch { } } } - if (darktheme != localStorage.getItem("bstly.darkTheme")) { - localStorage.setItem("bstly.darkTheme", darktheme); - updateTheme = true; - } + try { + if (darktheme != localStorage.getItem("bstly.darkTheme")) { + localStorage.setItem("bstly.darkTheme", darktheme); + updateTheme = true; + } + } catch { } if (updateLocale || updateTheme) { window.location.reload(); diff --git a/src/app/pages/services/services.component.ts b/src/app/pages/services/services.component.ts index 9016e92..d9ac3aa 100644 --- a/src/app/pages/services/services.component.ts +++ b/src/app/pages/services/services.component.ts @@ -18,7 +18,10 @@ export class ServicesComponent implements OnInit { ngOnInit(): void { - this.view = localStorage.getItem("bstly.servicesView") || 'grid'; + this.view = 'grid'; + try { + this.view = localStorage.getItem("bstly.servicesView") || this.view; + } catch { } this.serviceService.services().subscribe({ next: (data: Array) => { @@ -39,7 +42,9 @@ export class ServicesComponent implements OnInit { } updateView(): void { - localStorage.setItem("bstly.servicesView", this.view); + try { + localStorage.setItem("bstly.servicesView", this.view); + } catch { } } } diff --git a/src/app/services/i18n.service.ts b/src/app/services/i18n.service.ts index b641023..d2da9d0 100644 --- a/src/app/services/i18n.service.ts +++ b/src/app/services/i18n.service.ts @@ -37,31 +37,43 @@ export class I18nService { browserLocale = browserLocale.split("-")[ 0 ]; } - let locale = localStorage.getItem("bstly.locale") || browserLocale || this.locales[ 0 ]; + let locale = browserLocale || this.locales[ 0 ]; + try { + locale = localStorage.getItem("bstly.locale") || locale; + } catch { } if (locale == 'de') { locale = 'de-informal'; } - try { - await this.http.get(environment.apiUrl + "/i18n").toPromise().then((response: any) => { - this.locales = response; - }); - } catch (e) { - console.debug("fallback to default locales"); - } + await this.http.get(environment.apiUrl + "/i18n").subscribe({ + next: (data: any) => { + console.log("fetch3", data); + this.locales = data; + }, error: (error) => { + console.debug("fallback to default locales"); + } + }); if (this.locales.indexOf(locale) == -1) { locale = this.locales[ 0 ]; } this.setLocale(locale); - try { - this.i18n = await this.http.get(environment.apiUrl + "/i18n/" + locale).toPromise(); - } catch (e) { - this.i18n = await this.http.get("/assets/i18n/" + locale + ".json").toPromise(); - console.debug("fallback to default locale"); - } + await this.http.get(environment.apiUrl + "/i18n/" + locale).subscribe({ + next: (data: any) => { + this.i18n = data; + }, error: async (error) => { + await this.http.get("/assets/i18n/" + locale + ".json").subscribe({ + next: (data: any) => { + this.i18n = data; + }, error: (error) => { + } + + }); + } + }); + } get(key, args: string[]): string { @@ -72,7 +84,7 @@ export class I18nService { return this.getInternal(key, args, this.i18n, "", false); } - getInternal(key, args: string[], from, path, empty : boolean): string { + getInternal(key, args: string[], from, path, empty: boolean): string { key += ''; if (!from) { return empty ? this.empty(key, args, path) : (key || ""); diff --git a/src/app/ui/main/main.component.ts b/src/app/ui/main/main.component.ts index 1dfe14d..e166456 100644 --- a/src/app/ui/main/main.component.ts +++ b/src/app/ui/main/main.component.ts @@ -58,17 +58,20 @@ export class MainComponent { } else { this.opened = true; } - - if (localStorage.getItem("bstly.darkTheme") == "true") { - this.darkTheme = "true"; - window.document.body.classList.add("dark-theme"); - } + try { + if (localStorage.getItem("bstly.darkTheme") == "true") { + this.darkTheme = "true"; + window.document.body.classList.add("dark-theme"); + } + } catch { } this.touchEvents(); } setLocale(locale) { - localStorage.setItem("bstly.locale", locale); + try { + localStorage.setItem("bstly.locale", locale); + } catch { } if (this.auth && this.auth.authenticated) { this.profileService.getField("locale").subscribe({ @@ -102,7 +105,9 @@ export class MainComponent { this.darkTheme = "false"; } - localStorage.setItem("bstly.darkTheme", this.darkTheme); + try { + localStorage.setItem("bstly.darkTheme", this.darkTheme); + } catch { } if (this.auth && this.auth.authenticated) { this.profileService.getField("darkTheme").subscribe({