Compare commits

...

20 Commits

Author SHA1 Message Date
a81c6621a8 Update .bx-settings-row background 2024-08-09 21:50:34 +07:00
edc11b3b48 Update better-xcloud.user.js 2024-08-09 07:20:46 +07:00
c333fffab7 Fix not disconnecting StreamUiHandler's MutationObserver (#477) 2024-08-09 07:20:43 +07:00
8c904897b8 Add Korea IP 2024-08-09 06:53:03 +07:00
683709f980 Upgrade bun 2024-08-09 06:41:14 +07:00
4562ef8f19 Bump verstion to 5.5.4 2024-08-06 20:29:43 +07:00
2fcf14c5b9 Fix touch problem with Stream Menu 2024-08-06 20:24:40 +07:00
c1af19072d Switch to WebGL canvas context 2024-08-06 19:51:16 +07:00
5dc6f0c2f6 Fix StreamMenu not displaying correctly 2024-08-06 19:48:54 +07:00
3ba9565c3e Bump version to 5.5.3 2024-08-05 17:40:20 +07:00
2d6c56e25c Update better-xcloud.user.js 2024-08-04 17:48:16 +07:00
95d5fb8ed7 Rearrange settings 2024-08-04 17:45:15 +07:00
7dfe61f4ca Refactor SettingDefinition 2024-08-04 17:37:30 +07:00
3f66c1298e Update better-xcloud.user.js 2024-08-04 17:04:56 +07:00
6ab24e9231 Refactor StreamUiHandler 2024-08-04 12:33:03 +07:00
619d70d3cb Update better-xcloud.user.js 2024-08-03 17:20:27 +07:00
fb123e00d7 Fix Settings button not showing on Header sometimes 2024-08-03 17:04:54 +07:00
39f7ee6ddb Add "detectBrowserRouterReady" patch 2024-08-02 20:47:28 +07:00
5db35cdcc9 Bug fixes 2024-08-02 07:19:27 +07:00
8c7e4650d4 Create PatcherUtils 2024-08-02 07:07:59 +07:00
19 changed files with 696 additions and 465 deletions

View File

@ -27,6 +27,7 @@ const postProcess = (str: string): string => {
// Remove enum's inlining comments // Remove enum's inlining comments
str = str.replaceAll(/ \/\* [A-Z0-9_]+ \*\//g, ''); str = str.replaceAll(/ \/\* [A-Z0-9_]+ \*\//g, '');
str = str.replaceAll('/* @__PURE__ */ ', '');
// Remove comments from import // Remove comments from import
str = str.replaceAll(/\/\/ src.*\n/g, ''); str = str.replaceAll(/\/\/ src.*\n/g, '');

BIN
bun.lockb

Binary file not shown.

View File

@ -1,5 +1,5 @@
// ==UserScript== // ==UserScript==
// @name Better xCloud // @name Better xCloud
// @namespace https://github.com/redphx // @namespace https://github.com/redphx
// @version 5.5.2 // @version 5.5.4
// ==/UserScript== // ==/UserScript==

File diff suppressed because one or more lines are too long

View File

@ -10,7 +10,7 @@
}, },
"devDependencies": { "devDependencies": {
"@types/bun": "^1.1.6", "@types/bun": "^1.1.6",
"@types/node": "^20.14.12", "@types/node": "^20.14.14",
"@types/stylus": "^0.48.42", "@types/stylus": "^0.48.42",
"eslint": "^9.8.0", "eslint": "^9.8.0",
"eslint-plugin-compat": "^6.0.0", "eslint-plugin-compat": "^6.0.0",

View File

@ -245,10 +245,10 @@
.bx-settings-row { .bx-settings-row {
display: flex; display: flex;
gap: 10px; gap: 10px;
border-bottom: 1px solid #2c2c2e; padding: 16px 10px;
padding: 16px 8px;
margin: 0; margin: 0;
border-left: 2px solid transparent; background: #2a2a2a;
border-bottom: 1px solid #343434;
&:hover, &:focus-within { &:hover, &:focus-within {
background-color: #242424; background-color: #242424;
@ -265,9 +265,11 @@
} }
} }
/*
&:has(input:focus), &:has(select:focus), &:has(button:focus) { &:has(input:focus), &:has(select:focus), &:has(button:focus) {
border-left-color: white; border-left-color: white;
} }
*/
> span.bx-settings-label { > span.bx-settings-label {
font-size: 14px; font-size: 14px;
@ -379,3 +381,26 @@
font-weight: normal; font-weight: normal;
color: #828282; color: #828282;
} }
.bx-settings-tab-contents {
> div {
// Label at the beginning
*:not(.bx-settings-row):has(+ .bx-settings-row) + .bx-settings-row:has(+ .bx-settings-row) {
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
// Label at the end
.bx-settings-row:not(:has(+ .bx-settings-row)) {
border: none;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
// Single label
*:not(.bx-settings-row):has(+ .bx-settings-row) + .bx-settings-row:not(:has(+ .bx-settings-row)) {
border: none;
border-radius: 10px;
}
}
}

View File

@ -3,12 +3,14 @@ import { t } from "@/utils/translation"
export const BypassServers = { export const BypassServers = {
'br': t('brazil'), 'br': t('brazil'),
'jp': t('japan'), 'jp': t('japan'),
'kr': t('korea'),
'pl': t('poland'), 'pl': t('poland'),
'us': t('united-states'), 'us': t('united-states'),
} }
export const BypassServerIps = { export const BypassServerIps: Record<keyof typeof BypassServers, string> = {
'br': '169.150.198.66', 'br': '169.150.198.66',
'kr': '121.125.60.151',
'jp': '138.199.21.239', 'jp': '138.199.21.239',
'pl': '45.134.212.66', 'pl': '45.134.212.66',
'us': '143.244.47.65', 'us': '143.244.47.65',

View File

@ -22,7 +22,6 @@ import { VibrationManager } from "@modules/vibration-manager";
import { overridePreloadState } from "@utils/preload-state"; import { overridePreloadState } from "@utils/preload-state";
import { disableAdobeAudienceManager, patchAudioContext, patchCanvasContext, patchMeControl, patchPointerLockApi, patchRtcCodecs, patchRtcPeerConnection, patchVideoApi } from "@utils/monkey-patches"; import { disableAdobeAudienceManager, patchAudioContext, patchCanvasContext, patchMeControl, patchPointerLockApi, patchRtcCodecs, patchRtcPeerConnection, patchVideoApi } from "@utils/monkey-patches";
import { AppInterface, STATES } from "@utils/global"; import { AppInterface, STATES } from "@utils/global";
import { injectStreamMenuButtons } from "@modules/stream/stream-ui";
import { BxLogger } from "@utils/bx-logger"; import { BxLogger } from "@utils/bx-logger";
import { GameBar } from "./modules/game-bar/game-bar"; import { GameBar } from "./modules/game-bar/game-bar";
import { Screenshot } from "./utils/screenshot"; import { Screenshot } from "./utils/screenshot";
@ -38,6 +37,7 @@ import { PrefKey } from "./enums/pref-keys";
import { getPref } from "./utils/settings-storages/global-settings-storage"; import { getPref } from "./utils/settings-storages/global-settings-storage";
import { compressCss } from "@macros/build" with {type: "macro"}; import { compressCss } from "@macros/build" with {type: "macro"};
import { SettingsNavigationDialog } from "./modules/ui/dialog/settings-dialog"; import { SettingsNavigationDialog } from "./modules/ui/dialog/settings-dialog";
import { StreamUiHandler } from "./modules/stream/stream-ui";
// Handle login page // Handle login page
@ -186,7 +186,7 @@ window.addEventListener(BxEvent.STREAM_STARTING, e => {
window.addEventListener(BxEvent.STREAM_PLAYING, e => { window.addEventListener(BxEvent.STREAM_PLAYING, e => {
STATES.isPlaying = true; STATES.isPlaying = true;
injectStreamMenuButtons(); StreamUiHandler.observe();
if (getPref(PrefKey.GAME_BAR_POSITION) !== 'off') { if (getPref(PrefKey.GAME_BAR_POSITION) !== 'off') {
const gameBar = GameBar.getInstance(); const gameBar = GameBar.getInstance();

View File

@ -20,8 +20,35 @@ import { GamePassCloudGallery } from "@/enums/game-pass-gallery.js";
type PatchArray = (keyof typeof PATCHES)[]; type PatchArray = (keyof typeof PATCHES)[];
const ENDING_CHUNKS_PATCH_NAME = 'loadingEndingChunks'; class PatcherUtils {
static indexOf(txt: string, searchString: string, startIndex: number, maxRange: number): number {
const index = txt.indexOf(searchString, startIndex);
if (index < 0 || (maxRange && index - startIndex > maxRange)) {
return -1;
}
return index;
}
static lastIndexOf(txt: string, searchString: string, startIndex: number, maxRange: number): number {
const index = txt.lastIndexOf(searchString, startIndex);
if (index < 0 || (maxRange && startIndex - index > maxRange)) {
return -1;
}
return index;
}
static insertAt(txt: string, index: number, insertString: string): string {
return txt.substring(0, index) + insertString + txt.substring(index);
}
static replaceWith(txt: string, index: number, fromString: string, toString: string): string {
return txt.substring(0, index) + toString + txt.substring(index + fromString.length);
}
}
const ENDING_CHUNKS_PATCH_NAME = 'loadingEndingChunks';
const LOG_TAG = 'Patcher'; const LOG_TAG = 'Patcher';
const PATCHES = { const PATCHES = {
@ -33,11 +60,11 @@ const PATCHES = {
return false; return false;
} }
if (str.substring(0, index + 200).includes('"AppInsightsCore')) { if (PatcherUtils.indexOf(str, '"AppInsightsCore', index, 200) < 0) {
return false; return false;
} }
return str.substring(0, index) + '.track=function(e){},!!function(' + str.substring(index + text.length); return PatcherUtils.replaceWith(str, index, text, '.track=function(e){},!!function(');
}, },
// Set disableTelemetry() to true // Set disableTelemetry() to true
@ -716,12 +743,12 @@ true` + text;
return false; return false;
} }
index = str.indexOf('return', index - 50); index = PatcherUtils.lastIndexOf(str, 'return', index, 50);
if (index < 0) { if (index < 0) {
return false; return false;
} }
str = str.substring(0, index) + 'return null;' + str.substring(index + 6); str = PatcherUtils.replaceWith(str, index, 'return', 'return null;');
return str; return str;
}, },
@ -732,14 +759,17 @@ true` + text;
return false; return false;
} }
index = str.indexOf('grid:!0,', index); index = PatcherUtils.indexOf(str, 'grid:!0,', index, 1500);
index > -1 && (index = str.indexOf('(0,', index - 70));
if (index < 0) { if (index < 0) {
return false; return false;
} }
str = str.substring(0, index) + 'true ? null :' + str.substring(index); index = PatcherUtils.lastIndexOf(str, '(0,', index, 70);
if (index < 0) {
return false;
}
str = PatcherUtils.insertAt(str, index, 'true ? null :');
return str; return str;
}, },
@ -750,12 +780,12 @@ true` + text;
return false; return false;
} }
index = str.indexOf('const ', index - 30); index = PatcherUtils.lastIndexOf(str, 'const ', index, 30);
if (index < 0) { if (index < 0) {
return false; return false;
} }
str = str.substring(0, index) + 'return null;' + str.substring(index); str = PatcherUtils.insertAt(str, index, 'return null;');
return str; return str;
}, },
@ -766,7 +796,7 @@ true` + text;
return false; return false;
} }
index = str.indexOf('const[', index - 300); index = PatcherUtils.lastIndexOf(str, 'const[', index, 300);
if (index < 0) { if (index < 0) {
return false; return false;
} }
@ -794,7 +824,7 @@ if (e && e.id) {
} }
} }
`; `;
str = str.substring(0, index) + newCode + str.substring(index); str = PatcherUtils.insertAt(str, index, newCode);
return str; return str;
}, },
@ -862,6 +892,26 @@ if (this.baseStorageKey in window.BX_EXPOSED.overrideSettings) {
str = str.substring(0, index) + 'BxEvent.dispatch(window, BxEvent.XCLOUD_RENDERING_COMPONENT, {component: "product-details"});' + str.substring(index); str = str.substring(0, index) + 'BxEvent.dispatch(window, BxEvent.XCLOUD_RENDERING_COMPONENT, {component: "product-details"});' + str.substring(index);
return str; return str;
}, },
detectBrowserRouterReady(str: string) {
const text = 'BrowserRouter:()=>';
if (!str.includes(text)) {
return false;
}
let index = str.indexOf('{history:this.history,');
if (index < 0) {
return false;
}
index = PatcherUtils.lastIndexOf(str, 'return', index, 100);
if (index < 0) {
return false;
}
str = PatcherUtils.insertAt(str, index, 'window.BxEvent.dispatch(window, window.BxEvent.XCLOUD_ROUTER_HISTORY_READY, {history: this.history});');
return str;
},
}; };
let PATCH_ORDERS: PatchArray = [ let PATCH_ORDERS: PatchArray = [
@ -872,6 +922,7 @@ let PATCH_ORDERS: PatchArray = [
'exposeInputSink', 'exposeInputSink',
] : []), ] : []),
'detectBrowserRouterReady',
'patchRequestInfoCrash', 'patchRequestInfoCrash',
'disableStreamGate', 'disableStreamGate',
@ -1067,7 +1118,7 @@ export class Patcher {
item[1][id] = eval(patchedFuncStr); item[1][id] = eval(patchedFuncStr);
} catch (e: unknown) { } catch (e: unknown) {
if (e instanceof Error) { if (e instanceof Error) {
BxLogger.error(LOG_TAG, 'Error', appliedPatches, e.message); BxLogger.error(LOG_TAG, 'Error', appliedPatches, e.message, patchedFuncStr);
} }
} }
} }

View File

@ -124,7 +124,7 @@ export class WebGL2Player {
#setupShaders() { #setupShaders() {
BxLogger.info(LOG_TAG, 'Setting up', getPref(PrefKey.VIDEO_POWER_PREFERENCE)); BxLogger.info(LOG_TAG, 'Setting up', getPref(PrefKey.VIDEO_POWER_PREFERENCE));
const gl = this.#$canvas.getContext('webgl2', { const gl = this.#$canvas.getContext('webgl', {
isBx: true, isBx: true,
antialias: true, antialias: true,
alpha: false, alpha: false,

View File

@ -8,17 +8,30 @@ import { StreamStats } from "./stream-stats.ts";
import { SettingsNavigationDialog } from "../ui/dialog/settings-dialog.ts"; import { SettingsNavigationDialog } from "../ui/dialog/settings-dialog.ts";
function cloneStreamHudButton($orgButton: HTMLElement, label: string, svgIcon: typeof BxIcon) { export class StreamUiHandler {
const $container = $orgButton.cloneNode(true) as HTMLElement; private static $btnStreamSettings: HTMLElement | null | undefined;
private static $btnStreamStats: HTMLElement | null | undefined;
private static $btnRefresh: HTMLElement | null | undefined;
private static $btnHome: HTMLElement | null | undefined;
private static observer: MutationObserver | undefined;
private static cloneStreamHudButton($btnOrg: HTMLElement, label: string, svgIcon: typeof BxIcon): HTMLElement | null {
if (!$btnOrg) {
return null;
}
const $container = $btnOrg.cloneNode(true) as HTMLElement;
let timeout: number | null; let timeout: number | null;
// Prevent touching other button while the bar is showing/hiding
if (STATES.browser.capabilities.touch) {
const onTransitionStart = (e: TransitionEvent) => { const onTransitionStart = (e: TransitionEvent) => {
if (e.propertyName !== 'opacity') { if (e.propertyName !== 'opacity') {
return; return;
} }
timeout && clearTimeout(timeout); timeout && clearTimeout(timeout);
$container.style.pointerEvents = 'none'; (e.target as HTMLElement).style.pointerEvents = 'none';
}; };
const onTransitionEnd = (e: TransitionEvent) => { const onTransitionEnd = (e: TransitionEvent) => {
@ -26,24 +39,36 @@ function cloneStreamHudButton($orgButton: HTMLElement, label: string, svgIcon: t
return; return;
} }
const left = document.getElementById('StreamHud')?.style.left; const $streamHud = (e.target as HTMLElement).closest('#StreamHud') as HTMLElement;
if (!$streamHud) {
return;
}
const left = $streamHud.style.left;
if (left === '0px') { if (left === '0px') {
const $target = e.target as HTMLElement;
timeout && clearTimeout(timeout); timeout && clearTimeout(timeout);
timeout = window.setTimeout(() => { timeout = window.setTimeout(() => {
$container.style.pointerEvents = 'auto'; $target.style.pointerEvents = 'auto';
}, 100); }, 100);
} }
}; };
if (STATES.browser.capabilities.touch) {
$container.addEventListener('transitionstart', onTransitionStart); $container.addEventListener('transitionstart', onTransitionStart);
$container.addEventListener('transitionend', onTransitionEnd); $container.addEventListener('transitionend', onTransitionEnd);
} }
const $button = $container.querySelector('button')!; const $button = $container.querySelector('button') as HTMLElement;
if (!$button) {
return null;
}
$button.setAttribute('title', label); $button.setAttribute('title', label);
const $orgSvg = $button.querySelector('svg')!; const $orgSvg = $button.querySelector('svg') as SVGElement;
if (!$orgSvg) {
return null;
}
const $svg = createSvgIcon(svgIcon); const $svg = createSvgIcon(svgIcon);
$svg.style.fill = 'none'; $svg.style.fill = 'none';
$svg.setAttribute('class', $orgSvg.getAttribute('class') || ''); $svg.setAttribute('class', $orgSvg.getAttribute('class') || '');
@ -53,12 +78,13 @@ function cloneStreamHudButton($orgButton: HTMLElement, label: string, svgIcon: t
return $container; return $container;
} }
private static cloneCloseButton($btnOrg: HTMLElement, icon: typeof BxIcon, className: string, onChange: any): HTMLElement | null {
function cloneCloseButton($$btnOrg: HTMLElement, icon: typeof BxIcon, className: string, onChange: any) { if (!$btnOrg) {
return null;
}
// Create button from the Close button // Create button from the Close button
const $btn = $$btnOrg.cloneNode(true) as HTMLElement; const $btn = $btnOrg.cloneNode(true) as HTMLElement;
// Refresh SVG
const $svg = createSvgIcon(icon); const $svg = createSvgIcon(icon);
// Copy classes // Copy classes
$svg.setAttribute('class', $btn.firstElementChild!.getAttribute('class') || ''); $svg.setAttribute('class', $btn.firstElementChild!.getAttribute('class') || '');
@ -75,23 +101,131 @@ function cloneCloseButton($$btnOrg: HTMLElement, icon: typeof BxIcon, className:
return $btn; return $btn;
} }
private static async handleStreamMenu() {
const $btnCloseHud = document.querySelector('button[class*=StreamMenu-module__backButton]') as HTMLElement;
if (!$btnCloseHud) {
return;
}
let $btnRefresh = StreamUiHandler.$btnRefresh;
let $btnHome = StreamUiHandler.$btnHome;
// Create Refresh button from the Close button
if (typeof $btnRefresh === 'undefined') {
$btnRefresh = StreamUiHandler.cloneCloseButton($btnCloseHud, BxIcon.REFRESH, 'bx-stream-refresh-button', () => {
confirm(t('confirm-reload-stream')) && window.location.reload();
});
}
if (typeof $btnHome === 'undefined') {
$btnHome = StreamUiHandler.cloneCloseButton($btnCloseHud, BxIcon.HOME, 'bx-stream-home-button', () => {
confirm(t('back-to-home-confirm')) && (window.location.href = window.location.href.substring(0, 31));
});
}
// Add to website
if ($btnRefresh && $btnHome) {
$btnCloseHud.insertAdjacentElement('afterend', $btnRefresh);
$btnRefresh.insertAdjacentElement('afterend', $btnHome);
}
// Render stream badges
const $menu = document.querySelector('div[class*=StreamMenu-module__menuContainer] > div[class*=Menu-module]');
$menu?.appendChild(await StreamBadges.getInstance().render());
}
private static handleSystemMenu($streamHud: HTMLElement) {
// Grip handle
const $gripHandle = $streamHud.querySelector('button[class^=GripHandle]') as HTMLElement;
if (!$gripHandle) {
return;
}
// Get the last button
const $orgButton = $streamHud.querySelector('div[class^=HUDButton]') as HTMLElement;
if (!$orgButton) {
return;
}
const hideGripHandle = () => {
if (!$gripHandle) {
return;
}
$gripHandle.dispatchEvent(new PointerEvent('pointerdown'));
$gripHandle.click();
$gripHandle.dispatchEvent(new PointerEvent('pointerdown'));
$gripHandle.click();
}
// Create Stream Settings button
let $btnStreamSettings = StreamUiHandler.$btnStreamSettings;
if (typeof $btnStreamSettings === 'undefined') {
$btnStreamSettings = StreamUiHandler.cloneStreamHudButton($orgButton, t('better-xcloud'), BxIcon.BETTER_XCLOUD);
$btnStreamSettings?.addEventListener('click', e => {
hideGripHandle();
e.preventDefault();
// Show Stream Settings dialog
SettingsNavigationDialog.getInstance().show();
});
StreamUiHandler.$btnStreamSettings = $btnStreamSettings;
}
// Create Stream Stats button
const streamStats = StreamStats.getInstance();
let $btnStreamStats = StreamUiHandler.$btnStreamStats;
if (typeof $btnStreamStats === 'undefined') {
$btnStreamStats = StreamUiHandler.cloneStreamHudButton($orgButton, t('stream-stats'), BxIcon.STREAM_STATS);
$btnStreamStats?.addEventListener('click', e => {
hideGripHandle();
e.preventDefault();
// Toggle Stream Stats
streamStats.toggle();
const btnStreamStatsOn = (!streamStats.isHidden() && !streamStats.isGlancing());
$btnStreamStats!.classList.toggle('bx-stream-menu-button-on', btnStreamStatsOn);
});
StreamUiHandler.$btnStreamStats = $btnStreamStats;
}
const $btnParent = $orgButton.parentElement!;
if ($btnStreamSettings && $btnStreamStats) {
const btnStreamStatsOn = (!streamStats.isHidden() && !streamStats.isGlancing());
$btnStreamStats.classList.toggle('bx-stream-menu-button-on', btnStreamStatsOn);
// Insert buttons after Stream Settings button
$btnParent.insertBefore($btnStreamStats, $btnParent.lastElementChild);
$btnParent.insertBefore($btnStreamSettings, $btnStreamStats);
}
// Move the Dots button to the beginning
const $dotsButton = $btnParent.lastElementChild!;
$dotsButton.parentElement!.insertBefore($dotsButton, $dotsButton.parentElement!.firstElementChild);
}
static reset() {
StreamUiHandler.$btnStreamSettings = undefined;
StreamUiHandler.$btnStreamStats = undefined;
StreamUiHandler.$btnRefresh = undefined;
StreamUiHandler.$btnHome = undefined;
StreamUiHandler.observer && StreamUiHandler.observer.disconnect();
StreamUiHandler.observer = undefined;
}
static observe() {
StreamUiHandler.reset();
export function injectStreamMenuButtons() {
const $screen = document.querySelector('#PageContent section[class*=PureScreens]'); const $screen = document.querySelector('#PageContent section[class*=PureScreens]');
if (!$screen) { if (!$screen) {
return; return;
} }
if (($screen as any).xObserving) {
return;
}
($screen as any).xObserving = true;
let $btnStreamSettings: HTMLElement;
let $btnStreamStats: HTMLElement;
const streamStats = StreamStats.getInstance();
const observer = new MutationObserver(mutationList => { const observer = new MutationObserver(mutationList => {
mutationList.forEach(item => { mutationList.forEach(item => {
if (item.type !== 'childList') { if (item.type !== 'childList') {
@ -105,45 +239,26 @@ export function injectStreamMenuButtons() {
let $elm: HTMLElement | null = $node as HTMLElement; let $elm: HTMLElement | null = $node as HTMLElement;
// Ignore SVG elements // Ignore non-HTML elements
if ($elm instanceof SVGSVGElement) { if (!($elm instanceof HTMLElement)) {
return; return;
} }
const className = $elm.className || '';
// Error Page: .PureErrorPage.ErrorScreen // Error Page: .PureErrorPage.ErrorScreen
if ($elm.className?.includes('PureErrorPage')) { if (className.includes('PureErrorPage')) {
BxEvent.dispatch(window, BxEvent.STREAM_ERROR_PAGE); BxEvent.dispatch(window, BxEvent.STREAM_ERROR_PAGE);
return; return;
} }
// Render badges // Render badges
if ($elm.className?.startsWith('StreamMenu-module__container')) { if (className.startsWith('StreamMenu-module__container')) {
const $btnCloseHud = document.querySelector('button[class*=StreamMenu-module__backButton]') as HTMLElement; StreamUiHandler.handleStreamMenu();
if (!$btnCloseHud) {
return; return;
} }
// Create Refresh button from the Close button if (className.startsWith('Overlay-module_') || className.startsWith('InProgressScreen')) {
const $btnRefresh = cloneCloseButton($btnCloseHud, BxIcon.REFRESH, 'bx-stream-refresh-button', () => {
confirm(t('confirm-reload-stream')) && window.location.reload();
});
const $btnHome = cloneCloseButton($btnCloseHud, BxIcon.HOME, 'bx-stream-home-button', () => {
confirm(t('back-to-home-confirm')) && (window.location.href = window.location.href.substring(0, 31));
});
// Add to website
$btnCloseHud.insertAdjacentElement('afterend', $btnRefresh);
$btnRefresh.insertAdjacentElement('afterend', $btnHome);
// Render stream badges
const $menu = document.querySelector('div[class*=StreamMenu-module__menuContainer] > div[class*=Menu-module]');
$menu?.appendChild(await StreamBadges.getInstance().render());
return;
}
if ($elm.className?.startsWith('Overlay-module_') || $elm.className?.startsWith('InProgressScreen')) {
$elm = $elm.querySelector('#StreamHud'); $elm = $elm.querySelector('#StreamHud');
} }
@ -151,69 +266,13 @@ export function injectStreamMenuButtons() {
return; return;
} }
// Grip handle // Handle System Menu bar
const $gripHandle = $elm.querySelector('button[class^=GripHandle]') as HTMLElement; StreamUiHandler.handleSystemMenu($elm);
const hideGripHandle = () => {
if (!$gripHandle) {
return;
}
$gripHandle.dispatchEvent(new PointerEvent('pointerdown'));
$gripHandle.click();
$gripHandle.dispatchEvent(new PointerEvent('pointerdown'));
$gripHandle.click();
}
// Get the second last button
const $orgButton = $elm.querySelector('div[class^=HUDButton]') as HTMLElement;
if (!$orgButton) {
return;
}
// Create Stream Settings button
if (!$btnStreamSettings) {
$btnStreamSettings = cloneStreamHudButton($orgButton, t('better-xcloud'), BxIcon.BETTER_XCLOUD);
$btnStreamSettings.addEventListener('click', e => {
hideGripHandle();
e.preventDefault();
// Show Stream Settings dialog
SettingsNavigationDialog.getInstance().show();
});
}
// Create Stream Stats button
if (!$btnStreamStats) {
$btnStreamStats = cloneStreamHudButton($orgButton, t('stream-stats'), BxIcon.STREAM_STATS);
$btnStreamStats.addEventListener('click', e => {
hideGripHandle();
e.preventDefault();
// Toggle Stream Stats
streamStats.toggle();
const btnStreamStatsOn = (!streamStats.isHidden() && !streamStats.isGlancing());
$btnStreamStats.classList.toggle('bx-stream-menu-button-on', btnStreamStatsOn);
});
}
const btnStreamStatsOn = (!streamStats.isHidden() && !streamStats.isGlancing());
$btnStreamStats.classList.toggle('bx-stream-menu-button-on', btnStreamStatsOn);
if ($orgButton) {
const $btnParent = $orgButton.parentElement!;
// Insert buttons after Stream Settings button
$btnParent.insertBefore($btnStreamStats, $btnParent.lastElementChild);
$btnParent.insertBefore($btnStreamSettings, $btnStreamStats);
// Move the Dots button to the beginning
const $dotsButton = $btnParent.lastElementChild!;
$dotsButton.parentElement!.insertBefore($dotsButton, $dotsButton.parentElement!.firstElementChild);
}
}); });
}); });
}); });
observer.observe($screen, {subtree: true, childList: true}); observer.observe($screen, {subtree: true, childList: true});
StreamUiHandler.observer = observer;
}
} }

View File

@ -176,12 +176,6 @@ export class SettingsNavigationDialog extends NavigationDialog {
PrefKey.GAME_FORTNITE_FORCE_CONSOLE, PrefKey.GAME_FORTNITE_FORCE_CONSOLE,
PrefKey.STREAM_COMBINE_SOURCES, PrefKey.STREAM_COMBINE_SOURCES,
], ],
}, {
group: 'game-bar',
label: t('game-bar'),
items: [
PrefKey.GAME_BAR_POSITION,
],
}, { }, {
group: 'co-op', group: 'co-op',
label: t('local-co-op'), label: t('local-co-op'),
@ -208,14 +202,6 @@ export class SettingsNavigationDialog extends NavigationDialog {
PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_STANDARD, PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_STANDARD,
PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_CUSTOM, PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_CUSTOM,
], ],
}, {
group: 'loading-screen',
label: t('loading-screen'),
items: [
PrefKey.UI_LOADING_SCREEN_GAME_ART,
PrefKey.UI_LOADING_SCREEN_WAIT_TIME,
PrefKey.UI_LOADING_SCREEN_ROCKET,
],
}, { }, {
group: 'ui', group: 'ui',
label: t('ui'), label: t('ui'),
@ -232,6 +218,20 @@ export class SettingsNavigationDialog extends NavigationDialog {
PrefKey.BLOCK_SOCIAL_FEATURES, PrefKey.BLOCK_SOCIAL_FEATURES,
PrefKey.UI_HIDE_SECTIONS, PrefKey.UI_HIDE_SECTIONS,
], ],
}, {
group: 'game-bar',
label: t('game-bar'),
items: [
PrefKey.GAME_BAR_POSITION,
],
}, {
group: 'loading-screen',
label: t('loading-screen'),
items: [
PrefKey.UI_LOADING_SCREEN_GAME_ART,
PrefKey.UI_LOADING_SCREEN_WAIT_TIME,
PrefKey.UI_LOADING_SCREEN_ROCKET,
],
}, { }, {
group: 'other', group: 'other',
label: t('other'), label: t('other'),

View File

@ -57,21 +57,20 @@ export class HeaderSection {
} }
static checkHeader() { static checkHeader() {
if (!HeaderSection.#$buttonsWrapper.isConnected) {
let $target = document.querySelector('#PageContent div[class*=EdgewaterHeader-module__rightSectionSpacing]'); let $target = document.querySelector('#PageContent div[class*=EdgewaterHeader-module__rightSectionSpacing]');
if (!$target) { if (!$target) {
$target = document.querySelector("div[class^=UnsupportedMarketPage-module__buttons]"); $target = document.querySelector("div[class^=UnsupportedMarketPage-module__buttons]");
} }
$target && HeaderSection.#injectSettingsButton($target as HTMLElement); $target && HeaderSection.#injectSettingsButton($target as HTMLElement);
} }
}
static showRemotePlayButton() { static showRemotePlayButton() {
HeaderSection.#$remotePlayBtn.classList.remove('bx-gone'); HeaderSection.#$remotePlayBtn.classList.remove('bx-gone');
} }
static watchHeader() { static watchHeader() {
let $root = document.querySelector('#PageContent header') || document.querySelector('#root'); const $root = document.querySelector('#PageContent header') || document.querySelector('#root');
if (!$root) { if (!$root) {
return; return;
} }

View File

@ -1,19 +1,42 @@
export type SettingDefinition = { export type SettingDefinition = {
default: any; default: any;
optionsGroup?: string; } & Partial<{
options?: {[index: string]: string}; label: string;
multipleOptions?: {[index: string]: string}; note: string | HTMLElement;
unsupported?: string | boolean; experimental: boolean;
note?: string | HTMLElement; unsupported: string | boolean;
type?: SettingElementType; ready: (setting: SettingDefinition) => void;
ready?: (setting: SettingDefinition) => void;
// migrate?: (this: Preferences, savedPrefs: any, value: any) => void; // migrate?: (this: Preferences, savedPrefs: any, value: any) => void;
min?: number; }> & (
max?: number; {} | {
options: {[index: string]: string};
optionsGroup?: string;
} | {
multipleOptions: {[index: string]: string};
params: MultipleOptionsParams;
} | {
type: SettingElementType.NUMBER_STEPPER;
min: number;
max: number;
params: NumberStepperParams;
steps?: number; steps?: number;
experimental?: boolean; }
params?: any; );
label?: string;
};
export type SettingDefinitions = {[index in PrefKey]: SettingDefinition}; export type SettingDefinitions = {[index in PrefKey]: SettingDefinition};
export type MultipleOptionsParams = Partial<{
size?: number;
}>
export type NumberStepperParams = Partial<{
suffix: string;
disabled: boolean;
hideSlider: boolean;
ticks: number;
exactTicks: number;
customTextValue: (value: any) => string | null;
}>

View File

@ -53,6 +53,8 @@ export namespace BxEvent {
export const XCLOUD_RENDERING_COMPONENT = 'bx-xcloud-rendering-page'; export const XCLOUD_RENDERING_COMPONENT = 'bx-xcloud-rendering-page';
export const XCLOUD_ROUTER_HISTORY_READY = 'bx-xcloud-router-history-ready';
export function dispatch(target: Element | Window | null, eventName: string, data?: any) { export function dispatch(target: Element | Window | null, eventName: string, data?: any) {
if (!target) { if (!target) {
return; return;

View File

@ -6,7 +6,7 @@ import { getPref } from "./settings-storages/global-settings-storage";
export function addCss() { export function addCss() {
const STYLUS_CSS = renderStylus(); const STYLUS_CSS = renderStylus() as unknown as string;
let css = STYLUS_CSS; let css = STYLUS_CSS;
const PREF_HIDE_SECTIONS = getPref(PrefKey.UI_HIDE_SECTIONS); const PREF_HIDE_SECTIONS = getPref(PrefKey.UI_HIDE_SECTIONS);

View File

@ -3,21 +3,7 @@ import { CE } from "@utils/html";
import { setNearby } from "./navigation-utils"; import { setNearby } from "./navigation-utils";
import type { PrefKey } from "@/enums/pref-keys"; import type { PrefKey } from "@/enums/pref-keys";
import type { BaseSettingsStore } from "./settings-storages/base-settings-storage"; import type { BaseSettingsStore } from "./settings-storages/base-settings-storage";
import { type MultipleOptionsParams, type NumberStepperParams } from "@/types/setting-definition";
type MultipleOptionsParams = {
size?: number;
}
type NumberStepperParams = {
suffix?: string;
disabled?: boolean;
hideSlider?: boolean;
ticks?: number;
exactTicks?: number;
customTextValue?: (value: any) => string | null;
}
export enum SettingElementType { export enum SettingElementType {
OPTIONS = 'options', OPTIONS = 'options',
@ -381,7 +367,11 @@ export class SettingElement {
type = SettingElementType.CHECKBOX; type = SettingElementType.CHECKBOX;
} }
const params = Object.assign(overrideParams, definition.params || {}); let params: any = {};
if ('params' in definition) {
params = Object.assign(overrideParams, definition.params || {});
}
if (params.disabled) { if (params.disabled) {
currentValue = definition.default; currentValue = definition.default;
} }

View File

@ -5,14 +5,14 @@ import { UiSection } from "@/enums/ui-sections";
import { UserAgentProfile } from "@/enums/user-agent"; import { UserAgentProfile } from "@/enums/user-agent";
import { StreamStat } from "@/modules/stream/stream-stats"; import { StreamStat } from "@/modules/stream/stream-stats";
import type { PreferenceSetting } from "@/types/preferences"; import type { PreferenceSetting } from "@/types/preferences";
import type { SettingDefinitions } from "@/types/setting-definition"; import { type SettingDefinitions } from "@/types/setting-definition";
import { BX_FLAGS } from "../bx-flags"; import { BX_FLAGS } from "../bx-flags";
import { STATES, AppInterface, STORAGE } from "../global"; import { STATES, AppInterface, STORAGE } from "../global";
import { CE } from "../html"; import { CE } from "../html";
import { SettingElementType } from "../setting-element";
import { t, SUPPORTED_LANGUAGES } from "../translation"; import { t, SUPPORTED_LANGUAGES } from "../translation";
import { UserAgent } from "../user-agent"; import { UserAgent } from "../user-agent";
import { BaseSettingsStore as BaseSettingsStorage } from "./base-settings-storage"; import { BaseSettingsStore as BaseSettingsStorage } from "./base-settings-storage";
import { SettingElementType } from "../setting-element";
function getSupportedCodecProfiles() { function getSupportedCodecProfiles() {

View File

@ -129,6 +129,7 @@ const Texts = {
"install-android": "Better xCloud app for Android", "install-android": "Better xCloud app for Android",
"japan": "Japan", "japan": "Japan",
"keyboard-shortcuts": "Keyboard shortcuts", "keyboard-shortcuts": "Keyboard shortcuts",
"korea": "Korea",
"language": "Language", "language": "Language",
"large": "Large", "large": "Large",
"layout": "Layout", "layout": "Layout",