Use async/await in TouchController.getCustomLayouts()

This commit is contained in:
redphx 2024-02-10 14:57:11 +07:00
parent c1684abf27
commit dbe0435669

View File

@ -3534,7 +3534,7 @@ class TouchController {
});
};
static getCustomLayouts(xboxTitleId, retries) {
static async getCustomLayouts(xboxTitleId, retries) {
xboxTitleId = '' + xboxTitleId;
if (xboxTitleId in TouchController.#customLayouts) {
TouchController.#dispatchLayouts(TouchController.#customLayouts[xboxTitleId]);
@ -3553,9 +3553,10 @@ class TouchController {
const url = `${baseUrl}/${xboxTitleId}.json`;
// Get layout info
NATIVE_FETCH(url)
.then(resp => resp.json())
.then(json => {
try {
const resp = await NATIVE_FETCH(url);
const json = await resp.json();
const layouts = {};
json.layouts.forEach(async file => {
@ -3569,11 +3570,10 @@ class TouchController {
// Wait for BX_EXPOSED.touch_layout_manager
setTimeout(() => TouchController.#dispatchLayouts(json), 1000);
})
.catch(() => {
} catch (e) {
// Retry
TouchController.getCustomLayouts(xboxTitleId, retries + 1);
});
}
}
static loadCustomLayout(xboxTitleId, layoutId, delay) {