upfix localstorage iframe
This commit is contained in:
parent
578e6e6981
commit
5a9caf69a5
@ -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 { }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
|
@ -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 {
|
||||
localStorage.setItem("bstly.servicesView", this.view);
|
||||
try {
|
||||
localStorage.setItem("bstly.servicesView", this.view);
|
||||
} catch { }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 || "");
|
||||
|
@ -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({
|
||||
|
Loading…
Reference in New Issue
Block a user