mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-23 07:53:04 +02:00
Use a better method to show the Better xCloud button ASAP
This commit is contained in:
parent
63e5e90443
commit
2fd482bb7b
73
dist/better-xcloud.pretty.user.js
vendored
73
dist/better-xcloud.pretty.user.js
vendored
@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name Better xCloud
|
||||
// @namespace https://github.com/redphx
|
||||
// @version 6.4.0
|
||||
// @version 6.4.1-beta
|
||||
// @description Improve Xbox Cloud Gaming (xCloud) experience
|
||||
// @author redphx
|
||||
// @license MIT
|
||||
@ -192,7 +192,7 @@ class UserAgent {
|
||||
});
|
||||
}
|
||||
}
|
||||
var SCRIPT_VERSION = "6.4.0", SCRIPT_VARIANT = "full", AppInterface = window.AppInterface;
|
||||
var SCRIPT_VERSION = "6.4.1-beta", SCRIPT_VARIANT = "full", AppInterface = window.AppInterface;
|
||||
UserAgent.init();
|
||||
var userAgent = window.navigator.userAgent.toLowerCase(), isTv = userAgent.includes("smart-tv") || userAgent.includes("smarttv") || /\baft.*\b/.test(userAgent), isVr = window.navigator.userAgent.includes("VR") && window.navigator.userAgent.includes("OculusBrowser"), browserHasTouchSupport = "ontouchstart" in window || navigator.maxTouchPoints > 0, userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport, STATES = {
|
||||
supportedRegion: !0,
|
||||
@ -5674,8 +5674,8 @@ ${subsVar} = subs;
|
||||
exposeReactCreateComponent(str) {
|
||||
let index = str.indexOf(".prototype.isReactComponent={}");
|
||||
if (index > -1 && (index = PatcherUtils.indexOf(str, ".createElement=", index)), index < 0) return !1;
|
||||
let newCode = "window.BX_EXPOSED.reactCreateElement=";
|
||||
return str = PatcherUtils.insertAt(str, index - 1, newCode), str;
|
||||
if (str = PatcherUtils.insertAt(str, index - 1, "window.BX_EXPOSED.reactCreateElement="), index = PatcherUtils.indexOf(str, ".useEffect=", index), index < 0) return !1;
|
||||
return str = PatcherUtils.insertAt(str, index - 1, "window.BX_EXPOSED.reactUseEffect="), str;
|
||||
},
|
||||
gameCardCustomIcons(str) {
|
||||
let initialIndex = str.indexOf("const{supportedInputIcons:");
|
||||
@ -5705,6 +5705,16 @@ ${subsVar} = subs;
|
||||
let index = str.indexOf("}?w=${");
|
||||
if (index > -1 && (index = PatcherUtils.indexOf(str, "}", index + 1, 10, !0)), index < 0) return !1;
|
||||
return str = PatcherUtils.insertAt(str, index, `&q=${getGlobalPref("ui.imageQuality")}`), str;
|
||||
},
|
||||
injectHeaderUseEffect(str) {
|
||||
let index = str.indexOf('"EdgewaterHeader-module__spaceBetween');
|
||||
if (index > -1 && (index = PatcherUtils.lastIndexOf(str, "return", index, 300)), index < 0) return !1;
|
||||
let newCode = `
|
||||
window.BX_EXPOSED.reactUseEffect(() => {
|
||||
window.BxEventBus.Script.emit('header.rendered', {});
|
||||
});
|
||||
`;
|
||||
return str = PatcherUtils.insertAt(str, index, newCode), str;
|
||||
}
|
||||
}, PATCH_ORDERS = PatcherUtils.filterPatches([
|
||||
...AppInterface && getGlobalPref("nativeMkb.mode") === "on" ? [
|
||||
@ -5712,6 +5722,7 @@ ${subsVar} = subs;
|
||||
"disableAbsoluteMouse"
|
||||
] : [],
|
||||
"exposeReactCreateComponent",
|
||||
"injectHeaderUseEffect",
|
||||
"gameCardCustomIcons",
|
||||
...getGlobalPref("ui.imageQuality") < 90 ? [
|
||||
"setImageQuality"
|
||||
@ -8325,6 +8336,7 @@ var BxExposed = {
|
||||
},
|
||||
localCoOpManager: LocalCoOpManager.getInstance(),
|
||||
reactCreateElement: function(...args) {},
|
||||
reactUseEffect: function(...args) {},
|
||||
createReactLocalCoOpIcon: (attrs) => {
|
||||
let reactCE = window.BX_EXPOSED.reactCreateElement;
|
||||
return reactCE("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", viewBox: "0 0 32 32", "fill-rule": "evenodd", "stroke-linecap": "round", "stroke-linejoin": "round", ...attrs }, reactCE("g", null, reactCE("path", { d: "M24.272 11.165h-3.294l-3.14 3.564c-.391.391-.922.611-1.476.611a2.1 2.1 0 0 1-2.087-2.088 2.09 2.09 0 0 1 .031-.362l1.22-6.274a3.89 3.89 0 0 1 3.81-3.206h6.57c1.834 0 3.439 1.573 3.833 3.295l1.205 6.185a2.09 2.09 0 0 1 .031.362 2.1 2.1 0 0 1-2.087 2.088c-.554 0-1.085-.22-1.476-.611l-3.14-3.564", fill: "none", stroke: "#fff", "stroke-width": "2" }), reactCE("circle", { cx: "22.625", cy: "5.874", r: ".879" }), reactCE("path", { d: "M11.022 24.415H7.728l-3.14 3.564c-.391.391-.922.611-1.476.611a2.1 2.1 0 0 1-2.087-2.088 2.09 2.09 0 0 1 .031-.362l1.22-6.274a3.89 3.89 0 0 1 3.81-3.206h6.57c1.834 0 3.439 1.573 3.833 3.295l1.205 6.185a2.09 2.09 0 0 1 .031.362 2.1 2.1 0 0 1-2.087 2.088c-.554 0-1.085-.22-1.476-.611l-3.14-3.564", fill: "none", stroke: "#fff", "stroke-width": "2" }), reactCE("circle", { cx: "9.375", cy: "19.124", r: ".879" })));
|
||||
@ -8363,8 +8375,6 @@ class HeaderSection {
|
||||
$btnRemotePlay;
|
||||
$btnSettings;
|
||||
$buttonsWrapper;
|
||||
observer;
|
||||
timeoutId;
|
||||
constructor() {
|
||||
BxLogger.info(this.LOG_TAG, "constructor()"), this.$btnRemotePlay = createButton({
|
||||
classes: ["bx-header-remote-play-button", "bx-gone"],
|
||||
@ -8372,38 +8382,32 @@ class HeaderSection {
|
||||
title: t("remote-play"),
|
||||
style: 8 | 64 | 2048,
|
||||
onClick: (e) => RemotePlayManager.getInstance()?.togglePopup()
|
||||
}), this.$btnSettings = createButton({
|
||||
classes: ["bx-header-settings-button"],
|
||||
label: "???",
|
||||
});
|
||||
let $btnSettings = this.$btnSettings = createButton({
|
||||
classes: ["bx-header-settings-button", "bx-gone"],
|
||||
label: t("better-xcloud"),
|
||||
style: 16 | 32 | 64 | 256,
|
||||
onClick: (e) => SettingsDialog.getInstance().show()
|
||||
}), this.$buttonsWrapper = CE("div", !1, getGlobalPref("xhome.enabled") ? this.$btnRemotePlay : null, this.$btnSettings);
|
||||
});
|
||||
this.$buttonsWrapper = CE("div", !1, getGlobalPref("xhome.enabled") ? this.$btnRemotePlay : null, this.$btnSettings), BxEventBus.Script.on("xcloud.server", ({ status }) => {
|
||||
if (status === "ready") {
|
||||
STATES.isSignedIn = !0, $btnSettings.querySelector("span").textContent = getPreferredServerRegion(!0) || t("better-xcloud");
|
||||
let PREF_LATEST_VERSION = getGlobalPref("version.latest");
|
||||
if (!SCRIPT_VERSION.includes("beta") && PREF_LATEST_VERSION && PREF_LATEST_VERSION !== SCRIPT_VERSION) $btnSettings.setAttribute("data-update-available", "true");
|
||||
} else if (status === "unavailable") {
|
||||
if (STATES.supportedRegion = !1, document.querySelector("div[class^=UnsupportedMarketPage-module__container]")) SettingsDialog.getInstance().show();
|
||||
}
|
||||
injectSettingsButton($parent) {
|
||||
if (!$parent) return;
|
||||
let PREF_LATEST_VERSION = getGlobalPref("version.latest"), $btnSettings = this.$btnSettings;
|
||||
if (isElementVisible(this.$buttonsWrapper)) return;
|
||||
if ($btnSettings.querySelector("span").textContent = getPreferredServerRegion(!0) || t("better-xcloud"), !SCRIPT_VERSION.includes("beta") && PREF_LATEST_VERSION && PREF_LATEST_VERSION !== SCRIPT_VERSION) $btnSettings.setAttribute("data-update-available", "true");
|
||||
$parent.appendChild(this.$buttonsWrapper);
|
||||
$btnSettings.classList.remove("bx-gone");
|
||||
});
|
||||
}
|
||||
checkHeader = () => {
|
||||
let $target = document.querySelector("#PageContent div[class*=EdgewaterHeader-module__rightSectionSpacing]");
|
||||
if (!$target) $target = document.querySelector("div[class^=UnsupportedMarketPage-module__buttons]");
|
||||
$target && this.injectSettingsButton($target);
|
||||
if ($target?.appendChild(this.$buttonsWrapper), !STATES.isSignedIn) BxEventBus.Script.emit("xcloud.server", { status: "signed-out" });
|
||||
};
|
||||
watchHeader() {
|
||||
let $root = document.querySelector("#PageContent header") || document.querySelector("#root");
|
||||
if (!$root) return;
|
||||
this.timeoutId && clearTimeout(this.timeoutId), this.timeoutId = null, this.observer && this.observer.disconnect(), this.observer = new MutationObserver((mutationList) => {
|
||||
this.timeoutId && clearTimeout(this.timeoutId), this.timeoutId = window.setTimeout(this.checkHeader, 2000);
|
||||
}), this.observer.observe($root, { subtree: !0, childList: !0 }), this.checkHeader();
|
||||
}
|
||||
showRemotePlayButton() {
|
||||
this.$btnRemotePlay?.classList.remove("bx-gone");
|
||||
}
|
||||
static watchHeader() {
|
||||
HeaderSection.getInstance().watchHeader();
|
||||
}
|
||||
}
|
||||
class RemotePlayDialog extends NavigationDialog {
|
||||
static instance;
|
||||
@ -9065,7 +9069,7 @@ class XcloudInterceptor {
|
||||
ip && request.headers.set("X-Forwarded-For", ip);
|
||||
}
|
||||
let response = await NATIVE_FETCH(request, init);
|
||||
if (response.status !== 200) return BxEventBus.Script.emit("xcloud.server.unavailable", {}), response;
|
||||
if (response.status !== 200) return BxEventBus.Script.emit("xcloud.server", { status: "unavailable" }), response;
|
||||
let obj = await response.clone().json();
|
||||
RemotePlayManager.getInstance()?.setXcloudToken(obj.gsToken);
|
||||
let serverRegex = /\/\/(\w+)\./, serverExtra = XcloudInterceptor.SERVER_EXTRA_INFO, region;
|
||||
@ -9077,13 +9081,12 @@ class XcloudInterceptor {
|
||||
else region.contintent = "other", BX_FLAGS.Debug && alert("New server: " + shortName);
|
||||
region.shortName = shortName.toUpperCase(), STATES.serverRegions[region.name] = Object.assign({}, region);
|
||||
}
|
||||
BxEventBus.Script.emit("xcloud.server.ready", {});
|
||||
let preferredRegion = getPreferredServerRegion();
|
||||
if (preferredRegion && preferredRegion in STATES.serverRegions) {
|
||||
let tmp = Object.assign({}, STATES.serverRegions[preferredRegion]);
|
||||
tmp.isDefault = !0, obj.offeringSettings.regions = [tmp], STATES.selectedRegion = tmp;
|
||||
}
|
||||
return STATES.gsToken = obj.gsToken, response.json = () => Promise.resolve(obj), response;
|
||||
return STATES.gsToken = obj.gsToken, BxEventBus.Script.emit("xcloud.server", { status: "ready" }), response.json = () => Promise.resolve(obj), response;
|
||||
}
|
||||
static async handlePlay(request, init) {
|
||||
BxEventBus.Stream.emit("state.loading", {});
|
||||
@ -9389,7 +9392,7 @@ function patchHistoryMethod(type) {
|
||||
}
|
||||
function onHistoryChanged(e) {
|
||||
if (e && e.arguments && e.arguments[0] && e.arguments[0].origin === "better-xcloud") return;
|
||||
window.setTimeout(RemotePlayManager.detect, 10), NavigationDialogManager.getInstance().hide(), LoadingScreen.reset(), window.setTimeout(HeaderSection.watchHeader, 2000), BxEventBus.Stream.emit("state.stopped", {});
|
||||
window.setTimeout(RemotePlayManager.detect, 10), NavigationDialogManager.getInstance().hide(), LoadingScreen.reset(), BxEventBus.Stream.emit("state.stopped", {});
|
||||
}
|
||||
function setCodecPreferences(sdp, preferredCodec) {
|
||||
let h264Pattern = /a=fmtp:(\d+).*profile-level-id=([0-9a-f]{6})/g, profilePrefix = preferredCodec === "high" ? "4d" : preferredCodec === "low" ? "420" : "42e", preferredCodecIds = [], matches = sdp.matchAll(h264Pattern) || [];
|
||||
@ -10459,7 +10462,6 @@ window.addEventListener("load", (e) => {
|
||||
document.addEventListener("readystatechange", (e) => {
|
||||
if (document.readyState !== "interactive") return;
|
||||
if (STATES.isSignedIn = !!window.xbcUser?.isSignedIn, STATES.isSignedIn) RemotePlayManager.getInstance()?.initialize();
|
||||
else window.setTimeout(HeaderSection.watchHeader, 2000);
|
||||
if (getGlobalPref("ui.hideSections").includes("friends") || getGlobalPref("block.features").includes("friends")) {
|
||||
let $parent = document.querySelector("div[class*=PlayWithFriendsSkeleton]")?.closest("div[class*=HomePage-module]");
|
||||
$parent && ($parent.style.display = "none");
|
||||
@ -10471,11 +10473,8 @@ window.addEventListener(BxEvent.POPSTATE, onHistoryChanged);
|
||||
window.addEventListener("popstate", onHistoryChanged);
|
||||
window.history.pushState = patchHistoryMethod("pushState");
|
||||
window.history.replaceState = patchHistoryMethod("replaceState");
|
||||
BxEventBus.Script.once("xcloud.server.unavailable", () => {
|
||||
if (STATES.supportedRegion = !1, window.setTimeout(HeaderSection.watchHeader, 2000), document.querySelector("div[class^=UnsupportedMarketPage-module__container]")) SettingsDialog.getInstance().show();
|
||||
});
|
||||
BxEventBus.Script.on("xcloud.server.ready", () => {
|
||||
STATES.isSignedIn = !0, window.setTimeout(HeaderSection.watchHeader, 2000);
|
||||
BxEventBus.Script.on("header.rendered", () => {
|
||||
HeaderSection.getInstance().checkHeader();
|
||||
});
|
||||
BxEventBus.Stream.on("state.loading", () => {
|
||||
if (window.location.pathname.includes("/launch/") && STATES.currentStream.titleInfo) STATES.currentStream.titleSlug = productTitleToSlug(STATES.currentStream.titleInfo.product.title);
|
||||
|
21
dist/better-xcloud.user.js
vendored
21
dist/better-xcloud.user.js
vendored
File diff suppressed because one or more lines are too long
19
src/index.ts
19
src/index.ts
@ -33,7 +33,6 @@ import { GameTile } from "./modules/ui/game-tile";
|
||||
import { ProductDetailsPage } from "./modules/ui/product-details";
|
||||
import { NavigationDialogManager } from "./modules/ui/dialog/navigation-dialog";
|
||||
import { GlobalPref, StreamPref } from "./enums/pref-keys";
|
||||
import { SettingsDialog } from "./modules/ui/dialog/settings-dialog";
|
||||
import { StreamUiHandler } from "./modules/stream/stream-ui";
|
||||
import { UserAgent } from "./utils/user-agent";
|
||||
import { XboxApi } from "./utils/xbox-api";
|
||||
@ -174,7 +173,7 @@ document.addEventListener('readystatechange', e => {
|
||||
}
|
||||
} else {
|
||||
// Show Settings button in the header when not signed in
|
||||
window.setTimeout(HeaderSection.watchHeader, 2000);
|
||||
// window.setTimeout(HeaderSection.watchHeader, 2000);
|
||||
}
|
||||
|
||||
// Hide "Play with Friends" skeleton section
|
||||
@ -198,20 +197,8 @@ window.addEventListener('popstate', onHistoryChanged);
|
||||
window.history.pushState = patchHistoryMethod('pushState');
|
||||
window.history.replaceState = patchHistoryMethod('replaceState');
|
||||
|
||||
BxEventBus.Script.once('xcloud.server.unavailable', () => {
|
||||
STATES.supportedRegion = false;
|
||||
window.setTimeout(HeaderSection.watchHeader, 2000);
|
||||
|
||||
// Open Settings dialog on Unsupported page
|
||||
const $unsupportedPage = document.querySelector<HTMLElement>('div[class^=UnsupportedMarketPage-module__container]');
|
||||
if ($unsupportedPage) {
|
||||
SettingsDialog.getInstance().show();
|
||||
}
|
||||
});
|
||||
|
||||
BxEventBus.Script.on('xcloud.server.ready', () => {
|
||||
STATES.isSignedIn = true;
|
||||
window.setTimeout(HeaderSection.watchHeader, 2000);
|
||||
BxEventBus.Script.on('header.rendered', () => {
|
||||
HeaderSection.getInstance().checkHeader();
|
||||
});
|
||||
|
||||
BxEventBus.Stream.on('state.loading', () => {
|
||||
|
@ -1029,9 +1029,14 @@ ${subsVar} = subs;
|
||||
return false;
|
||||
}
|
||||
|
||||
const newCode = 'window.BX_EXPOSED.reactCreateElement=';
|
||||
str = PatcherUtils.insertAt(str, index - 1, newCode);
|
||||
str = PatcherUtils.insertAt(str, index - 1, 'window.BX_EXPOSED.reactCreateElement=');
|
||||
|
||||
index = PatcherUtils.indexOf(str, '.useEffect=', index);
|
||||
if (index < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
str = PatcherUtils.insertAt(str, index - 1, 'window.BX_EXPOSED.reactUseEffect=');
|
||||
return str;
|
||||
},
|
||||
|
||||
@ -1130,7 +1135,24 @@ ${subsVar} = subs;
|
||||
|
||||
str = PatcherUtils.insertAt(str, index, `&q=${getGlobalPref(GlobalPref.UI_IMAGE_QUALITY)}`);
|
||||
return str;
|
||||
},
|
||||
|
||||
injectHeaderUseEffect(str: string) {
|
||||
let index = str.indexOf('"EdgewaterHeader-module__spaceBetween');
|
||||
index > -1 && (index = PatcherUtils.lastIndexOf(str, 'return', index, 300));
|
||||
|
||||
if (index < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const newCode = `
|
||||
window.BX_EXPOSED.reactUseEffect(() => {
|
||||
window.BxEventBus.Script.emit('header.rendered', {});
|
||||
});
|
||||
`;
|
||||
str = PatcherUtils.insertAt(str, index, newCode);
|
||||
return str;
|
||||
},
|
||||
};
|
||||
|
||||
let PATCH_ORDERS = PatcherUtils.filterPatches([
|
||||
@ -1140,6 +1162,7 @@ let PATCH_ORDERS = PatcherUtils.filterPatches([
|
||||
] : []),
|
||||
|
||||
'exposeReactCreateComponent',
|
||||
'injectHeaderUseEffect',
|
||||
'gameCardCustomIcons',
|
||||
// 'gameCardPassTitle',
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { isFullVersion } from "@macros/build" with { type: "macro" };
|
||||
|
||||
import { SCRIPT_VERSION } from "@utils/global";
|
||||
import { createButton, ButtonStyle, CE, isElementVisible } from "@utils/html";
|
||||
import { SCRIPT_VERSION, STATES } from "@utils/global";
|
||||
import { createButton, ButtonStyle, CE } from "@utils/html";
|
||||
import { BxIcon } from "@utils/bx-icon";
|
||||
import { getPreferredServerRegion } from "@utils/region";
|
||||
import { RemotePlayManager } from "@/modules/remote-play-manager";
|
||||
@ -10,6 +10,7 @@ import { SettingsDialog } from "./dialog/settings-dialog";
|
||||
import { GlobalPref } from "@/enums/pref-keys";
|
||||
import { getGlobalPref } from "@/utils/pref-utils";
|
||||
import { BxLogger } from "@/utils/bx-logger";
|
||||
import { BxEventBus } from "@/utils/bx-event-bus";
|
||||
|
||||
export class HeaderSection {
|
||||
private static instance: HeaderSection;
|
||||
@ -20,9 +21,6 @@ export class HeaderSection {
|
||||
private $btnSettings: HTMLElement;
|
||||
private $buttonsWrapper: HTMLElement;
|
||||
|
||||
private observer?: MutationObserver;
|
||||
private timeoutId?: number | null;
|
||||
|
||||
constructor() {
|
||||
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||
|
||||
@ -38,9 +36,9 @@ export class HeaderSection {
|
||||
this.$btnRemotePlay = null;
|
||||
}
|
||||
|
||||
this.$btnSettings = createButton({
|
||||
classes: ['bx-header-settings-button'],
|
||||
label: '???',
|
||||
let $btnSettings = this.$btnSettings = createButton({
|
||||
classes: ['bx-header-settings-button', 'bx-gone'],
|
||||
label: t('better-xcloud'),
|
||||
style: ButtonStyle.FROSTED | ButtonStyle.DROP_SHADOW | ButtonStyle.FOCUSABLE | ButtonStyle.FULL_HEIGHT,
|
||||
onClick: e => SettingsDialog.getInstance().show(),
|
||||
});
|
||||
@ -49,65 +47,47 @@ export class HeaderSection {
|
||||
getGlobalPref(GlobalPref.REMOTE_PLAY_ENABLED) ? this.$btnRemotePlay : null,
|
||||
this.$btnSettings,
|
||||
);
|
||||
}
|
||||
|
||||
private injectSettingsButton($parent?: HTMLElement) {
|
||||
if (!$parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
const PREF_LATEST_VERSION = getGlobalPref(GlobalPref.VERSION_LATEST);
|
||||
|
||||
// Setup Settings button
|
||||
const $btnSettings = this.$btnSettings;
|
||||
if (isElementVisible(this.$buttonsWrapper)) {
|
||||
return;
|
||||
}
|
||||
BxEventBus.Script.on('xcloud.server', ({status}) => {
|
||||
if (status === 'ready') {
|
||||
STATES.isSignedIn = true;
|
||||
|
||||
// Show server name
|
||||
$btnSettings.querySelector('span')!.textContent = getPreferredServerRegion(true) || t('better-xcloud');
|
||||
|
||||
const PREF_LATEST_VERSION = getGlobalPref(GlobalPref.VERSION_LATEST);
|
||||
// Show new update status
|
||||
if (!SCRIPT_VERSION.includes('beta') && PREF_LATEST_VERSION && PREF_LATEST_VERSION !== SCRIPT_VERSION) {
|
||||
$btnSettings.setAttribute('data-update-available', 'true');
|
||||
}
|
||||
} else if (status === 'unavailable') {
|
||||
STATES.supportedRegion = false;
|
||||
|
||||
// Add the Settings button to the web page
|
||||
$parent.appendChild(this.$buttonsWrapper);
|
||||
// Open Settings dialog on Unsupported page
|
||||
const $unsupportedPage = document.querySelector<HTMLElement>('div[class^=UnsupportedMarketPage-module__container]');
|
||||
if ($unsupportedPage) {
|
||||
SettingsDialog.getInstance().show();
|
||||
}
|
||||
}
|
||||
|
||||
private checkHeader = () => {
|
||||
$btnSettings.classList.remove('bx-gone');
|
||||
});
|
||||
}
|
||||
|
||||
checkHeader = () => {
|
||||
let $target = document.querySelector('#PageContent div[class*=EdgewaterHeader-module__rightSectionSpacing]');
|
||||
if (!$target) {
|
||||
$target = document.querySelector('div[class^=UnsupportedMarketPage-module__buttons]');
|
||||
}
|
||||
|
||||
$target && this.injectSettingsButton($target as HTMLElement);
|
||||
// Add the Settings button to the web page
|
||||
$target?.appendChild(this.$buttonsWrapper);
|
||||
|
||||
if (!STATES.isSignedIn) {
|
||||
BxEventBus.Script.emit('xcloud.server', { status: 'signed-out' });
|
||||
}
|
||||
|
||||
private watchHeader() {
|
||||
const $root = document.querySelector('#PageContent header') || document.querySelector('#root');
|
||||
if (!$root) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.timeoutId && clearTimeout(this.timeoutId);
|
||||
this.timeoutId = null;
|
||||
|
||||
this.observer && this.observer.disconnect();
|
||||
this.observer = new MutationObserver(mutationList => {
|
||||
this.timeoutId && clearTimeout(this.timeoutId);
|
||||
this.timeoutId = window.setTimeout(this.checkHeader, 2000);
|
||||
});
|
||||
this.observer.observe($root, { subtree: true, childList: true });
|
||||
|
||||
this.checkHeader();
|
||||
}
|
||||
|
||||
showRemotePlayButton() {
|
||||
this.$btnRemotePlay?.classList.remove('bx-gone');
|
||||
}
|
||||
|
||||
static watchHeader() {
|
||||
HeaderSection.getInstance().watchHeader();
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,9 @@ import type { SpeakerState } from "@/modules/shortcuts/sound-shortcut";
|
||||
type EventCallback<T = any> = (payload: T) => void;
|
||||
|
||||
type ScriptEvents = {
|
||||
'xcloud.server.ready': {};
|
||||
'xcloud.server.unavailable': {};
|
||||
'xcloud.server': {
|
||||
status: 'ready' | 'unavailable' | 'signed-out',
|
||||
};
|
||||
|
||||
'dialog.shown': {};
|
||||
'dialog.dismissed': {};
|
||||
@ -34,6 +35,8 @@ type ScriptEvents = {
|
||||
};
|
||||
|
||||
'webgpu.ready': {},
|
||||
|
||||
'header.rendered': {},
|
||||
};
|
||||
|
||||
type StreamEvents = {
|
||||
|
@ -14,6 +14,7 @@ export namespace BxEvent {
|
||||
export const TOUCH_LAYOUT_MANAGER_READY = 'bx-touch-layout-manager-ready';
|
||||
|
||||
// Inside app
|
||||
// TODO: Use EventBus
|
||||
export const REMOTE_PLAY_READY = 'bx-remote-play-ready';
|
||||
export const REMOTE_PLAY_FAILED = 'bx-remote-play-failed';
|
||||
|
||||
|
@ -242,6 +242,7 @@ export const BxExposed = {
|
||||
|
||||
localCoOpManager: isFullVersion() ? LocalCoOpManager.getInstance() : null,
|
||||
reactCreateElement: function(...args: any[]) {},
|
||||
reactUseEffect: function(...args: any[]) {},
|
||||
|
||||
createReactLocalCoOpIcon: isFullVersion() ? (attrs: any): any => {
|
||||
const reactCE = window.BX_EXPOSED.reactCreateElement;
|
||||
|
@ -3,7 +3,6 @@ import { isFullVersion } from "@macros/build" with { type: "macro" };
|
||||
import { BxEvent } from "@utils/bx-event";
|
||||
import { LoadingScreen } from "@modules/loading-screen";
|
||||
import { RemotePlayManager } from "@/modules/remote-play-manager";
|
||||
import { HeaderSection } from "@/modules/ui/header";
|
||||
import { BxEventBus } from "./bx-event-bus";
|
||||
import { NavigationDialogManager } from "@/modules/ui/dialog/navigation-dialog";
|
||||
|
||||
@ -35,7 +34,5 @@ export function onHistoryChanged(e: PopStateEvent) {
|
||||
NavigationDialogManager.getInstance().hide();
|
||||
|
||||
LoadingScreen.reset();
|
||||
window.setTimeout(HeaderSection.watchHeader, 2000);
|
||||
|
||||
BxEventBus.Stream.emit('state.stopped', {});
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import { ControllerCustomizationDefaultPresetId } from "../local-db/controller-c
|
||||
import { ControllerShortcutDefaultId } from "../local-db/controller-shortcuts-table";
|
||||
import { BxEventBus } from "../bx-event-bus";
|
||||
import { WebGPUPlayer } from "@/modules/player/webgpu/webgpu-player";
|
||||
import { BX_FLAGS } from "../bx-flags";
|
||||
|
||||
|
||||
export class StreamSettingsStorage extends BaseSettingsStorage<StreamPref> {
|
||||
|
@ -52,7 +52,7 @@ export class XcloudInterceptor {
|
||||
const response = await NATIVE_FETCH(request, init);
|
||||
if (response.status !== 200) {
|
||||
// Unsupported region
|
||||
BxEventBus.Script.emit('xcloud.server.unavailable', {});
|
||||
BxEventBus.Script.emit('xcloud.server', { status: 'unavailable' });
|
||||
return response;
|
||||
}
|
||||
|
||||
@ -92,8 +92,6 @@ export class XcloudInterceptor {
|
||||
STATES.serverRegions[region.name] = Object.assign({}, region);
|
||||
}
|
||||
|
||||
BxEventBus.Script.emit('xcloud.server.ready', {});
|
||||
|
||||
const preferredRegion = getPreferredServerRegion();
|
||||
if (preferredRegion && preferredRegion in STATES.serverRegions) {
|
||||
const tmp = Object.assign({}, STATES.serverRegions[preferredRegion]);
|
||||
@ -104,6 +102,7 @@ export class XcloudInterceptor {
|
||||
}
|
||||
|
||||
STATES.gsToken = obj.gsToken;
|
||||
BxEventBus.Script.emit('xcloud.server', { status: 'ready' });
|
||||
|
||||
response.json = () => Promise.resolve(obj);
|
||||
return response;
|
||||
|
Loading…
x
Reference in New Issue
Block a user