refactor: receive workspace names to handle missing idb function in firefox
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = []
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user