mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-08-08 14:18:26 +02:00
Fix Virtual Controller Remapper's bug (contd)
This commit is contained in:
@@ -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<void>((resolve, reject) => {
|
||||
@@ -29,7 +29,7 @@ export abstract class LocalDb {
|
||||
|
||||
protected abstract onUpgradeNeeded(e: IDBVersionChangeEvent): void;
|
||||
|
||||
protected table(name: string, type: string): Promise<IDBObjectStore> {
|
||||
protected table(name: string, type: IDBTransactionMode): Promise<IDBObjectStore> {
|
||||
const transaction = this.db.transaction(name, type || 'readonly');
|
||||
const table = transaction.objectStore(name);
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user