Merge branch 'feature/snjs-preferences' into develop
This commit is contained in:
@@ -4,6 +4,5 @@ export { DesktopManager } from './desktopManager';
|
|||||||
export { KeyboardManager } from './keyboardManager';
|
export { KeyboardManager } from './keyboardManager';
|
||||||
export { AutolockService } from './autolock_service';
|
export { AutolockService } from './autolock_service';
|
||||||
export { NativeExtManager } from './nativeExtManager';
|
export { NativeExtManager } from './nativeExtManager';
|
||||||
export { PreferencesManager } from './preferencesManager';
|
|
||||||
export { StatusManager } from './statusManager';
|
export { StatusManager } from './statusManager';
|
||||||
export { ThemeManager } from './themeManager';
|
export { ThemeManager } from './themeManager';
|
||||||
|
|||||||
@@ -1,99 +0,0 @@
|
|||||||
import { WebApplication } from '@/ui_models/application';
|
|
||||||
import {
|
|
||||||
SNPredicate,
|
|
||||||
ContentType,
|
|
||||||
ApplicationService,
|
|
||||||
SNUserPrefs,
|
|
||||||
WebPrefKey,
|
|
||||||
UserPrefsMutator,
|
|
||||||
FillItemContent,
|
|
||||||
ApplicationEvent,
|
|
||||||
} from '@standardnotes/snjs';
|
|
||||||
|
|
||||||
export class PreferencesManager extends ApplicationService {
|
|
||||||
private userPreferences!: SNUserPrefs;
|
|
||||||
private loadingPrefs = false;
|
|
||||||
private unubscribeStreamItems?: () => void;
|
|
||||||
private needsSingletonReload = true;
|
|
||||||
|
|
||||||
/** @override */
|
|
||||||
async onAppLaunch() {
|
|
||||||
super.onAppLaunch();
|
|
||||||
this.reloadSingleton();
|
|
||||||
this.streamPreferences();
|
|
||||||
}
|
|
||||||
|
|
||||||
async onAppEvent(event: ApplicationEvent) {
|
|
||||||
super.onAppEvent(event);
|
|
||||||
if (event === ApplicationEvent.CompletedFullSync) {
|
|
||||||
this.reloadSingleton();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deinit() {
|
|
||||||
this.unubscribeStreamItems?.();
|
|
||||||
}
|
|
||||||
|
|
||||||
get webApplication() {
|
|
||||||
return this.application as WebApplication;
|
|
||||||
}
|
|
||||||
|
|
||||||
streamPreferences() {
|
|
||||||
this.unubscribeStreamItems = this.application!.streamItems(
|
|
||||||
ContentType.UserPrefs,
|
|
||||||
() => {
|
|
||||||
this.needsSingletonReload = true;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async reloadSingleton() {
|
|
||||||
if (this.loadingPrefs || !this.needsSingletonReload) {
|
|
||||||
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.loadingPrefs = false;
|
|
||||||
this.needsSingletonReload = false;
|
|
||||||
if (
|
|
||||||
previousRef?.uuid !== this.userPreferences.uuid ||
|
|
||||||
this.userPreferences.lastSyncBegan?.getTime() !==
|
|
||||||
previousRef?.lastSyncBegan?.getTime()
|
|
||||||
) {
|
|
||||||
this.webApplication
|
|
||||||
.getAppState()
|
|
||||||
.setUserPreferences(this.userPreferences);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
syncUserPreferences() {
|
|
||||||
if (this.userPreferences) {
|
|
||||||
this.application!.saveItem(this.userPreferences.uuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getValue(key: WebPrefKey, defaultValue?: any) {
|
|
||||||
if (!this.userPreferences) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
const value = this.userPreferences.getPref(key);
|
|
||||||
return value !== undefined && value !== null ? value : defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
async setUserPrefValue(key: WebPrefKey, value: any, sync = false) {
|
|
||||||
await this.application!.changeItem(this.userPreferences.uuid, (m) => {
|
|
||||||
const mutator = m as UserPrefsMutator;
|
|
||||||
mutator.setWebPref(key, value);
|
|
||||||
});
|
|
||||||
if (sync) {
|
|
||||||
this.syncUserPreferences();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -19,20 +19,19 @@ import { action, makeObservable, observable } from 'mobx';
|
|||||||
import { Bridge } from '@/services/bridge';
|
import { Bridge } from '@/services/bridge';
|
||||||
|
|
||||||
export enum AppStateEvent {
|
export enum AppStateEvent {
|
||||||
TagChanged = 1,
|
TagChanged,
|
||||||
ActiveEditorChanged = 2,
|
ActiveEditorChanged,
|
||||||
PreferencesChanged = 3,
|
PanelResized,
|
||||||
PanelResized = 4,
|
EditorFocused,
|
||||||
EditorFocused = 5,
|
BeganBackupDownload,
|
||||||
BeganBackupDownload = 6,
|
EndedBackupDownload,
|
||||||
EndedBackupDownload = 7,
|
WindowDidFocus,
|
||||||
WindowDidFocus = 9,
|
WindowDidBlur,
|
||||||
WindowDidBlur = 10,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum EventSource {
|
export enum EventSource {
|
||||||
UserInteraction = 1,
|
UserInteraction,
|
||||||
Script = 2
|
Script,
|
||||||
};
|
};
|
||||||
|
|
||||||
type ObserverCallback = (event: AppStateEvent, data?: any) => Promise<void>
|
type ObserverCallback = (event: AppStateEvent, data?: any) => Promise<void>
|
||||||
@@ -103,7 +102,6 @@ export class AppState {
|
|||||||
rootScopeCleanup2: any;
|
rootScopeCleanup2: any;
|
||||||
onVisibilityChange: any;
|
onVisibilityChange: any;
|
||||||
selectedTag?: SNTag;
|
selectedTag?: SNTag;
|
||||||
userPreferences?: SNUserPrefs;
|
|
||||||
multiEditorEnabled = false;
|
multiEditorEnabled = false;
|
||||||
showBetaWarning = false;
|
showBetaWarning = false;
|
||||||
readonly actionsMenu = new ActionsMenuState();
|
readonly actionsMenu = new ActionsMenuState();
|
||||||
@@ -379,13 +377,6 @@ export class AppState {
|
|||||||
return this.selectedTag;
|
return this.selectedTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
setUserPreferences(preferences: SNUserPrefs) {
|
|
||||||
this.userPreferences = preferences;
|
|
||||||
this.notifyEvent(
|
|
||||||
AppStateEvent.PreferencesChanged
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
panelDidResize(name: string, collapsed: boolean) {
|
panelDidResize(name: string, collapsed: boolean) {
|
||||||
this.notifyEvent(
|
this.notifyEvent(
|
||||||
AppStateEvent.PanelResized,
|
AppStateEvent.PanelResized,
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import {
|
|||||||
NativeExtManager,
|
NativeExtManager,
|
||||||
StatusManager,
|
StatusManager,
|
||||||
ThemeManager,
|
ThemeManager,
|
||||||
PreferencesManager,
|
|
||||||
KeyboardManager
|
KeyboardManager
|
||||||
} from '@/services';
|
} from '@/services';
|
||||||
import { AppState } from '@/ui_models/app_state';
|
import { AppState } from '@/ui_models/app_state';
|
||||||
@@ -38,7 +37,6 @@ type WebServices = {
|
|||||||
nativeExtService: NativeExtManager
|
nativeExtService: NativeExtManager
|
||||||
statusManager: StatusManager
|
statusManager: StatusManager
|
||||||
themeService: ThemeManager
|
themeService: ThemeManager
|
||||||
prefsService: PreferencesManager
|
|
||||||
keyboardService: KeyboardManager
|
keyboardService: KeyboardManager
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,10 +139,6 @@ export class WebApplication extends SNApplication {
|
|||||||
return this.webServices.themeService;
|
return this.webServices.themeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getPrefsService() {
|
|
||||||
return this.webServices.prefsService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getKeyboardService() {
|
public getKeyboardService() {
|
||||||
return this.webServices.keyboardService;
|
return this.webServices.keyboardService;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import {
|
|||||||
KeyboardManager,
|
KeyboardManager,
|
||||||
AutolockService,
|
AutolockService,
|
||||||
NativeExtManager,
|
NativeExtManager,
|
||||||
PreferencesManager,
|
|
||||||
StatusManager,
|
StatusManager,
|
||||||
ThemeManager
|
ThemeManager
|
||||||
} from '@/services';
|
} from '@/services';
|
||||||
@@ -82,9 +81,6 @@ export class ApplicationGroup extends SNApplicationGroup {
|
|||||||
const nativeExtService = new NativeExtManager(
|
const nativeExtService = new NativeExtManager(
|
||||||
application
|
application
|
||||||
);
|
);
|
||||||
const prefsService = new PreferencesManager(
|
|
||||||
application
|
|
||||||
);
|
|
||||||
const statusService = new StatusManager();
|
const statusService = new StatusManager();
|
||||||
const themeService = new ThemeManager(
|
const themeService = new ThemeManager(
|
||||||
application,
|
application,
|
||||||
@@ -96,7 +92,6 @@ export class ApplicationGroup extends SNApplicationGroup {
|
|||||||
keyboardService,
|
keyboardService,
|
||||||
autolockService,
|
autolockService,
|
||||||
nativeExtService,
|
nativeExtService,
|
||||||
prefsService,
|
|
||||||
statusManager: statusService,
|
statusManager: statusService,
|
||||||
themeService
|
themeService
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {
|
|||||||
Uuids,
|
Uuids,
|
||||||
ComponentArea,
|
ComponentArea,
|
||||||
ComponentAction,
|
ComponentAction,
|
||||||
WebPrefKey,
|
PrefKey,
|
||||||
ComponentMutator,
|
ComponentMutator,
|
||||||
} from '@standardnotes/snjs';
|
} from '@standardnotes/snjs';
|
||||||
import find from 'lodash/find';
|
import find from 'lodash/find';
|
||||||
@@ -135,9 +135,9 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
onReady: () => this.reloadPreferences()
|
onReady: () => this.reloadPreferences()
|
||||||
};
|
};
|
||||||
/** Used by .pug template */
|
/** Used by .pug template */
|
||||||
this.prefKeyMonospace = WebPrefKey.EditorMonospaceEnabled;
|
this.prefKeyMonospace = PrefKey.EditorMonospaceEnabled;
|
||||||
this.prefKeySpellcheck = WebPrefKey.EditorSpellcheck;
|
this.prefKeySpellcheck = PrefKey.EditorSpellcheck;
|
||||||
this.prefKeyMarginResizers = WebPrefKey.EditorResizersEnabled;
|
this.prefKeyMarginResizers = PrefKey.EditorResizersEnabled;
|
||||||
|
|
||||||
this.editorMenuOnSelect = this.editorMenuOnSelect.bind(this);
|
this.editorMenuOnSelect = this.editorMenuOnSelect.bind(this);
|
||||||
this.onPanelResizeFinish = this.onPanelResizeFinish.bind(this);
|
this.onPanelResizeFinish = this.onPanelResizeFinish.bind(this);
|
||||||
@@ -239,38 +239,39 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
this.registerComponentHandler();
|
this.registerComponentHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @override */
|
|
||||||
onAppStateEvent(eventName: AppStateEvent, data: any) {
|
|
||||||
if (eventName === AppStateEvent.PreferencesChanged) {
|
|
||||||
this.reloadPreferences();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
onAppEvent(eventName: ApplicationEvent) {
|
onAppEvent(eventName: ApplicationEvent) {
|
||||||
if (eventName === ApplicationEvent.HighLatencySync) {
|
switch (eventName) {
|
||||||
this.setState({ syncTakingTooLong: true });
|
case ApplicationEvent.PreferencesChanged:
|
||||||
} else if (eventName === ApplicationEvent.CompletedFullSync) {
|
this.reloadPreferences();
|
||||||
this.setState({ syncTakingTooLong: false });
|
break;
|
||||||
const isInErrorState = this.state.saveError;
|
case ApplicationEvent.HighLatencySync:
|
||||||
/** if we're still dirty, don't change status, a sync is likely upcoming. */
|
this.setState({ syncTakingTooLong: true });
|
||||||
if (!this.note.dirty && isInErrorState) {
|
break;
|
||||||
this.showAllChangesSavedStatus();
|
case ApplicationEvent.CompletedFullSync:
|
||||||
}
|
this.setState({ syncTakingTooLong: false });
|
||||||
} else if (eventName === ApplicationEvent.FailedSync) {
|
const isInErrorState = this.state.saveError;
|
||||||
/**
|
/** if we're still dirty, don't change status, a sync is likely upcoming. */
|
||||||
* Only show error status in editor if the note is dirty.
|
if (!this.note.dirty && isInErrorState) {
|
||||||
* Otherwise, it means the originating sync came from somewhere else
|
this.showAllChangesSavedStatus();
|
||||||
* and we don't want to display an error here.
|
}
|
||||||
*/
|
break;
|
||||||
if (this.note.dirty) {
|
case ApplicationEvent.FailedSync:
|
||||||
this.showErrorStatus();
|
/**
|
||||||
}
|
* Only show error status in editor if the note is dirty.
|
||||||
} else if (eventName === ApplicationEvent.LocalDatabaseWriteError) {
|
* Otherwise, it means the originating sync came from somewhere else
|
||||||
this.showErrorStatus({
|
* and we don't want to display an error here.
|
||||||
message: "Offline Saving Issue",
|
*/
|
||||||
desc: "Changes not saved"
|
if (this.note.dirty) {
|
||||||
});
|
this.showErrorStatus();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ApplicationEvent.LocalDatabaseWriteError:
|
||||||
|
this.showErrorStatus({
|
||||||
|
message: "Offline Saving Issue",
|
||||||
|
desc: "Changes not saved"
|
||||||
|
});
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -891,40 +892,40 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
|
|
||||||
async onPanelResizeFinish(width: number, left: number, isMaxWidth: boolean) {
|
async onPanelResizeFinish(width: number, left: number, isMaxWidth: boolean) {
|
||||||
if (isMaxWidth) {
|
if (isMaxWidth) {
|
||||||
await this.application.getPrefsService().setUserPrefValue(
|
await this.application.setPreference(
|
||||||
WebPrefKey.EditorWidth,
|
PrefKey.EditorWidth,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (width !== undefined && width !== null) {
|
if (width !== undefined && width !== null) {
|
||||||
await this.application.getPrefsService().setUserPrefValue(
|
await this.application.setPreference(
|
||||||
WebPrefKey.EditorWidth,
|
PrefKey.EditorWidth,
|
||||||
width
|
width
|
||||||
);
|
);
|
||||||
this.leftPanelPuppet!.setWidth!(width);
|
this.leftPanelPuppet!.setWidth!(width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (left !== undefined && left !== null) {
|
if (left !== undefined && left !== null) {
|
||||||
await this.application.getPrefsService().setUserPrefValue(
|
await this.application.setPreference(
|
||||||
WebPrefKey.EditorLeft,
|
PrefKey.EditorLeft,
|
||||||
left
|
left
|
||||||
);
|
);
|
||||||
this.rightPanelPuppet!.setLeft!(left);
|
this.rightPanelPuppet!.setLeft!(left);
|
||||||
}
|
}
|
||||||
this.application.getPrefsService().syncUserPreferences();
|
this.application.sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
async reloadPreferences() {
|
async reloadPreferences() {
|
||||||
const monospaceFont = this.application.getPrefsService().getValue(
|
const monospaceFont = this.application.getPreference(
|
||||||
WebPrefKey.EditorMonospaceEnabled,
|
PrefKey.EditorMonospaceEnabled,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
const spellcheck = this.application.getPrefsService().getValue(
|
const spellcheck = this.application.getPreference(
|
||||||
WebPrefKey.EditorSpellcheck,
|
PrefKey.EditorSpellcheck,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
const marginResizersEnabled = this.application.getPrefsService().getValue(
|
const marginResizersEnabled = this.application.getPreference(
|
||||||
WebPrefKey.EditorResizersEnabled,
|
PrefKey.EditorResizersEnabled,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
await this.setState({
|
await this.setState({
|
||||||
@@ -945,16 +946,16 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
this.leftPanelPuppet?.ready &&
|
this.leftPanelPuppet?.ready &&
|
||||||
this.rightPanelPuppet?.ready
|
this.rightPanelPuppet?.ready
|
||||||
) {
|
) {
|
||||||
const width = this.application.getPrefsService().getValue(
|
const width = this.application.getPreference(
|
||||||
WebPrefKey.EditorWidth,
|
PrefKey.EditorWidth,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
if (width != null) {
|
if (width != null) {
|
||||||
this.leftPanelPuppet!.setWidth!(width);
|
this.leftPanelPuppet!.setWidth!(width);
|
||||||
this.rightPanelPuppet!.setWidth!(width);
|
this.rightPanelPuppet!.setWidth!(width);
|
||||||
}
|
}
|
||||||
const left = this.application.getPrefsService().getValue(
|
const left = this.application.getPreference(
|
||||||
WebPrefKey.EditorLeft,
|
PrefKey.EditorLeft,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
if (left != null) {
|
if (left != null) {
|
||||||
@@ -982,24 +983,23 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async toggleWebPrefKey(key: WebPrefKey) {
|
async toggleWebPrefKey(key: PrefKey) {
|
||||||
const currentValue = (this.state as any)[key];
|
const currentValue = (this.state as any)[key];
|
||||||
await this.application.getPrefsService().setUserPrefValue(
|
await this.application.setPreference(
|
||||||
key,
|
key,
|
||||||
!currentValue,
|
!currentValue,
|
||||||
true
|
|
||||||
);
|
);
|
||||||
await this.setState({
|
await this.setState({
|
||||||
[key]: !currentValue
|
[key]: !currentValue
|
||||||
})
|
})
|
||||||
this.reloadFont();
|
this.reloadFont();
|
||||||
|
|
||||||
if (key === WebPrefKey.EditorSpellcheck) {
|
if (key === PrefKey.EditorSpellcheck) {
|
||||||
/** Allows textarea to reload */
|
/** Allows textarea to reload */
|
||||||
await this.setState({ textareaUnloading: true });
|
await this.setState({ textareaUnloading: true });
|
||||||
await this.setState({ textareaUnloading: false });
|
await this.setState({ textareaUnloading: false });
|
||||||
this.reloadFont();
|
this.reloadFont();
|
||||||
} else if (key === WebPrefKey.EditorResizersEnabled && this.state[key] === true) {
|
} else if (key === PrefKey.EditorResizersEnabled && this.state[key] === true) {
|
||||||
this.$timeout(() => {
|
this.$timeout(() => {
|
||||||
this.leftPanelPuppet!.flash!();
|
this.leftPanelPuppet!.flash!();
|
||||||
this.rightPanelPuppet!.flash!();
|
this.rightPanelPuppet!.flash!();
|
||||||
|
|||||||
@@ -1,16 +1,5 @@
|
|||||||
import { SNNote } from '@standardnotes/snjs';
|
import { SNNote } from '@standardnotes/snjs';
|
||||||
|
|
||||||
export enum NoteSortKey {
|
|
||||||
CreatedAt = 'created_at',
|
|
||||||
UserUpdatedAt = 'userModifiedDate',
|
|
||||||
Title = 'title',
|
|
||||||
|
|
||||||
/** @legacy Use UserUpdatedAt instead */
|
|
||||||
UpdatedAt = 'updated_at',
|
|
||||||
/** @legacy Use UserUpdatedAt instead */
|
|
||||||
ClientUpdatedAt = 'client_updated_at',
|
|
||||||
}
|
|
||||||
|
|
||||||
export function notePassesFilter(
|
export function notePassesFilter(
|
||||||
note: SNNote,
|
note: SNNote,
|
||||||
showArchived: boolean,
|
showArchived: boolean,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
removeFromArray,
|
removeFromArray,
|
||||||
SNNote,
|
SNNote,
|
||||||
SNTag,
|
SNTag,
|
||||||
WebPrefKey,
|
PrefKey,
|
||||||
findInArray,
|
findInArray,
|
||||||
CollectionSort,
|
CollectionSort,
|
||||||
} from '@standardnotes/snjs';
|
} from '@standardnotes/snjs';
|
||||||
@@ -17,7 +17,6 @@ import {
|
|||||||
PANEL_NAME_NOTES
|
PANEL_NAME_NOTES
|
||||||
} from '@/views/constants';
|
} from '@/views/constants';
|
||||||
import {
|
import {
|
||||||
NoteSortKey,
|
|
||||||
notePassesFilter
|
notePassesFilter
|
||||||
} from './note_utils';
|
} from './note_utils';
|
||||||
import { UuidString } from '@standardnotes/snjs';
|
import { UuidString } from '@standardnotes/snjs';
|
||||||
@@ -37,13 +36,13 @@ type NotesState = {
|
|||||||
noteFilter: { text: string }
|
noteFilter: { text: string }
|
||||||
mutable: { showMenu: boolean }
|
mutable: { showMenu: boolean }
|
||||||
completedFullSync: boolean
|
completedFullSync: boolean
|
||||||
[WebPrefKey.TagsPanelWidth]?: number
|
[PrefKey.TagsPanelWidth]?: number
|
||||||
[WebPrefKey.NotesPanelWidth]?: number
|
[PrefKey.NotesPanelWidth]?: number
|
||||||
[WebPrefKey.EditorWidth]?: number
|
[PrefKey.EditorWidth]?: number
|
||||||
[WebPrefKey.EditorLeft]?: number
|
[PrefKey.EditorLeft]?: number
|
||||||
[WebPrefKey.EditorMonospaceEnabled]?: boolean
|
[PrefKey.EditorMonospaceEnabled]?: boolean
|
||||||
[WebPrefKey.EditorSpellcheck]?: boolean
|
[PrefKey.EditorSpellcheck]?: boolean
|
||||||
[WebPrefKey.EditorResizersEnabled]?: boolean
|
[PrefKey.EditorResizersEnabled]?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
type NoteFlag = {
|
type NoteFlag = {
|
||||||
@@ -147,8 +146,6 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
|
|||||||
this.handleTagChange(this.selectedTag!);
|
this.handleTagChange(this.selectedTag!);
|
||||||
} else if (eventName === AppStateEvent.ActiveEditorChanged) {
|
} else if (eventName === AppStateEvent.ActiveEditorChanged) {
|
||||||
this.handleEditorChange();
|
this.handleEditorChange();
|
||||||
} else if (eventName === AppStateEvent.PreferencesChanged) {
|
|
||||||
this.reloadPreferences();
|
|
||||||
} else if (eventName === AppStateEvent.EditorFocused) {
|
} else if (eventName === AppStateEvent.EditorFocused) {
|
||||||
this.setShowMenuFalse();
|
this.setShowMenuFalse();
|
||||||
}
|
}
|
||||||
@@ -166,6 +163,9 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
|
|||||||
/** @override */
|
/** @override */
|
||||||
async onAppEvent(eventName: ApplicationEvent) {
|
async onAppEvent(eventName: ApplicationEvent) {
|
||||||
switch (eventName) {
|
switch (eventName) {
|
||||||
|
case ApplicationEvent.PreferencesChanged:
|
||||||
|
this.reloadPreferences();
|
||||||
|
break;
|
||||||
case ApplicationEvent.SignedIn:
|
case ApplicationEvent.SignedIn:
|
||||||
this.appState.closeAllEditors();
|
this.appState.closeAllEditors();
|
||||||
this.selectFirstNote();
|
this.selectFirstNote();
|
||||||
@@ -420,37 +420,40 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
|
|||||||
async reloadPreferences() {
|
async reloadPreferences() {
|
||||||
const viewOptions = {} as NotesState;
|
const viewOptions = {} as NotesState;
|
||||||
const prevSortValue = this.getState().sortBy;
|
const prevSortValue = this.getState().sortBy;
|
||||||
let sortBy = this.application!.getPrefsService().getValue(
|
let sortBy = this.application!.getPreference(
|
||||||
WebPrefKey.SortNotesBy,
|
PrefKey.SortNotesBy,
|
||||||
NoteSortKey.CreatedAt
|
CollectionSort.CreatedAt
|
||||||
);
|
);
|
||||||
if (sortBy === NoteSortKey.UpdatedAt || sortBy === NoteSortKey.ClientUpdatedAt) {
|
if (
|
||||||
|
sortBy === CollectionSort.UpdatedAt ||
|
||||||
|
(sortBy as string) === "client_updated_at"
|
||||||
|
) {
|
||||||
/** Use UserUpdatedAt instead */
|
/** Use UserUpdatedAt instead */
|
||||||
sortBy = NoteSortKey.UserUpdatedAt;
|
sortBy = CollectionSort.UpdatedAt;
|
||||||
}
|
}
|
||||||
viewOptions.sortBy = sortBy;
|
viewOptions.sortBy = sortBy;
|
||||||
viewOptions.sortReverse = this.application!.getPrefsService().getValue(
|
viewOptions.sortReverse = this.application!.getPreference(
|
||||||
WebPrefKey.SortNotesReverse,
|
PrefKey.SortNotesReverse,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
viewOptions.showArchived = this.application!.getPrefsService().getValue(
|
viewOptions.showArchived = this.application!.getPreference(
|
||||||
WebPrefKey.NotesShowArchived,
|
PrefKey.NotesShowArchived,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
viewOptions.hidePinned = this.application!.getPrefsService().getValue(
|
viewOptions.hidePinned = this.application!.getPreference(
|
||||||
WebPrefKey.NotesHidePinned,
|
PrefKey.NotesHidePinned,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
viewOptions.hideNotePreview = this.application!.getPrefsService().getValue(
|
viewOptions.hideNotePreview = this.application!.getPreference(
|
||||||
WebPrefKey.NotesHideNotePreview,
|
PrefKey.NotesHideNotePreview,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
viewOptions.hideDate = this.application!.getPrefsService().getValue(
|
viewOptions.hideDate = this.application!.getPreference(
|
||||||
WebPrefKey.NotesHideDate,
|
PrefKey.NotesHideDate,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
viewOptions.hideTags = this.application.getPrefsService().getValue(
|
viewOptions.hideTags = this.application.getPreference(
|
||||||
WebPrefKey.NotesHideTags,
|
PrefKey.NotesHideTags,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
const state = this.getState();
|
const state = this.getState();
|
||||||
@@ -475,8 +478,8 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reloadPanelWidth() {
|
reloadPanelWidth() {
|
||||||
const width = this.application!.getPrefsService().getValue(
|
const width = this.application!.getPreference(
|
||||||
WebPrefKey.NotesPanelWidth
|
PrefKey.NotesPanelWidth
|
||||||
);
|
);
|
||||||
if (width && this.panelPuppet!.ready) {
|
if (width && this.panelPuppet!.ready) {
|
||||||
this.panelPuppet!.setWidth!(width);
|
this.panelPuppet!.setWidth!(width);
|
||||||
@@ -495,10 +498,9 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
|
|||||||
__: boolean,
|
__: boolean,
|
||||||
isCollapsed: boolean
|
isCollapsed: boolean
|
||||||
) {
|
) {
|
||||||
this.application!.getPrefsService().setUserPrefValue(
|
this.application!.setPreference(
|
||||||
WebPrefKey.NotesPanelWidth,
|
PrefKey.NotesPanelWidth,
|
||||||
newWidth,
|
newWidth
|
||||||
true
|
|
||||||
);
|
);
|
||||||
this.application!.getAppState().panelDidResize(
|
this.application!.getAppState().panelDidResize(
|
||||||
PANEL_NAME_NOTES,
|
PANEL_NAME_NOTES,
|
||||||
@@ -541,11 +543,11 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
|
|||||||
|
|
||||||
optionsSubtitle() {
|
optionsSubtitle() {
|
||||||
let base = "";
|
let base = "";
|
||||||
if (this.getState().sortBy === NoteSortKey.CreatedAt) {
|
if (this.getState().sortBy === CollectionSort.CreatedAt) {
|
||||||
base += " Date Added";
|
base += " Date Added";
|
||||||
} else if (this.getState().sortBy === NoteSortKey.UserUpdatedAt) {
|
} else if (this.getState().sortBy === CollectionSort.UpdatedAt) {
|
||||||
base += " Date Modified";
|
base += " Date Modified";
|
||||||
} else if (this.getState().sortBy === NoteSortKey.Title) {
|
} else if (this.getState().sortBy === CollectionSort.Title) {
|
||||||
base += " Title";
|
base += " Title";
|
||||||
}
|
}
|
||||||
if (this.getState().showArchived) {
|
if (this.getState().showArchived) {
|
||||||
@@ -709,40 +711,37 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
|
|||||||
this.setShowMenuFalse();
|
this.setShowMenuFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleWebPrefKey(key: WebPrefKey) {
|
togglePrefKey(key: PrefKey) {
|
||||||
this.application!.getPrefsService().setUserPrefValue(
|
this.application!.setPreference(
|
||||||
key,
|
key,
|
||||||
!this.state[key],
|
!this.state[key]
|
||||||
true
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedSortByCreated() {
|
selectedSortByCreated() {
|
||||||
this.setSortBy(NoteSortKey.CreatedAt);
|
this.setSortBy(CollectionSort.CreatedAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedSortByUpdated() {
|
selectedSortByUpdated() {
|
||||||
this.setSortBy(NoteSortKey.ClientUpdatedAt);
|
this.setSortBy(CollectionSort.UpdatedAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedSortByTitle() {
|
selectedSortByTitle() {
|
||||||
this.setSortBy(NoteSortKey.Title);
|
this.setSortBy(CollectionSort.Title);
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleReverseSort() {
|
toggleReverseSort() {
|
||||||
this.selectedMenuItem();
|
this.selectedMenuItem();
|
||||||
this.application!.getPrefsService().setUserPrefValue(
|
this.application!.setPreference(
|
||||||
WebPrefKey.SortNotesReverse,
|
PrefKey.SortNotesReverse,
|
||||||
!this.getState().sortReverse,
|
!this.getState().sortReverse
|
||||||
true
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
setSortBy(type: NoteSortKey) {
|
setSortBy(type: CollectionSort) {
|
||||||
this.application!.getPrefsService().setUserPrefValue(
|
this.application!.setPreference(
|
||||||
WebPrefKey.SortNotesBy,
|
PrefKey.SortNotesBy,
|
||||||
type,
|
type
|
||||||
true
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
SNSmartTag,
|
SNSmartTag,
|
||||||
ComponentArea,
|
ComponentArea,
|
||||||
SNComponent,
|
SNComponent,
|
||||||
WebPrefKey,
|
PrefKey,
|
||||||
UuidString,
|
UuidString,
|
||||||
TagMutator
|
TagMutator
|
||||||
} from '@standardnotes/snjs';
|
} from '@standardnotes/snjs';
|
||||||
@@ -145,10 +145,8 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
onAppStateEvent(eventName: AppStateEvent, data?: any) {
|
onAppStateEvent(eventName: AppStateEvent) {
|
||||||
if (eventName === AppStateEvent.PreferencesChanged) {
|
if (eventName === AppStateEvent.TagChanged) {
|
||||||
this.loadPreferences();
|
|
||||||
} else if (eventName === AppStateEvent.TagChanged) {
|
|
||||||
this.setState({
|
this.setState({
|
||||||
selectedTag: this.application.getAppState().getSelectedTag()
|
selectedTag: this.application.getAppState().getSelectedTag()
|
||||||
});
|
});
|
||||||
@@ -159,8 +157,13 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> {
|
|||||||
/** @override */
|
/** @override */
|
||||||
async onAppEvent(eventName: ApplicationEvent) {
|
async onAppEvent(eventName: ApplicationEvent) {
|
||||||
super.onAppEvent(eventName);
|
super.onAppEvent(eventName);
|
||||||
if (eventName === ApplicationEvent.LocalDataIncrementalLoad) {
|
switch (eventName) {
|
||||||
this.reloadNoteCounts();
|
case ApplicationEvent.LocalDataIncrementalLoad:
|
||||||
|
this.reloadNoteCounts();
|
||||||
|
break;
|
||||||
|
case ApplicationEvent.PreferencesChanged:
|
||||||
|
this.loadPreferences();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +206,7 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> {
|
|||||||
if (!this.panelPuppet.ready) {
|
if (!this.panelPuppet.ready) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const width = this.application.getPrefsService().getValue(WebPrefKey.TagsPanelWidth);
|
const width = this.application.getPreference(PrefKey.TagsPanelWidth);
|
||||||
if (width) {
|
if (width) {
|
||||||
this.panelPuppet.setWidth!(width);
|
this.panelPuppet.setWidth!(width);
|
||||||
if (this.panelPuppet.isCollapsed!()) {
|
if (this.panelPuppet.isCollapsed!()) {
|
||||||
@@ -221,11 +224,10 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> {
|
|||||||
_isAtMaxWidth: boolean,
|
_isAtMaxWidth: boolean,
|
||||||
isCollapsed: boolean
|
isCollapsed: boolean
|
||||||
) => {
|
) => {
|
||||||
this.application.getPrefsService().setUserPrefValue(
|
this.application.setPreference(
|
||||||
WebPrefKey.TagsPanelWidth,
|
PrefKey.TagsPanelWidth,
|
||||||
newWidth,
|
newWidth
|
||||||
true
|
).then(() => this.application.sync());
|
||||||
);
|
|
||||||
this.application.getAppState().panelDidResize(
|
this.application.getAppState().panelDidResize(
|
||||||
PANEL_NAME_TAGS,
|
PANEL_NAME_TAGS,
|
||||||
isCollapsed
|
isCollapsed
|
||||||
|
|||||||
@@ -42,8 +42,6 @@
|
|||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"eslint": "^6.8.0",
|
"eslint": "^6.8.0",
|
||||||
"eslint-config-prettier": "^6.10.0",
|
"eslint-config-prettier": "^6.10.0",
|
||||||
"eslint-config-semistandard": "^15.0.0",
|
|
||||||
"eslint-config-standard": "^14.1.0",
|
|
||||||
"eslint-plugin-import": "^2.20.1",
|
"eslint-plugin-import": "^2.20.1",
|
||||||
"eslint-plugin-promise": "^4.2.1",
|
"eslint-plugin-promise": "^4.2.1",
|
||||||
"eslint-plugin-standard": "^4.0.1",
|
"eslint-plugin-standard": "^4.0.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user