upfix localstorage iframe

This commit is contained in:
_Bastler 2022-03-20 11:21:25 +01:00
parent 578e6e6981
commit 5a9caf69a5
6 changed files with 68 additions and 37 deletions

View File

@ -17,9 +17,11 @@ export class AppComponent {
ngOnInit() {
this._adapter.setLocale(this.i18n.getLocale());
try {
if (localStorage.getItem("bstly.darkTheme") == "true") {
window.document.body.classList.add("dark-theme");
}
} catch { }
}
}

View File

@ -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()

View File

@ -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) {
} 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 { }
}
}
try {
if (darktheme != localStorage.getItem("bstly.darkTheme")) {
localStorage.setItem("bstly.darkTheme", darktheme);
updateTheme = true;
}
} catch { }
if (updateLocale || updateTheme) {
window.location.reload();

View File

@ -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<any>) => {
@ -39,7 +42,9 @@ export class ServicesComponent implements OnInit {
}
updateView(): void {
try {
localStorage.setItem("bstly.servicesView", this.view);
} catch { }
}
}

View File

@ -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) {
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 {

View File

@ -58,17 +58,20 @@ export class MainComponent {
} else {
this.opened = true;
}
try {
if (localStorage.getItem("bstly.darkTheme") == "true") {
this.darkTheme = "true";
window.document.body.classList.add("dark-theme");
}
} catch { }
this.touchEvents();
}
setLocale(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";
}
try {
localStorage.setItem("bstly.darkTheme", this.darkTheme);
} catch { }
if (this.auth && this.auth.authenticated) {
this.profileService.getField("darkTheme").subscribe({