Trying to fix custom touch control sometimes not showing

This commit is contained in:
redphx 2024-05-12 15:07:18 +07:00
parent 4068930db7
commit e867f156e8
3 changed files with 17 additions and 1 deletions

View File

@ -286,7 +286,13 @@ if (window.BX_VIBRATION_INTENSITY && window.BX_VIBRATION_INTENSITY < 1) {
return false;
}
str = str.replace(text, 'window.BX_EXPOSED["touchLayoutManager"] = this,' + text);
const newCode = `
true;
window.BX_EXPOSED["touchLayoutManager"] = this;
window.dispatchEvent(new Event("${BxEvent.TOUCH_LAYOUT_MANAGER_READY}"));
`;
str = str.replace(text, newCode + text);
return str;
},

View File

@ -143,7 +143,16 @@ export class TouchController {
}
static loadCustomLayout(xboxTitleId: string, layoutId: string, delay: number=0) {
// TODO: fix this
if (!window.BX_EXPOSED.touchLayoutManager) {
const listener = (e: Event) => {
window.removeEventListener(BxEvent.TOUCH_LAYOUT_MANAGER_READY, listener);
if (TouchController.#enable) {
TouchController.loadCustomLayout(xboxTitleId, layoutId, 0);
}
};
window.addEventListener(BxEvent.TOUCH_LAYOUT_MANAGER_READY, listener);
return;
}

View File

@ -23,6 +23,7 @@ export enum BxEvent {
STREAM_SESSION_READY = 'bx-stream-session-ready',
CUSTOM_TOUCH_LAYOUTS_LOADED = 'bx-custom-touch-layouts-loaded',
TOUCH_LAYOUT_MANAGER_READY = 'bx-touch-layout-manager-ready',
REMOTE_PLAY_READY = 'bx-remote-play-ready',
REMOTE_PLAY_FAILED = 'bx-remote-play-failed',