Fixes user prefs sync race condition

This commit is contained in:
Mo Bitar
2020-04-16 10:17:19 -05:00
parent c94742d248
commit 4451832c9e
5 changed files with 211 additions and 145 deletions

View File

@@ -60,8 +60,8 @@ export class PreferencesManager extends ApplicationService {
return (value !== undefined && value !== null) ? value : defaultValue;
}
setUserPrefValue(key: WebPrefKey, value: any, sync = false) {
this.application!.changeItem(
async setUserPrefValue(key: WebPrefKey, value: any, sync = false) {
await this.application!.changeItem(
this.userPreferences.uuid,
(m) => {
const mutator = m as UserPrefsMutator;

View File

@@ -477,7 +477,7 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
}
if (this.editor.isTemplateNote) {
await this.editor.insertTemplatedNote();
if (this.appState.selectedTag) {
if (this.appState.selectedTag?.isSmartTag() === false) {
await this.application.changeItem(
this.appState.selectedTag!.uuid,
(mutator) => {
@@ -879,15 +879,15 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
this.reloadTagsString();
}
onPanelResizeFinish(width: number, left: number, isMaxWidth: boolean) {
async onPanelResizeFinish(width: number, left: number, isMaxWidth: boolean) {
if (isMaxWidth) {
this.application.getPrefsService().setUserPrefValue(
await this.application.getPrefsService().setUserPrefValue(
WebPrefKey.EditorWidth,
null
);
} else {
if (width !== undefined && width !== null) {
this.application.getPrefsService().setUserPrefValue(
await this.application.getPrefsService().setUserPrefValue(
WebPrefKey.EditorWidth,
width
);
@@ -895,7 +895,7 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
}
}
if (left !== undefined && left !== null) {
this.application.getPrefsService().setUserPrefValue(
await this.application.getPrefsService().setUserPrefValue(
WebPrefKey.EditorLeft,
left
);

View File

@@ -400,9 +400,9 @@ class NotesViewCtrl extends PureViewCtrl {
) {
this.application!.getPrefsService().setUserPrefValue(
WebPrefKey.NotesPanelWidth,
newWidth
newWidth,
true
);
this.application!.getPrefsService().syncUserPreferences();
this.application!.getAppState().panelDidResize(
PANEL_NAME_NOTES,
isCollapsed
@@ -563,7 +563,7 @@ class NotesViewCtrl extends PureViewCtrl {
const note = this.getFirstNonProtectedNote();
if (note) {
this.selectNote(note);
} else if (!this.appState.selectedTag|| !this.appState.selectedTag.isSmartTag()) {
} else if (!this.appState.selectedTag || !this.appState.selectedTag.isSmartTag()) {
this.createPlaceholderNote();
} else {
this.appState.closeActiveEditor();
@@ -624,8 +624,11 @@ class NotesViewCtrl extends PureViewCtrl {
}
toggleWebPrefKey(key: WebPrefKey) {
this.application!.getPrefsService().setUserPrefValue(key, !this.state[key]);
this.application!.getPrefsService().syncUserPreferences();
this.application!.getPrefsService().setUserPrefValue(
key,
!this.state[key],
true
);
}
selectedSortByCreated() {
@@ -644,17 +647,17 @@ class NotesViewCtrl extends PureViewCtrl {
this.selectedMenuItem();
this.application!.getPrefsService().setUserPrefValue(
WebPrefKey.SortNotesReverse,
!this.getState().sortReverse
!this.getState().sortReverse,
true
);
this.application!.getPrefsService().syncUserPreferences();
}
setSortBy(type: NoteSortKey) {
this.application!.getPrefsService().setUserPrefValue(
WebPrefKey.SortNotesBy,
type
type,
true
);
this.application!.getPrefsService().syncUserPreferences();
}
getSearchBar() {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long