From d3ef988af777081c6150013027ee5b4beb570907 Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:50:23 +0700 Subject: [PATCH] Fix problem with controller in Settings dialog --- dist/better-xcloud.lite.user.js | 16 +++++------ dist/better-xcloud.meta.js | 2 +- dist/better-xcloud.user.js | 16 +++++------ src/modules/ui/dialog/navigation-dialog.ts | 32 +++++++++++----------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/dist/better-xcloud.lite.user.js b/dist/better-xcloud.lite.user.js index 0a4d444..aafbd9e 100755 --- a/dist/better-xcloud.lite.user.js +++ b/dist/better-xcloud.lite.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Better xCloud (Lite) // @namespace https://github.com/redphx -// @version 6.2.1 +// @version 6.2.2 // @description Improve Xbox Cloud Gaming (xCloud) experience // @author redphx // @license MIT @@ -105,7 +105,7 @@ class UserAgent { }); } } -var SCRIPT_VERSION = "6.2.1", SCRIPT_VARIANT = "lite", AppInterface = window.AppInterface; +var SCRIPT_VERSION = "6.2.2", SCRIPT_VARIANT = "lite", AppInterface = window.AppInterface; UserAgent.init(); var userAgent = window.navigator.userAgent.toLowerCase(), isTv = userAgent.includes("smart-tv") || userAgent.includes("smarttv") || /\baft.*\b/.test(userAgent), isVr = window.navigator.userAgent.includes("VR") && window.navigator.userAgent.includes("OculusBrowser"), browserHasTouchSupport = "ontouchstart" in window || navigator.maxTouchPoints > 0, userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport, STATES = { supportedRegion: !0, @@ -3784,15 +3784,15 @@ class NavigationDialogManager { this.gamepadHoldingIntervalId && window.clearInterval(this.gamepadHoldingIntervalId), this.gamepadHoldingIntervalId = null; } show(dialog, configs = {}, clearStack = !1) { - this.clearGamepadHoldingInterval(), BxEventBus.Script.emit("dialog.shown", {}), 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.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.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.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); } - if (this.unmountCurrentDialog(), this.dialogsStack.length) this.dialogsStack[this.dialogsStack.length - 1].show(); + if (this.unmountCurrentDialog(), window.BX_EXPOSED.disableGamepadPolling = !1, this.dialogsStack.length) this.dialogsStack[this.dialogsStack.length - 1].show(); } focus($elm) { if (!$elm) return !1; @@ -3862,10 +3862,10 @@ class NavigationDialogManager { return null; } startGamepadPolling() { - window.BX_EXPOSED.disableGamepadPolling = !0, this.stopGamepadPolling(), this.gamepadPollingIntervalId = window.setInterval(this.pollGamepad, NavigationDialogManager.GAMEPAD_POLLING_INTERVAL); + this.stopGamepadPolling(); } stopGamepadPolling() { - window.BX_EXPOSED.disableGamepadPolling = !1, this.gamepadLastStates = [], this.gamepadPollingIntervalId && window.clearInterval(this.gamepadPollingIntervalId), this.gamepadPollingIntervalId = null; + this.gamepadLastStates = [], this.gamepadPollingIntervalId && window.clearInterval(this.gamepadPollingIntervalId), this.gamepadPollingIntervalId = null; } focusDirection(direction) { let dialog = this.dialog; diff --git a/dist/better-xcloud.meta.js b/dist/better-xcloud.meta.js index 4ba2fd3..b16a277 100644 --- a/dist/better-xcloud.meta.js +++ b/dist/better-xcloud.meta.js @@ -1,5 +1,5 @@ // ==UserScript== // @name Better xCloud // @namespace https://github.com/redphx -// @version 6.2.1 +// @version 6.2.2 // ==/UserScript== diff --git a/dist/better-xcloud.user.js b/dist/better-xcloud.user.js index 1b1fd55..7ee58a1 100755 --- a/dist/better-xcloud.user.js +++ b/dist/better-xcloud.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Better xCloud // @namespace https://github.com/redphx -// @version 6.2.1 +// @version 6.2.2 // @description Improve Xbox Cloud Gaming (xCloud) experience // @author redphx // @license MIT @@ -107,7 +107,7 @@ class UserAgent { }); } } -var SCRIPT_VERSION = "6.2.1", SCRIPT_VARIANT = "full", AppInterface = window.AppInterface; +var SCRIPT_VERSION = "6.2.2", SCRIPT_VARIANT = "full", AppInterface = window.AppInterface; UserAgent.init(); var userAgent = window.navigator.userAgent.toLowerCase(), isTv = userAgent.includes("smart-tv") || userAgent.includes("smarttv") || /\baft.*\b/.test(userAgent), isVr = window.navigator.userAgent.includes("VR") && window.navigator.userAgent.includes("OculusBrowser"), browserHasTouchSupport = "ontouchstart" in window || navigator.maxTouchPoints > 0, userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport, STATES = { supportedRegion: !0, @@ -3911,15 +3911,15 @@ class NavigationDialogManager { this.gamepadHoldingIntervalId && window.clearInterval(this.gamepadHoldingIntervalId), this.gamepadHoldingIntervalId = null; } show(dialog, configs = {}, clearStack = !1) { - this.clearGamepadHoldingInterval(), BxEventBus.Script.emit("dialog.shown", {}), 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(); + 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(), this.stopGamepadPolling(), !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.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); } - if (this.unmountCurrentDialog(), this.dialogsStack.length) this.dialogsStack[this.dialogsStack.length - 1].show(); + if (this.unmountCurrentDialog(), window.BX_EXPOSED.disableGamepadPolling = !1, this.dialogsStack.length) this.dialogsStack[this.dialogsStack.length - 1].show(); } focus($elm) { if (!$elm) return !1; @@ -3989,10 +3989,10 @@ class NavigationDialogManager { return null; } startGamepadPolling() { - window.BX_EXPOSED.disableGamepadPolling = !0, this.stopGamepadPolling(), this.gamepadPollingIntervalId = window.setInterval(this.pollGamepad, NavigationDialogManager.GAMEPAD_POLLING_INTERVAL); + this.stopGamepadPolling(), this.gamepadPollingIntervalId = window.setInterval(this.pollGamepad, NavigationDialogManager.GAMEPAD_POLLING_INTERVAL); } stopGamepadPolling() { - window.BX_EXPOSED.disableGamepadPolling = !1, this.gamepadLastStates = [], this.gamepadPollingIntervalId && window.clearInterval(this.gamepadPollingIntervalId), this.gamepadPollingIntervalId = null; + this.gamepadLastStates = [], this.gamepadPollingIntervalId && window.clearInterval(this.gamepadPollingIntervalId), this.gamepadPollingIntervalId = null; } focusDirection(direction) { let dialog = this.dialog; diff --git a/src/modules/ui/dialog/navigation-dialog.ts b/src/modules/ui/dialog/navigation-dialog.ts index 9626fcc..6cd5736 100755 --- a/src/modules/ui/dialog/navigation-dialog.ts +++ b/src/modules/ui/dialog/navigation-dialog.ts @@ -410,6 +410,9 @@ export class NavigationDialogManager { BxEventBus.Script.emit('dialog.shown', {}); + // Stop xCloud's navigation polling + window.BX_EXPOSED.disableGamepadPolling = true; + // Lock scroll bar document.body.classList.add('bx-no-scroll'); @@ -436,18 +439,11 @@ export class NavigationDialogManager { this.$container.addEventListener('keydown', this); // Start gamepad polling - if (isFullVersion()) { - this.startGamepadPolling(); - } + this.startGamepadPolling(); } hide() { - // Stop gamepad polling - if (isFullVersion()) { - this.clearGamepadHoldingInterval(); - this.stopGamepadPolling(); - } - + this.clearGamepadHoldingInterval(); if (!this.isShowing()) { return; } @@ -465,6 +461,9 @@ export class NavigationDialogManager { // Remove event listeners this.$container.removeEventListener('keydown', this); + // Stop gamepad polling + this.stopGamepadPolling(); + // Remove current dialog and everything after it from dialogs stack if (this.dialog) { const dialogIndex = this.dialogsStack.indexOf(this.dialog); @@ -476,6 +475,9 @@ export class NavigationDialogManager { // Unmount dialog this.unmountCurrentDialog(); + // Enable xCloud's navigation polling + window.BX_EXPOSED.disableGamepadPolling = false; + // Show the last dialog in dialogs stack if (this.dialogsStack.length) { this.dialogsStack[this.dialogsStack.length - 1].show(); @@ -639,18 +641,16 @@ export class NavigationDialogManager { } private startGamepadPolling() { - // Stop xCloud's navigation polling - window.BX_EXPOSED.disableGamepadPolling = true; - this.stopGamepadPolling(); - this.gamepadPollingIntervalId = window.setInterval(this.pollGamepad, NavigationDialogManager.GAMEPAD_POLLING_INTERVAL); + + if (isFullVersion()) { + this.gamepadPollingIntervalId = window.setInterval(this.pollGamepad, NavigationDialogManager.GAMEPAD_POLLING_INTERVAL); + } } private stopGamepadPolling() { - // Enable xCloud's navigation polling - window.BX_EXPOSED.disableGamepadPolling = false; - this.gamepadLastStates = []; + this.gamepadPollingIntervalId && window.clearInterval(this.gamepadPollingIntervalId); this.gamepadPollingIntervalId = null; }