fix: deregister stream observers on editor deinit

This commit is contained in:
Mo Bitar
2020-04-21 12:17:01 -05:00
parent 84de39375c
commit f9733f8dac
7 changed files with 318 additions and 247 deletions

View File

@@ -12,12 +12,12 @@ import {
export class PreferencesManager extends ApplicationService {
private userPreferences!: SNUserPrefs
private loadingPrefs = false;
/** @override */
async onAppLaunch() {
super.onAppLaunch();
this.streamPreferences();
this.loadSingleton();
}
get webApplication() {
@@ -33,19 +33,26 @@ export class PreferencesManager extends ApplicationService {
);
}
async loadSingleton() {
private async loadSingleton() {
if(this.loadingPrefs) {
return;
}
this.loadingPrefs = true;
const contentType = ContentType.UserPrefs;
const predicate = new SNPredicate('content_type', '=', contentType);
const previousRef = this.userPreferences;
this.userPreferences = (await this.application!.singletonManager!.findOrCreateSingleton(
predicate,
contentType,
FillItemContent({})
)) as SNUserPrefs;
this.preferencesDidChange();
}
preferencesDidChange() {
this.webApplication.getAppState().setUserPreferences(this.userPreferences);
this.loadingPrefs = false;
const didChange = !previousRef || (
this.userPreferences.lastSyncBegan?.getTime() !== previousRef?.lastSyncBegan?.getTime()
)
if (didChange) {
this.webApplication.getAppState().setUserPreferences(this.userPreferences);
}
}
syncUserPreferences() {