style: formatting
This commit is contained in:
@@ -7,12 +7,11 @@ import {
|
|||||||
WebPrefKey,
|
WebPrefKey,
|
||||||
UserPrefsMutator,
|
UserPrefsMutator,
|
||||||
FillItemContent,
|
FillItemContent,
|
||||||
ApplicationEvent
|
ApplicationEvent,
|
||||||
} from 'snjs';
|
} from 'snjs';
|
||||||
|
|
||||||
export class PreferencesManager extends ApplicationService {
|
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 shouldReloadSingleton = true;
|
||||||
@@ -58,14 +57,17 @@ export class PreferencesManager extends ApplicationService {
|
|||||||
this.userPreferences = (await this.application!.singletonManager!.findOrCreateSingleton(
|
this.userPreferences = (await this.application!.singletonManager!.findOrCreateSingleton(
|
||||||
predicate,
|
predicate,
|
||||||
contentType,
|
contentType,
|
||||||
FillItemContent({})
|
FillItemContent({}),
|
||||||
)) as SNUserPrefs;
|
)) as SNUserPrefs;
|
||||||
this.loadingPrefs = false;
|
this.loadingPrefs = false;
|
||||||
const didChange = !previousRef || (
|
const didChange =
|
||||||
this.userPreferences.lastSyncBegan?.getTime() !== previousRef?.lastSyncBegan?.getTime()
|
!previousRef ||
|
||||||
)
|
this.userPreferences.lastSyncBegan?.getTime() !==
|
||||||
|
previousRef?.lastSyncBegan?.getTime();
|
||||||
if (didChange) {
|
if (didChange) {
|
||||||
this.webApplication.getAppState().setUserPreferences(this.userPreferences);
|
this.webApplication
|
||||||
|
.getAppState()
|
||||||
|
.setUserPreferences(this.userPreferences);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,19 +78,18 @@ export class PreferencesManager extends ApplicationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getValue(key: WebPrefKey, defaultValue?: any) {
|
getValue(key: WebPrefKey, defaultValue?: any) {
|
||||||
if (!this.userPreferences) { return defaultValue; }
|
if (!this.userPreferences) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
const value = this.userPreferences.getPref(key);
|
const value = this.userPreferences.getPref(key);
|
||||||
return (value !== undefined && value !== null) ? value : defaultValue;
|
return value !== undefined && value !== null ? value : defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
async setUserPrefValue(key: WebPrefKey, value: any, sync = false) {
|
async setUserPrefValue(key: WebPrefKey, value: any, sync = false) {
|
||||||
await this.application!.changeItem(
|
await this.application!.changeItem(this.userPreferences.uuid, (m) => {
|
||||||
this.userPreferences.uuid,
|
const mutator = m as UserPrefsMutator;
|
||||||
(m) => {
|
mutator.setWebPref(key, value);
|
||||||
const mutator = m as UserPrefsMutator;
|
});
|
||||||
mutator.setWebPref(key, value);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
if (sync) {
|
if (sync) {
|
||||||
this.syncUserPreferences();
|
this.syncUserPreferences();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user