From 9332f375b851916abab51c819e79a8282aeed65e Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Sat, 10 Feb 2024 15:05:13 +0700 Subject: [PATCH] Cache base custom touch layouts --- better-xcloud.user.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/better-xcloud.user.js b/better-xcloud.user.js index 7e9eb56..5c55700 100644 --- a/better-xcloud.user.js +++ b/better-xcloud.user.js @@ -3472,6 +3472,7 @@ class TouchController { static #dataChannel; static #customLayouts = {}; + static #baseCustomLayouts = {}; static #currentLayoutId; static enable() { @@ -3559,10 +3560,22 @@ class TouchController { const layouts = {}; - json.layouts.forEach(async file => { - const layoutUrl = `${baseUrl}/layouts/${file}.json`; - const json = await (await NATIVE_FETCH(layoutUrl)).json(); - Object.assign(layouts, json.layouts); + json.layouts.forEach(async layoutName => { + let baseLayouts = {}; + if (layoutName in TouchController.#baseCustomLayouts) { + baseLayouts = TouchController.#baseCustomLayouts[layoutName]; + } else { + try { + const layoutUrl = `${baseUrl}/layouts/${layoutName}.json`; + const resp = await NATIVE_FETCH(layoutUrl); + const json = await resp.json(); + + baseLayouts = json.layouts; + TouchController.#baseCustomLayouts[layoutName] = baseLayouts; + } catch (e) {} + } + + Object.assign(layouts, baseLayouts); }); json.layouts = layouts;