refactor: new snjs support (#967)

This commit is contained in:
Mo
2022-04-11 12:48:19 -05:00
committed by GitHub
parent 3126d97dca
commit 3a2ff2f440
44 changed files with 569 additions and 799 deletions

View File

@@ -1,11 +1,10 @@
import { WebApplication } from '@/ui_models/application';
import { parseFileName } from '@standardnotes/filepicker';
import {
EncryptionIntent,
ContentType,
SNNote,
BackupFile,
PayloadContent,
BackupFileDecryptedContextualPayload,
NoteContent,
} from '@standardnotes/snjs';
function sanitizeFileName(name: string): string {
@@ -79,6 +78,7 @@ export class ArchiveManager {
const blob = new Blob([JSON.stringify(data, null, 2)], {
type: 'text/plain',
});
const fileName = zippableFileName('Standard Notes Backup and Import File');
await zipWriter.add(fileName, new zip.BlobReader(blob));
@@ -88,9 +88,9 @@ export class ArchiveManager {
let name, contents;
if (item.content_type === ContentType.Note) {
const note = item as SNNote;
name = (note.content as PayloadContent).title;
contents = (note.content as PayloadContent).text;
const note = item as BackupFileDecryptedContextualPayload<NoteContent>;
name = note.content.title;
contents = note.content.text;
} else {
name = item.content_type;
contents = JSON.stringify(item.content, null, 2);

View File

@@ -8,13 +8,11 @@ import {
removeFromArray,
DesktopManagerInterface,
PayloadSource,
EncryptionIntent,
CreateIntentPayloadFromObject,
InternalEventBus,
} from '@standardnotes/snjs';
import { WebAppEvent, WebApplication } from '@/ui_models/application';
import { isDesktopApplication } from '@/utils';
import { Bridge, ElectronDesktopCallbacks } from './bridge';
import { InternalEventBus } from '@standardnotes/services';
/**
* An interface used by the Desktop application to interact with SN
@@ -68,10 +66,7 @@ export class DesktopManager
* Keys are not passed into ItemParams, so the result is not encrypted
*/
convertComponentForTransmission(component: SNComponent) {
return CreateIntentPayloadFromObject(
component.payloadRepresentation(),
EncryptionIntent.FileDecrypted
);
return component.payloadRepresentation().ejected();
}
// All `components` should be installed
@@ -84,11 +79,7 @@ export class DesktopManager
return this.convertComponentForTransmission(component);
})
).then((payloads) => {
this.bridge.syncComponents(
payloads.filter(
(payload) => !payload.errorDecrypting && !payload.waitingForKey
)
);
this.bridge.syncComponents(payloads);
});
}
@@ -137,7 +128,7 @@ export class DesktopManager
return;
}
const updatedComponent = await this.application.mutator.changeAndSaveItem(
component.uuid,
component,
(m) => {
const mutator = m as ComponentMutator;
if (error) {

View File

@@ -1,7 +1,6 @@
import { WebApplication } from '@/ui_models/application';
import {
StorageValueModes,
EncryptionIntent,
ApplicationService,
SNTheme,
removeFromArray,
@@ -11,9 +10,9 @@ import {
FeatureStatus,
PayloadSource,
PrefKey,
CreateIntentPayloadFromObject,
CreateDecryptedLocalStorageContextPayload,
InternalEventBus,
} from '@standardnotes/snjs';
import { InternalEventBus } from '@standardnotes/services';
const CACHED_THEMES_KEY = 'cachedThemes';
@@ -156,9 +155,9 @@ export class ThemeManager extends ApplicationService {
const preference = prefersDarkColorScheme
? PrefKey.AutoDarkThemeIdentifier
: PrefKey.AutoLightThemeIdentifier;
const themes = this.application.items.getDisplayableItems(
const themes = this.application.items.getDisplayableItems<SNTheme>(
ContentType.Theme
) as SNTheme[];
);
const enableDefaultTheme = () => {
const activeTheme = themes.find(
@@ -206,7 +205,8 @@ export class ThemeManager extends ApplicationService {
this.unregisterStream = this.application.streamItems(
ContentType.Theme,
(items, source) => {
({ changed, inserted, source }) => {
const items = changed.concat(inserted);
const themes = items as SNTheme[];
for (const theme of themes) {
if (theme.active) {
@@ -275,10 +275,7 @@ export class ThemeManager extends ApplicationService {
const mapped = themes.map((theme) => {
const payload = theme.payloadRepresentation();
return CreateIntentPayloadFromObject(
payload,
EncryptionIntent.LocalStorageDecrypted
);
return CreateDecryptedLocalStorageContextPayload(payload);
});
return this.application.setValue(