feat: snjs upgrade and fixes

This commit is contained in:
Mo Bitar
2021-12-05 11:04:46 -06:00
parent ac9c19d681
commit 82ee0974c1
6 changed files with 47 additions and 36 deletions

View File

@@ -35,8 +35,8 @@ class EditorMenuCtrl extends PureViewCtrl implements EditorMenuScope {
$onInit() { $onInit() {
super.$onInit(); super.$onInit();
const editors = this.application const editors = this.application.componentManager
.componentManager!.componentsForArea(ComponentArea.Editor) .componentsForArea(ComponentArea.Editor)
.sort((a, b) => { .sort((a, b) => {
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1; return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1;
}); });

View File

@@ -5,16 +5,16 @@ import {
ApplicationService, ApplicationService,
SNTheme, SNTheme,
removeFromArray, removeFromArray,
ApplicationEvent, ContentType ApplicationEvent,
ContentType,
} from '@standardnotes/snjs'; } from '@standardnotes/snjs';
const CACHED_THEMES_KEY = 'cachedThemes'; const CACHED_THEMES_KEY = 'cachedThemes';
export class ThemeManager extends ApplicationService { export class ThemeManager extends ApplicationService {
private activeThemes: string[] = [];
private activeThemes: string[] = [] private unregisterDesktop!: () => void;
private unregisterDesktop!: () => void private unregisterStream!: () => void;
private unregisterStream!: () => void
async onAppEvent(event: ApplicationEvent) { async onAppEvent(event: ApplicationEvent) {
super.onAppEvent(event); super.onAppEvent(event);
@@ -54,7 +54,8 @@ export class ThemeManager extends ApplicationService {
} }
private registerObservers() { private registerObservers() {
this.unregisterDesktop = this.webApplication.getDesktopService() this.unregisterDesktop = this.webApplication
.getDesktopService()
.registerUpdateObserver((component) => { .registerUpdateObserver((component) => {
if (component.active && component.isTheme()) { if (component.active && component.isTheme()) {
this.deactivateTheme(component.uuid); this.deactivateTheme(component.uuid);
@@ -64,16 +65,21 @@ export class ThemeManager extends ApplicationService {
} }
}); });
this.unregisterStream = this.application.streamItems(ContentType.Theme, (items) => { this.unregisterStream = this.application.streamItems(
const themes = items as SNTheme[]; ContentType.Theme,
for (const theme of themes) { () => {
if (theme.active) { const themes = this.application.getDisplayableItems(
this.activateTheme(theme); ContentType.Theme
} else { ) as SNTheme[];
this.deactivateTheme(theme.uuid); for (const theme of themes) {
if (theme.active) {
this.activateTheme(theme);
} else {
this.deactivateTheme(theme.uuid);
}
} }
} }
}); );
} }
private clearAppThemeState() { private clearAppThemeState() {
@@ -120,14 +126,17 @@ export class ThemeManager extends ApplicationService {
private async cacheThemes() { private async cacheThemes() {
const themes = this.application!.getAll(this.activeThemes) as SNTheme[]; const themes = this.application!.getAll(this.activeThemes) as SNTheme[];
const mapped = await Promise.all(themes.map(async (theme) => { const mapped = await Promise.all(
const payload = theme.payloadRepresentation(); themes.map(async (theme) => {
const processedPayload = await this.application!.protocolService!.payloadByEncryptingPayload( const payload = theme.payloadRepresentation();
payload, const processedPayload =
EncryptionIntent.LocalStorageDecrypted await this.application!.protocolService!.payloadByEncryptingPayload(
); payload,
return processedPayload; EncryptionIntent.LocalStorageDecrypted
})); );
return processedPayload;
})
);
return this.application!.setValue( return this.application!.setValue(
CACHED_THEMES_KEY, CACHED_THEMES_KEY,
mapped, mapped,
@@ -145,15 +154,17 @@ export class ThemeManager extends ApplicationService {
} }
private async getCachedThemes() { private async getCachedThemes() {
const cachedThemes = await this.application!.getValue( const cachedThemes = (await this.application!.getValue(
CACHED_THEMES_KEY, CACHED_THEMES_KEY,
StorageValueModes.Nonwrapped StorageValueModes.Nonwrapped
) as SNTheme[]; )) as SNTheme[];
if (cachedThemes) { if (cachedThemes) {
const themes = []; const themes = [];
for (const cachedTheme of cachedThemes) { for (const cachedTheme of cachedThemes) {
const payload = this.application!.createPayloadFromObject(cachedTheme); 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); themes.push(theme);
} }
return themes; return themes;

View File

@@ -261,7 +261,7 @@ export class AppState {
} }
streamNotesAndTags() { streamNotesAndTags() {
this.application!.streamItems( this.application.streamItems(
[ContentType.Note, ContentType.Tag], [ContentType.Note, ContentType.Tag],
async (items, source) => { async (items, source) => {
/** Close any editors for deleted/trashed/archived notes */ /** Close any editors for deleted/trashed/archived notes */

View File

@@ -740,8 +740,8 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
async reloadStackComponents() { async reloadStackComponents() {
const stackComponents = sortAlphabetically( const stackComponents = sortAlphabetically(
this.application this.application.componentManager
.componentManager!.componentsForArea(ComponentArea.EditorStack) .componentsForArea(ComponentArea.EditorStack)
.filter((component) => component.active) .filter((component) => component.active)
); );
if (this.note) { if (this.note) {

View File

@@ -1,6 +1,6 @@
{ {
"name": "standard-notes-web", "name": "standard-notes-web",
"version": "3.9.5", "version": "3.9.6",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"repository": { "repository": {
"type": "git", "type": "git",
@@ -80,7 +80,7 @@
"@reach/listbox": "^0.16.2", "@reach/listbox": "^0.16.2",
"@standardnotes/features": "1.10.1", "@standardnotes/features": "1.10.1",
"@standardnotes/sncrypto-web": "1.5.3", "@standardnotes/sncrypto-web": "1.5.3",
"@standardnotes/snjs": "2.18.3", "@standardnotes/snjs": "2.19.6",
"mobx": "^6.3.5", "mobx": "^6.3.5",
"mobx-react-lite": "^3.2.2", "mobx-react-lite": "^3.2.2",
"preact": "^10.5.15", "preact": "^10.5.15",

View File

@@ -2614,10 +2614,10 @@
buffer "^6.0.3" buffer "^6.0.3"
libsodium-wrappers "^0.7.9" libsodium-wrappers "^0.7.9"
"@standardnotes/snjs@2.18.3": "@standardnotes/snjs@2.19.6":
version "2.18.3" version "2.19.6"
resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.18.3.tgz#5dd685c6e0df4c07c98b087aa672411e9becde4c" resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.19.6.tgz#a7bf568944f87ee83e39083ef6facc2ba0d56255"
integrity sha512-Q8X1UUSUw4NkKcZPHFYZ/WH9weOXW7LelOE1kCBx/O1g284dJWvHhqQh8qTgjHQnrcYR8Xh3AfoR0bh1Ms+iyA== integrity sha512-OlImG2UHHgf4zo5QmMeeKb9xNoRWUVaxLdzfhpV95PQShp8Nrl4zsxrDKehh9d6zN5dM/iaxF897cI6bT9D1uw==
dependencies: dependencies:
"@standardnotes/auth" "^3.8.1" "@standardnotes/auth" "^3.8.1"
"@standardnotes/common" "^1.2.1" "@standardnotes/common" "^1.2.1"