mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-03 06:07:19 +02:00
Use Set() for local co-op list
This commit is contained in:
parent
6448a00271
commit
a6c19fec15
@ -33,9 +33,7 @@ type ScriptEvents = {
|
||||
};
|
||||
|
||||
'list.localCoOp.updated': {
|
||||
data: {
|
||||
data: any;
|
||||
};
|
||||
ids: Set<string>,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -56,6 +56,8 @@ export class GhPagesUtils {
|
||||
BxEventBus.Script.emit('list.forcedNativeMkb.updated', {
|
||||
data: json,
|
||||
});
|
||||
} else {
|
||||
window.localStorage.removeItem(key);
|
||||
}
|
||||
});
|
||||
|
||||
@ -70,6 +72,7 @@ export class GhPagesUtils {
|
||||
}
|
||||
|
||||
static getTouchControlCustomList() {
|
||||
// TODO: use Set()
|
||||
const key = StorageKey.LIST_CUSTOM_TOUCH_LAYOUTS;
|
||||
|
||||
NATIVE_FETCH(GhPagesUtils.getUrl('touch-layouts/ids.json'))
|
||||
@ -84,7 +87,7 @@ export class GhPagesUtils {
|
||||
return customList;
|
||||
}
|
||||
|
||||
static getLocalCoOpList() {
|
||||
static getLocalCoOpList(): Set<string> {
|
||||
const supportedSchema = 1;
|
||||
const key = StorageKey.LIST_LOCAL_CO_OP;
|
||||
|
||||
@ -93,14 +96,21 @@ export class GhPagesUtils {
|
||||
.then(json => {
|
||||
if (json.$schemaVersion === supportedSchema) {
|
||||
window.localStorage.setItem(key, JSON.stringify(json));
|
||||
BxEventBus.Script.emit('list.localCoOp.updated', { data: json });
|
||||
const ids = new Set(Object.keys(json.data));
|
||||
BxEventBus.Script.emit('list.localCoOp.updated', { ids });
|
||||
} else {
|
||||
window.localStorage.removeItem(key);
|
||||
BxEventBus.Script.emit('list.localCoOp.updated', { data: { data: {} } });
|
||||
BxEventBus.Script.emit('list.localCoOp.updated', { ids: new Set() });
|
||||
}
|
||||
});
|
||||
|
||||
const customList = JSON.parse(window.localStorage.getItem(key) || '[]');
|
||||
return customList;
|
||||
const info = JSON.parse(window.localStorage.getItem(key) || '{}');
|
||||
if (info.$schemaVersion !== supportedSchema) {
|
||||
// Delete storage;
|
||||
window.localStorage.removeItem(key);
|
||||
return new Set();
|
||||
}
|
||||
|
||||
return new Set(Object.keys(info.data || {}));
|
||||
}
|
||||
}
|
||||
|
@ -5,17 +5,17 @@ export class LocalCoOpManager {
|
||||
private static instance: LocalCoOpManager;
|
||||
public static getInstance = () => LocalCoOpManager.instance ?? (LocalCoOpManager.instance = new LocalCoOpManager());
|
||||
|
||||
private supportedIds: string[] = [];
|
||||
private supportedIds: Set<string>;
|
||||
|
||||
constructor() {
|
||||
BxEventBus.Script.once('list.localCoOp.updated', e => {
|
||||
this.supportedIds = Object.keys(e.data.data);
|
||||
console.log('supportedIds', this.supportedIds);
|
||||
this.supportedIds = e.ids;
|
||||
});
|
||||
GhPagesUtils.getLocalCoOpList();
|
||||
this.supportedIds = GhPagesUtils.getLocalCoOpList();
|
||||
console.log('this.supportedIds', this.supportedIds);
|
||||
}
|
||||
|
||||
isSupported(productId: string) {
|
||||
return this.supportedIds.includes(productId);
|
||||
return this.supportedIds.has(productId);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user