From e867f156e8f92c608370393fc2712de49394983a Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Sun, 12 May 2024 15:07:18 +0700 Subject: [PATCH] Trying to fix custom touch control sometimes not showing --- src/modules/patcher.ts | 8 +++++++- src/modules/touch-controller.ts | 9 +++++++++ src/utils/bx-event.ts | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/modules/patcher.ts b/src/modules/patcher.ts index 0dd9790..538b14f 100644 --- a/src/modules/patcher.ts +++ b/src/modules/patcher.ts @@ -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; }, diff --git a/src/modules/touch-controller.ts b/src/modules/touch-controller.ts index d6d47d9..11add4d 100644 --- a/src/modules/touch-controller.ts +++ b/src/modules/touch-controller.ts @@ -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; } diff --git a/src/utils/bx-event.ts b/src/utils/bx-event.ts index d2868cf..e0eca40 100644 --- a/src/utils/bx-event.ts +++ b/src/utils/bx-event.ts @@ -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',