refactor: receive workspace names to handle missing idb function in firefox

This commit is contained in:
Mo
2022-05-18 10:38:02 -05:00
parent a97ca854a6
commit c5ded6da3c
4 changed files with 58 additions and 39 deletions

View File

@@ -1,4 +1,4 @@
import { isString, AlertService } from '@standardnotes/snjs'
import { isString, AlertService, uniqueArray } from '@standardnotes/snjs'
const STORE_NAME = 'items'
const READ_WRITE = 'readwrite'
@@ -33,15 +33,29 @@ export class Database {
this.locked = false
}
static async deleteAll(): Promise<void> {
const rawDatabases = await window.indexedDB.databases()
static async getAllDatabaseNames(): Promise<string[] | undefined> {
if (!window.indexedDB.databases) {
return undefined
}
for (const rawDb of rawDatabases) {
if (!rawDb.name) {
continue
const rawDatabases = await window.indexedDB.databases()
return rawDatabases.map((db) => db.name).filter((name) => name && name.length > 0) as string[]
}
static async deleteAll(databaseNames: string[]): Promise<void> {
if (window.indexedDB.databases != undefined) {
const idbNames = await this.getAllDatabaseNames()
if (idbNames) {
databaseNames = uniqueArray([...idbNames, ...databaseNames])
}
const db = new Database(rawDb.name)
}
for (const name of databaseNames) {
const db = new Database(name)
await db.clearAllPayloads()
db.deinit()
}
}

View File

@@ -41,16 +41,21 @@ export abstract class WebOrDesktopDevice implements WebOrDesktopDeviceInterface
return this.databases.find((database) => database.databaseName === identifier) as Database
}
async clearAllDataFromDevice(): Promise<void> {
async clearAllDataFromDevice(workspaceIdentifiers: ApplicationIdentifier[]): Promise<{ killsApplication: boolean }> {
await this.clearRawKeychainValue()
await this.removeAllRawStorageValues()
await Database.deleteAll()
await Database.deleteAll(workspaceIdentifiers)
return { killsApplication: false }
}
deinit() {
for (const database of this.databases) {
database.deinit()
}
this.databases = []
}

View File

@@ -70,10 +70,10 @@
"@reach/tooltip": "^0.16.2",
"@reach/visually-hidden": "^0.16.0",
"@standardnotes/components": "1.8.1",
"@standardnotes/filepicker": "1.14.8",
"@standardnotes/filepicker": "1.14.9",
"@standardnotes/icons": "^1.1.7",
"@standardnotes/sncrypto-web": "1.9.2",
"@standardnotes/snjs": "2.109.4",
"@standardnotes/snjs": "2.109.5",
"@standardnotes/stylekit": "5.27.1",
"@zip.js/zip.js": "^2.4.10",
"mobx": "^6.5.0",

View File

@@ -2311,14 +2311,14 @@
"@standardnotes/auth" "^3.18.16"
"@standardnotes/features" "^1.44.0"
"@standardnotes/encryption@^1.7.8":
version "1.7.8"
resolved "https://registry.yarnpkg.com/@standardnotes/encryption/-/encryption-1.7.8.tgz#ab59f9c37c3e577f89df1891b6ac2683e2d1dec9"
integrity sha512-RMyFC3OgTDDFgDq0VMU9sBdC1GKvFthW2D0belSojaxtu/3J1SZ6BUiZ5TYMar+jrVKIMs2X976ukmZ0C8KPPA==
"@standardnotes/encryption@^1.7.9":
version "1.7.9"
resolved "https://registry.yarnpkg.com/@standardnotes/encryption/-/encryption-1.7.9.tgz#4a66fcdeca8957f4a29ed327cdc677174cf904f7"
integrity sha512-Mqt8XPOXdbn4jbHnORqLsqeqKXAc5PILo1sO51J/lCODxjHAbvnCo+ZQ5mbGzalAp6sZTQ5J+RkwKDnINlzhNA==
dependencies:
"@standardnotes/models" "^1.8.6"
"@standardnotes/responses" "^1.6.23"
"@standardnotes/services" "^1.11.8"
"@standardnotes/services" "^1.11.9"
"@standardnotes/features@^1.44.0":
version "1.44.0"
@@ -2328,24 +2328,24 @@
"@standardnotes/auth" "^3.18.16"
"@standardnotes/common" "^1.21.0"
"@standardnotes/filepicker@1.14.8", "@standardnotes/filepicker@^1.14.8":
version "1.14.8"
resolved "https://registry.yarnpkg.com/@standardnotes/filepicker/-/filepicker-1.14.8.tgz#aa915399df9d7da3b30b0ea901bcf7d97aca3a42"
integrity sha512-52ABvJ79wuINIe6cGKgqV4qulnQbJrw1OwazWVvUWtX3rghWqiFgDT84gH4kma2kZxi0v03VLdbpvd2+i0yIBA==
"@standardnotes/filepicker@1.14.9", "@standardnotes/filepicker@^1.14.9":
version "1.14.9"
resolved "https://registry.yarnpkg.com/@standardnotes/filepicker/-/filepicker-1.14.9.tgz#daf1586a7147166dba259a04a17248c69e5b12ca"
integrity sha512-Iv0H3NeTmO88k8oesPJY3LRuhfOyyvh4pYp+eD19he91JHNK87K97fdmIc2fa2JkFccW1TthX+1VP/nbUt3YyQ==
dependencies:
"@standardnotes/common" "^1.21.0"
"@standardnotes/services" "^1.11.8"
"@standardnotes/services" "^1.11.9"
"@standardnotes/utils" "^1.6.9"
"@standardnotes/files@^1.1.9":
version "1.1.9"
resolved "https://registry.yarnpkg.com/@standardnotes/files/-/files-1.1.9.tgz#9a4bfd60ee26ba6b9f5281853626e87155d11cc5"
integrity sha512-yE4zB5QrP4o+sU2EfaK5oidhF4LpSC6slA82787dxKQ9ILDexnH8nyI/YH6sw82OiLHe+CeRR5mW01Pv8A7aYA==
"@standardnotes/files@^1.1.10":
version "1.1.10"
resolved "https://registry.yarnpkg.com/@standardnotes/files/-/files-1.1.10.tgz#caa98571cd93588949cd13b8264f5a99f70f372b"
integrity sha512-xdq/aC6x8vh8c97L2eNpBSJwmZwuXKdEveHl+KAOxPvRWMyLm8RLtTBME0QtdmfI2ZwkdJiiR4VK+8ZYNMYUsA==
dependencies:
"@standardnotes/encryption" "^1.7.8"
"@standardnotes/encryption" "^1.7.9"
"@standardnotes/models" "^1.8.6"
"@standardnotes/responses" "^1.6.23"
"@standardnotes/services" "^1.11.8"
"@standardnotes/services" "^1.11.9"
"@standardnotes/utils" "^1.6.9"
"@standardnotes/icons@^1.1.7":
@@ -2371,10 +2371,10 @@
"@standardnotes/common" "^1.21.0"
"@standardnotes/features" "^1.44.0"
"@standardnotes/services@^1.11.8":
version "1.11.8"
resolved "https://registry.yarnpkg.com/@standardnotes/services/-/services-1.11.8.tgz#8a9ef3212ef0693f611661cff552f22add00a236"
integrity sha512-E+hougOnKobH5nKPzpTxaGvYUSw3BWS0rKRMY2Jh5ZhD+y4GqCCA7VoR/7lbxR2GjP5xGpKHYgZR5QIyW+wFJQ==
"@standardnotes/services@^1.11.9":
version "1.11.9"
resolved "https://registry.yarnpkg.com/@standardnotes/services/-/services-1.11.9.tgz#9f25eeaf12df66eab1fb4eada9be9143424f7f13"
integrity sha512-N1Ij0c4JKnWXemCRa4qKiiuVmJJPqa1hkbxqXn6Zmstbfnl0DxAxE73Lx9qG/EEzE0yGw0uu51/U7pNQ613OLg==
dependencies:
"@standardnotes/auth" "^3.18.16"
"@standardnotes/common" "^1.21.0"
@@ -2401,21 +2401,21 @@
buffer "^6.0.3"
libsodium-wrappers "^0.7.9"
"@standardnotes/snjs@2.109.4":
version "2.109.4"
resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.109.4.tgz#46c1915b2c8d43e0806fd9ad8bb9868f2ae3a3e8"
integrity sha512-DLoLR9RI517zz0N+sA6iHYY8bJ1rGVgOFyKWQVHjJajPwnCllEvETLGKz4IodfAao4lxU9Q3xPQ31q6VyCvWxQ==
"@standardnotes/snjs@2.109.5":
version "2.109.5"
resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.109.5.tgz#e11c8a1d86b25957dcb09664fa37344321c1f0bd"
integrity sha512-BfGvsE7sthKlJ+RSBqPxDH3+chyYHkzcReQWoXOKPNbimQlG3AWk/aFvf+ypRYPB6CkmlKD32s0cSFhQIl3dMQ==
dependencies:
"@standardnotes/auth" "^3.18.16"
"@standardnotes/common" "^1.21.0"
"@standardnotes/domain-events" "^2.28.7"
"@standardnotes/encryption" "^1.7.8"
"@standardnotes/encryption" "^1.7.9"
"@standardnotes/features" "^1.44.0"
"@standardnotes/filepicker" "^1.14.8"
"@standardnotes/files" "^1.1.9"
"@standardnotes/filepicker" "^1.14.9"
"@standardnotes/files" "^1.1.10"
"@standardnotes/models" "^1.8.6"
"@standardnotes/responses" "^1.6.23"
"@standardnotes/services" "^1.11.8"
"@standardnotes/services" "^1.11.9"
"@standardnotes/settings" "^1.14.3"
"@standardnotes/sncrypto-common" "^1.8.2"
"@standardnotes/utils" "^1.6.9"