From 2142c4a83c56a46ad6ac81b88ea48fa2893e5080 Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Wed, 7 Feb 2024 15:15:53 +0700 Subject: [PATCH] Only request custom touch control when the game is focused --- better-xcloud.user.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/better-xcloud.user.js b/better-xcloud.user.js index 3c914ae..807d083 100644 --- a/better-xcloud.user.js +++ b/better-xcloud.user.js @@ -3650,13 +3650,14 @@ class TouchController { setTimeout(TouchController.#show, 1000); }); + let focused = false; dataChannel.addEventListener('message', msg => { if (msg.origin === 'better-xcloud' || typeof msg.data !== 'string') { return; } // Dispatch a message to display generic touch controller - if (msg.data.includes('touchcontrols/showtitledefault')) { + if (focused && msg.data.includes('touchcontrols/showtitledefault')) { TouchController.#enable && TouchController.getCustomLayouts(GAME_XBOX_TITLE_ID); return; } @@ -3667,6 +3668,7 @@ class TouchController { const json = JSON.parse(JSON.parse(msg.data).content); TouchController.#toggleBar(json.focused); + focused = json.focused; if (!json.focused) { TouchController.#show(); } @@ -9077,7 +9079,6 @@ function interceptHttpRequests() { const xboxTitleId = JSON.parse(opts.body).titleIds[0]; GAME_XBOX_TITLE_ID = xboxTitleId; - TouchController.getCustomLayouts(xboxTitleId); } response.json = () => Promise.resolve(obj);