Fix errors with setTimeout/setInterval

This commit is contained in:
redphx 2024-04-25 17:46:02 +07:00
parent 9b9a7d2bf2
commit 53676ad733
16 changed files with 30 additions and 30 deletions

View File

@ -33,7 +33,7 @@ import { injectStreamMenuButtons } from "./modules/stream/stream-ui";
// Handle login page
if (window.location.pathname.includes('/auth/msa')) {
window.addEventListener('load', e => {
window.location.search.includes('loggedIn') && setTimeout(() => {
window.location.search.includes('loggedIn') && window.setTimeout(() => {
const location = window.location;
// @ts-ignore
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
window.addEventListener('load', e => {
setTimeout(() => {
window.setTimeout(() => {
if (document.body.classList.contains('legacyBackground')) {
// Has error message -> reload page
window.stop();
@ -105,7 +105,7 @@ window.history.replaceState = patchHistoryMethod('replaceState');
window.addEventListener(BxEvent.XCLOUD_SERVERS_READY, e => {
// Start rendering UI
if (document.querySelector('div[class^=UnsupportedMarketPage]')) {
setTimeout(watchHeader, 2000);
window.setTimeout(watchHeader, 2000);
} else {
watchHeader();
}

View File

@ -135,7 +135,7 @@ export class LoadingScreen {
$countDown.textContent = LoadingScreen.#secondsToString(secondsLeft);
document.title = `[${$countDown.textContent}] ${LoadingScreen.#orgWebTitle}`;
LoadingScreen.#waitTimeInterval = setInterval(() => {
LoadingScreen.#waitTimeInterval = window.setInterval(() => {
secondsLeft--;
$countDown.textContent = LoadingScreen.#secondsToString(secondsLeft);
document.title = `[${$countDown.textContent}] ${LoadingScreen.#orgWebTitle}`;

View File

@ -214,7 +214,7 @@ export class MkbHandler {
this.#pressButton(buttonIndex, true);
}
this.#wheelStoppedTimeout = setTimeout(() => {
this.#wheelStoppedTimeout = window.setTimeout(() => {
this.#prevWheelCode = null;
this.#pressButton(buttonIndex, false);
}, 20);
@ -272,7 +272,7 @@ export class MkbHandler {
this.#allowStickDecaying = false;
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 deltaY = e.movementY;

View File

@ -151,7 +151,7 @@ export class MkbRemapper {
this.#clearEventListeners();
this.#bindKey(this.#$.currentBindingKey!, KeyHelper.getKeyFromEvent(e));
setTimeout(() => this.bindingDialog.hide(), 200);
window.setTimeout(() => this.bindingDialog.hide(), 200);
};
#onMouseDown = (e: MouseEvent) => {
@ -159,7 +159,7 @@ export class MkbRemapper {
this.#clearEventListeners();
this.#bindKey(this.#$.currentBindingKey!, KeyHelper.getKeyFromEvent(e));
setTimeout(() => this.bindingDialog.hide(), 200);
window.setTimeout(() => this.bindingDialog.hide(), 200);
};
#onKeyDown = (e: KeyboardEvent) => {
@ -171,7 +171,7 @@ export class MkbRemapper {
this.#bindKey(this.#$.currentBindingKey!, KeyHelper.getKeyFromEvent(e));
}
setTimeout(() => this.bindingDialog.hide(), 200);
window.setTimeout(() => this.bindingDialog.hide(), 200);
};
#onBindingKey = (e: MouseEvent) => {

View File

@ -18,7 +18,7 @@ export class MouseCursorHider {
!MouseCursorHider.#cursorVisible && MouseCursorHider.show();
// Setup timeout
MouseCursorHider.#timeout && clearTimeout(MouseCursorHider.#timeout);
MouseCursorHider.#timeout = setTimeout(MouseCursorHider.hide, 3000);
MouseCursorHider.#timeout = window.setTimeout(MouseCursorHider.hide, 3000);
}
static start() {

View File

@ -67,7 +67,7 @@ export function setupScreenshotButton() {
takeScreenshot(() => {
// Hide button
$btn.setAttribute('data-showing', 'false');
setTimeout(() => {
window.setTimeout(() => {
if (!timeout) {
$btn.setAttribute('data-capturing', 'false');
}
@ -84,7 +84,7 @@ export function setupScreenshotButton() {
$btn.setAttribute('data-capturing', 'false');
timeout && clearTimeout(timeout);
timeout = setTimeout(() => {
timeout = window.setTimeout(() => {
timeout = null;
$btn.setAttribute('data-showing', 'false');
$btn.setAttribute('data-capturing', 'false');

View File

@ -76,7 +76,7 @@ export class SettingElement {
$control.addEventListener('mousedown', function(e) {
const self = this;
const orgScrollTop = self.scrollTop;
setTimeout(() => (self.scrollTop = orgScrollTop), 0);
window.setTimeout(() => (self.scrollTop = orgScrollTop), 0);
});
$control.addEventListener('mousemove', e => e.preventDefault());
@ -209,7 +209,7 @@ export class SettingElement {
isHolding = true;
const args = arguments;
interval = setInterval(() => {
interval = window.setInterval(() => {
const event = new Event('click');
(event as any).arguments = args;

View File

@ -215,7 +215,7 @@ export class StreamBadges {
await StreamBadges.#updateBadges(true);
StreamBadges.#stop();
StreamBadges.#interval = setInterval(StreamBadges.#updateBadges, StreamBadges.#REFRESH_INTERVAL);
StreamBadges.#interval = window.setInterval(StreamBadges.#updateBadges, StreamBadges.#REFRESH_INTERVAL);
return $wrapper;
}

View File

@ -39,7 +39,7 @@ export class StreamStats {
StreamStats.#$container.classList.remove('bx-gone');
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) {

View File

@ -20,7 +20,7 @@ class MouseHoldEvent {
this.#isHolding = false;
this.#timeout && clearTimeout(this.#timeout);
this.#timeout = setTimeout(() => {
this.#timeout = window.setTimeout(() => {
_this.#isHolding = true;
_this.#callback();
}, this.#duration);
@ -87,7 +87,7 @@ function cloneStreamHudButton($orgButton: HTMLElement, label: string, svgIcon: I
const left = document.getElementById('StreamHud')?.style.left;
if (left === '0px') {
timeout && clearTimeout(timeout);
timeout = setTimeout(() => {
timeout = window.setTimeout(() => {
$container.style.pointerEvents = 'auto';
}, 100);
}

View File

@ -79,7 +79,7 @@ export class TouchController {
}
static #dispatchMessage(msg: any) {
TouchController.#dataChannel && setTimeout(() => {
TouchController.#dataChannel && window.setTimeout(() => {
TouchController.#dataChannel!.dispatchEvent(msg);
}, 10);
}
@ -100,7 +100,7 @@ export class TouchController {
if (retries > 2) {
TouchController.#customLayouts[xboxTitleId] = null;
// Wait for BX_EXPOSED.touch_layout_manager
setTimeout(() => TouchController.#dispatchLayouts(null), 1000);
window.setTimeout(() => TouchController.#dispatchLayouts(null), 1000);
return;
}
@ -136,7 +136,7 @@ export class TouchController {
TouchController.#customLayouts[xboxTitleId] = json;
// Wait for BX_EXPOSED.touch_layout_manager
setTimeout(() => TouchController.#dispatchLayouts(json), 1000);
window.setTimeout(() => TouchController.#dispatchLayouts(json), 1000);
} catch (e) {
// Retry
TouchController.getCustomLayouts(xboxTitleId, retries + 1);
@ -166,7 +166,7 @@ export class TouchController {
// Show a toast with layout's name
layoutChanged && Toast.show(t('touch-control-layout'), layout.name);
setTimeout(() => {
window.setTimeout(() => {
window.BX_EXPOSED.touch_layout_manager.changeLayoutForScope({
type: 'showLayout',
scope: xboxTitleId,
@ -221,7 +221,7 @@ export class TouchController {
return;
}
clickTimeout = setTimeout(() => {
clickTimeout = window.setTimeout(() => {
clickTimeout = null;
}, 400);
});
@ -260,7 +260,7 @@ export class TouchController {
// Fix sometimes the touch controller doesn't show at the beginning
dataChannel.addEventListener('open', () => {
setTimeout(TouchController.#show, 1000);
window.setTimeout(TouchController.#show, 1000);
});
let focused = false;

View File

@ -76,7 +76,7 @@ export function watchHeader() {
let timeout: number | null;
const observer = new MutationObserver(mutationList => {
timeout && clearTimeout(timeout);
timeout = setTimeout(checkHeader, 2000);
timeout = window.setTimeout(checkHeader, 2000);
});
observer.observe($header, {subtree: true, childList: true});

View File

@ -25,7 +25,7 @@ export function localRedirect(path: string) {
}, '');
$anchor.addEventListener('click', e => {
// Remove element after clicking on it
setTimeout(() => {
window.setTimeout(() => {
$pageContent.removeChild($anchor);
}, 1000);
});

View File

@ -23,7 +23,7 @@ export function onHistoryChanged(e: PopStateEvent) {
return;
}
setTimeout(RemotePlay.detect, 10);
window.setTimeout(RemotePlay.detect, 10);
const $settings = document.querySelector('.bx-settings-container');
if ($settings) {
@ -34,7 +34,7 @@ export function onHistoryChanged(e: PopStateEvent) {
RemotePlay.detachPopup();
LoadingScreen.reset();
setTimeout(checkHeader, 2000);
window.setTimeout(checkHeader, 2000);
BxEvent.dispatch(window, BxEvent.STREAM_STOPPED);
}

View File

@ -543,7 +543,7 @@ export function interceptHttpRequests() {
for (const blocked of BLOCKED_URLS) {
if ((this as any)._url.startsWith(blocked)) {
if (blocked === 'https://dc.services.visualstudio.com') {
setTimeout(clearAllLogs, 1000);
window.setTimeout(clearAllLogs, 1000);
}
return false;
}

View File

@ -37,7 +37,7 @@ export class Toast {
Toast.#isShowing = true;
Toast.#timeout && clearTimeout(Toast.#timeout);
Toast.#timeout = setTimeout(Toast.#hide, Toast.#DURATION);
Toast.#timeout = window.setTimeout(Toast.#hide, Toast.#DURATION);
// Get values from item
const [msg, status, _] = Toast.#stack.shift()!;