mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-08-12 08:05:15 +02:00
Optimize + refactor code
This commit is contained in:
@@ -50,6 +50,7 @@ enum StreamBadge {
|
||||
export class StreamBadges {
|
||||
private static instance: StreamBadges;
|
||||
public static getInstance = () => StreamBadges.instance ?? (StreamBadges.instance = new StreamBadges());
|
||||
private readonly LOG_TAG = 'StreamBadges';
|
||||
|
||||
private serverInfo: StreamServerInfo = {};
|
||||
|
||||
@@ -96,6 +97,10 @@ export class StreamBadges {
|
||||
private intervalId?: number | null;
|
||||
private readonly REFRESH_INTERVAL = 3 * 1000;
|
||||
|
||||
private constructor() {
|
||||
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||
}
|
||||
|
||||
setRegion(region: string) {
|
||||
this.serverInfo.server = {
|
||||
region: region,
|
||||
|
@@ -18,7 +18,7 @@ export function onChangeVideoPlayerType() {
|
||||
|
||||
let isDisabled = false;
|
||||
|
||||
const $optCas = $videoProcessing.querySelector(`option[value=${StreamVideoProcessing.CAS}]`) as HTMLOptionElement;
|
||||
const $optCas = $videoProcessing.querySelector<HTMLOptionElement>(`option[value=${StreamVideoProcessing.CAS}]`);
|
||||
|
||||
if (playerType === StreamPlayerType.WEBGL2) {
|
||||
$optCas && ($optCas.disabled = false);
|
||||
|
@@ -5,11 +5,13 @@ import { STATES } from "@utils/global"
|
||||
import { PrefKey } from "@/enums/pref-keys"
|
||||
import { getPref } from "@/utils/settings-storages/global-settings-storage"
|
||||
import { StreamStat, StreamStatsCollector, type StreamStatGrade } from "@/utils/stream-stats-collector"
|
||||
import { BxLogger } from "@/utils/bx-logger"
|
||||
|
||||
|
||||
export class StreamStats {
|
||||
private static instance: StreamStats;
|
||||
public static getInstance = () => StreamStats.instance ?? (StreamStats.instance = new StreamStats());
|
||||
private readonly LOG_TAG = 'StreamStats';
|
||||
|
||||
private intervalId?: number | null;
|
||||
private readonly REFRESH_INTERVAL = 1 * 1000;
|
||||
@@ -69,7 +71,8 @@ export class StreamStats {
|
||||
|
||||
quickGlanceObserver?: MutationObserver | null;
|
||||
|
||||
constructor() {
|
||||
private constructor() {
|
||||
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||
this.render();
|
||||
}
|
||||
|
||||
|
@@ -39,7 +39,7 @@ export class StreamUiHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
const $streamHud = (e.target as HTMLElement).closest('#StreamHud') as HTMLElement;
|
||||
const $streamHud = (e.target as HTMLElement).closest<HTMLElement>('#StreamHud');
|
||||
if (!$streamHud) {
|
||||
return;
|
||||
}
|
||||
@@ -58,13 +58,13 @@ export class StreamUiHandler {
|
||||
$container.addEventListener('transitionend', onTransitionEnd);
|
||||
}
|
||||
|
||||
const $button = $container.querySelector('button') as HTMLElement;
|
||||
const $button = $container.querySelector<HTMLButtonElement>('button');
|
||||
if (!$button) {
|
||||
return null;
|
||||
}
|
||||
$button.setAttribute('title', label);
|
||||
|
||||
const $orgSvg = $button.querySelector('svg') as SVGElement;
|
||||
const $orgSvg = $button.querySelector<SVGElement>('svg');
|
||||
if (!$orgSvg) {
|
||||
return null;
|
||||
}
|
||||
@@ -102,7 +102,7 @@ export class StreamUiHandler {
|
||||
}
|
||||
|
||||
private static async handleStreamMenu() {
|
||||
const $btnCloseHud = document.querySelector('button[class*=StreamMenu-module__backButton]') as HTMLElement;
|
||||
const $btnCloseHud = document.querySelector<HTMLElement>('button[class*=StreamMenu-module__backButton]');
|
||||
if (!$btnCloseHud) {
|
||||
return;
|
||||
}
|
||||
@@ -136,14 +136,14 @@ export class StreamUiHandler {
|
||||
|
||||
private static handleSystemMenu($streamHud: HTMLElement) {
|
||||
// Get the last button
|
||||
const $orgButton = $streamHud.querySelector('div[class^=HUDButton]') as HTMLElement;
|
||||
const $orgButton = $streamHud.querySelector<HTMLElement>('div[class^=HUDButton]');
|
||||
if (!$orgButton) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hideGripHandle = () => {
|
||||
// Grip handle
|
||||
const $gripHandle = document.querySelector('#StreamHud button[class^=GripHandle]') as HTMLElement;
|
||||
const $gripHandle = document.querySelector<HTMLElement>('#StreamHud button[class^=GripHandle]');
|
||||
if ($gripHandle && $gripHandle.ariaExpanded === 'true') {
|
||||
$gripHandle.dispatchEvent(new PointerEvent('pointerdown'));
|
||||
$gripHandle.click();
|
||||
|
Reference in New Issue
Block a user