mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 23:57:19 +02:00
Fix errors with setTimeout/setInterval
This commit is contained in:
parent
9b9a7d2bf2
commit
53676ad733
@ -33,7 +33,7 @@ import { injectStreamMenuButtons } from "./modules/stream/stream-ui";
|
|||||||
// Handle login page
|
// Handle login page
|
||||||
if (window.location.pathname.includes('/auth/msa')) {
|
if (window.location.pathname.includes('/auth/msa')) {
|
||||||
window.addEventListener('load', e => {
|
window.addEventListener('load', e => {
|
||||||
window.location.search.includes('loggedIn') && setTimeout(() => {
|
window.location.search.includes('loggedIn') && window.setTimeout(() => {
|
||||||
const location = window.location;
|
const location = window.location;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
location.pathname.includes('/play') && location.reload(true);
|
location.pathname.includes('/play') && location.reload(true);
|
||||||
@ -81,7 +81,7 @@ if (BX_FLAGS.SafariWorkaround && document.readyState !== 'loading') {
|
|||||||
|
|
||||||
// Automatically reload the page when running into the "We are sorry..." error message
|
// Automatically reload the page when running into the "We are sorry..." error message
|
||||||
window.addEventListener('load', e => {
|
window.addEventListener('load', e => {
|
||||||
setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
if (document.body.classList.contains('legacyBackground')) {
|
if (document.body.classList.contains('legacyBackground')) {
|
||||||
// Has error message -> reload page
|
// Has error message -> reload page
|
||||||
window.stop();
|
window.stop();
|
||||||
@ -105,7 +105,7 @@ window.history.replaceState = patchHistoryMethod('replaceState');
|
|||||||
window.addEventListener(BxEvent.XCLOUD_SERVERS_READY, e => {
|
window.addEventListener(BxEvent.XCLOUD_SERVERS_READY, e => {
|
||||||
// Start rendering UI
|
// Start rendering UI
|
||||||
if (document.querySelector('div[class^=UnsupportedMarketPage]')) {
|
if (document.querySelector('div[class^=UnsupportedMarketPage]')) {
|
||||||
setTimeout(watchHeader, 2000);
|
window.setTimeout(watchHeader, 2000);
|
||||||
} else {
|
} else {
|
||||||
watchHeader();
|
watchHeader();
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ export class LoadingScreen {
|
|||||||
$countDown.textContent = LoadingScreen.#secondsToString(secondsLeft);
|
$countDown.textContent = LoadingScreen.#secondsToString(secondsLeft);
|
||||||
document.title = `[${$countDown.textContent}] ${LoadingScreen.#orgWebTitle}`;
|
document.title = `[${$countDown.textContent}] ${LoadingScreen.#orgWebTitle}`;
|
||||||
|
|
||||||
LoadingScreen.#waitTimeInterval = setInterval(() => {
|
LoadingScreen.#waitTimeInterval = window.setInterval(() => {
|
||||||
secondsLeft--;
|
secondsLeft--;
|
||||||
$countDown.textContent = LoadingScreen.#secondsToString(secondsLeft);
|
$countDown.textContent = LoadingScreen.#secondsToString(secondsLeft);
|
||||||
document.title = `[${$countDown.textContent}] ${LoadingScreen.#orgWebTitle}`;
|
document.title = `[${$countDown.textContent}] ${LoadingScreen.#orgWebTitle}`;
|
||||||
|
@ -214,7 +214,7 @@ export class MkbHandler {
|
|||||||
this.#pressButton(buttonIndex, true);
|
this.#pressButton(buttonIndex, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#wheelStoppedTimeout = setTimeout(() => {
|
this.#wheelStoppedTimeout = window.setTimeout(() => {
|
||||||
this.#prevWheelCode = null;
|
this.#prevWheelCode = null;
|
||||||
this.#pressButton(buttonIndex, false);
|
this.#pressButton(buttonIndex, false);
|
||||||
}, 20);
|
}, 20);
|
||||||
@ -272,7 +272,7 @@ export class MkbHandler {
|
|||||||
|
|
||||||
this.#allowStickDecaying = false;
|
this.#allowStickDecaying = false;
|
||||||
this.#detectMouseStoppedTimeout && clearTimeout(this.#detectMouseStoppedTimeout);
|
this.#detectMouseStoppedTimeout && clearTimeout(this.#detectMouseStoppedTimeout);
|
||||||
this.#detectMouseStoppedTimeout = setTimeout(this.#onMouseStopped.bind(this), 100);
|
this.#detectMouseStoppedTimeout = window.setTimeout(this.#onMouseStopped.bind(this), 100);
|
||||||
|
|
||||||
const deltaX = e.movementX;
|
const deltaX = e.movementX;
|
||||||
const deltaY = e.movementY;
|
const deltaY = e.movementY;
|
||||||
|
@ -151,7 +151,7 @@ export class MkbRemapper {
|
|||||||
this.#clearEventListeners();
|
this.#clearEventListeners();
|
||||||
|
|
||||||
this.#bindKey(this.#$.currentBindingKey!, KeyHelper.getKeyFromEvent(e));
|
this.#bindKey(this.#$.currentBindingKey!, KeyHelper.getKeyFromEvent(e));
|
||||||
setTimeout(() => this.bindingDialog.hide(), 200);
|
window.setTimeout(() => this.bindingDialog.hide(), 200);
|
||||||
};
|
};
|
||||||
|
|
||||||
#onMouseDown = (e: MouseEvent) => {
|
#onMouseDown = (e: MouseEvent) => {
|
||||||
@ -159,7 +159,7 @@ export class MkbRemapper {
|
|||||||
this.#clearEventListeners();
|
this.#clearEventListeners();
|
||||||
|
|
||||||
this.#bindKey(this.#$.currentBindingKey!, KeyHelper.getKeyFromEvent(e));
|
this.#bindKey(this.#$.currentBindingKey!, KeyHelper.getKeyFromEvent(e));
|
||||||
setTimeout(() => this.bindingDialog.hide(), 200);
|
window.setTimeout(() => this.bindingDialog.hide(), 200);
|
||||||
};
|
};
|
||||||
|
|
||||||
#onKeyDown = (e: KeyboardEvent) => {
|
#onKeyDown = (e: KeyboardEvent) => {
|
||||||
@ -171,7 +171,7 @@ export class MkbRemapper {
|
|||||||
this.#bindKey(this.#$.currentBindingKey!, KeyHelper.getKeyFromEvent(e));
|
this.#bindKey(this.#$.currentBindingKey!, KeyHelper.getKeyFromEvent(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => this.bindingDialog.hide(), 200);
|
window.setTimeout(() => this.bindingDialog.hide(), 200);
|
||||||
};
|
};
|
||||||
|
|
||||||
#onBindingKey = (e: MouseEvent) => {
|
#onBindingKey = (e: MouseEvent) => {
|
||||||
|
@ -18,7 +18,7 @@ export class MouseCursorHider {
|
|||||||
!MouseCursorHider.#cursorVisible && MouseCursorHider.show();
|
!MouseCursorHider.#cursorVisible && MouseCursorHider.show();
|
||||||
// Setup timeout
|
// Setup timeout
|
||||||
MouseCursorHider.#timeout && clearTimeout(MouseCursorHider.#timeout);
|
MouseCursorHider.#timeout && clearTimeout(MouseCursorHider.#timeout);
|
||||||
MouseCursorHider.#timeout = setTimeout(MouseCursorHider.hide, 3000);
|
MouseCursorHider.#timeout = window.setTimeout(MouseCursorHider.hide, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
static start() {
|
static start() {
|
||||||
|
@ -67,7 +67,7 @@ export function setupScreenshotButton() {
|
|||||||
takeScreenshot(() => {
|
takeScreenshot(() => {
|
||||||
// Hide button
|
// Hide button
|
||||||
$btn.setAttribute('data-showing', 'false');
|
$btn.setAttribute('data-showing', 'false');
|
||||||
setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
if (!timeout) {
|
if (!timeout) {
|
||||||
$btn.setAttribute('data-capturing', 'false');
|
$btn.setAttribute('data-capturing', 'false');
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ export function setupScreenshotButton() {
|
|||||||
$btn.setAttribute('data-capturing', 'false');
|
$btn.setAttribute('data-capturing', 'false');
|
||||||
|
|
||||||
timeout && clearTimeout(timeout);
|
timeout && clearTimeout(timeout);
|
||||||
timeout = setTimeout(() => {
|
timeout = window.setTimeout(() => {
|
||||||
timeout = null;
|
timeout = null;
|
||||||
$btn.setAttribute('data-showing', 'false');
|
$btn.setAttribute('data-showing', 'false');
|
||||||
$btn.setAttribute('data-capturing', 'false');
|
$btn.setAttribute('data-capturing', 'false');
|
||||||
|
@ -76,7 +76,7 @@ export class SettingElement {
|
|||||||
$control.addEventListener('mousedown', function(e) {
|
$control.addEventListener('mousedown', function(e) {
|
||||||
const self = this;
|
const self = this;
|
||||||
const orgScrollTop = self.scrollTop;
|
const orgScrollTop = self.scrollTop;
|
||||||
setTimeout(() => (self.scrollTop = orgScrollTop), 0);
|
window.setTimeout(() => (self.scrollTop = orgScrollTop), 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
$control.addEventListener('mousemove', e => e.preventDefault());
|
$control.addEventListener('mousemove', e => e.preventDefault());
|
||||||
@ -209,7 +209,7 @@ export class SettingElement {
|
|||||||
isHolding = true;
|
isHolding = true;
|
||||||
|
|
||||||
const args = arguments;
|
const args = arguments;
|
||||||
interval = setInterval(() => {
|
interval = window.setInterval(() => {
|
||||||
const event = new Event('click');
|
const event = new Event('click');
|
||||||
(event as any).arguments = args;
|
(event as any).arguments = args;
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ export class StreamBadges {
|
|||||||
|
|
||||||
await StreamBadges.#updateBadges(true);
|
await StreamBadges.#updateBadges(true);
|
||||||
StreamBadges.#stop();
|
StreamBadges.#stop();
|
||||||
StreamBadges.#interval = setInterval(StreamBadges.#updateBadges, StreamBadges.#REFRESH_INTERVAL);
|
StreamBadges.#interval = window.setInterval(StreamBadges.#updateBadges, StreamBadges.#REFRESH_INTERVAL);
|
||||||
|
|
||||||
return $wrapper;
|
return $wrapper;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ export class StreamStats {
|
|||||||
StreamStats.#$container.classList.remove('bx-gone');
|
StreamStats.#$container.classList.remove('bx-gone');
|
||||||
StreamStats.#$container.setAttribute('data-display', glancing ? 'glancing' : 'fixed');
|
StreamStats.#$container.setAttribute('data-display', glancing ? 'glancing' : 'fixed');
|
||||||
|
|
||||||
StreamStats.#interval = setInterval(StreamStats.update, StreamStats.#updateInterval);
|
StreamStats.#interval = window.setInterval(StreamStats.update, StreamStats.#updateInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
static stop(glancing=false) {
|
static stop(glancing=false) {
|
||||||
|
@ -20,7 +20,7 @@ class MouseHoldEvent {
|
|||||||
this.#isHolding = false;
|
this.#isHolding = false;
|
||||||
|
|
||||||
this.#timeout && clearTimeout(this.#timeout);
|
this.#timeout && clearTimeout(this.#timeout);
|
||||||
this.#timeout = setTimeout(() => {
|
this.#timeout = window.setTimeout(() => {
|
||||||
_this.#isHolding = true;
|
_this.#isHolding = true;
|
||||||
_this.#callback();
|
_this.#callback();
|
||||||
}, this.#duration);
|
}, this.#duration);
|
||||||
@ -87,7 +87,7 @@ function cloneStreamHudButton($orgButton: HTMLElement, label: string, svgIcon: I
|
|||||||
const left = document.getElementById('StreamHud')?.style.left;
|
const left = document.getElementById('StreamHud')?.style.left;
|
||||||
if (left === '0px') {
|
if (left === '0px') {
|
||||||
timeout && clearTimeout(timeout);
|
timeout && clearTimeout(timeout);
|
||||||
timeout = setTimeout(() => {
|
timeout = window.setTimeout(() => {
|
||||||
$container.style.pointerEvents = 'auto';
|
$container.style.pointerEvents = 'auto';
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ export class TouchController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static #dispatchMessage(msg: any) {
|
static #dispatchMessage(msg: any) {
|
||||||
TouchController.#dataChannel && setTimeout(() => {
|
TouchController.#dataChannel && window.setTimeout(() => {
|
||||||
TouchController.#dataChannel!.dispatchEvent(msg);
|
TouchController.#dataChannel!.dispatchEvent(msg);
|
||||||
}, 10);
|
}, 10);
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ export class TouchController {
|
|||||||
if (retries > 2) {
|
if (retries > 2) {
|
||||||
TouchController.#customLayouts[xboxTitleId] = null;
|
TouchController.#customLayouts[xboxTitleId] = null;
|
||||||
// Wait for BX_EXPOSED.touch_layout_manager
|
// Wait for BX_EXPOSED.touch_layout_manager
|
||||||
setTimeout(() => TouchController.#dispatchLayouts(null), 1000);
|
window.setTimeout(() => TouchController.#dispatchLayouts(null), 1000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ export class TouchController {
|
|||||||
TouchController.#customLayouts[xboxTitleId] = json;
|
TouchController.#customLayouts[xboxTitleId] = json;
|
||||||
|
|
||||||
// Wait for BX_EXPOSED.touch_layout_manager
|
// Wait for BX_EXPOSED.touch_layout_manager
|
||||||
setTimeout(() => TouchController.#dispatchLayouts(json), 1000);
|
window.setTimeout(() => TouchController.#dispatchLayouts(json), 1000);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Retry
|
// Retry
|
||||||
TouchController.getCustomLayouts(xboxTitleId, retries + 1);
|
TouchController.getCustomLayouts(xboxTitleId, retries + 1);
|
||||||
@ -166,7 +166,7 @@ export class TouchController {
|
|||||||
// Show a toast with layout's name
|
// Show a toast with layout's name
|
||||||
layoutChanged && Toast.show(t('touch-control-layout'), layout.name);
|
layoutChanged && Toast.show(t('touch-control-layout'), layout.name);
|
||||||
|
|
||||||
setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
window.BX_EXPOSED.touch_layout_manager.changeLayoutForScope({
|
window.BX_EXPOSED.touch_layout_manager.changeLayoutForScope({
|
||||||
type: 'showLayout',
|
type: 'showLayout',
|
||||||
scope: xboxTitleId,
|
scope: xboxTitleId,
|
||||||
@ -221,7 +221,7 @@ export class TouchController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clickTimeout = setTimeout(() => {
|
clickTimeout = window.setTimeout(() => {
|
||||||
clickTimeout = null;
|
clickTimeout = null;
|
||||||
}, 400);
|
}, 400);
|
||||||
});
|
});
|
||||||
@ -260,7 +260,7 @@ export class TouchController {
|
|||||||
|
|
||||||
// Fix sometimes the touch controller doesn't show at the beginning
|
// Fix sometimes the touch controller doesn't show at the beginning
|
||||||
dataChannel.addEventListener('open', () => {
|
dataChannel.addEventListener('open', () => {
|
||||||
setTimeout(TouchController.#show, 1000);
|
window.setTimeout(TouchController.#show, 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
let focused = false;
|
let focused = false;
|
||||||
|
@ -76,7 +76,7 @@ export function watchHeader() {
|
|||||||
let timeout: number | null;
|
let timeout: number | null;
|
||||||
const observer = new MutationObserver(mutationList => {
|
const observer = new MutationObserver(mutationList => {
|
||||||
timeout && clearTimeout(timeout);
|
timeout && clearTimeout(timeout);
|
||||||
timeout = setTimeout(checkHeader, 2000);
|
timeout = window.setTimeout(checkHeader, 2000);
|
||||||
});
|
});
|
||||||
observer.observe($header, {subtree: true, childList: true});
|
observer.observe($header, {subtree: true, childList: true});
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ export function localRedirect(path: string) {
|
|||||||
}, '');
|
}, '');
|
||||||
$anchor.addEventListener('click', e => {
|
$anchor.addEventListener('click', e => {
|
||||||
// Remove element after clicking on it
|
// Remove element after clicking on it
|
||||||
setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
$pageContent.removeChild($anchor);
|
$pageContent.removeChild($anchor);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
|
@ -23,7 +23,7 @@ export function onHistoryChanged(e: PopStateEvent) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(RemotePlay.detect, 10);
|
window.setTimeout(RemotePlay.detect, 10);
|
||||||
|
|
||||||
const $settings = document.querySelector('.bx-settings-container');
|
const $settings = document.querySelector('.bx-settings-container');
|
||||||
if ($settings) {
|
if ($settings) {
|
||||||
@ -34,7 +34,7 @@ export function onHistoryChanged(e: PopStateEvent) {
|
|||||||
RemotePlay.detachPopup();
|
RemotePlay.detachPopup();
|
||||||
|
|
||||||
LoadingScreen.reset();
|
LoadingScreen.reset();
|
||||||
setTimeout(checkHeader, 2000);
|
window.setTimeout(checkHeader, 2000);
|
||||||
|
|
||||||
BxEvent.dispatch(window, BxEvent.STREAM_STOPPED);
|
BxEvent.dispatch(window, BxEvent.STREAM_STOPPED);
|
||||||
}
|
}
|
||||||
|
@ -543,7 +543,7 @@ export function interceptHttpRequests() {
|
|||||||
for (const blocked of BLOCKED_URLS) {
|
for (const blocked of BLOCKED_URLS) {
|
||||||
if ((this as any)._url.startsWith(blocked)) {
|
if ((this as any)._url.startsWith(blocked)) {
|
||||||
if (blocked === 'https://dc.services.visualstudio.com') {
|
if (blocked === 'https://dc.services.visualstudio.com') {
|
||||||
setTimeout(clearAllLogs, 1000);
|
window.setTimeout(clearAllLogs, 1000);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ export class Toast {
|
|||||||
Toast.#isShowing = true;
|
Toast.#isShowing = true;
|
||||||
|
|
||||||
Toast.#timeout && clearTimeout(Toast.#timeout);
|
Toast.#timeout && clearTimeout(Toast.#timeout);
|
||||||
Toast.#timeout = setTimeout(Toast.#hide, Toast.#DURATION);
|
Toast.#timeout = window.setTimeout(Toast.#hide, Toast.#DURATION);
|
||||||
|
|
||||||
// Get values from item
|
// Get values from item
|
||||||
const [msg, status, _] = Toast.#stack.shift()!;
|
const [msg, status, _] = Toast.#stack.shift()!;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user