fix: reload user preferences singleton at the right time
This commit is contained in:
@@ -6,7 +6,8 @@ import {
|
|||||||
SNUserPrefs,
|
SNUserPrefs,
|
||||||
WebPrefKey,
|
WebPrefKey,
|
||||||
UserPrefsMutator,
|
UserPrefsMutator,
|
||||||
FillItemContent
|
FillItemContent,
|
||||||
|
ApplicationEvent
|
||||||
} from 'snjs';
|
} from 'snjs';
|
||||||
|
|
||||||
export class PreferencesManager extends ApplicationService {
|
export class PreferencesManager extends ApplicationService {
|
||||||
@@ -14,6 +15,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;
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
async onAppLaunch() {
|
async onAppLaunch() {
|
||||||
@@ -21,9 +23,15 @@ export class PreferencesManager extends ApplicationService {
|
|||||||
this.reloadSingleton();
|
this.reloadSingleton();
|
||||||
this.streamPreferences();
|
this.streamPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async onAppEvent(event: ApplicationEvent) {
|
||||||
|
if (event === ApplicationEvent.CompletedFullSync) {
|
||||||
|
this.reloadSingleton();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
deinit() {
|
deinit() {
|
||||||
this.unubscribeStreamItems && this.unubscribeStreamItems();
|
this.unubscribeStreamItems?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
get webApplication() {
|
get webApplication() {
|
||||||
@@ -34,13 +42,13 @@ export class PreferencesManager extends ApplicationService {
|
|||||||
this.unubscribeStreamItems = this.application!.streamItems(
|
this.unubscribeStreamItems = this.application!.streamItems(
|
||||||
ContentType.UserPrefs,
|
ContentType.UserPrefs,
|
||||||
() => {
|
() => {
|
||||||
this.reloadSingleton();
|
this.shouldReloadSingleton = true;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async reloadSingleton() {
|
private async reloadSingleton() {
|
||||||
if(this.loadingPrefs) {
|
if (this.loadingPrefs || !this.shouldReloadSingleton) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.loadingPrefs = true;
|
this.loadingPrefs = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user