diff --git a/dist/better-xcloud.lite.user.js b/dist/better-xcloud.lite.user.js index 78842e0..1221068 100644 --- a/dist/better-xcloud.lite.user.js +++ b/dist/better-xcloud.lite.user.js @@ -2381,7 +2381,7 @@ class MouseDataProvider { class MkbHandler {} class LocalDb { static DB_NAME = "BetterXcloud"; - static DB_VERSION = 1; + static DB_VERSION = 2; db; open() { return new Promise((resolve, reject) => { @@ -2438,17 +2438,16 @@ class MkbPresetsDb extends LocalDb { super(); BxLogger.info(this.LOG_TAG, "constructor()"); } + createTable(db) { + db.createObjectStore(this.TABLE_PRESETS, { + keyPath: "id", + autoIncrement: !0 + }).createIndex("name_idx", "name"); + } onUpgradeNeeded(e) { let db = e.target.result; - switch (e.oldVersion) { - case 0: { - db.createObjectStore(this.TABLE_PRESETS, { - keyPath: "id", - autoIncrement: !0 - }).createIndex("name_idx", "name"); - break; - } - } + if (db.objectStoreNames.contains("undefined")) db.deleteObjectStore("undefined"); + if (!db.objectStoreNames.contains(this.TABLE_PRESETS)) this.createTable(db); } async presetsTable() { return await this.open(), await this.table(this.TABLE_PRESETS, "readwrite"); diff --git a/dist/better-xcloud.user.js b/dist/better-xcloud.user.js index 6fd22f7..0c02466 100644 --- a/dist/better-xcloud.user.js +++ b/dist/better-xcloud.user.js @@ -2656,7 +2656,7 @@ class NativeMkbHandler extends MkbHandler { } class LocalDb { static DB_NAME = "BetterXcloud"; - static DB_VERSION = 1; + static DB_VERSION = 2; db; open() { return new Promise((resolve, reject) => { @@ -2713,17 +2713,16 @@ class MkbPresetsDb extends LocalDb { super(); BxLogger.info(this.LOG_TAG, "constructor()"); } + createTable(db) { + db.createObjectStore(this.TABLE_PRESETS, { + keyPath: "id", + autoIncrement: !0 + }).createIndex("name_idx", "name"); + } onUpgradeNeeded(e) { let db = e.target.result; - switch (e.oldVersion) { - case 0: { - db.createObjectStore(this.TABLE_PRESETS, { - keyPath: "id", - autoIncrement: !0 - }).createIndex("name_idx", "name"); - break; - } - } + if (db.objectStoreNames.contains("undefined")) db.deleteObjectStore("undefined"); + if (!db.objectStoreNames.contains(this.TABLE_PRESETS)) this.createTable(db); } async presetsTable() { return await this.open(), await this.table(this.TABLE_PRESETS, "readwrite"); diff --git a/src/utils/local-db/local-db.ts b/src/utils/local-db/local-db.ts index 1406ceb..cd4b330 100644 --- a/src/utils/local-db/local-db.ts +++ b/src/utils/local-db/local-db.ts @@ -1,8 +1,8 @@ export abstract class LocalDb { static readonly DB_NAME = 'BetterXcloud'; - static readonly DB_VERSION = 1; + static readonly DB_VERSION = 2; - private db: any; + protected db!: IDBDatabase; protected open() { return new Promise((resolve, reject) => { @@ -29,7 +29,7 @@ export abstract class LocalDb { protected abstract onUpgradeNeeded(e: IDBVersionChangeEvent): void; - protected table(name: string, type: string): Promise { + protected table(name: string, type: IDBTransactionMode): Promise { const transaction = this.db.transaction(name, type || 'readonly'); const table = transaction.objectStore(name); diff --git a/src/utils/local-db/mkb-presets-db.ts b/src/utils/local-db/mkb-presets-db.ts index 1aa6e3b..be45dae 100644 --- a/src/utils/local-db/mkb-presets-db.ts +++ b/src/utils/local-db/mkb-presets-db.ts @@ -18,17 +18,23 @@ export class MkbPresetsDb extends LocalDb { BxLogger.info(this.LOG_TAG, 'constructor()'); } + private createTable(db: IDBDatabase) { + const presets = db.createObjectStore(this.TABLE_PRESETS, { + keyPath: 'id', + autoIncrement: true, + }); + presets.createIndex('name_idx', 'name'); + } + protected onUpgradeNeeded(e: IDBVersionChangeEvent): void { - const db = (e.target! as any).result; - switch (e.oldVersion) { - case 0: { - const presets = db.createObjectStore(this.TABLE_PRESETS, { - keyPath: 'id', - autoIncrement: true, - }); - presets.createIndex('name_idx', 'name'); - break; - } + const db = (e.target! as any).result as IDBDatabase; + + if (db.objectStoreNames.contains('undefined')) { + db.deleteObjectStore('undefined'); + } + + if (!db.objectStoreNames.contains(this.TABLE_PRESETS)) { + this.createTable(db); } }