Show stats in the Guide menu & refactor

This commit is contained in:
redphx
2024-06-01 10:11:06 +07:00
parent 60cadb4b04
commit ed3c4041ff
16 changed files with 467 additions and 299 deletions

View File

@@ -1,5 +1,5 @@
import "@utils/global";
import { BxEvent } from "@utils/bx-event";
import { BxEvent, XcloudGuideWhere } from "@utils/bx-event";
import { BX_FLAGS } from "@utils/bx-flags";
import { BxExposed } from "@utils/bx-exposed";
import { t } from "@utils/translation";
@@ -185,7 +185,7 @@ window.addEventListener(BxEvent.STREAM_STOPPED, e => {
STATES.currentStream.audioGainNode = null;
STATES.currentStream.$video = null;
StreamStats.onStoppedPlaying();
StreamStats.getInstance().onStoppedPlaying();
MouseCursorHider.stop();
TouchController.reset();
@@ -206,6 +206,25 @@ function observeRootDialog($root: HTMLElement) {
continue;
}
if (mutation.addedNodes.length === 1) {
const $addedElm = mutation.addedNodes[0];
if ($addedElm instanceof HTMLElement && $addedElm.className) {
if ($addedElm.className.startsWith('NavigationAnimation') || $addedElm.className.startsWith('DialogRoutes') || $addedElm.className.startsWith('Dialog-module__container')) {
// Find navigation bar
const $selectedTab = $addedElm.querySelector('div[class^=NavigationMenu] button[aria-selected=true');
if ($selectedTab) {
let $elm: Element | null = $selectedTab;
let index;
for (index = 0; ($elm = $elm?.previousElementSibling); index++);
if (index === 0) {
BxEvent.dispatch(window, BxEvent.XCLOUD_GUIDE_SHOWN, {where: XcloudGuideWhere.HOME});
}
}
}
}
}
const shown = ($root.firstElementChild && $root.firstElementChild.childElementCount > 0) || false;
if (shown !== currentShown) {
currentShown = shown;