mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-08-07 05:38:27 +02:00
Stop using MutationObserver in root-dialog
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
import { isFullVersion } from "@macros/build" with { type: "macro" };
|
||||
|
||||
import { BxEvent } from "@/utils/bx-event";
|
||||
import { AppInterface, STATES } from "@/utils/global";
|
||||
import { createButton, ButtonStyle, CE } from "@/utils/html";
|
||||
import { t } from "@/utils/translation";
|
||||
import { SettingsDialog } from "./dialog/settings-dialog";
|
||||
import { TrueAchievements } from "@/utils/true-achievements";
|
||||
import { BxIcon } from "@/utils/bx-icon";
|
||||
import { BxEventBus } from "@/utils/bx-event-bus";
|
||||
import { getGlobalPref } from "@/utils/pref-utils";
|
||||
@@ -141,11 +137,9 @@ export class GuideMenu {
|
||||
}
|
||||
|
||||
injectHome($root: HTMLElement, isPlaying = false) {
|
||||
if (isFullVersion()) {
|
||||
const $achievementsProgress = $root.querySelector('button[class*=AchievementsButton-module__progressBarContainer]');
|
||||
if ($achievementsProgress) {
|
||||
TrueAchievements.getInstance().injectAchievementsProgress($achievementsProgress as HTMLElement);
|
||||
}
|
||||
const $buttons = this.renderButtons();
|
||||
if ($root.contains($buttons)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the element to add buttons to
|
||||
@@ -169,67 +163,7 @@ export class GuideMenu {
|
||||
return false;
|
||||
}
|
||||
|
||||
const $buttons = this.renderButtons();
|
||||
$buttons.dataset.isPlaying = isPlaying.toString();
|
||||
$target.insertAdjacentElement('afterend', $buttons);
|
||||
}
|
||||
|
||||
private onShown = async (e: Event) => {
|
||||
const where = (e as any).where as GuideMenuTab;
|
||||
|
||||
if (where === GuideMenuTab.HOME) {
|
||||
const $root = document.querySelector<HTMLElement>('#gamepass-dialog-root div[role=dialog] div[role=tabpanel] div[class*=HomeLandingPage]');
|
||||
$root && this.injectHome($root, STATES.isPlaying);
|
||||
}
|
||||
}
|
||||
|
||||
addEventListeners() {
|
||||
window.addEventListener(BxEvent.XCLOUD_GUIDE_MENU_SHOWN, this.onShown);
|
||||
}
|
||||
|
||||
observe($addedElm: HTMLElement) {
|
||||
let className = $addedElm.className;
|
||||
|
||||
// Fix custom buttons disappearing in Guide Menu (#551)
|
||||
if (!className) {
|
||||
className = $addedElm.firstElementChild?.className ?? '';
|
||||
}
|
||||
|
||||
if (!className || className.startsWith('bx-')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TrueAchievements
|
||||
if (isFullVersion() && className.includes('AchievementsButton-module__progressBarContainer')) {
|
||||
TrueAchievements.getInstance().injectAchievementsProgress($addedElm);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!className.startsWith('NavigationAnimation') &&
|
||||
!className.startsWith('DialogRoutes') &&
|
||||
!className.startsWith('Dialog-module__container')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Achievement Details page
|
||||
if (isFullVersion()) {
|
||||
const $achievDetailPage = $addedElm.querySelector('div[class*=AchievementDetailPage]');
|
||||
if ($achievDetailPage) {
|
||||
TrueAchievements.getInstance().injectAchievementDetailPage($achievDetailPage as HTMLElement);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 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_MENU_SHOWN, { where: GuideMenuTab.HOME });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user