chore: upgrade snjs deps

This commit is contained in:
Mo
2022-05-02 13:08:28 -05:00
parent 99d83af3ba
commit c2adf74ad2
6 changed files with 126 additions and 84 deletions

View File

@@ -1,4 +1,4 @@
import { SNAlertService } from '@standardnotes/snjs'
import { isString, AlertService } from '@standardnotes/snjs'
const STORE_NAME = 'items'
const READ_WRITE = 'readwrite'
@@ -19,7 +19,7 @@ export class Database {
private locked = true
private db?: IDBDatabase
constructor(public databaseName: string, private alertService: SNAlertService) {}
constructor(public databaseName: string, private alertService: AlertService) {}
public deinit() {
;(this.alertService as any) = undefined
@@ -113,6 +113,28 @@ export class Database {
})
}
public async getAllKeys(): Promise<string[]> {
const db = (await this.openDatabase()) as IDBDatabase
return new Promise((resolve) => {
const objectStore = db.transaction(STORE_NAME).objectStore(STORE_NAME)
const getAllKeysRequest = objectStore.getAllKeys()
getAllKeysRequest.onsuccess = function () {
const result = getAllKeysRequest.result
const strings = result.map((key) => {
if (isString(key)) {
return key
} else {
return JSON.stringify(key)
}
})
resolve(strings)
}
})
}
public async savePayload(payload: any): Promise<void> {
return this.savePayloads([payload])
}

View File

@@ -6,6 +6,7 @@ import {
RawKeychainValue,
TransferPayload,
NamespacedRootKeyInKeychain,
extendArray,
} from '@standardnotes/snjs'
import { Database } from '../Database'
import { WebOrDesktopDeviceInterface } from './WebOrDesktopDeviceInterface'
@@ -126,10 +127,17 @@ export abstract class WebOrDesktopDevice implements WebOrDesktopDeviceInterface
return keychain[identifier]
}
async setNamespacedKeychainValue(
value: NamespacedRootKeyInKeychain,
identifier: ApplicationIdentifier,
) {
async getDatabaseKeys(): Promise<string[]> {
const keys: string[] = []
for (const database of this.databases) {
extendArray(keys, await database.getAllKeys())
}
return keys
}
async setNamespacedKeychainValue(value: NamespacedRootKeyInKeychain, identifier: ApplicationIdentifier) {
let keychain = await this.getKeychainValue()
if (!keychain) {

View File

@@ -1,4 +1,4 @@
import { SNAlertService, ButtonType, sanitizeHtmlString } from '@standardnotes/snjs'
import { AlertService, ButtonType, sanitizeHtmlString } from '@standardnotes/snjs'
import { SKAlert } from '@standardnotes/stylekit'
/** @returns a promise resolving to true if the user confirmed, false if they canceled */
@@ -65,7 +65,7 @@ export function alertDialog({
})
}
export class AlertService extends SNAlertService {
export class WebAlertService extends AlertService {
alert(text: string, title?: string, closeButtonText?: string) {
return alertDialog({ text, title, closeButtonText })
}

View File

@@ -1,5 +1,5 @@
import { WebCrypto } from '@/Crypto'
import { AlertService } from '@/Services/AlertService'
import { WebAlertService } from '@/Services/AlertService'
import { ArchiveManager } from '@/Services/ArchiveManager'
import { AutolockService } from '@/Services/AutolockService'
import { DesktopDeviceInterface, isDesktopDevice } from '@/Device/DesktopDeviceInterface'
@@ -56,7 +56,7 @@ export class WebApplication extends SNApplication {
platform: platform,
deviceInterface: deviceInterface,
crypto: WebCrypto,
alertService: new AlertService(),
alertService: new WebAlertService(),
identifier,
defaultHost: defaultSyncServerHost,
appVersion: deviceInterface.appVersion,