fix: user preferences

This commit is contained in:
Baptiste Grob
2020-10-26 16:10:18 +01:00
parent 5cd7aa908b
commit 19243082e2

View File

@@ -14,7 +14,7 @@ export class PreferencesManager extends ApplicationService {
private userPreferences!: SNUserPrefs; private userPreferences!: SNUserPrefs;
private loadingPrefs = false; private loadingPrefs = false;
private unubscribeStreamItems?: () => void; private unubscribeStreamItems?: () => void;
private shouldReloadSingleton = true; private needsSingletonReload = true;
/** @override */ /** @override */
async onAppLaunch() { async onAppLaunch() {
@@ -24,6 +24,7 @@ export class PreferencesManager extends ApplicationService {
} }
async onAppEvent(event: ApplicationEvent) { async onAppEvent(event: ApplicationEvent) {
super.onAppEvent(event);
if (event === ApplicationEvent.CompletedFullSync) { if (event === ApplicationEvent.CompletedFullSync) {
this.reloadSingleton(); this.reloadSingleton();
} }
@@ -41,13 +42,13 @@ export class PreferencesManager extends ApplicationService {
this.unubscribeStreamItems = this.application!.streamItems( this.unubscribeStreamItems = this.application!.streamItems(
ContentType.UserPrefs, ContentType.UserPrefs,
() => { () => {
this.shouldReloadSingleton = true; this.needsSingletonReload = true;
} }
); );
} }
private async reloadSingleton() { private async reloadSingleton() {
if (this.loadingPrefs || !this.shouldReloadSingleton) { if (this.loadingPrefs || !this.needsSingletonReload) {
return; return;
} }
this.loadingPrefs = true; this.loadingPrefs = true;
@@ -60,6 +61,7 @@ export class PreferencesManager extends ApplicationService {
FillItemContent({}), FillItemContent({}),
)) as SNUserPrefs; )) as SNUserPrefs;
this.loadingPrefs = false; this.loadingPrefs = false;
this.needsSingletonReload = false;
const didChange = const didChange =
!previousRef || !previousRef ||
this.userPreferences.lastSyncBegan?.getTime() !== this.userPreferences.lastSyncBegan?.getTime() !==