Compare commits

...

57 Commits

Author SHA1 Message Date
8ca6a9e08c Update better-xcloud.user.js 2024-08-14 18:26:23 +07:00
344b6bb2c9 Dispatch "TvRemoteBack" in backButtonPressed() 2024-08-14 18:26:19 +07:00
8b56ae218d Fix disabling touch control doesn't always work 2024-08-14 17:52:09 +07:00
3d2b887859 Update better-xcloud.user.js 2024-08-14 08:52:37 +07:00
370fc7b2c2 Upgrade bun 2024-08-14 08:52:22 +07:00
5f4a1c24f0 Fix touch border 2024-08-14 08:51:38 +07:00
382cd1aa51 Fix Settings button keep being added/removed from header 2024-08-14 08:51:23 +07:00
d929a958ff Bump version to 5.5.5 2024-08-10 18:43:39 +07:00
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
a77460e242 Bump version to 5.5.2 2024-08-02 05:57:10 +07:00
d2839b2b7c Fix crashing when hiding "Play with touch" section 2024-08-02 05:56:35 +07:00
8aa5177e10 Update 02-feature-request.yml 2024-08-01 19:28:54 +07:00
ff490be713 Fix Settings dialog not showing full settings when signed in 2024-08-01 19:23:57 +07:00
eb340e7f2a Update Device Code page's CSS 2024-08-01 17:51:37 +07:00
654862fd1c Bump version to 5.5.1 2024-07-31 17:45:45 +07:00
ddb234673c Update better-xcloud.user.js 2024-07-31 17:43:46 +07:00
e822072836 Open Settings dialog on Unsupported page 2024-07-31 17:31:26 +07:00
362638ff0c Fix not setting default User-Agent correctly 2024-07-31 17:31:05 +07:00
b4a94c95c0 Fix CSS of focus border + shortcut button 2024-07-31 08:47:34 +07:00
a996c0e367 Update better-xcloud.user.js 2024-07-31 07:39:58 +07:00
09a2c86ad4 Fix macros/build.renderStylus() not loading CSS each build 2024-07-31 07:39:39 +07:00
0d3385790c Show fullscreen text when reloading page 2024-07-31 07:37:23 +07:00
a39d056eba Render Settings footer in lite mode 2024-07-31 06:54:14 +07:00
847adb1fff Compress CSS 2024-07-31 06:27:43 +07:00
b49ee400f1 Close Settings dialog when opening App settings 2024-07-31 06:08:00 +07:00
ab91323abd Rearrange visual quality & resolution options 2024-07-30 18:34:57 +07:00
74237dbd24 Minor fixes 2024-07-30 18:31:47 +07:00
825db798db Update better-xcloud.user.js 2024-07-30 18:23:49 +07:00
41fe12afc6 Try to fix Remote Play issue 2024-07-30 18:23:17 +07:00
361ce057b7 Minor fixes 2024-07-30 18:06:40 +07:00
9fad2914ac Fix Settings sometimes not being injected to header 2024-07-28 15:58:03 +07:00
eb42f4a3d3 Update better-xcloud.user.js 2024-07-28 10:51:24 +07:00
857c7ec0c3 Update build script 2024-07-28 10:51:01 +07:00
8d559a53a8 Disable AAM 2024-07-28 09:41:23 +07:00
13323cce24 Minor fix 2024-07-28 09:07:45 +07:00
03eb323fd9 Implement es-lint-plugin-compat 2024-07-28 09:00:31 +07:00
fd21fe63f7 Remove disableTrackEvent() patch 2024-07-28 08:02:36 +07:00
857b63a9f9 Remove unused flags 2024-07-28 07:25:11 +07:00
35 changed files with 1105 additions and 720 deletions

View File

@ -14,41 +14,12 @@ body:
id: device_type id: device_type
attributes: attributes:
label: Device label: Device
description: "Which device are you using?" description: "Which device type is this feature for?"
options: options:
- All devices
- Phone/Tablet - Phone/Tablet
- Laptop
- Desktop - Desktop
- TV - TV
- Other
multiple: false
validations:
required: true
- type: dropdown
id: os
attributes:
label: "Operating System"
description: "Which operating system is it running?"
options:
- Windows
- macOS
- Linux
- Android
- iOS/iPadOS
- Other
multiple: false
validations:
required: true
- type: dropdown
id: browser
attributes:
label: "Browser"
description: "Which browser are you using?"
options:
- Chrome/Edge/Chromium
- Kiwi Browser
- Safari
- Other
multiple: false multiple: false
validations: validations:
required: true required: true

View File

@ -2,9 +2,12 @@
import { readFile } from "node:fs/promises"; import { readFile } from "node:fs/promises";
import { parseArgs } from "node:util"; import { parseArgs } from "node:util";
import { sys } from "typescript"; import { sys } from "typescript";
// @ts-ignore
import txtScriptHeader from "./src/assets/header_script.txt" with { type: "text" }; import txtScriptHeader from "./src/assets/header_script.txt" with { type: "text" };
// @ts-ignore
import txtMetaHeader from "./src/assets/header_meta.txt" with { type: "text" }; import txtMetaHeader from "./src/assets/header_meta.txt" with { type: "text" };
import { assert } from "node:console"; import { assert } from "node:console";
import { ESLint } from "eslint";
enum BuildTarget { enum BuildTarget {
ALL = 'all', ALL = 'all',
@ -24,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, '');
@ -80,10 +84,19 @@ const build = async (target: BuildTarget, version: string, config: any={}) => {
// Save to script // Save to script
await Bun.write(path, scriptHeader + result); await Bun.write(path, scriptHeader + result);
console.log(`---- [${target}] done in ${performance.now() - startTime} ms`);
// Create meta file // Create meta file
await Bun.write(outDir + '/' + outputMetaName, txtMetaHeader.replace('[[VERSION]]', version)); await Bun.write(outDir + '/' + outputMetaName, txtMetaHeader.replace('[[VERSION]]', version));
// Check with ESLint
const eslint = new ESLint();
const results = await eslint.lintFiles([path]);
results[0].messages.forEach((msg: any) => {
console.error(`${path}#${msg.line}: ${msg.message}`);
});
console.log(`---- [${target}] done in ${performance.now() - startTime} ms`);
console.log(`---- [${target}] ${new Date()}`);
} }
const buildTargets = [ const buildTargets = [
@ -110,9 +123,26 @@ if (!values['version']) {
sys.exit(-1); sys.exit(-1);
} }
console.log('Building: ', values['version']); async function main() {
const config = {};
const config = {}; console.log('Building: ', values['version']);
for (const target of buildTargets) { for (const target of buildTargets) {
await build(target, values['version']!!, config); await build(target, values['version']!!, config);
}
console.log('\n** Press Enter to build or Esc to exit');
} }
function onKeyPress(data: any) {
const keyCode = data[0];
if (keyCode === 13) { // Enter key
main();
} else if (keyCode === 27) { // Esc key
process.exit(0);
}
}
main();
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.on('data', onKeyPress);

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.0 // @version 5.5.5
// ==/UserScript== // ==/UserScript==

File diff suppressed because one or more lines are too long

3
eslint.config.mjs Normal file
View File

@ -0,0 +1,3 @@
import compat from "eslint-plugin-compat";
export default [compat.configs['flat/recommended']];

View File

@ -2,13 +2,18 @@
"name": "better-xcloud", "name": "better-xcloud",
"module": "src/index.ts", "module": "src/index.ts",
"type": "module", "type": "module",
"browserslist": [
"Chrome >= 80"
],
"bin": { "bin": {
"build": "build.ts" "build": "build.ts"
}, },
"devDependencies": { "devDependencies": {
"@types/bun": "^1.1.6", "@types/bun": "^1.1.6",
"@types/node": "^20.14.12", "@types/node": "^20.14.15",
"@types/stylus": "^0.48.42", "@types/stylus": "^0.48.42",
"eslint": "^9.9.0",
"eslint-plugin-compat": "^6.0.0",
"stylus": "^0.63.0" "stylus": "^0.63.0"
}, },
"peerDependencies": { "peerDependencies": {

View File

@ -141,9 +141,8 @@
border-radius: 10px; border-radius: 10px;
} }
&:focus-visible::after { &:focus::after {
offset = -6px; offset = -6px;
content: ''; content: '';
border-color: white; border-color: white;
position: absolute; position: absolute;
@ -153,6 +152,13 @@
bottom: offset; bottom: offset;
} }
html[data-active-input=touch] &,
html[data-active-input=mouse] & {
&:focus::after {
border-color: transparent !important;
}
}
&.bx-circular { &.bx-circular {
&::after { &::after {
border-radius: var(--bx-button-height); border-radius: var(--bx-button-height);
@ -177,7 +183,7 @@ button.bx-inactive {
.bx-button-shortcut { .bx-button-shortcut {
max-width: max-content; max-width: max-content;
margin: 10px 0 0 0; margin: 10px 0 0 0;
overflow: hidden; flex: 1 0 auto;
} }
@media (min-width: 568px) and (max-height: 480px) { @media (min-width: 568px) and (max-height: 480px) {

View File

@ -26,20 +26,22 @@ button_color(name, normal, hover, active, disabled)
button_color('primary', #008746, #04b358, #044e2a, #448262); button_color('primary', #008746, #04b358, #044e2a, #448262);
button_color('danger', #c10404, #e61d1d, #a26c6c, #df5656); button_color('danger', #c10404, #e61d1d, #a26c6c, #df5656);
--bx-toast-z-index: 9999; --bx-fullscreen-text-z-index: 9999;
--bx-dialog-z-index: 9101; --bx-toast-z-index: 6000;
--bx-dialog-overlay-z-index: 9100; --bx-dialog-z-index: 5000;
--bx-stats-bar-z-index: 9010;
--bx-mkb-pointer-lock-msg-z-index: 9000;
--bx-navigation-dialog-z-index: 8999; --bx-dialog-overlay-z-index: 4020;
--bx-navigation-dialog-overlay-z-index: 8998; --bx-stats-bar-z-index: 4010;
--bx-mkb-pointer-lock-msg-z-index: 4000;
--bx-navigation-dialog-z-index: 3010;
--bx-navigation-dialog-overlay-z-index: 3000;
--bx-remote-play-popup-z-index: 2000; --bx-remote-play-popup-z-index: 2000;
--bx-game-bar-z-index: 1000; --bx-game-bar-z-index: 1000;
--bx-wait-time-box-z-index: 100; --bx-wait-time-box-z-index: 100;
--bx-screenshot-animation-z-index: 1; --bx-screenshot-animation-z-index: 10;
} }
@font-face { @font-face {
@ -190,3 +192,36 @@ div[class*=SupportedInputsBadge] {
font-weight: bold; font-weight: bold;
} }
} }
.bx-fullscreen-text {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: #000000cc;
z-index: var(--bx-fullscreen-text-z-index);
line-height: 100vh;
color: #fff;
text-align: center;
font-weight: 400;
font-family: var(--bx-normal-font);
font-size: 1.3rem;
user-select: none;
-webkit-user-select: none;
}
/* Device Code page */
#root {
section[class*=DeviceCodePage-module__page] {
margin-left: 20px !important;
margin-right: 20px !important;
margin-top: 20px !important;
max-width: 800px !important;
}
div[class*=DeviceCodePage-module__back] {
display: none;
}
}

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

@ -20,9 +20,8 @@ import { RemotePlay } from "@modules/remote-play";
import { onHistoryChanged, patchHistoryMethod } from "@utils/history"; import { onHistoryChanged, patchHistoryMethod } from "@utils/history";
import { VibrationManager } from "@modules/vibration-manager"; import { VibrationManager } from "@modules/vibration-manager";
import { overridePreloadState } from "@utils/preload-state"; import { overridePreloadState } from "@utils/preload-state";
import { 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";
@ -36,6 +35,9 @@ import { ProductDetailsPage } from "./modules/ui/product-details";
import { NavigationDialogManager } from "./modules/ui/dialog/navigation-dialog"; import { NavigationDialogManager } from "./modules/ui/dialog/navigation-dialog";
import { PrefKey } from "./enums/pref-keys"; 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 { SettingsNavigationDialog } from "./modules/ui/dialog/settings-dialog";
import { StreamUiHandler } from "./modules/stream/stream-ui";
// Handle login page // Handle login page
@ -64,7 +66,7 @@ if (BX_FLAGS.SafariWorkaround && document.readyState !== 'loading') {
window.stop(); window.stop();
// Show the reloading overlay // Show the reloading overlay
const css = ` const css = compressCss(`
.bx-reload-overlay { .bx-reload-overlay {
position: fixed; position: fixed;
top: 0; top: 0;
@ -78,7 +80,7 @@ if (BX_FLAGS.SafariWorkaround && document.readyState !== 'loading') {
font-family: "Segoe UI", Arial, Helvetica, sans-serif; font-family: "Segoe UI", Arial, Helvetica, sans-serif;
font-size: 1.3rem; font-size: 1.3rem;
} }
`; `);
const $fragment = document.createDocumentFragment(); const $fragment = document.createDocumentFragment();
$fragment.appendChild(CE('style', {}, css)); $fragment.appendChild(CE('style', {}, css));
$fragment.appendChild(CE('div', {'class': 'bx-reload-overlay'}, t('safari-failed-message'))); $fragment.appendChild(CE('div', {'class': 'bx-reload-overlay'}, t('safari-failed-message')));
@ -110,14 +112,14 @@ document.addEventListener('readystatechange', e => {
return; return;
} }
STATES.isSignedIn = (window as any).xbcUser?.isSignedIn; STATES.isSignedIn = !!((window as any).xbcUser?.isSignedIn);
if (STATES.isSignedIn) { if (STATES.isSignedIn) {
// Preload Remote Play // Preload Remote Play
getPref(PrefKey.REMOTE_PLAY_ENABLED) && BX_FLAGS.PreloadRemotePlay && RemotePlay.preload(); getPref(PrefKey.REMOTE_PLAY_ENABLED) && RemotePlay.preload();
} else { } else {
// Show Settings button in the header when not signed // Show Settings button in the header when not signed in
HeaderSection.watchHeader(); window.setTimeout(HeaderSection.watchHeader, 2000);
} }
// Hide "Play with Friends" skeleton section // Hide "Play with Friends" skeleton section
@ -144,10 +146,14 @@ window.history.replaceState = patchHistoryMethod('replaceState');
window.addEventListener(BxEvent.XCLOUD_SERVERS_UNAVAILABLE, e => { window.addEventListener(BxEvent.XCLOUD_SERVERS_UNAVAILABLE, e => {
STATES.supportedRegion = false; STATES.supportedRegion = false;
window.setTimeout(HeaderSection.watchHeader, 2000); window.setTimeout(HeaderSection.watchHeader, 2000);
// Open Settings dialog on Unsupported page
SettingsNavigationDialog.getInstance().show();
}); });
window.addEventListener(BxEvent.XCLOUD_SERVERS_READY, e => { window.addEventListener(BxEvent.XCLOUD_SERVERS_READY, e => {
HeaderSection.watchHeader(); STATES.isSignedIn = true;
window.setTimeout(HeaderSection.watchHeader, 2000);
}); });
window.addEventListener(BxEvent.STREAM_LOADING, e => { window.addEventListener(BxEvent.STREAM_LOADING, e => {
@ -180,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();
@ -313,7 +319,11 @@ function main() {
AppInterface && patchPointerLockApi(); AppInterface && patchPointerLockApi();
getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL) && patchAudioContext(); getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL) && patchAudioContext();
getPref(PrefKey.BLOCK_TRACKING) && patchMeControl();
if (getPref(PrefKey.BLOCK_TRACKING)) {
patchMeControl();
disableAdobeAudienceManager();
}
STATES.userAgent.capabilities.touch && TouchController.updateCustomList(); STATES.userAgent.capabilities.touch && TouchController.updateCustomList();
overridePreloadState(); overridePreloadState();

View File

@ -1,14 +1,15 @@
import stylus from 'stylus'; import stylus from 'stylus';
import cssStr from "@assets/css/styles.styl" with { type: "text" }; export const renderStylus = async () => {
const file = Bun.file('./src/assets/css/styles.styl');
const cssStr = await file.text();
const generatedCss = await (stylus(cssStr, {}) const generatedCss = await (stylus(cssStr, {})
.set('filename', 'styles.css') .set('filename', 'styles.css')
.set('compress', true) .set('compress', true)
.include('src/assets/css/')) .include('src/assets/css/'))
.render(); .render();
export const renderStylus = () => {
return generatedCss; return generatedCss;
}; };

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
@ -140,16 +167,6 @@ if (!!window.BX_REMOTE_PLAY_CONFIG) {
return str.replace(text, text + newCode); return str.replace(text, text + newCode);
}, },
// Disable trackEvent() function
disableTrackEvent(str: string) {
const text = 'this.trackEvent=';
if (!str.includes(text)) {
return false;
}
return str.replace(text, 'this.trackEvent=e=>{},this.uwuwu=');
},
// Block WebRTC stats collector // Block WebRTC stats collector
blockWebRtcStatsCollector(str: string) { blockWebRtcStatsCollector(str: string) {
const text = 'this.shouldCollectStats=!0'; const text = 'this.shouldCollectStats=!0';
@ -375,9 +392,11 @@ if (window.BX_EXPOSED.stopTakRendering) {
return false; return false;
} }
let remotePlayCode = ''; let autoOffCode = '';
if (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) !== 'off' && getPref(PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF)) { if (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'off') {
remotePlayCode = ` autoOffCode = 'return;';
} else if (getPref(PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF)) {
autoOffCode = `
const gamepads = window.navigator.getGamepads(); const gamepads = window.navigator.getGamepads();
let gamepadFound = false; let gamepadFound = false;
@ -395,13 +414,11 @@ if (gamepadFound) {
} }
const newCode = ` const newCode = `
if (!!window.BX_REMOTE_PLAY_CONFIG) { ${autoOffCode}
${remotePlayCode}
} else { const titleInfo = window.BX_EXPOSED.getTitleInfo();
const titleInfo = window.BX_EXPOSED.getTitleInfo(); if (titleInfo && !titleInfo.details.hasTouchSupport && !titleInfo.details.hasFakeTouchSupport) {
if (titleInfo && !titleInfo.details.hasTouchSupport && !titleInfo.details.hasFakeTouchSupport) {
return; return;
}
} }
`; `;
@ -726,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;
}, },
@ -742,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;
}, },
@ -760,12 +780,12 @@ true` + text;
return false; return false;
} }
index = str.indexOf('const ', index - 100); 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;
}, },
@ -776,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;
} }
@ -804,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;
}, },
@ -872,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 = [
@ -882,6 +922,7 @@ let PATCH_ORDERS: PatchArray = [
'exposeInputSink', 'exposeInputSink',
] : []), ] : []),
'detectBrowserRouterReady',
'patchRequestInfoCrash', 'patchRequestInfoCrash',
'disableStreamGate', 'disableStreamGate',
@ -915,7 +956,6 @@ let PATCH_ORDERS: PatchArray = [
'disableIndexDbLogging', 'disableIndexDbLogging',
'disableTelemetryProvider', 'disableTelemetryProvider',
'disableTrackEvent',
] : []), ] : []),
...(getPref(PrefKey.REMOTE_PLAY_ENABLED) ? [ ...(getPref(PrefKey.REMOTE_PLAY_ENABLED) ? [
@ -1078,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') || '');
@ -51,14 +76,15 @@ function cloneStreamHudButton($orgButton: HTMLElement, label: string, svgIcon: t
$orgSvg.replaceWith($svg); $orgSvg.replaceWith($svg);
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') || '');
@ -73,25 +99,133 @@ function cloneCloseButton($$btnOrg: HTMLElement, icon: typeof BxIcon, className:
$btn.addEventListener('click', onChange); $btn.addEventListener('click', onChange);
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

@ -2,7 +2,7 @@ import { GamepadKey } from "@/enums/mkb";
import { EmulatedMkbHandler } from "@/modules/mkb/mkb-handler"; import { EmulatedMkbHandler } from "@/modules/mkb/mkb-handler";
import { BxEvent } from "@/utils/bx-event"; import { BxEvent } from "@/utils/bx-event";
import { STATES } from "@/utils/global"; import { STATES } from "@/utils/global";
import { CE } from "@/utils/html"; import { CE, isElementVisible } from "@/utils/html";
import { setNearby } from "@/utils/navigation-utils"; import { setNearby } from "@/utils/navigation-utils";
export enum NavigationDirection { export enum NavigationDirection {
@ -519,11 +519,8 @@ export class NavigationDialogManager {
return null; return null;
} }
const rect = $elm.getBoundingClientRect();
const isVisible = !!rect.width && !!rect.height;
// Ignore hidden element // Ignore hidden element
if (!isVisible) { if (!isElementVisible($elm)) {
return null; return null;
} }

View File

@ -24,6 +24,7 @@ import { PrefKey, StorageKey } from "@/enums/pref-keys";
import { getPref, getPrefDefinition, setPref } from "@/utils/settings-storages/global-settings-storage"; import { getPref, getPrefDefinition, setPref } from "@/utils/settings-storages/global-settings-storage";
import { SettingElement } from "@/utils/setting-element"; import { SettingElement } from "@/utils/setting-element";
import type { SettingDefinition } from "@/types/setting-definition"; import type { SettingDefinition } from "@/types/setting-definition";
import { FullscreenText } from "../fullscreen-text";
type SettingTabContentItem = Partial<{ type SettingTabContentItem = Partial<{
@ -40,8 +41,8 @@ type SettingTabContentItem = Partial<{
}> }>
type SettingTabContent = { type SettingTabContent = {
group: 'general' | 'server' | 'stream' | 'game-bar' | 'co-op' | 'mkb' | 'touch-control' | 'loading-screen' | 'ui' | 'other' | 'advanced' | 'audio' | 'video' | 'controller' | 'native-mkb' | 'stats' | 'controller-shortcuts'; group: 'general' | 'server' | 'stream' | 'game-bar' | 'co-op' | 'mkb' | 'touch-control' | 'loading-screen' | 'ui' | 'other' | 'advanced' | 'footer' | 'audio' | 'video' | 'controller' | 'native-mkb' | 'stats' | 'controller-shortcuts';
label: string; label?: string;
note?: string | Text | null; note?: string | Text | null;
unsupported?: boolean; unsupported?: boolean;
helpUrl?: string; helpUrl?: string;
@ -69,7 +70,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
private $settings!: HTMLElement; private $settings!: HTMLElement;
private $btnReload!: HTMLElement; private $btnReload!: HTMLElement;
private $btnGlobalReload!: HTMLElement; private $btnGlobalReload!: HTMLButtonElement;
private $noteGlobalReload!: HTMLElement; private $noteGlobalReload!: HTMLElement;
private renderFullSettings: boolean; private renderFullSettings: boolean;
@ -103,6 +104,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
style: ButtonStyle.FULL_WIDTH | ButtonStyle.FOCUSABLE, style: ButtonStyle.FULL_WIDTH | ButtonStyle.FOCUSABLE,
onClick: e => { onClick: e => {
AppInterface.openAppSettings && AppInterface.openAppSettings(); AppInterface.openAppSettings && AppInterface.openAppSettings();
this.hide();
}, },
})); }));
} else { } else {
@ -122,11 +124,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
classes: ['bx-settings-reload-button', 'bx-gone'], classes: ['bx-settings-reload-button', 'bx-gone'],
style: ButtonStyle.FOCUSABLE | ButtonStyle.FULL_WIDTH, style: ButtonStyle.FOCUSABLE | ButtonStyle.FULL_WIDTH,
onClick: e => { onClick: e => {
const $target = (e.target as HTMLButtonElement).closest('button')!; this.reloadPage();
$target.disabled = true;
$target.firstElementChild!.textContent = t('settings-reloading');
window.location.reload();
}, },
}); });
@ -178,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'),
@ -210,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'),
@ -234,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'),
@ -273,7 +271,10 @@ export class SettingsNavigationDialog extends NavigationDialog {
}); });
}, },
}, },
],
}, {
group: 'footer',
items: [
// Donation link // Donation link
($parent) => { ($parent) => {
$parent.appendChild(CE('a', { $parent.appendChild(CE('a', {
@ -320,7 +321,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
); );
$parent.appendChild($debugInfo); $parent.appendChild($debugInfo);
} },
], ],
}]; }];
@ -607,7 +608,13 @@ export class SettingsNavigationDialog extends NavigationDialog {
} }
} }
onUnmounted(): void { private reloadPage() {
this.$btnGlobalReload.disabled = true;
this.$btnGlobalReload.firstElementChild!.textContent = t('settings-reloading');
this.hide();
FullscreenText.getInstance().show(t('settings-reloading'));
window.location.reload();
} }
private renderTab(settingTab: SettingTab) { private renderTab(settingTab: SettingTab) {
@ -851,8 +858,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
icon: BxIcon.REFRESH, icon: BxIcon.REFRESH,
style: ButtonStyle.FOCUSABLE | ButtonStyle.DROP_SHADOW, style: ButtonStyle.FOCUSABLE | ButtonStyle.DROP_SHADOW,
onClick: e => { onClick: e => {
window.location.reload(); this.reloadPage();
this.dialogManager.hide();
}, },
}), }),
@ -920,8 +926,8 @@ export class SettingsNavigationDialog extends NavigationDialog {
} }
// Don't render other settings in unsupported regions // Don't render other settings in unsupported regions
if (!this.renderFullSettings && settingTab.group === 'global' && settingTabContent.group !== 'general') { if (!this.renderFullSettings && settingTab.group === 'global' && settingTabContent.group !== 'general' && settingTabContent.group !== 'footer') {
break; continue;
} }
let label = settingTabContent.label; let label = settingTabContent.label;
@ -936,6 +942,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
}); });
} }
if (label) {
const $title = CE('h2', { const $title = CE('h2', {
_nearby: { _nearby: {
orientation: 'horizontal', orientation: 'horizontal',
@ -951,6 +958,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
); );
$tabContent.appendChild($title); $tabContent.appendChild($title);
}
// Add note // Add note
if (settingTabContent.note) { if (settingTabContent.note) {

View File

@ -0,0 +1,33 @@
import { CE } from "@/utils/html";
export class FullscreenText {
private static instance: FullscreenText;
public static getInstance(): FullscreenText {
if (!FullscreenText.instance) {
FullscreenText.instance = new FullscreenText();
}
return FullscreenText.instance;
}
$text: HTMLElement;
constructor() {
this.$text = CE('div', {
class: 'bx-fullscreen-text bx-gone',
});
document.documentElement.appendChild(this.$text);
}
show(msg: string) {
document.body.classList.add('bx-no-scroll');
this.$text.classList.remove('bx-gone');
this.$text.textContent = msg;
}
hide() {
document.body.classList.remove('bx-no-scroll');
this.$text.classList.add('bx-gone');
}
}

View File

@ -1,5 +1,5 @@
import { SCRIPT_VERSION } from "@utils/global"; import { SCRIPT_VERSION } from "@utils/global";
import { createButton, ButtonStyle, CE } from "@utils/html"; import { createButton, ButtonStyle, CE, isElementVisible } from "@utils/html";
import { BxIcon } from "@utils/bx-icon"; import { BxIcon } from "@utils/bx-icon";
import { getPreferredServerRegion } from "@utils/region"; import { getPreferredServerRegion } from "@utils/region";
import { RemotePlay } from "@modules/remote-play"; import { RemotePlay } from "@modules/remote-play";
@ -44,12 +44,16 @@ export class HeaderSection {
const PREF_LATEST_VERSION = getPref(PrefKey.LATEST_VERSION); const PREF_LATEST_VERSION = getPref(PrefKey.LATEST_VERSION);
// Setup Settings button // Setup Settings button
const $settingsBtn = HeaderSection.#$settingsBtn; const $btnSettings = HeaderSection.#$settingsBtn;
$settingsBtn.querySelector('span')!.textContent = getPreferredServerRegion(true) || t('better-xcloud'); if (isElementVisible(HeaderSection.#$buttonsWrapper)) {
return;
}
$btnSettings.querySelector('span')!.textContent = getPreferredServerRegion(true) || t('better-xcloud');
// Show new update status // Show new update status
if (!SCRIPT_VERSION.includes('beta') && PREF_LATEST_VERSION && PREF_LATEST_VERSION !== SCRIPT_VERSION) { if (!SCRIPT_VERSION.includes('beta') && PREF_LATEST_VERSION && PREF_LATEST_VERSION !== SCRIPT_VERSION) {
$settingsBtn.setAttribute('data-update-available', 'true'); $btnSettings.setAttribute('data-update-available', 'true');
} }
// Add the Settings button to the web page // Add the Settings button to the web page
@ -57,10 +61,12 @@ export class HeaderSection {
} }
static checkHeader() { static checkHeader() {
if (!HeaderSection.#$buttonsWrapper.isConnected) { let $target = document.querySelector('#PageContent div[class*=EdgewaterHeader-module__rightSectionSpacing]');
const $rightHeader = document.querySelector('#PageContent div[class*=EdgewaterHeader-module__rightSectionSpacing]'); if (!$target) {
HeaderSection.#injectSettingsButton($rightHeader as HTMLElement); $target = document.querySelector("div[class^=UnsupportedMarketPage-module__buttons]");
} }
$target && HeaderSection.#injectSettingsButton($target as HTMLElement);
} }
static showRemotePlayButton() { static showRemotePlayButton() {
@ -68,17 +74,20 @@ export class HeaderSection {
} }
static watchHeader() { static watchHeader() {
const $header = document.querySelector('#PageContent header'); const $root = document.querySelector('#PageContent header') || document.querySelector('#root');
if (!$header) { if (!$root) {
return; return;
} }
HeaderSection.#timeout && clearTimeout(HeaderSection.#timeout);
HeaderSection.#timeout = null;
HeaderSection.#observer && HeaderSection.#observer.disconnect(); HeaderSection.#observer && HeaderSection.#observer.disconnect();
HeaderSection.#observer = new MutationObserver(mutationList => { HeaderSection.#observer = new MutationObserver(mutationList => {
HeaderSection.#timeout && clearTimeout(HeaderSection.#timeout); HeaderSection.#timeout && clearTimeout(HeaderSection.#timeout);
HeaderSection.#timeout = window.setTimeout(HeaderSection.checkHeader, 2000); HeaderSection.#timeout = window.setTimeout(HeaderSection.checkHeader, 2000);
}); });
HeaderSection.#observer.observe($header, {subtree: true, childList: true}); HeaderSection.#observer.observe($root, {subtree: true, childList: true});
HeaderSection.checkHeader(); HeaderSection.checkHeader();
} }

View File

@ -19,7 +19,7 @@ export class ProductDetailsPage {
private static shortcutTimeoutId: number | null = null; private static shortcutTimeoutId: number | null = null;
static injectShortcutButton() { static injectShortcutButton() {
if (!AppInterface || BX_FLAGS.DeviceInfo!.deviceType !== 'android') { if (!AppInterface || BX_FLAGS.DeviceInfo.deviceType !== 'android') {
return; return;
} }

3
src/types/network.ts Normal file
View File

@ -0,0 +1,3 @@
export type RemotePlayConsoleAddresses = {
[key: string]: number[],
}

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

@ -128,6 +128,18 @@ export const BxExposed = {
return true; return true;
} }
const dict = {
bubbles: true,
cancelable: true,
key: 'XF86Back',
code: 'XF86Back',
keyCode: 4,
which: 4,
};
document.body.dispatchEvent(new KeyboardEvent('keydown', dict));
document.body.dispatchEvent(new KeyboardEvent('keyup', dict));
return false; return false;
}, },
}; };

View File

@ -1,26 +1,20 @@
type BxFlags = Partial<{ type BxFlags = {
CheckForUpdate: boolean; CheckForUpdate: boolean;
PreloadRemotePlay: boolean;
PreloadUi: boolean;
EnableXcloudLogging: boolean; EnableXcloudLogging: boolean;
SafariWorkaround: boolean; SafariWorkaround: boolean;
ForceNativeMkbTitles: string[]; ForceNativeMkbTitles: string[];
FeatureGates: {[key: string]: boolean} | null, FeatureGates: {[key: string]: boolean} | null,
IsSupportedTvBrowser: boolean, DeviceInfo: {
DeviceInfo: Partial<{
deviceType: 'android' | 'android-tv' | 'webos' | 'unknown', deviceType: 'android' | 'android-tv' | 'webos' | 'unknown',
userAgent?: string, userAgent?: string,
}>, }
}> }
// Setup flags // Setup flags
const DEFAULT_FLAGS: BxFlags = { const DEFAULT_FLAGS: BxFlags = {
CheckForUpdate: true, CheckForUpdate: true,
PreloadRemotePlay: true,
PreloadUi: false,
EnableXcloudLogging: false, EnableXcloudLogging: false,
SafariWorkaround: true, SafariWorkaround: true,
@ -37,8 +31,8 @@ try {
delete window.BX_FLAGS; delete window.BX_FLAGS;
} catch (e) {} } catch (e) {}
if (!BX_FLAGS.DeviceInfo!.userAgent) { if (!BX_FLAGS.DeviceInfo.userAgent) {
BX_FLAGS.DeviceInfo!.userAgent = window.navigator.userAgent; BX_FLAGS.DeviceInfo.userAgent = window.navigator.userAgent;
} }
export const NATIVE_FETCH = window.fetch; export const NATIVE_FETCH = window.fetch;

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

@ -146,5 +146,10 @@ export function escapeHtml(html: string): string {
return $span.innerHTML; return $span.innerHTML;
} }
export function isElementVisible($elm: HTMLElement): boolean {
const rect = $elm.getBoundingClientRect();
return !!rect.width && !!rect.height;
}
export const CTN = document.createTextNode.bind(document); export const CTN = document.createTextNode.bind(document);
window.BX_CE = createElement; window.BX_CE = createElement;

View File

@ -201,6 +201,14 @@ export function patchMeControl() {
(window as any).MeControl = new Proxy(MeControl, MeControlHandler); (window as any).MeControl = new Proxy(MeControl, MeControlHandler);
} }
/**
* Disable Adobe Audience Manager (AAM)
*/
export function disableAdobeAudienceManager() {
(window as any).adobe = Object.freeze({});
}
/** /**
* Use power-saving flags for touch control * Use power-saving flags for touch control
*/ */

View File

@ -9,6 +9,7 @@ import { XhomeInterceptor } from "./xhome-interceptor";
import { XcloudInterceptor } from "./xcloud-interceptor"; import { XcloudInterceptor } from "./xcloud-interceptor";
import { PrefKey } from "@/enums/pref-keys"; import { PrefKey } from "@/enums/pref-keys";
import { getPref } from "./settings-storages/global-settings-storage"; import { getPref } from "./settings-storages/global-settings-storage";
import type { RemotePlayConsoleAddresses } from "@/types/network";
type RequestType = 'xcloud' | 'xhome'; type RequestType = 'xcloud' | 'xhome';
@ -39,7 +40,7 @@ function clearAllLogs() {
clearDbLogs('XCloudAppLogs', 'logs'); clearDbLogs('XCloudAppLogs', 'logs');
} }
function updateIceCandidates(candidates: any, options: any) { function updateIceCandidates(candidates: any, options: {preferIpv6Server: boolean, consoleAddrs?: RemotePlayConsoleAddresses}) {
const pattern = new RegExp(/a=candidate:(?<foundation>\d+) (?<component>\d+) UDP (?<priority>\d+) (?<ip>[^\s]+) (?<port>\d+) (?<the_rest>.*)/); const pattern = new RegExp(/a=candidate:(?<foundation>\d+) (?<component>\d+) UDP (?<priority>\d+) (?<ip>[^\s]+) (?<port>\d+) (?<the_rest>.*)/);
const lst = []; const lst = [];
@ -83,11 +84,11 @@ function updateIceCandidates(candidates: any, options: any) {
if (options.consoleAddrs) { if (options.consoleAddrs) {
for (const ip in options.consoleAddrs) { for (const ip in options.consoleAddrs) {
const port = options.consoleAddrs[ip]; for (const port of options.consoleAddrs[ip]) {
newCandidates.push(newCandidate(`a=candidate:${newCandidates.length + 1} 1 UDP 1 ${ip} ${port} typ host`)); newCandidates.push(newCandidate(`a=candidate:${newCandidates.length + 1} 1 UDP 1 ${ip} ${port} typ host`));
} }
} }
}
newCandidates.push(newCandidate('a=end-of-candidates')); newCandidates.push(newCandidate('a=end-of-candidates'));
@ -96,7 +97,7 @@ function updateIceCandidates(candidates: any, options: any) {
} }
export async function patchIceCandidates(request: Request, consoleAddrs?: {[index: string]: number}) { export async function patchIceCandidates(request: Request, consoleAddrs?: RemotePlayConsoleAddresses) {
const response = await NATIVE_FETCH(request); const response = await NATIVE_FETCH(request);
const text = await response.clone().text(); const text = await response.clone().text();

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() {
@ -44,11 +44,11 @@ function getSupportedCodecProfiles() {
} }
} }
if (hasHighCodec) { if (hasLowCodec) {
if (!hasLowCodec && !hasNormalCodec) { if (!hasNormalCodec && !hasHighCodec) {
options.default = `${t('visual-quality-high')} (${t('default')})`; options.default = `${t('visual-quality-low')} (${t('default')})`;
} else { } else {
options.high = t('visual-quality-high'); options.low = t('visual-quality-low');
} }
} }
@ -60,11 +60,11 @@ function getSupportedCodecProfiles() {
} }
} }
if (hasLowCodec) { if (hasHighCodec) {
if (!hasNormalCodec && !hasHighCodec) { if (!hasLowCodec && !hasNormalCodec) {
options.default = `${t('visual-quality-low')} (${t('default')})`; options.default = `${t('visual-quality-high')} (${t('default')})`;
} else { } else {
options.low = t('visual-quality-low'); options.high = t('visual-quality-high');
} }
} }
@ -140,8 +140,8 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
default: 'auto', default: 'auto',
options: { options: {
auto: t('default'), auto: t('default'),
'1080p': '1080p',
'720p': '720p', '720p': '720p',
'1080p': '1080p',
}, },
}, },
[PrefKey.STREAM_CODEC_PROFILE]: { [PrefKey.STREAM_CODEC_PROFILE]: {
@ -457,7 +457,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
[PrefKey.UI_CONTROLLER_FRIENDLY]: { [PrefKey.UI_CONTROLLER_FRIENDLY]: {
label: t('controller-friendly-ui'), label: t('controller-friendly-ui'),
default: BX_FLAGS.DeviceInfo!.deviceType !== 'unknown', default: BX_FLAGS.DeviceInfo.deviceType !== 'unknown',
}, },
[PrefKey.UI_LAYOUT]: { [PrefKey.UI_LAYOUT]: {
@ -512,7 +512,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
[PrefKey.USER_AGENT_PROFILE]: { [PrefKey.USER_AGENT_PROFILE]: {
label: t('user-agent-profile'), label: t('user-agent-profile'),
note: '⚠️ ' + t('unexpected-behavior'), note: '⚠️ ' + t('unexpected-behavior'),
default: BX_FLAGS.DeviceInfo!.deviceType === 'android-tv' ? UserAgentProfile.VR_OCULUS : 'default', default: (BX_FLAGS.DeviceInfo.deviceType === 'android-tv' || BX_FLAGS.DeviceInfo.deviceType === 'webos') ? UserAgentProfile.VR_OCULUS : 'default',
options: { options: {
[UserAgentProfile.DEFAULT]: t('default'), [UserAgentProfile.DEFAULT]: t('default'),
[UserAgentProfile.WINDOWS_EDGE]: 'Edge + Windows', [UserAgentProfile.WINDOWS_EDGE]: 'Edge + Windows',

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",

View File

@ -36,7 +36,7 @@ export class UserAgent {
static init() { static init() {
UserAgent.#config = JSON.parse(window.localStorage.getItem(UserAgent.STORAGE_KEY) || '{}') as UserAgentConfig; UserAgent.#config = JSON.parse(window.localStorage.getItem(UserAgent.STORAGE_KEY) || '{}') as UserAgentConfig;
if (!UserAgent.#config.profile) { if (!UserAgent.#config.profile) {
UserAgent.#config.profile = UserAgentProfile.DEFAULT; UserAgent.#config.profile = (BX_FLAGS.DeviceInfo.deviceType === 'android-tv' || BX_FLAGS.DeviceInfo.deviceType === 'webos') ? UserAgentProfile.VR_OCULUS : UserAgentProfile.DEFAULT;
} }
if (!UserAgent.#config.custom) { if (!UserAgent.#config.custom) {
@ -120,14 +120,11 @@ export class UserAgent {
let newUserAgent = UserAgent.get(profile); let newUserAgent = UserAgent.get(profile);
// Pretend to be Tizen TV
if (BX_FLAGS.IsSupportedTvBrowser) {
newUserAgent += ` SmartTV ${SMART_TV_UNIQUE_ID}`;
}
// Clear data of navigator.userAgentData, force xCloud to detect browser based on navigator.userAgent // Clear data of navigator.userAgentData, force xCloud to detect browser based on navigator.userAgent
if ('userAgentData' in window.navigator) {
(window.navigator as any).orgUserAgentData = (window.navigator as any).userAgentData; (window.navigator as any).orgUserAgentData = (window.navigator as any).userAgentData;
Object.defineProperty(window.navigator, 'userAgentData', {}); Object.defineProperty(window.navigator, 'userAgentData', {});
}
// Override navigator.userAgent // Override navigator.userAgent
(window.navigator as any).orgUserAgent = window.navigator.userAgent; (window.navigator as any).orgUserAgent = window.navigator.userAgent;

View File

@ -7,9 +7,10 @@ import { STATES } from "./global";
import { patchIceCandidates } from "./network"; import { patchIceCandidates } from "./network";
import { PrefKey } from "@/enums/pref-keys"; import { PrefKey } from "@/enums/pref-keys";
import { getPref } from "./settings-storages/global-settings-storage"; import { getPref } from "./settings-storages/global-settings-storage";
import type { RemotePlayConsoleAddresses } from "@/types/network";
export class XhomeInterceptor { export class XhomeInterceptor {
static #consoleAddrs: {[index: string]: number} = {}; static #consoleAddrs: RemotePlayConsoleAddresses = {};
static async #handleLogin(request: Request) { static async #handleLogin(request: Request) {
try { try {
@ -39,17 +40,25 @@ export class XhomeInterceptor {
const obj = await response.clone().json() const obj = await response.clone().json()
console.log(obj); console.log(obj);
const processPorts = (port: number): number[] => {
const ports = new Set<number>();
ports.add(port);
ports.add(9002);
return Array.from(ports);
};
const serverDetails = obj.serverDetails; const serverDetails = obj.serverDetails;
if (serverDetails.ipAddress) { if (serverDetails.ipAddress) {
XhomeInterceptor.#consoleAddrs[serverDetails.ipAddress] = serverDetails.port; XhomeInterceptor.#consoleAddrs[serverDetails.ipAddress] = processPorts(serverDetails.port);
} }
if (serverDetails.ipV4Address) { if (serverDetails.ipV4Address) {
XhomeInterceptor.#consoleAddrs[serverDetails.ipV4Address] = serverDetails.ipV4Port; XhomeInterceptor.#consoleAddrs[serverDetails.ipV4Address] = processPorts(serverDetails.ipV4Port);
} }
if (serverDetails.ipV6Address) { if (serverDetails.ipV6Address) {
XhomeInterceptor.#consoleAddrs[serverDetails.ipV6Address] = serverDetails.ipV6Port; XhomeInterceptor.#consoleAddrs[serverDetails.ipV6Address] = processPorts(serverDetails.ipV6Port);
} }
response.json = () => Promise.resolve(obj); response.json = () => Promise.resolve(obj);