From f0e4d4b8d0f3e5c05e3fc2105227d9b84da48b43 Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Mon, 9 Dec 2024 18:18:40 +0700 Subject: [PATCH] Fix exception in app --- dist/better-xcloud.lite.user.js | 15 ++++++++++----- dist/better-xcloud.user.js | 15 ++++++++++----- src/modules/ui/dialog/navigation-dialog.ts | 3 +++ src/utils/bx-event-bus.ts | 14 +++++++++----- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/dist/better-xcloud.lite.user.js b/dist/better-xcloud.lite.user.js index 97090eb..b02ab05 100755 --- a/dist/better-xcloud.lite.user.js +++ b/dist/better-xcloud.lite.user.js @@ -198,10 +198,14 @@ class BxEventBus { let callbacks = this.listeners.get(event) || []; for (let callback of callbacks) callback(payload); - if (AppInterface) if (event in this.appJsInterfaces) { - let method = this.appJsInterfaces[event]; - AppInterface[method] && AppInterface[method](); - } else AppInterface.onEventBus(this.group + "." + event); + if (AppInterface) try { + if (event in this.appJsInterfaces) { + let method = this.appJsInterfaces[event]; + AppInterface[method] && AppInterface[method](); + } else AppInterface.onEventBus(this.group + "." + event); + } catch (e) { + console.log(e); + } BX_FLAGS.Debug && BxLogger.warning("EventBus", "emit", event, payload); } } @@ -3381,7 +3385,8 @@ class NavigationDialogManager { this.clearGamepadHoldingInterval(), BxEventBus.Script.emit("dialog.shown", {}), window.BX_EXPOSED.disableGamepadPolling = !0, document.body.classList.add("bx-no-scroll"), this.unmountCurrentDialog(), this.dialogsStack.push(dialog), this.dialog = dialog, dialog.onBeforeMount(configs), this.$container.appendChild(dialog.getContent()), dialog.onMounted(configs), this.$overlay.classList.remove("bx-gone"), this.$overlay.classList.toggle("bx-invisible", !dialog.isOverlayVisible()), this.$container.classList.remove("bx-gone"), this.$container.addEventListener("keydown", this), this.startGamepadPolling(); } hide() { - if (this.clearGamepadHoldingInterval(), document.body.classList.remove("bx-no-scroll"), BxEventBus.Script.emit("dialog.dismissed", {}), this.$overlay.classList.add("bx-gone"), this.$overlay.classList.remove("bx-invisible"), this.$container.classList.add("bx-gone"), this.$container.removeEventListener("keydown", this), this.stopGamepadPolling(), this.dialog) { + if (this.clearGamepadHoldingInterval(), !this.isShowing()) return; + if (document.body.classList.remove("bx-no-scroll"), BxEventBus.Script.emit("dialog.dismissed", {}), this.$overlay.classList.add("bx-gone"), this.$overlay.classList.remove("bx-invisible"), this.$container.classList.add("bx-gone"), this.$container.removeEventListener("keydown", this), this.stopGamepadPolling(), this.dialog) { let dialogIndex = this.dialogsStack.indexOf(this.dialog); if (dialogIndex > -1) this.dialogsStack = this.dialogsStack.slice(0, dialogIndex); } diff --git a/dist/better-xcloud.user.js b/dist/better-xcloud.user.js index 854acd8..cf3e9de 100755 --- a/dist/better-xcloud.user.js +++ b/dist/better-xcloud.user.js @@ -227,10 +227,14 @@ class BxEventBus { let callbacks = this.listeners.get(event) || []; for (let callback of callbacks) callback(payload); - if (AppInterface) if (event in this.appJsInterfaces) { - let method = this.appJsInterfaces[event]; - AppInterface[method] && AppInterface[method](); - } else AppInterface.onEventBus(this.group + "." + event); + if (AppInterface) try { + if (event in this.appJsInterfaces) { + let method = this.appJsInterfaces[event]; + AppInterface[method] && AppInterface[method](); + } else AppInterface.onEventBus(this.group + "." + event); + } catch (e) { + console.log(e); + } BX_FLAGS.Debug && BxLogger.warning("EventBus", "emit", event, payload); } } @@ -3534,7 +3538,8 @@ class NavigationDialogManager { this.clearGamepadHoldingInterval(), BxEventBus.Script.emit("dialog.shown", {}), window.BX_EXPOSED.disableGamepadPolling = !0, document.body.classList.add("bx-no-scroll"), this.unmountCurrentDialog(), this.dialogsStack.push(dialog), this.dialog = dialog, dialog.onBeforeMount(configs), this.$container.appendChild(dialog.getContent()), dialog.onMounted(configs), this.$overlay.classList.remove("bx-gone"), this.$overlay.classList.toggle("bx-invisible", !dialog.isOverlayVisible()), this.$container.classList.remove("bx-gone"), this.$container.addEventListener("keydown", this), this.startGamepadPolling(); } hide() { - if (this.clearGamepadHoldingInterval(), document.body.classList.remove("bx-no-scroll"), BxEventBus.Script.emit("dialog.dismissed", {}), this.$overlay.classList.add("bx-gone"), this.$overlay.classList.remove("bx-invisible"), this.$container.classList.add("bx-gone"), this.$container.removeEventListener("keydown", this), this.stopGamepadPolling(), this.dialog) { + if (this.clearGamepadHoldingInterval(), !this.isShowing()) return; + if (document.body.classList.remove("bx-no-scroll"), BxEventBus.Script.emit("dialog.dismissed", {}), this.$overlay.classList.add("bx-gone"), this.$overlay.classList.remove("bx-invisible"), this.$container.classList.add("bx-gone"), this.$container.removeEventListener("keydown", this), this.stopGamepadPolling(), this.dialog) { let dialogIndex = this.dialogsStack.indexOf(this.dialog); if (dialogIndex > -1) this.dialogsStack = this.dialogsStack.slice(0, dialogIndex); } diff --git a/src/modules/ui/dialog/navigation-dialog.ts b/src/modules/ui/dialog/navigation-dialog.ts index 6f1e8f3..dbb6918 100755 --- a/src/modules/ui/dialog/navigation-dialog.ts +++ b/src/modules/ui/dialog/navigation-dialog.ts @@ -476,6 +476,9 @@ export class NavigationDialogManager { hide() { this.clearGamepadHoldingInterval(); + if (!this.isShowing()) { + return; + } // Unlock scroll bar document.body.classList.remove('bx-no-scroll'); diff --git a/src/utils/bx-event-bus.ts b/src/utils/bx-event-bus.ts index e6fa5df..c4c38d1 100644 --- a/src/utils/bx-event-bus.ts +++ b/src/utils/bx-event-bus.ts @@ -120,11 +120,15 @@ export class BxEventBus> { // Call method inside Android app if (AppInterface) { - if (event in this.appJsInterfaces) { - const method = this.appJsInterfaces[event]; - AppInterface[method] && AppInterface[method](); - } else { - AppInterface.onEventBus(this.group + '.' + (event as string)); + try { + if (event in this.appJsInterfaces) { + const method = this.appJsInterfaces[event]; + AppInterface[method] && AppInterface[method](); + } else { + AppInterface.onEventBus(this.group + '.' + (event as string)); + } + } catch (e) { + console.log(e); } }