From 82ee0974c1a94a09e71558edbb94f65283d9f663 Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Sun, 5 Dec 2021 11:04:46 -0600 Subject: [PATCH] feat: snjs upgrade and fixes --- .../directives/views/editorMenu.ts | 4 +- .../javascripts/services/themeManager.ts | 61 +++++++++++-------- .../ui_models/app_state/app_state.ts | 2 +- .../javascripts/views/editor/editor_view.ts | 4 +- package.json | 4 +- yarn.lock | 8 +-- 6 files changed, 47 insertions(+), 36 deletions(-) diff --git a/app/assets/javascripts/directives/views/editorMenu.ts b/app/assets/javascripts/directives/views/editorMenu.ts index 2c41dc302c1..646e943e94f 100644 --- a/app/assets/javascripts/directives/views/editorMenu.ts +++ b/app/assets/javascripts/directives/views/editorMenu.ts @@ -35,8 +35,8 @@ class EditorMenuCtrl extends PureViewCtrl implements EditorMenuScope { $onInit() { super.$onInit(); - const editors = this.application - .componentManager!.componentsForArea(ComponentArea.Editor) + const editors = this.application.componentManager + .componentsForArea(ComponentArea.Editor) .sort((a, b) => { return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1; }); diff --git a/app/assets/javascripts/services/themeManager.ts b/app/assets/javascripts/services/themeManager.ts index 2357bc8682e..ff514ad3446 100644 --- a/app/assets/javascripts/services/themeManager.ts +++ b/app/assets/javascripts/services/themeManager.ts @@ -5,16 +5,16 @@ import { ApplicationService, SNTheme, removeFromArray, - ApplicationEvent, ContentType + ApplicationEvent, + ContentType, } from '@standardnotes/snjs'; const CACHED_THEMES_KEY = 'cachedThemes'; export class ThemeManager extends ApplicationService { - - private activeThemes: string[] = [] - private unregisterDesktop!: () => void - private unregisterStream!: () => void + private activeThemes: string[] = []; + private unregisterDesktop!: () => void; + private unregisterStream!: () => void; async onAppEvent(event: ApplicationEvent) { super.onAppEvent(event); @@ -54,7 +54,8 @@ export class ThemeManager extends ApplicationService { } private registerObservers() { - this.unregisterDesktop = this.webApplication.getDesktopService() + this.unregisterDesktop = this.webApplication + .getDesktopService() .registerUpdateObserver((component) => { if (component.active && component.isTheme()) { this.deactivateTheme(component.uuid); @@ -64,16 +65,21 @@ export class ThemeManager extends ApplicationService { } }); - this.unregisterStream = this.application.streamItems(ContentType.Theme, (items) => { - const themes = items as SNTheme[]; - for (const theme of themes) { - if (theme.active) { - this.activateTheme(theme); - } else { - this.deactivateTheme(theme.uuid); + this.unregisterStream = this.application.streamItems( + ContentType.Theme, + () => { + const themes = this.application.getDisplayableItems( + ContentType.Theme + ) as SNTheme[]; + for (const theme of themes) { + if (theme.active) { + this.activateTheme(theme); + } else { + this.deactivateTheme(theme.uuid); + } } } - }); + ); } private clearAppThemeState() { @@ -120,14 +126,17 @@ export class ThemeManager extends ApplicationService { private async cacheThemes() { const themes = this.application!.getAll(this.activeThemes) as SNTheme[]; - const mapped = await Promise.all(themes.map(async (theme) => { - const payload = theme.payloadRepresentation(); - const processedPayload = await this.application!.protocolService!.payloadByEncryptingPayload( - payload, - EncryptionIntent.LocalStorageDecrypted - ); - return processedPayload; - })); + const mapped = await Promise.all( + themes.map(async (theme) => { + const payload = theme.payloadRepresentation(); + const processedPayload = + await this.application!.protocolService!.payloadByEncryptingPayload( + payload, + EncryptionIntent.LocalStorageDecrypted + ); + return processedPayload; + }) + ); return this.application!.setValue( CACHED_THEMES_KEY, mapped, @@ -145,15 +154,17 @@ export class ThemeManager extends ApplicationService { } private async getCachedThemes() { - const cachedThemes = await this.application!.getValue( + const cachedThemes = (await this.application!.getValue( CACHED_THEMES_KEY, StorageValueModes.Nonwrapped - ) as SNTheme[]; + )) as SNTheme[]; if (cachedThemes) { const themes = []; for (const cachedTheme of cachedThemes) { const payload = this.application!.createPayloadFromObject(cachedTheme); - const theme = this.application!.createItemFromPayload(payload) as SNTheme; + const theme = this.application!.createItemFromPayload( + payload + ) as SNTheme; themes.push(theme); } return themes; diff --git a/app/assets/javascripts/ui_models/app_state/app_state.ts b/app/assets/javascripts/ui_models/app_state/app_state.ts index 1361419e867..7ee09f8d8e6 100644 --- a/app/assets/javascripts/ui_models/app_state/app_state.ts +++ b/app/assets/javascripts/ui_models/app_state/app_state.ts @@ -261,7 +261,7 @@ export class AppState { } streamNotesAndTags() { - this.application!.streamItems( + this.application.streamItems( [ContentType.Note, ContentType.Tag], async (items, source) => { /** Close any editors for deleted/trashed/archived notes */ diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index 81af133c344..2f322451ef3 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/editor/editor_view.ts @@ -740,8 +740,8 @@ class EditorViewCtrl extends PureViewCtrl { async reloadStackComponents() { const stackComponents = sortAlphabetically( - this.application - .componentManager!.componentsForArea(ComponentArea.EditorStack) + this.application.componentManager + .componentsForArea(ComponentArea.EditorStack) .filter((component) => component.active) ); if (this.note) { diff --git a/package.json b/package.json index edaf490f774..55f7a715e83 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "standard-notes-web", - "version": "3.9.5", + "version": "3.9.6", "license": "AGPL-3.0-or-later", "repository": { "type": "git", @@ -80,7 +80,7 @@ "@reach/listbox": "^0.16.2", "@standardnotes/features": "1.10.1", "@standardnotes/sncrypto-web": "1.5.3", - "@standardnotes/snjs": "2.18.3", + "@standardnotes/snjs": "2.19.6", "mobx": "^6.3.5", "mobx-react-lite": "^3.2.2", "preact": "^10.5.15", diff --git a/yarn.lock b/yarn.lock index 14d82273ea6..79ddebdf0c6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2614,10 +2614,10 @@ buffer "^6.0.3" libsodium-wrappers "^0.7.9" -"@standardnotes/snjs@2.18.3": - version "2.18.3" - resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.18.3.tgz#5dd685c6e0df4c07c98b087aa672411e9becde4c" - integrity sha512-Q8X1UUSUw4NkKcZPHFYZ/WH9weOXW7LelOE1kCBx/O1g284dJWvHhqQh8qTgjHQnrcYR8Xh3AfoR0bh1Ms+iyA== +"@standardnotes/snjs@2.19.6": + version "2.19.6" + resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.19.6.tgz#a7bf568944f87ee83e39083ef6facc2ba0d56255" + integrity sha512-OlImG2UHHgf4zo5QmMeeKb9xNoRWUVaxLdzfhpV95PQShp8Nrl4zsxrDKehh9d6zN5dM/iaxF897cI6bT9D1uw== dependencies: "@standardnotes/auth" "^3.8.1" "@standardnotes/common" "^1.2.1"