Compare commits

...

152 Commits

Author SHA1 Message Date
153b9e0cfe Bump version to 6.7.0 2025-06-21 19:19:27 +07:00
88151c9426 Show error when not able to get the server list 2025-06-21 18:12:58 +07:00
f7048a38b3 Fix crashing when reload the page while Remote Play-ing 2025-06-21 17:59:01 +07:00
c76a3cc7a4 Add "Prefer IPv6 server" option for Remote Play 2025-06-21 17:24:37 +07:00
80f47a93d4 Upgrade bun 2025-06-21 16:18:29 +07:00
67fdf5ea12 Fix clearAllData() not working properly (#708) 2025-06-21 16:00:46 +07:00
4da2cfaf49 Handle deep link 2025-06-21 15:51:28 +07:00
e1d053a634 Add back the ability to create shortcut for Remote Play 2025-06-21 15:34:50 +07:00
f7f01fd27e Bump version to 6.6.2 2025-06-06 07:30:46 +07:00
67c2fb125f Fix "ignoreNewsSection" patch 2025-06-06 07:29:53 +07:00
fad91d14a6 Fix "patchPollGamepads" patch 2025-06-06 07:27:34 +07:00
3a3fc77e83 Fix virtual controller stopped working (#731) 2025-06-06 07:25:11 +07:00
4bf3bd3bb4 Use findAndParseParams() in "gameCardCustomIcons" patch 2025-05-31 11:30:21 +07:00
cc33e27bd6 Fix "ignoreSiglSections" patch 2025-05-31 11:16:34 +07:00
9112853dfc Update stale.yaml 2025-05-31 09:59:55 +07:00
368164b567 Create stale.yaml 2025-05-31 09:58:13 +07:00
ce71c3043e Bump version to 6.6.1 2025-05-29 21:03:52 +07:00
3bb138cd05 Fix "injectErrorPageUseEffect" patch (not showing Error page) 2025-05-29 20:59:31 +07:00
3d6688e1db Set script version to 6.6.1-beta 2025-05-29 20:56:39 +07:00
fc354e680c Upgrade bun 2025-05-29 20:56:25 +07:00
be51199279 Fix built scripts 2025-05-29 20:54:17 +07:00
e276d9a2b9 Fix "disableGamepadDisconnectedScreen" patch 2025-05-29 20:51:30 +07:00
c2f9f129d0 Bump version to 6.6.0 2025-05-29 08:50:09 +07:00
aa50261726 Update translations 2025-05-29 08:49:52 +07:00
bb32d97ae8 Fix "disableTouchContextMenu" patch 2025-05-29 08:44:16 +07:00
3d2abf6b12 Fix "enableTvRoutes" patch 2025-05-29 08:39:06 +07:00
4c8a49a43a Fix "injectErrorPageUseEffect" patch 2025-05-29 08:38:41 +07:00
256f28695e Fix "injectErrorPageUseEffect" patch 2025-05-29 08:27:20 +07:00
9e851fbd15 Fix "skipFeedbackDialog" patch 2025-05-29 08:21:36 +07:00
c829f74dcc Fix "patchStreamHud" patch 2025-05-29 08:16:29 +07:00
62cf045f05 Fix "ignorePlayWithFriendsSection" patch 2025-05-29 07:53:13 +07:00
fdb4e58b5d Fix "gameCardCustomIcons" patch 2025-05-29 07:47:32 +07:00
b1407c2447 Update translations 2025-05-29 07:34:25 +07:00
b5ba6e9600 Fix web's version detection 2025-05-29 07:34:07 +07:00
a3094d2c9f Set Performance mode before Quality mode 2025-05-14 17:59:44 +07:00
3290a36886 Add Clarity boost mode 2025-05-14 17:21:50 +07:00
e502e49d64 Bump version to 6.5.0 2025-04-26 08:30:53 +07:00
604cf7094a Update translations 2025-04-26 08:23:47 +07:00
3bfa7e5f21 Inject Better xCloud button to Remote Play page's header 2025-04-26 08:22:20 +07:00
e3789b4fb7 Add webOS and xboxOS to the list of OS names 2025-04-26 07:47:24 +07:00
0551d909e5 Support new screen ratios: 20:9, 3:2, 5:4 2025-04-21 07:15:51 +07:00
da6ab51ba0 Refactor Remote Play feature 2025-04-20 20:28:48 +07:00
4a65221ad0 Upgrade bun 2025-04-20 15:29:25 +07:00
528c6774fe Bump version to 6.4.10 2025-04-16 16:43:40 +07:00
3c8a35d441 Fix "disableTouchContextMenu" patch 2025-04-16 16:42:59 +07:00
544ededb64 Bump version to 6.4.9 2025-04-15 04:52:46 +07:00
f4f88f688b Fix script running on non-xCloud pages (#698) 2025-04-15 04:52:21 +07:00
1fb1a64767 Fix Remote Play stopped working with xCloud 29.1.60 2025-04-15 04:39:50 +07:00
769649a376 Upgrade bun 2025-04-15 04:36:54 +07:00
057adb62df Bump version to 6.4.8 2025-03-27 07:36:23 +07:00
98e8ff4783 Fix header's style in other pages 2025-03-27 07:26:05 +07:00
f5e1b0a9fa Upgrade bun 2025-03-27 07:19:50 +07:00
8ea3503dd3 Update header's style for small screens 2025-03-27 07:19:08 +07:00
b733d55e9e Bump version to 6.4.7 2025-03-21 06:37:13 +07:00
317ac9017b Fix custom input icons not showing in game card 2025-03-21 06:28:59 +07:00
b8c62a1f4d Fix Remote Play's achievement notification 2025-03-21 05:37:38 +07:00
7332528f72 Remove "enableConsoleLogging" patch from Stream page 2025-03-21 05:29:14 +07:00
d063500aae Fix not detecting new xCloud version correctly 2025-03-21 05:26:09 +07:00
29ff1bc09c Bump version to 6.4.6 2025-03-11 17:49:46 +07:00
8998daf14c Always check for new version 2025-03-11 17:49:15 +07:00
8bdad8b319 Add Czech translations 2025-03-11 17:43:49 +07:00
5dd3ebdea1 Fix unable to connect to console using Remote Play in some cases 2025-03-11 17:27:59 +07:00
55d7796f96 Bump version to 6.4.5 2025-02-21 07:17:23 +07:00
0b02a758db Fix custom touch control not working in Remote Play (#674) 2025-02-21 07:10:54 +07:00
3b2abbf6bb Fix video in detail page not playing (#679) 2025-02-21 06:55:55 +07:00
43a66db697 Fix patches 2025-02-21 06:46:29 +07:00
a3130101f4 Bump version to 6.4.4 2025-02-14 09:04:49 +07:00
3483672554 Fix Remote Play stopped working 2025-02-14 09:04:33 +07:00
75d7443e0f Bump version to 6.4.3 2025-02-14 06:25:04 +07:00
b5d2d0fdec Enable "1080p (HQ)" setting for Remote Play 2025-02-14 06:24:52 +07:00
20afe92371 Bump version to 6.4.2 2025-02-14 06:06:01 +07:00
5738412f71 Fix crashing in LoadingScreen 2025-02-14 06:05:46 +07:00
d2ee3d2122 Bump version to 6.4.1 2025-02-08 20:21:20 +07:00
a65fd8233b Upgrade bun 2025-02-08 20:20:58 +07:00
1375fb115d Highlight "Bypass region" row in unsupported regions 2025-02-08 20:11:48 +07:00
bedf82d363 Minify shaders 2025-02-08 11:05:52 +07:00
b463e4f014 Define types for Patcher 2025-02-08 09:57:42 +07:00
2f8c776133 Stop using MutationObserver in root-dialog 2025-02-07 22:02:58 +07:00
585ee82776 Only call useEffect on mounted 2025-02-07 21:32:18 +07:00
3c2549178b Patch createPortal 2025-02-07 21:31:01 +07:00
2fb2cfb004 Fix starting StreamStats multiple times 2025-02-07 18:21:07 +07:00
ac20cc51cc Stop using MutationObserver in stream-ui 2025-02-07 17:31:30 +07:00
85339f09da Simplify Patcher's logs 2025-02-07 17:10:18 +07:00
4b06d9fcff useEffect() for Error page 2025-02-07 17:01:03 +07:00
d4c1e8cce3 Bug fixes 2025-02-07 09:00:22 +07:00
cf1f656ecf Stop using MutationObserver to track StreamHud's expanded status 2025-02-07 08:43:06 +07:00
2fd482bb7b Use a better method to show the Better xCloud button ASAP 2025-02-06 21:23:56 +07:00
63e5e90443 Bump version to 6.4.0 2025-02-05 20:25:15 +07:00
9034c173e7 Update translations 2025-02-05 20:22:39 +07:00
5949e1e411 Disable header & footer 2025-02-05 20:11:24 +07:00
5ce7ade574 Optimize CSS selectors 2025-02-05 17:29:21 +07:00
e45537adf0 Add EnableWebGPURenderer flag 2025-02-04 21:17:43 +07:00
f9c9dc9684 Remove "See All Games" 's background color in OLED theme 2025-02-04 21:07:04 +07:00
ff9a7962c5 Hide Friends section 2025-02-04 20:54:56 +07:00
d4f070f6bb Allow hiding BYOG section 2025-02-04 20:51:50 +07:00
66b1f92f4c Disable dropdown's animation 2025-02-04 20:24:46 +07:00
7a69e7f284 Add OLED theme (#658) 2025-02-04 20:20:48 +07:00
664e865b82 Hide WebGPU renderer behind EnableWebGPURenderer flag 2025-02-04 19:29:43 +07:00
7894dea5ff Allow hiding "Recently added, "Leaving soon" and "Genres" sections (#658) 2025-02-03 21:25:38 +07:00
fd665b6fcd Add WebGPU renderer (#648) 2025-02-02 21:37:21 +07:00
39ecef976c Optimize WebGL2 2025-02-02 21:12:21 +07:00
0d5fa0fc96 Optimize WebGPU 2025-02-02 17:57:46 +07:00
fccd84b7ef Optimize WebGPU 2025-02-02 12:18:00 +07:00
eb1c027c30 Optimize WebGPU 2025-02-01 20:56:33 +07:00
6a211db52e Test WebGPU 2025-02-01 17:14:31 +07:00
17dc7996b1 Replace alwaysTriggerOnChange with onChangeUi 2025-01-30 16:39:52 +07:00
fe418e6918 Automatically reset game setting's value if it has the same value as global's 2025-01-30 16:10:51 +07:00
96de61c301 Bump version to 6.3.1 2025-01-29 17:31:25 +07:00
54a3e144a6 Show "Unknown Game" when unable to get game's title 2025-01-29 15:47:29 +07:00
277a830d99 Fix unable to reset Virtual controller's preset & Keyboard shortcuts' preset 2025-01-29 15:28:04 +07:00
0ef8fe18ac Fix calling definition.ready() multiple times 2025-01-29 15:06:34 +07:00
706665713f Only switch to game settings if it's not empty (#652) 2025-01-29 11:15:51 +07:00
bf23943da8 Bump version to 6.3.0 2025-01-29 05:26:53 +07:00
6e31caa4fc Migrate Stream settings in Global storage to Stream storage 2025-01-28 19:22:48 +07:00
91f9d76c57 Increase title's font-size 2025-01-28 17:20:59 +07:00
f81627ac7a Update Toast's style 2025-01-28 16:04:53 +07:00
7c94afacc2 Delete lite.js 2025-01-28 15:34:19 +07:00
8f37263386 Build pretty.js 2025-01-28 15:15:19 +07:00
d281db5767 Don't store invalid keys in localStorage 2025-01-28 14:54:57 +07:00
d638700e03 Update dists 2025-01-28 11:29:42 +07:00
e3f971845f Game-specific settings (#623) 2025-01-28 11:28:26 +07:00
91c8172564 Update better-xcloud.user.js 2025-01-28 06:33:10 +07:00
ee4055e169 Update better-xcloud.user.js 2025-01-28 06:23:22 +07:00
84415de09f Update better-xcloud.user.js 2025-01-27 19:56:27 +07:00
d3ef988af7 Fix problem with controller in Settings dialog 2025-01-16 21:50:23 +07:00
0bf4c289db Bump version to 6.2.1 2025-01-16 20:37:00 +07:00
c8865bd8a0 Re-arrange patches 2025-01-16 20:26:15 +07:00
a2f062d9d5 Lite: remove LocalCoOpManager 2025-01-16 20:05:51 +07:00
b6d4c51ca9 Update dists 2025-01-16 16:49:08 +07:00
785df72972 Lite: hide unsupported features 2025-01-16 16:37:18 +07:00
48da8bc527 Update Remote Play dialog's styling 2025-01-16 07:14:52 +07:00
f9cf02b2da Fix the Y button in default MKB preset 2025-01-16 06:46:12 +07:00
77e0f2d8ba Lite: disable navigating using gamepad in Settings dialog 2025-01-16 06:45:12 +07:00
d05a68c470 Fix exception when viewing deviceCode page 2025-01-15 21:30:50 +07:00
153873e034 Reduce Virtual Controller's input latency 2025-01-08 21:16:07 +07:00
8d7fbf2804 Bump version to 6.2.0 2025-01-04 19:39:40 +07:00
488b0dfef2 Show local co-op icon in settings 2025-01-04 18:43:24 +07:00
b3697df8dc Set background image's quality 2025-01-04 18:30:53 +07:00
de21549e0d Hide image quality's slider 2025-01-04 13:14:51 +07:00
097164b92e Set image quality 2025-01-04 12:33:47 +07:00
3fe6d97133 Update dists 2025-01-04 10:31:45 +07:00
328fdf46ea Don't render controller icon in game card 2025-01-04 10:31:13 +07:00
e4dbdea9a5 await requestPointerLock 2025-01-03 20:43:21 +07:00
f13ce94cf2 Update dists 2025-01-03 20:04:25 +07:00
a6c19fec15 Use Set() for local co-op list 2025-01-03 20:03:56 +07:00
6448a00271 Show local co-op icon in details page 2025-01-03 19:49:40 +07:00
68b29ecb50 Fix not applying class names to local co-op icon 2025-01-03 17:01:51 +07:00
90f89a0244 Show local co-op icon in game card 2025-01-02 21:39:27 +07:00
9862f794cf Update button's styling 2024-12-31 06:57:22 +07:00
e109cdec6a Attempt to fix problem with unadjustedMovement (#628) 2024-12-31 06:52:50 +07:00
40d1878fb2 Add icon to Better xCloud button 2024-12-29 15:41:35 +07:00
95f842d9f6 Update 02-feature-request.yml 2024-12-29 08:35:21 +07:00
127 changed files with 15574 additions and 19311 deletions

View File

@ -13,7 +13,7 @@ body:
- type: dropdown - type: dropdown
id: device_type id: device_type
attributes: attributes:
label: Device label: Device type
description: "Which device type is this feature for?" description: "Which device type is this feature for?"
options: options:
- All devices - All devices
@ -23,10 +23,20 @@ body:
multiple: false multiple: false
validations: validations:
required: true required: true
- type: input
id: device_name
attributes:
label: "Device"
description: "Name of the device"
placeholder: "e.g., Google Pixel 8"
validations:
required: true
- type: textarea - type: textarea
id: suggestion id: suggestion
attributes: attributes:
label: "Suggestion" label: "Suggestion"
description: "What do you want to suggest?" description: "What do you want to suggest? Include (mockup) screenshot if possible."
validations: validations:
required: true required: true

25
.github/workflows/stale.yaml vendored Normal file
View File

@ -0,0 +1,25 @@
name: 'Mark stale bug issues'
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # Runs daily at midnight UTC
jobs:
stale:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- uses: actions/stale@v9
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: |
This issue has been marked `stale` due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days.
close-issue-message: |
This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.
days-before-stale: 60
days-before-close: 30
stale-issue-label: 'stale'
only-issues: true
only-labels: 'bug'

7
.gitignore vendored
View File

@ -1,9 +1,4 @@
src/modules/patcher/patches/controller-customization.js src/modules/patcher/patches/*.js
src/modules/patcher/patches/expose-stream-session.js
src/modules/patcher/patches/local-co-op-enable.js
src/modules/patcher/patches/poll-gamepad.js
src/modules/patcher/patches/remote-play-keep-alive.js
src/modules/patcher/patches/vibration-adjust.js
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore # Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

View File

@ -3,6 +3,7 @@
"dist/**/*": true, "dist/**/*": true,
"src/modules/patcher/patches/controller-customization.js": true, "src/modules/patcher/patches/controller-customization.js": true,
"src/modules/patcher/patches/expose-stream-session.js": true, "src/modules/patcher/patches/expose-stream-session.js": true,
"src/modules/patcher/patches/game-card-icons.js": true,
"src/modules/patcher/patches/local-co-op-enable.js": true, "src/modules/patcher/patches/local-co-op-enable.js": true,
"src/modules/patcher/patches/poll-gamepad.js": true, "src/modules/patcher/patches/poll-gamepad.js": true,
"src/modules/patcher/patches/remote-play-keep-alive.js": true, "src/modules/patcher/patches/remote-play-keep-alive.js": true,

View File

@ -5,8 +5,9 @@ build_all () {
printf "\033c" printf "\033c"
# Build all variants # Build all variants
bun build.ts --version $1 --variant full bun build.ts --version $1 --variant full --pretty
bun build.ts --version $1 --variant lite bun build.ts --version $1 --variant full --meta
# bun build.ts --version $1 --variant lite
# Wait for key # Wait for key
read -p ">> Press Enter to build again..." read -p ">> Press Enter to build again..."

View File

@ -72,7 +72,7 @@ function removeComments(str: string): string {
return str; return str;
} }
function postProcess(str: string): string { function postProcess(str: string, pretty: boolean): string {
// Unescape unicode charaters // Unescape unicode charaters
str = unescape((str.replace(/\\u/g, '%u'))); str = unescape((str.replace(/\\u/g, '%u')));
// Replace \x00 to normal character // Replace \x00 to normal character
@ -127,9 +127,17 @@ function postProcess(str: string): string {
if (MINIFY_SYNTAX) { if (MINIFY_SYNTAX) {
str = minifyIfElse(str); str = minifyIfElse(str);
str = str.replaceAll(/\n(\s+)/g, (match, p1) => { str = str.replaceAll(/\n(\s+|\})/g, (match, p1) => {
const len = p1.length / 2; if (pretty) {
return '\n' + ' '.repeat(len); if (p1 === '}') {
return '\n}';
} else {
const len = p1.length / 2;
return '\n' + ' '.repeat(len);
}
} else {
return (p1 === '}') ? '}' : '';
}
}); });
} }
@ -184,7 +192,9 @@ async function buildPatches() {
}); });
} }
async function build(target: BuildTarget, version: string, variant: BuildVariant, config: any={}) { async function build(target: BuildTarget, params: { version: string, variant: BuildVariant, pretty: boolean, meta: boolean }, config: any={}) {
const { version, variant, pretty, meta } = params;
console.log('-- Target:', target); console.log('-- Target:', target);
const startTime = performance.now(); const startTime = performance.now();
@ -198,6 +208,9 @@ async function build(target: BuildTarget, version: string, variant: BuildVariant
} }
let outputMetaName = outputScriptName; let outputMetaName = outputScriptName;
if (pretty) {
outputScriptName += '.pretty';
}
outputScriptName += '.user.js'; outputScriptName += '.user.js';
outputMetaName += '.meta.js'; outputMetaName += '.meta.js';
@ -226,7 +239,7 @@ async function build(target: BuildTarget, version: string, variant: BuildVariant
const {path} = output.outputs[0]; const {path} = output.outputs[0];
// Get generated file // Get generated file
let result = postProcess(await readFile(path, 'utf-8')); let result = postProcess(await readFile(path, 'utf-8'), pretty);
// Replace [[VERSION]] with real value // Replace [[VERSION]] with real value
let scriptHeader: string; let scriptHeader: string;
@ -241,7 +254,7 @@ async function build(target: BuildTarget, version: string, variant: BuildVariant
await Bun.write(path, scriptHeader + result); await Bun.write(path, scriptHeader + result);
// Create meta file (don't build if it's beta version) // Create meta file (don't build if it's beta version)
if (!version.includes('beta') && variant === 'full') { if (meta && !version.includes('beta') && variant === 'full') {
await Bun.write(outDir + '/' + outputMetaName, txtMetaHeader.replace('[[VERSION]]', version)); await Bun.write(outDir + '/' + outputMetaName, txtMetaHeader.replace('[[VERSION]]', version));
} }
@ -274,6 +287,16 @@ const { values, positionals } = parseArgs({
type: 'string', type: 'string',
default: 'full', default: 'full',
}, },
pretty: {
type: 'boolean',
default: false,
},
meta: {
type: 'boolean',
default: false,
},
}, },
strict: true, strict: true,
allowPositionals: true, allowPositionals: true,
@ -281,6 +304,8 @@ const { values, positionals } = parseArgs({
values: { values: {
version: string, version: string,
variant: BuildVariant, variant: BuildVariant,
pretty: boolean,
meta: boolean,
}, },
positionals: string[], positionals: string[],
}; };
@ -299,7 +324,7 @@ async function main() {
const config = {}; const config = {};
console.log(`Building: VERSION=${values['version']}, VARIANT=${values['variant']}`); console.log(`Building: VERSION=${values['version']}, VARIANT=${values['variant']}`);
for (const target of buildTargets) { for (const target of buildTargets) {
await build(target, values['version']!!, values['variant'], config); await build(target, values, config);
} }
console.log('') console.log('')

69
bun.lock Executable file → Normal file
View File

@ -1,17 +1,18 @@
{ {
"lockfileVersion": 0, "lockfileVersion": 1,
"workspaces": { "workspaces": {
"": { "": {
"devDependencies": { "devDependencies": {
"@types/bun": "^1.1.14", "@types/bun": "latest",
"@types/node": "^22.10.2", "@types/node": "latest",
"@types/stylus": "^0.48.43", "@types/stylus": "latest",
"eslint": "^9.17.0", "@webgpu/types": "latest",
"eslint-plugin-compat": "^6.0.2", "eslint": "latest",
"stylus": "^0.64.0", "eslint-plugin-compat": "latest",
"stylus": "latest",
}, },
"peerDependencies": { "peerDependencies": {
"typescript": "^5.7.2", "typescript": "latest",
}, },
}, },
}, },
@ -22,17 +23,19 @@
"@eslint-community/regexpp": ["@eslint-community/regexpp@4.12.1", "", {}, "sha512-CCZCDJuduB9OUkFkY2IgppNZMi2lBQgD2qzwXkEia16cge2pijY/aXi96CJMquDMn3nJdlPV1A5KrJEXwfLNzQ=="], "@eslint-community/regexpp": ["@eslint-community/regexpp@4.12.1", "", {}, "sha512-CCZCDJuduB9OUkFkY2IgppNZMi2lBQgD2qzwXkEia16cge2pijY/aXi96CJMquDMn3nJdlPV1A5KrJEXwfLNzQ=="],
"@eslint/config-array": ["@eslint/config-array@0.19.0", "", { "dependencies": { "@eslint/object-schema": "^2.1.4", "debug": "^4.3.1", "minimatch": "^3.1.2" } }, "sha512-zdHg2FPIFNKPdcHWtiNT+jEFCHYVplAXRDlQDyqy0zGx/q2parwh7brGJSiTxRk/TSMkbM//zt/f5CHgyTyaSQ=="], "@eslint/config-array": ["@eslint/config-array@0.20.1", "", { "dependencies": { "@eslint/object-schema": "^2.1.6", "debug": "^4.3.1", "minimatch": "^3.1.2" } }, "sha512-OL0RJzC/CBzli0DrrR31qzj6d6i6Mm3HByuhflhl4LOBiWxN+3i6/t/ZQQNii4tjksXi8r2CRW1wMpWA2ULUEw=="],
"@eslint/core": ["@eslint/core@0.9.0", "", {}, "sha512-7ATR9F0e4W85D/0w7cU0SNj7qkAexMG+bAHEZOjo9akvGuhHE2m7umzWzfnpa0XAg5Kxc1BWmtPMV67jJ+9VUg=="], "@eslint/config-helpers": ["@eslint/config-helpers@0.2.1", "", {}, "sha512-RI17tsD2frtDu/3dmI7QRrD4bedNKPM08ziRYaC5AhkGrzIAJelm9kJU1TznK+apx6V+cqRz8tfpEeG3oIyjxw=="],
"@eslint/eslintrc": ["@eslint/eslintrc@3.2.0", "", { "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", "espree": "^10.0.1", "globals": "^14.0.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", "js-yaml": "^4.1.0", "minimatch": "^3.1.2", "strip-json-comments": "^3.1.1" } }, "sha512-grOjVNN8P3hjJn/eIETF1wwd12DdnwFDoyceUJLYYdkpbwq3nLi+4fqrTAONx7XDALqlL220wC/RHSC/QTI/0w=="], "@eslint/core": ["@eslint/core@0.14.0", "", { "dependencies": { "@types/json-schema": "^7.0.15" } }, "sha512-qIbV0/JZr7iSDjqAc60IqbLdsj9GDt16xQtWD+B78d/HAlvysGdZZ6rpJHGAc2T0FQx1X6thsSPdnoiGKdNtdg=="],
"@eslint/js": ["@eslint/js@9.17.0", "", {}, "sha512-Sxc4hqcs1kTu0iID3kcZDW3JHq2a77HO9P8CP6YEA/FpH3Ll8UXE2r/86Rz9YJLKme39S9vU5OWNjC6Xl0Cr3w=="], "@eslint/eslintrc": ["@eslint/eslintrc@3.3.1", "", { "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", "espree": "^10.0.1", "globals": "^14.0.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", "js-yaml": "^4.1.0", "minimatch": "^3.1.2", "strip-json-comments": "^3.1.1" } }, "sha512-gtF186CXhIl1p4pJNGZw8Yc6RlshoePRvE0X91oPGb3vZ8pM3qOS9W9NGPat9LziaBV7XrJWGylNQXkGcnM3IQ=="],
"@eslint/object-schema": ["@eslint/object-schema@2.1.4", "", {}, "sha512-BsWiH1yFGjXXS2yvrf5LyuoSIIbPrGUWob917o+BTKuZ7qJdxX8aJLRxs1fS9n6r7vESrq1OUqb68dANcFXuQQ=="], "@eslint/js": ["@eslint/js@9.29.0", "", {}, "sha512-3PIF4cBw/y+1u2EazflInpV+lYsSG0aByVIQzAgb1m1MhHFSbqTyNqtBKHgWf/9Ykud+DhILS9EGkmekVhbKoQ=="],
"@eslint/plugin-kit": ["@eslint/plugin-kit@0.2.3", "", { "dependencies": { "levn": "^0.4.1" } }, "sha512-2b/g5hRmpbb1o4GnTZax9N9m0FXzz9OV42ZzI4rDDMDuHUqigAiQCEWChBWCY4ztAGVRjoWT19v0yMmc5/L5kA=="], "@eslint/object-schema": ["@eslint/object-schema@2.1.6", "", {}, "sha512-RBMg5FRL0I0gs51M/guSAj5/e14VQ4tpZnQNWwuDT66P14I43ItmPfIZRhO9fUVIPOAQXU47atlywZ/czoqFPA=="],
"@eslint/plugin-kit": ["@eslint/plugin-kit@0.3.1", "", { "dependencies": { "@eslint/core": "^0.14.0", "levn": "^0.4.1" } }, "sha512-0J+zgWxHN+xXONWIyPWKFMgVuJoZuGiIFu8yxk7RJjxkzpGmyja5wRFqZIVtjDVOQpV+Rw0iOAjYPE2eQyjr0w=="],
"@humanfs/core": ["@humanfs/core@0.19.1", "", {}, "sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA=="], "@humanfs/core": ["@humanfs/core@0.19.1", "", {}, "sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA=="],
@ -40,7 +43,7 @@
"@humanwhocodes/module-importer": ["@humanwhocodes/module-importer@1.0.1", "", {}, "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA=="], "@humanwhocodes/module-importer": ["@humanwhocodes/module-importer@1.0.1", "", {}, "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA=="],
"@humanwhocodes/retry": ["@humanwhocodes/retry@0.4.1", "", {}, "sha512-c7hNEllBlenFTHBky65mhq8WD2kbN9Q6gk0bTk8lSBvc554jpXSkST1iePudpt7+A/AQvuHs9EMqjHDXMY1lrA=="], "@humanwhocodes/retry": ["@humanwhocodes/retry@0.4.2", "", {}, "sha512-xeO57FpIu4p1Ri3Jq/EXq4ClRm86dVF2z/+kvFnyqVYRavTZmaFaUBbWCOuuTh0o/g7DSsk6kc2vrS4Vl5oPOQ=="],
"@isaacs/cliui": ["@isaacs/cliui@8.0.2", "", { "dependencies": { "string-width": "^5.1.2", "string-width-cjs": "npm:string-width@^4.2.0", "strip-ansi": "^7.0.1", "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", "wrap-ansi": "^8.1.0", "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" } }, "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA=="], "@isaacs/cliui": ["@isaacs/cliui@8.0.2", "", { "dependencies": { "string-width": "^5.1.2", "string-width-cjs": "npm:string-width@^4.2.0", "strip-ansi": "^7.0.1", "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", "wrap-ansi": "^8.1.0", "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" } }, "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA=="],
@ -48,19 +51,19 @@
"@pkgjs/parseargs": ["@pkgjs/parseargs@0.11.0", "", {}, "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg=="], "@pkgjs/parseargs": ["@pkgjs/parseargs@0.11.0", "", {}, "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg=="],
"@types/bun": ["@types/bun@1.1.14", "", { "dependencies": { "bun-types": "1.1.37" } }, "sha512-opVYiFGtO2af0dnWBdZWlioLBoxSdDO5qokaazLhq8XQtGZbY4pY3/JxY8Zdf/hEwGubbp7ErZXoN1+h2yesxA=="], "@types/bun": ["@types/bun@1.2.17", "", { "dependencies": { "bun-types": "1.2.17" } }, "sha512-l/BYs/JYt+cXA/0+wUhulYJB6a6p//GTPiJ7nV+QHa8iiId4HZmnu/3J/SowP5g0rTiERY2kfGKXEK5Ehltx4Q=="],
"@types/estree": ["@types/estree@1.0.6", "", {}, "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw=="], "@types/estree": ["@types/estree@1.0.6", "", {}, "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw=="],
"@types/json-schema": ["@types/json-schema@7.0.15", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="], "@types/json-schema": ["@types/json-schema@7.0.15", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="],
"@types/node": ["@types/node@22.10.2", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ=="], "@types/node": ["@types/node@24.0.3", "", { "dependencies": { "undici-types": "~7.8.0" } }, "sha512-R4I/kzCYAdRLzfiCabn9hxWfbuHS573x+r0dJMkkzThEa7pbrcDWK+9zu3e7aBOouf+rQAciqPFMnxwr0aWgKg=="],
"@types/stylus": ["@types/stylus@0.48.43", "", { "dependencies": { "@types/node": "*" } }, "sha512-72dv/zdhuyXWVHUXG2VTPEQdOG+oen95/DNFx2aMFFaY6LoITI6PwEqf5x31JF49kp2w9hvUzkNfTGBIeg61LQ=="], "@types/stylus": ["@types/stylus@0.48.43", "", { "dependencies": { "@types/node": "*" } }, "sha512-72dv/zdhuyXWVHUXG2VTPEQdOG+oen95/DNFx2aMFFaY6LoITI6PwEqf5x31JF49kp2w9hvUzkNfTGBIeg61LQ=="],
"@types/ws": ["@types/ws@8.5.10", "", { "dependencies": { "@types/node": "*" } }, "sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A=="], "@webgpu/types": ["@webgpu/types@0.1.61", "", {}, "sha512-w2HbBvH+qO19SB5pJOJFKs533CdZqxl3fcGonqL321VHkW7W/iBo6H8bjDy6pr/+pbMwIu5dnuaAxH7NxBqUrQ=="],
"acorn": ["acorn@8.14.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA=="], "acorn": ["acorn@8.15.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg=="],
"acorn-jsx": ["acorn-jsx@5.3.2", "", { "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ=="], "acorn-jsx": ["acorn-jsx@5.3.2", "", { "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ=="],
@ -80,7 +83,7 @@
"browserslist": ["browserslist@4.24.3", "", { "dependencies": { "caniuse-lite": "^1.0.30001688", "electron-to-chromium": "^1.5.73", "node-releases": "^2.0.19", "update-browserslist-db": "^1.1.1" }, "bin": { "browserslist": "cli.js" } }, "sha512-1CPmv8iobE2fyRMV97dAcMVegvvWKxmq94hkLiAkUGwKVTyDLw33K+ZxiFrREKmmps4rIw6grcCFCnTMSZ/YiA=="], "browserslist": ["browserslist@4.24.3", "", { "dependencies": { "caniuse-lite": "^1.0.30001688", "electron-to-chromium": "^1.5.73", "node-releases": "^2.0.19", "update-browserslist-db": "^1.1.1" }, "bin": { "browserslist": "cli.js" } }, "sha512-1CPmv8iobE2fyRMV97dAcMVegvvWKxmq94hkLiAkUGwKVTyDLw33K+ZxiFrREKmmps4rIw6grcCFCnTMSZ/YiA=="],
"bun-types": ["bun-types@1.1.37", "", { "dependencies": { "@types/node": "~20.12.8", "@types/ws": "~8.5.10" } }, "sha512-C65lv6eBr3LPJWFZ2gswyrGZ82ljnH8flVE03xeXxKhi2ZGtFiO4isRKTKnitbSqtRAcaqYSR6djt1whI66AbA=="], "bun-types": ["bun-types@1.2.17", "", { "dependencies": { "@types/node": "*" } }, "sha512-ElC7ItwT3SCQwYZDYoAH+q6KT4Fxjl8DtZ6qDulUFBmXA8YB4xo+l54J9ZJN+k2pphfn9vk7kfubeSd5QfTVJQ=="],
"callsites": ["callsites@3.1.0", "", {}, "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ=="], "callsites": ["callsites@3.1.0", "", {}, "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ=="],
@ -110,15 +113,15 @@
"escape-string-regexp": ["escape-string-regexp@4.0.0", "", {}, "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA=="], "escape-string-regexp": ["escape-string-regexp@4.0.0", "", {}, "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA=="],
"eslint": ["eslint@9.17.0", "", { "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.12.1", "@eslint/config-array": "^0.19.0", "@eslint/core": "^0.9.0", "@eslint/eslintrc": "^3.2.0", "@eslint/js": "9.17.0", "@eslint/plugin-kit": "^0.2.3", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.4.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", "eslint-scope": "^8.2.0", "eslint-visitor-keys": "^4.2.0", "espree": "^10.3.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^8.0.0", "find-up": "^5.0.0", "glob-parent": "^6.0.2", "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3" }, "peerDependencies": { "jiti": "*" }, "optionalPeers": ["jiti"], "bin": { "eslint": "bin/eslint.js" } }, "sha512-evtlNcpJg+cZLcnVKwsai8fExnqjGPicK7gnUtlNuzu+Fv9bI0aLpND5T44VLQtoMEnI57LoXO9XAkIXwohKrA=="], "eslint": ["eslint@9.29.0", "", { "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.12.1", "@eslint/config-array": "^0.20.1", "@eslint/config-helpers": "^0.2.1", "@eslint/core": "^0.14.0", "@eslint/eslintrc": "^3.3.1", "@eslint/js": "9.29.0", "@eslint/plugin-kit": "^0.3.1", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.4.2", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", "eslint-scope": "^8.4.0", "eslint-visitor-keys": "^4.2.1", "espree": "^10.4.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^8.0.0", "find-up": "^5.0.0", "glob-parent": "^6.0.2", "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3" }, "peerDependencies": { "jiti": "*" }, "optionalPeers": ["jiti"], "bin": { "eslint": "bin/eslint.js" } }, "sha512-GsGizj2Y1rCWDu6XoEekL3RLilp0voSePurjZIkxL3wlm5o5EC9VpgaP7lrCvjnkuLvzFBQWB3vWB3K5KQTveQ=="],
"eslint-plugin-compat": ["eslint-plugin-compat@6.0.2", "", { "dependencies": { "@mdn/browser-compat-data": "^5.5.35", "ast-metadata-inferer": "^0.8.1", "browserslist": "^4.24.2", "caniuse-lite": "^1.0.30001687", "find-up": "^5.0.0", "globals": "^15.7.0", "lodash.memoize": "^4.1.2", "semver": "^7.6.2" }, "peerDependencies": { "eslint": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0" } }, "sha512-1ME+YfJjmOz1blH0nPZpHgjMGK4kjgEeoYqGCqoBPQ/mGu/dJzdoP0f1C8H2jcWZjzhZjAMccbM/VdXhPORIfA=="], "eslint-plugin-compat": ["eslint-plugin-compat@6.0.2", "", { "dependencies": { "@mdn/browser-compat-data": "^5.5.35", "ast-metadata-inferer": "^0.8.1", "browserslist": "^4.24.2", "caniuse-lite": "^1.0.30001687", "find-up": "^5.0.0", "globals": "^15.7.0", "lodash.memoize": "^4.1.2", "semver": "^7.6.2" }, "peerDependencies": { "eslint": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0" } }, "sha512-1ME+YfJjmOz1blH0nPZpHgjMGK4kjgEeoYqGCqoBPQ/mGu/dJzdoP0f1C8H2jcWZjzhZjAMccbM/VdXhPORIfA=="],
"eslint-scope": ["eslint-scope@8.2.0", "", { "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^5.2.0" } }, "sha512-PHlWUfG6lvPc3yvP5A4PNyBL1W8fkDUccmI21JUu/+GKZBoH/W5u6usENXUrWFRsyoW5ACUjFGgAFQp5gUlb/A=="], "eslint-scope": ["eslint-scope@8.4.0", "", { "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^5.2.0" } }, "sha512-sNXOfKCn74rt8RICKMvJS7XKV/Xk9kA7DyJr8mJik3S7Cwgy3qlkkmyS2uQB3jiJg6VNdZd/pDBJu0nvG2NlTg=="],
"eslint-visitor-keys": ["eslint-visitor-keys@4.2.0", "", {}, "sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw=="], "eslint-visitor-keys": ["eslint-visitor-keys@4.2.1", "", {}, "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ=="],
"espree": ["espree@10.3.0", "", { "dependencies": { "acorn": "^8.14.0", "acorn-jsx": "^5.3.2", "eslint-visitor-keys": "^4.2.0" } }, "sha512-0QYC8b24HWY8zjRnDTL6RiHfDbAWn63qb4LMj1Z4b076A4une81+z03Kg7l7mn/48PUTqoLptSXez8oknU8Clg=="], "espree": ["espree@10.4.0", "", { "dependencies": { "acorn": "^8.15.0", "acorn-jsx": "^5.3.2", "eslint-visitor-keys": "^4.2.1" } }, "sha512-j6PAQ2uUr79PZhBjP5C5fhl8e39FmRnOjsD5lGnWrFU8i2G776tBK7+nP8KuQUTTyAZUwfQqXAgrVH5MbH9CYQ=="],
"esquery": ["esquery@1.6.0", "", { "dependencies": { "estraverse": "^5.1.0" } }, "sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg=="], "esquery": ["esquery@1.6.0", "", { "dependencies": { "estraverse": "^5.1.0" } }, "sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg=="],
@ -250,9 +253,9 @@
"type-check": ["type-check@0.4.0", "", { "dependencies": { "prelude-ls": "^1.2.1" } }, "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew=="], "type-check": ["type-check@0.4.0", "", { "dependencies": { "prelude-ls": "^1.2.1" } }, "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew=="],
"typescript": ["typescript@5.7.2", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg=="], "typescript": ["typescript@5.8.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ=="],
"undici-types": ["undici-types@6.20.0", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="], "undici-types": ["undici-types@7.8.0", "", {}, "sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw=="],
"update-browserslist-db": ["update-browserslist-db@1.1.1", "", { "dependencies": { "escalade": "^3.2.0", "picocolors": "^1.1.0" }, "peerDependencies": { "browserslist": ">= 4.21.0" }, "bin": { "update-browserslist-db": "cli.js" } }, "sha512-R8UzCaa9Az+38REPiJ1tXlImTJXlVfgHZsglwBD/k6nj76ctsH1E3q4doGrukiLQd3sGQYu56r5+lo5r94l29A=="], "update-browserslist-db": ["update-browserslist-db@1.1.1", "", { "dependencies": { "escalade": "^3.2.0", "picocolors": "^1.1.0" }, "peerDependencies": { "browserslist": ">= 4.21.0" }, "bin": { "update-browserslist-db": "cli.js" } }, "sha512-R8UzCaa9Az+38REPiJ1tXlImTJXlVfgHZsglwBD/k6nj76ctsH1E3q4doGrukiLQd3sGQYu56r5+lo5r94l29A=="],
@ -270,17 +273,17 @@
"@eslint-community/eslint-utils/eslint-visitor-keys": ["eslint-visitor-keys@3.4.3", "", {}, "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag=="], "@eslint-community/eslint-utils/eslint-visitor-keys": ["eslint-visitor-keys@3.4.3", "", {}, "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag=="],
"@eslint/eslintrc/espree": ["espree@10.3.0", "", { "dependencies": { "acorn": "^8.14.0", "acorn-jsx": "^5.3.2", "eslint-visitor-keys": "^4.2.0" } }, "sha512-0QYC8b24HWY8zjRnDTL6RiHfDbAWn63qb4LMj1Z4b076A4une81+z03Kg7l7mn/48PUTqoLptSXez8oknU8Clg=="],
"@eslint/eslintrc/globals": ["globals@14.0.0", "", {}, "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ=="], "@eslint/eslintrc/globals": ["globals@14.0.0", "", {}, "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ=="],
"@humanfs/node/@humanwhocodes/retry": ["@humanwhocodes/retry@0.3.1", "", {}, "sha512-JBxkERygn7Bv/GbN5Rv8Ul6LVknS+5Bp6RgDC/O8gEBU/yeH5Ui5C/OlWrTb6qct7LjjfT6Re2NxB0ln0yYybA=="], "@humanfs/node/@humanwhocodes/retry": ["@humanwhocodes/retry@0.3.1", "", {}, "sha512-JBxkERygn7Bv/GbN5Rv8Ul6LVknS+5Bp6RgDC/O8gEBU/yeH5Ui5C/OlWrTb6qct7LjjfT6Re2NxB0ln0yYybA=="],
"@types/stylus/@types/node": ["@types/node@22.5.5", "", { "dependencies": { "undici-types": "~6.19.2" } }, "sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA=="], "@types/stylus/@types/node": ["@types/node@22.5.5", "", { "dependencies": { "undici-types": "~6.19.2" } }, "sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA=="],
"@types/ws/@types/node": ["@types/node@20.14.2", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-xyu6WAMVwv6AKFLB+e/7ySZVr/0zLCzOa7rSpq6jNwpqOrUbcACDWC+53d4n2QHOnDou0fbIsg8wZu/sxrnI4Q=="],
"ast-metadata-inferer/@mdn/browser-compat-data": ["@mdn/browser-compat-data@5.6.26", "", {}, "sha512-7NdgdOR7lkzrN70zGSULmrcvKyi/aJjpTJRCbuy8IZuHiLkPTvsr10jW0MJgWzK2l2wTmhdQvegTw6yNU5AVNQ=="], "ast-metadata-inferer/@mdn/browser-compat-data": ["@mdn/browser-compat-data@5.6.26", "", {}, "sha512-7NdgdOR7lkzrN70zGSULmrcvKyi/aJjpTJRCbuy8IZuHiLkPTvsr10jW0MJgWzK2l2wTmhdQvegTw6yNU5AVNQ=="],
"bun-types/@types/node": ["@types/node@20.12.14", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-scnD59RpYD91xngrQQLGkE+6UrHUPzeKZWhhjBSa3HSkwjbQc38+q3RoIVEwxQGRw3M+j5hpNAM+lgV3cVormg=="], "bun-types/@types/node": ["@types/node@22.15.32", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-3jigKqgSjsH6gYZv2nEsqdXfZqIFGAV36XYYjf9KGZ3PSG+IhLecqPnI310RvjutyMwifE2hhhNEklOUrvx/wA=="],
"foreground-child/cross-spawn": ["cross-spawn@7.0.3", "", { "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", "which": "^2.0.1" } }, "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w=="], "foreground-child/cross-spawn": ["cross-spawn@7.0.3", "", { "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", "which": "^2.0.1" } }, "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w=="],
@ -298,11 +301,13 @@
"wrap-ansi-cjs/strip-ansi": ["strip-ansi@6.0.1", "", { "dependencies": { "ansi-regex": "^5.0.1" } }, "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A=="], "wrap-ansi-cjs/strip-ansi": ["strip-ansi@6.0.1", "", { "dependencies": { "ansi-regex": "^5.0.1" } }, "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A=="],
"@eslint/eslintrc/espree/acorn": ["acorn@8.14.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA=="],
"@eslint/eslintrc/espree/eslint-visitor-keys": ["eslint-visitor-keys@4.2.0", "", {}, "sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw=="],
"@types/stylus/@types/node/undici-types": ["undici-types@6.19.8", "", {}, "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw=="], "@types/stylus/@types/node/undici-types": ["undici-types@6.19.8", "", {}, "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw=="],
"@types/ws/@types/node/undici-types": ["undici-types@5.26.5", "", {}, "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="], "bun-types/@types/node/undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="],
"bun-types/@types/node/undici-types": ["undici-types@5.26.5", "", {}, "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="],
"glob/minimatch/brace-expansion": ["brace-expansion@2.0.1", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA=="], "glob/minimatch/brace-expansion": ["brace-expansion@2.0.1", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA=="],

File diff suppressed because one or more lines are too long

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 6.1.1 // @version 6.7.0
// ==/UserScript== // ==/UserScript==

10461
dist/better-xcloud.pretty.user.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -10,14 +10,15 @@
"build": "build.ts" "build": "build.ts"
}, },
"devDependencies": { "devDependencies": {
"@types/bun": "^1.1.14", "@types/bun": "^1.2.17",
"@types/node": "^22.10.2", "@types/node": "^24.0.3",
"@types/stylus": "^0.48.43", "@types/stylus": "^0.48.43",
"eslint": "^9.17.0", "@webgpu/types": "^0.1.61",
"eslint": "^9.29.0",
"eslint-plugin-compat": "^6.0.2", "eslint-plugin-compat": "^6.0.2",
"stylus": "^0.64.0" "stylus": "^0.64.0"
}, },
"peerDependencies": { "peerDependencies": {
"typescript": "^5.7.2" "typescript": "^5.8.3"
} }
} }

View File

@ -24,8 +24,12 @@ How to:
const enabled = true; const enabled = true;
enabled && (window.BX_FLAGS = { enabled && (window.BX_FLAGS = {
// Toggle WebGPU Renderer
// https://github.com/redphx/better-xcloud/discussions/657
EnableWebGPURenderer: false,
/* /*
Add titleId of the game(s) you want to add here. Add titleId of the game(s) you want to test native M&KB support here.
Keep in mind: this method only works with some games. Keep in mind: this method only works with some games.
Example: Example:

View File

@ -37,6 +37,7 @@
&:disabled { &:disabled {
cursor: default; cursor: default;
background-color: unquote('rgb(var(--button-disabled-rgb))'); background-color: unquote('rgb(var(--button-disabled-rgb))');
opacity: 0.5;
} }
&.bx-ghost { &.bx-ghost {
@ -106,7 +107,6 @@
&.bx-frosted { &.bx-frosted {
--button-alpha: 0.2; --button-alpha: 0.2;
background-color: unquote('rgba(var(--button-rgb), var(--button-alpha))'); background-color: unquote('rgba(var(--button-rgb), var(--button-alpha))');
backdrop-filter: blur(4px) brightness(1.5);
&:not([disabled]):not(:active) { &:not([disabled]):not(:active) {
&:hover, &.bx-focusable:focus { &:hover, &.bx-focusable:focus {
@ -145,15 +145,16 @@
overflow: hidden; overflow: hidden;
white-space: nowrap; white-space: nowrap;
// Text with icon
&:not(:only-child) { &:not(:only-child) {
margin-left: 10px; margin-inline-start: 8px;
} }
} }
&.bx-button-multi-lines { &.bx-button-multi-lines {
height: auto; height: auto;
text-align: left; text-align: left;
padding: 10px 0; padding: 10px;
span { span {
line-height: unset; line-height: unset;

View File

@ -1,3 +1,12 @@
.bx-product-details-icons {
padding: 8px;
border-radius: 4px;
svg {
margin-right: 8px;
}
}
.bx-product-details-buttons { .bx-product-details-buttons {
display: flex; display: flex;
gap: 10px; gap: 10px;

View File

@ -78,7 +78,7 @@
padding: 0; padding: 0;
margin: 0; margin: 0;
flex: 1; flex: 1;
font-size: 1.2rem; font-size: 1.5rem;
font-weight: bold; font-weight: bold;
} }

View File

@ -1,42 +1,30 @@
.bx-remote-play-container {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
background: #1a1b1e;
border-radius: 10px;
width: 420px;
max-width: calc(100vw - 20px);
margin: 0 0 0 auto;
padding: 16px;
> .bx-button {
display: table;
margin: 0 0 0 auto;
}
}
.bx-remote-play-settings { .bx-remote-play-settings {
margin-bottom: 12px; margin-bottom: 12px;
padding-bottom: 12px; padding-bottom: 12px;
border-bottom: 1px solid #2d2d2d; border-bottom: 1px solid #2d2d2d;
display: flex;
flex-direction: column;
gap: 10px;
> div { > div {
display: flex; display: flex;
} min-height: 30px;
label { > label {
flex: 1; flex: 1;
font-size: 14px;
align-self: center;
p { p {
margin: 4px 0 0; margin: 4px 0 0;
padding: 0; padding: 0;
color: #888; color: #888;
font-size: 12px; font-size: 12px;
}
} }
} }
} }
.bx-remote-play-resolution { .bx-remote-play-resolution {
@ -55,31 +43,32 @@
.bx-remote-play-device-wrapper { .bx-remote-play-device-wrapper {
display: flex; display: flex;
margin-bottom: 12px; margin-bottom: 12px;
gap: 10px;
&:last-child { &:last-child {
margin-bottom: 2px; margin-bottom: 2px;
} }
} }
.bx-remote-play-device-info { .bx-remote-play-device-info {
flex: 1; flex: 1;
padding: 4px 0; align-self: center;
} }
.bx-remote-play-device-name { .bx-remote-play-device-name {
font-size: 20px; font-size: 14px;
font-weight: bold; font-weight: bold;
display: inline-block; display: inline-block;
vertical-align: middle; vertical-align: middle;
} }
.bx-remote-play-console-type { .bx-remote-play-console-type {
font-size: 12px; font-size: 8px;
background: #004c87; background: #004c87;
color: #fff; color: #fff;
display: inline-block; display: inline-block;
border-radius: 14px; border-radius: 8px;
padding: 2px 10px; padding: 2px 6px;
margin-left: 8px; margin-left: 8px;
vertical-align: middle; vertical-align: middle;
} }
@ -91,7 +80,6 @@
.bx-remote-play-connect-button { .bx-remote-play-connect-button {
min-height: 100%; min-height: 100%;
margin: 4px 0;
} }
.bx-remote-play-buttons { .bx-remote-play-buttons {

View File

@ -25,7 +25,7 @@ button_color(name, normal, hover, active, disabled)
button_color('default', #2d3036, #515863, #222428, #8e8e8e); button_color('default', #2d3036, #515863, #222428, #8e8e8e);
button_color('primary', #008746, #04b358, #044e2a, #448262); button_color('primary', #008746, #04b358, #044e2a, #448262);
button_color('warning', #c16e04, #fa9005, #965603, #a2816c); button_color('warning', #c16e04, #fa9005, #965603, #a2816c);
button_color('danger', #c10404, #e61d1d, #a26c6c, #df5656); button_color('danger', #c10404, #e61d1d, #a26c6c, #bd8282);
--bx-fullscreen-text-z-index: 9999; --bx-fullscreen-text-z-index: 9999;
--bx-toast-z-index: 6000; --bx-toast-z-index: 6000;
@ -47,11 +47,11 @@ button_color(name, normal, hover, active, disabled)
@font-face { @font-face {
font-family: 'promptfont'; font-family: 'promptfont';
src: url('https://redphx.github.io/better-xcloud/fonts/promptfont.otf'); src: url('https://redphx.github.io/better-xcloud/fonts/promptfont.otf');
unicode-range: U+2196-E011; unicode-range: U+2196-E011, U+27F6, U+FF31;
} }
/* Fix Stream menu buttons not hiding */ /* Fix Stream menu buttons not hiding */
div[class^=HUDButton-module__hiddenContainer] ~ div:not([class^=HUDButton-module__hiddenContainer]) { #StreamHud div[class^=HUDButton-module__hiddenContainer] ~ div:not([class^=HUDButton-module__hiddenContainer]) {
opacity: 0; opacity: 0;
pointer-events: none !important; pointer-events: none !important;
position: absolute; position: absolute;
@ -60,9 +60,35 @@ div[class^=HUDButton-module__hiddenContainer] ~ div:not([class^=HUDButton-module
} }
/* Remove the "Cloud Gaming" text in header when the screen is too small */ /* Remove the "Cloud Gaming" text in header when the screen is too small */
@media screen and (min-width: 641px) and (max-width: 767px) {
header {
button[class^="ExperienceDropdown-module__toggleButton"],
button[class^="XboxButton-module__headerXboxButton"] {
margin-right: 10px !important;
}
a[href="/play"],
button[class^="ExperienceDropdown-module__toggleButton"] {
> div {
> div {
font-size: 12px;
}
> svg {
width: 20px;
height: 20px;
}
}
}
}
}
@media screen and (max-width: 640px) { @media screen and (max-width: 640px) {
header a[href="/play"] { header {
display: none; a[href="/play"],
button[class^="ExperienceDropdown-module__toggleButton"] {
display: none;
}
} }
} }
@ -149,6 +175,10 @@ div[class^=HUDButton-module__hiddenContainer] ~ div:not([class^=HUDButton-module
font-family: var(--bx-normal-font) !important; font-family: var(--bx-normal-font) !important;
} }
.bx-frosted {
backdrop-filter: blur(4px) brightness(1.5);
}
select[multiple], select[multiple]:focus { select[multiple], select[multiple]:focus {
overflow: auto; overflow: auto;
border: none; border: none;
@ -178,26 +208,20 @@ select[multiple], select[multiple]:focus {
display: none; display: none;
} }
div[class*=NotFocusedDialog] { #game-stream {
position: absolute !important; div[class^=NotFocusedDialog] {
top: -9999px !important; position: absolute !important;
left: -9999px !important; top: -9999px !important;
width: 0px !important; left: -9999px !important;
height: 0px !important; width: 0px !important;
} height: 0px !important;
}
#game-stream video:not([src]) { video:not([src]) {
visibility: hidden; visibility: hidden;
}
/* Hide Controller icon in Game tiles */
div[class*=SupportedInputsBadge] {
&:not(:has(:nth-child(2))), svg:first-of-type {
display: none;
} }
} }
.bx-game-tile-wait-time { .bx-game-tile-wait-time {
position: absolute; position: absolute;
top: 0; top: 0;

View File

@ -98,10 +98,8 @@
tabsWidth = 48px; tabsWidth = 48px;
flex-direction: column; flex-direction: column;
padding: 10px;
margin-left: tabsWidth; margin-left: tabsWidth;
width: 450px; width: 450px;
max-width: calc(100vw - tabsWidth);
background: #1a1b1e; background: #1a1b1e;
color: #fff; color: #fff;
font-weight: 400; font-weight: 400;
@ -112,13 +110,6 @@
overflow: overlay; overflow: overlay;
z-index: 1; z-index: 1;
> div[data-tab-group=mkb] {
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;
}
.bx-top-buttons { .bx-top-buttons {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -164,7 +155,6 @@
display: flex; display: flex;
gap: 10px; gap: 10px;
padding: 16px 10px; padding: 16px 10px;
margin: 0;
background: #2a2a2a; background: #2a2a2a;
border-bottom: 1px solid #343434; border-bottom: 1px solid #343434;
@ -190,6 +180,12 @@
margin-bottom: 0 !important; margin-bottom: 0 !important;
flex: 1; flex: 1;
svg {
width: 20px;
height: 20px;
margin-inline-end: 8px;
}
+ * { + * {
margin: 0 0 0 auto; margin: 0 0 0 auto;
} }
@ -206,6 +202,10 @@
} }
} }
} }
&.bx-settings-important-row {
background: #733b00;
}
} }
.bx-settings-dialog-note { .bx-settings-dialog-note {
@ -278,7 +278,8 @@
color: #828282; color: #828282;
} }
.bx-settings-tab-contents { .bx-settings-tab-content {
padding: 10px;
border-radius-size = 6px; border-radius-size = 6px;
> div { > div {
@ -301,6 +302,15 @@
border-radius: border-radius-size; border-radius: border-radius-size;
} }
} }
&:not([data-game-id="-1"]) {
.bx-settings-row[data-override=true], .bx-settings-row:has(*[data-override=true]) {
border-left: 4px solid orange !important;
border-top-left-radius: 0 !important;
border-bottom-left-radius: 0 !important;
padding-left: 6px !important;
}
}
} }
.bx-suggest-toggler { .bx-suggest-toggler {
@ -527,3 +537,53 @@
flex: 1; flex: 1;
} }
} }
.bx-stream-settings-selection {
margin-bottom: 8px;
position: sticky;
z-index: 1000;
top: 0;
> div {
display: flex;
gap: 8px;
background: #222222;
padding: 10px;
border-bottom: 4px solid #353638;
box-shadow: 0 0 6px #000;
position: relative;
z-index: 1;
.bx-select {
flex: 1;
label {
font-weight: bold;
font-size: 1.1rem;
line-height: initial;
span {
line-height: initial;
}
}
.bx-select-indicators {
display: none;
}
}
}
p {
font-family: var(--bx-promptfont-font), var(--bx-normal-font);
margin: 0;
font-size: 13px;
background: #505050f2;
height: 25px;
line-height: 23px;
position: absolute;
bottom: -25px;
left: 0;
right: 0;
text-shadow: 0 1px #000;
}
}

View File

@ -1,4 +1,4 @@
div[class*=StreamMenu-module__menuContainer] > div[class*=Menu-module] { #game-stream div[class^=StreamMenu-module__menuContainer] > div[class^=Menu-module] {
overflow: visible; overflow: visible;
} }

View File

@ -5,8 +5,8 @@
left: 50%; left: 50%;
top: 24px; top: 24px;
transform: translate(-50%, 0); transform: translate(-50%, 0);
background: #000000; background: #212121;
border-radius: 16px; border-radius: 10px;
color: white; color: white;
z-index: var(--bx-toast-z-index); z-index: var(--bx-toast-z-index);
font-family: var(--bx-normal-font); font-family: var(--bx-normal-font);
@ -16,9 +16,10 @@
opacity: 0; opacity: 0;
overflow: clip; overflow: clip;
transition: opacity 0.2s ease-in; transition: opacity 0.2s ease-in;
box-shadow: 0 0 6px #000;
&.bx-show { &.bx-show {
opacity: 0.85; opacity: 0.95;
} }
&.bx-hide { &.bx-hide {
@ -39,8 +40,8 @@
font-size: 14px; font-size: 14px;
text-transform: uppercase; text-transform: uppercase;
display: inline-block; display: inline-block;
background: #515863; background: #fff;
padding: 12px 16px; padding: 12px 16px;
color: #fff; color: #212121;
white-space: pre; white-space: pre;
} }

View File

@ -7,6 +7,7 @@
// @license MIT // @license MIT
// @match https://www.xbox.com/*/play* // @match https://www.xbox.com/*/play*
// @match https://www.xbox.com/*/auth/msa?*loggedIn* // @match https://www.xbox.com/*/auth/msa?*loggedIn*
// @exclude https://www.xbox.com/*/xbox-game-pass/play-day-one
// @run-at document-start // @run-at document-start
// @grant none // @grant none
// @updateURL https://raw.githubusercontent.com/redphx/better-xcloud/typescript/dist/better-xcloud.meta.js // @updateURL https://raw.githubusercontent.com/redphx/better-xcloud/typescript/dist/better-xcloud.meta.js

View File

@ -0,0 +1,6 @@
<svg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='#fff' fill-rule='evenodd' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' viewBox='0 0 32 32'>
<path d='M1.681 16h28.638'/>
<path d='M16 30.319C8.145 30.319 1.681 23.855 1.681 16S8.145 1.681 16 1.681 30.319 8.145 30.319 16'/>
<path d='M16 30.319S10.034 25.546 10.034 16 16 1.681 16 1.681 21.966 6.454 21.966 16m-.238 8.592l-2.864 2.864 2.864 2.863'/>
<path d='M21.728 20.773h5.25a3.36 3.36 0 0 1 3.341 3.341 3.36 3.36 0 0 1-3.341 3.342h-8.114'/>
</svg>

After

Width:  |  Height:  |  Size: 545 B

View File

@ -0,0 +1,7 @@
<svg xmlns='http://www.w3.org/2000/svg' width='1em' height='1em' viewBox='0 0 32 32' fill-rule='evenodd' stroke-linecap='round' stroke-linejoin='round'>
<g>
<path d='M24.272 11.165h-3.294l-3.14 3.564c-.391.391-.922.611-1.476.611a2.1 2.1 0 0 1-2.087-2.088 2.09 2.09 0 0 1 .031-.362l1.22-6.274a3.89 3.89 0 0 1 3.81-3.206h6.57c1.834 0 3.439 1.573 3.833 3.295l1.205 6.185a2.09 2.09 0 0 1 .031.362 2.1 2.1 0 0 1-2.087 2.088c-.554 0-1.085-.22-1.476-.611l-3.14-3.564' fill='none' stroke='#fff' stroke-width='2'/>
<circle cx='22.625' cy='5.874' r='.879'/><path d='M11.022 24.415H7.728l-3.14 3.564c-.391.391-.922.611-1.476.611a2.1 2.1 0 0 1-2.087-2.088 2.09 2.09 0 0 1 .031-.362l1.22-6.274a3.89 3.89 0 0 1 3.81-3.206h6.57c1.834 0 3.439 1.573 3.833 3.295l1.205 6.185a2.09 2.09 0 0 1 .031.362 2.1 2.1 0 0 1-2.087 2.088c-.554 0-1.085-.22-1.476-.611l-3.14-3.564' fill='none' stroke='#fff' stroke-width='2'/>
<circle cx='9.375' cy='19.124' r='.879'/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 981 B

View File

@ -1,7 +1,9 @@
export enum GamePassCloudGallery { export enum GamePassCloudGallery {
ALL = '29a81209-df6f-41fd-a528-2ae6b91f719c', ALL = '29a81209-df6f-41fd-a528-2ae6b91f719c',
ALL_WITH_BYGO = 'ce573635-7c18-4d0c-9d68-90b932393470', ALL_WITH_BYGO = 'ce573635-7c18-4d0c-9d68-90b932393470',
LEAVING_SOON = '393f05bf-e596-4ef6-9487-6d4fa0eab987',
MOST_POPULAR = 'e7590b22-e299-44db-ae22-25c61405454c', MOST_POPULAR = 'e7590b22-e299-44db-ae22-25c61405454c',
NATIVE_MKB = '8fa264dd-124f-4af3-97e8-596fcdf4b486', NATIVE_MKB = '8fa264dd-124f-4af3-97e8-596fcdf4b486',
RECENTLY_ADDED = '44a55037-770f-4bbf-bde5-a9fa27dba1da',
TOUCH = '9c86f07a-f3e8-45ad-82a0-a1f759597059', TOUCH = '9c86f07a-f3e8-45ad-82a0-a1f759597059',
} }

View File

@ -37,131 +37,6 @@ export const enum MkbPresetKey {
} }
export type KeyCode =
| 'Backspace'
| 'Tab'
| 'Enter'
| 'ShiftLeft'
| 'ShiftRight'
| 'ControlLeft'
| 'ControlRight'
| 'AltLeft'
| 'AltRight'
| 'Pause'
| 'CapsLock'
| 'Escape'
| 'Space'
| 'PageUp'
| 'PageDown'
| 'End'
| 'Home'
| 'ArrowLeft'
| 'ArrowUp'
| 'ArrowRight'
| 'ArrowDown'
| 'PrintScreen'
| 'Insert'
| 'Delete'
| 'Digit0'
| 'Digit1'
| 'Digit2'
| 'Digit3'
| 'Digit4'
| 'Digit5'
| 'Digit6'
| 'Digit7'
| 'Digit8'
| 'Digit9'
| 'KeyA'
| 'KeyB'
| 'KeyC'
| 'KeyD'
| 'KeyE'
| 'KeyF'
| 'KeyG'
| 'KeyH'
| 'KeyI'
| 'KeyJ'
| 'KeyK'
| 'KeyL'
| 'KeyM'
| 'KeyN'
| 'KeyO'
| 'KeyP'
| 'KeyQ'
| 'KeyR'
| 'KeyS'
| 'KeyT'
| 'KeyU'
| 'KeyV'
| 'KeyW'
| 'KeyX'
| 'KeyY'
| 'KeyZ'
| 'MetaLeft'
| 'MetaRight'
| 'ContextMenu'
| 'F1'
| 'F2'
| 'F3'
| 'F4'
| 'F5'
| 'F6'
| 'F7'
| 'F8'
| 'F9'
| 'F10'
| 'F11'
| 'F12'
| 'NumLock'
| 'ScrollLock'
| 'AudioVolumeMute'
| 'AudioVolumeDown'
| 'AudioVolumeUp'
| 'MediaTrackNext'
| 'MediaTrackPrevious'
| 'MediaStop'
| 'MediaPlayPause'
| 'LaunchMail'
| 'LaunchMediaPlayer'
| 'LaunchApplication1'
| 'LaunchApplication2'
| 'Semicolon'
| 'Equal'
| 'Comma'
| 'Minus'
| 'Period'
| 'Slash'
| 'Backquote'
| 'BracketLeft'
| 'Backslash'
| 'BracketRight'
| 'Quote'
| 'Numpad0'
| 'Numpad1'
| 'Numpad2'
| 'Numpad3'
| 'Numpad4'
| 'Numpad5'
| 'Numpad6'
| 'Numpad7'
| 'Numpad8'
| 'Numpad9'
| 'NumpadMultiply'
| 'NumpadAdd'
| 'NumpadSubtract'
| 'NumpadDecimal'
| 'NumpadDivide';
export type KeyCodeExcludeModifiers = Exclude<KeyCode,
'ShiftLeft'
| 'ShiftRight'
| 'ControlLeft'
| 'ControlRight'
| 'AltLeft'
| 'AltRight'
>
export const enum KeyModifier { export const enum KeyModifier {
CTRL = 1, CTRL = 1,
ALT = 2, ALT = 2,

View File

@ -1,7 +1,9 @@
import type { BlockFeature, CodecProfile, DeviceVibrationMode, GameBarPosition, LoadingScreenRocket, NativeMkbMode, StreamPlayerType, StreamResolution, StreamStat, StreamStatPosition, StreamVideoProcessing, TouchControllerMode, TouchControllerStyleCustom, TouchControllerStyleStandard, UiLayout, UiSection, VideoPosition, VideoPowerPreference, VideoRatio } from "./pref-values" import type { BaseSettingsStorage } from "@/utils/settings-storages/base-settings-storage";
import type { BlockFeature, CodecProfile, DeviceVibrationMode, GameBarPosition, LoadingScreenRocket, NativeMkbMode, StreamPlayerType, StreamResolution, StreamStat, StreamStatPosition, StreamVideoProcessing, StreamVideoProcessingMode, TouchControllerMode, TouchControllerStyleCustom, TouchControllerStyleStandard, UiLayout, UiSection, UiTheme, VideoPosition, VideoPowerPreference, VideoRatio } from "./pref-values"
export const enum StorageKey { export const enum StorageKey {
GLOBAL = 'BetterXcloud', GLOBAL = 'BetterXcloud',
STREAM = 'BetterXcloud.Stream',
LOCALE = 'BetterXcloud.Locale', LOCALE = 'BetterXcloud.Locale',
LOCALE_TRANSLATIONS = 'BetterXcloud.Locale.Translations', LOCALE_TRANSLATIONS = 'BetterXcloud.Locale.Translations',
@ -12,10 +14,11 @@ export const enum StorageKey {
GH_PAGES_COMMIT_HASH = 'BetterXcloud.GhPages.CommitHash', GH_PAGES_COMMIT_HASH = 'BetterXcloud.GhPages.CommitHash',
LIST_CUSTOM_TOUCH_LAYOUTS = 'BetterXcloud.GhPages.CustomTouchLayouts', LIST_CUSTOM_TOUCH_LAYOUTS = 'BetterXcloud.GhPages.CustomTouchLayouts',
LIST_FORCE_NATIVE_MKB = 'BetterXcloud.GhPages.ForceNativeMkb', LIST_FORCE_NATIVE_MKB = 'BetterXcloud.GhPages.ForceNativeMkb',
LIST_LOCAL_CO_OP = 'BetterXcloud.GhPages.LocalCoOp',
} }
export const enum PrefKey { export const enum GlobalPref {
VERSION_LAST_CHECK = 'version.lastCheck', VERSION_LAST_CHECK = 'version.lastCheck',
VERSION_LATEST = 'version.latest', VERSION_LATEST = 'version.latest',
VERSION_CURRENT = 'version.current', VERSION_CURRENT = 'version.current',
@ -42,26 +45,11 @@ export const enum PrefKey {
GAME_BAR_POSITION = 'gameBar.position', GAME_BAR_POSITION = 'gameBar.position',
LOCAL_CO_OP_ENABLED = 'localCoOp.enabled',
DEVICE_VIBRATION_MODE = 'deviceVibration.mode',
DEVICE_VIBRATION_INTENSITY = 'deviceVibration.intensity',
CONTROLLER_POLLING_RATE = 'controller.pollingRate',
NATIVE_MKB_MODE = 'nativeMkb.mode', NATIVE_MKB_MODE = 'nativeMkb.mode',
NATIVE_MKB_FORCED_GAMES = 'nativeMkb.forcedGames', NATIVE_MKB_FORCED_GAMES = 'nativeMkb.forcedGames',
NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY = 'nativeMkb.scroll.sensitivityX',
NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY = 'nativeMkb.scroll.sensitivityY',
MKB_ENABLED = 'mkb.enabled', MKB_ENABLED = 'mkb.enabled',
MKB_HIDE_IDLE_CURSOR = 'mkb.cursor.hideIdle', MKB_HIDE_IDLE_CURSOR = 'mkb.cursor.hideIdle',
MKB_P1_MAPPING_PRESET_ID = 'mkb.p1.preset.mappingId',
MKB_P1_SLOT = 'mkb.p1.slot',
MKB_P2_MAPPING_PRESET_ID = 'mkb.p2.preset.mappingId',
MKB_P2_SLOT = 'mkb.p2.slot',
KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID = 'keyboardShortcuts.preset.inGameId',
SCREENSHOT_APPLY_FILTERS = 'screenshot.applyFilters', SCREENSHOT_APPLY_FILTERS = 'screenshot.applyFilters',
@ -85,10 +73,92 @@ export const enum PrefKey {
UI_SKIP_SPLASH_VIDEO = 'ui.splashVideo.skip', UI_SKIP_SPLASH_VIDEO = 'ui.splashVideo.skip',
UI_HIDE_SYSTEM_MENU_ICON = 'ui.systemMenu.hideHandle', UI_HIDE_SYSTEM_MENU_ICON = 'ui.systemMenu.hideHandle',
UI_REDUCE_ANIMATIONS = 'ui.reduceAnimations', UI_REDUCE_ANIMATIONS = 'ui.reduceAnimations',
UI_IMAGE_QUALITY = 'ui.imageQuality',
UI_THEME = 'ui.theme',
AUDIO_MIC_ON_PLAYING = 'audio.mic.onPlaying',
AUDIO_VOLUME_CONTROL_ENABLED = 'audio.volume.booster.enabled',
REMOTE_PLAY_STREAM_RESOLUTION = 'xhome.video.resolution',
REMOTE_PLAY_PREFER_IPV6 = 'xhome.ipv6.prefer',
GAME_FORTNITE_FORCE_CONSOLE = 'game.fortnite.forceConsole',
}
export type GlobalPrefTypeMap = {
[GlobalPref.AUDIO_MIC_ON_PLAYING]: boolean;
[GlobalPref.AUDIO_VOLUME_CONTROL_ENABLED]: boolean;
[GlobalPref.BLOCK_FEATURES]: BlockFeature[];
[GlobalPref.BLOCK_TRACKING]: boolean;
[GlobalPref.GAME_BAR_POSITION]: GameBarPosition;
[GlobalPref.GAME_FORTNITE_FORCE_CONSOLE]: boolean;
[GlobalPref.LOADING_SCREEN_GAME_ART]: boolean;
[GlobalPref.LOADING_SCREEN_ROCKET]: LoadingScreenRocket;
[GlobalPref.LOADING_SCREEN_SHOW_WAIT_TIME]: boolean;
[GlobalPref.MKB_ENABLED]: boolean;
[GlobalPref.MKB_HIDE_IDLE_CURSOR]: boolean;
[GlobalPref.NATIVE_MKB_FORCED_GAMES]: string[];
[GlobalPref.NATIVE_MKB_MODE]: NativeMkbMode;
[GlobalPref.REMOTE_PLAY_STREAM_RESOLUTION]: StreamResolution;
[GlobalPref.REMOTE_PLAY_PREFER_IPV6]: boolean;
[GlobalPref.SCREENSHOT_APPLY_FILTERS]: boolean;
[GlobalPref.SERVER_BYPASS_RESTRICTION]: string;
[GlobalPref.SERVER_PREFER_IPV6]: boolean;
[GlobalPref.SERVER_REGION]: string;
[GlobalPref.STREAM_CODEC_PROFILE]: CodecProfile;
[GlobalPref.STREAM_COMBINE_SOURCES]: boolean;
[GlobalPref.STREAM_MAX_VIDEO_BITRATE]: number;
[GlobalPref.STREAM_PREFERRED_LOCALE]: StreamPreferredLocale;
[GlobalPref.STREAM_RESOLUTION]: StreamResolution;
[GlobalPref.TOUCH_CONTROLLER_AUTO_OFF]: boolean;
[GlobalPref.TOUCH_CONTROLLER_DEFAULT_OPACITY]: number;
[GlobalPref.TOUCH_CONTROLLER_MODE]: TouchControllerMode;
[GlobalPref.TOUCH_CONTROLLER_STYLE_CUSTOM]: TouchControllerStyleCustom;
[GlobalPref.TOUCH_CONTROLLER_STYLE_STANDARD]: TouchControllerStyleStandard;
[GlobalPref.UI_CONTROLLER_FRIENDLY]: boolean;
[GlobalPref.UI_CONTROLLER_SHOW_STATUS]: boolean;
[GlobalPref.UI_DISABLE_FEEDBACK_DIALOG]: boolean;
[GlobalPref.UI_GAME_CARD_SHOW_WAIT_TIME]: boolean;
[GlobalPref.UI_HIDE_SECTIONS]: UiSection[];
[GlobalPref.UI_HIDE_SYSTEM_MENU_ICON]: boolean;
[GlobalPref.UI_IMAGE_QUALITY]: number;
[GlobalPref.UI_LAYOUT]: UiLayout;
[GlobalPref.UI_REDUCE_ANIMATIONS]: boolean;
[GlobalPref.UI_SCROLLBAR_HIDE]: boolean;
[GlobalPref.UI_SIMPLIFY_STREAM_MENU]: boolean;
[GlobalPref.UI_SKIP_SPLASH_VIDEO]: boolean;
[GlobalPref.UI_THEME]: UiTheme;
[GlobalPref.VERSION_CURRENT]: string;
[GlobalPref.VERSION_LAST_CHECK]: number;
[GlobalPref.VERSION_LATEST]: string;
[GlobalPref.SCRIPT_LOCALE]: string;
[GlobalPref.USER_AGENT_PROFILE]: string;
}
export const enum StreamPref {
LOCAL_CO_OP_ENABLED = 'localCoOp.enabled',
DEVICE_VIBRATION_MODE = 'deviceVibration.mode',
DEVICE_VIBRATION_INTENSITY = 'deviceVibration.intensity',
CONTROLLER_POLLING_RATE = 'controller.pollingRate',
CONTROLLER_SETTINGS = 'controller.settings',
NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY = 'nativeMkb.scroll.sensitivityX',
NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY = 'nativeMkb.scroll.sensitivityY',
MKB_P1_MAPPING_PRESET_ID = 'mkb.p1.preset.mappingId',
MKB_P1_SLOT = 'mkb.p1.slot',
MKB_P2_MAPPING_PRESET_ID = 'mkb.p2.preset.mappingId',
MKB_P2_SLOT = 'mkb.p2.slot',
KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID = 'keyboardShortcuts.preset.inGameId',
VIDEO_PLAYER_TYPE = 'video.player.type', VIDEO_PLAYER_TYPE = 'video.player.type',
VIDEO_POWER_PREFERENCE = 'video.player.powerPreference', VIDEO_POWER_PREFERENCE = 'video.player.powerPreference',
VIDEO_PROCESSING = 'video.processing', VIDEO_PROCESSING = 'video.processing',
VIDEO_PROCESSING_MODE = 'video.processing.mode',
VIDEO_SHARPNESS = 'video.processing.sharpness', VIDEO_SHARPNESS = 'video.processing.sharpness',
VIDEO_MAX_FPS = 'video.maxFps', VIDEO_MAX_FPS = 'video.maxFps',
VIDEO_RATIO = 'video.ratio', VIDEO_RATIO = 'video.ratio',
@ -97,8 +167,6 @@ export const enum PrefKey {
VIDEO_SATURATION = 'video.saturation', VIDEO_SATURATION = 'video.saturation',
VIDEO_POSITION = 'video.position', VIDEO_POSITION = 'video.position',
AUDIO_MIC_ON_PLAYING = 'audio.mic.onPlaying',
AUDIO_VOLUME_CONTROL_ENABLED = 'audio.volume.booster.enabled',
AUDIO_VOLUME = 'audio.volume', AUDIO_VOLUME = 'audio.volume',
STATS_ITEMS = 'stats.items', STATS_ITEMS = 'stats.items',
@ -109,84 +177,140 @@ export const enum PrefKey {
STATS_OPACITY_ALL = 'stats.opacity.all', STATS_OPACITY_ALL = 'stats.opacity.all',
STATS_OPACITY_BACKGROUND = 'stats.opacity.background', STATS_OPACITY_BACKGROUND = 'stats.opacity.background',
STATS_CONDITIONAL_FORMATTING = 'stats.colors', STATS_CONDITIONAL_FORMATTING = 'stats.colors',
REMOTE_PLAY_ENABLED = 'xhome.enabled',
REMOTE_PLAY_STREAM_RESOLUTION = 'xhome.video.resolution',
GAME_FORTNITE_FORCE_CONSOLE = 'game.fortnite.forceConsole',
} }
export type StreamPrefTypeMap = {
export type PrefTypeMap = { [StreamPref.AUDIO_VOLUME]: number;
[PrefKey.AUDIO_MIC_ON_PLAYING]: boolean, [StreamPref.CONTROLLER_POLLING_RATE]: number;
[PrefKey.AUDIO_VOLUME_CONTROL_ENABLED]: boolean, [StreamPref.CONTROLLER_SETTINGS]: ControllerSettings;
[PrefKey.AUDIO_VOLUME]: number, [StreamPref.DEVICE_VIBRATION_INTENSITY]: number;
[PrefKey.BLOCK_FEATURES]: BlockFeature[], [StreamPref.DEVICE_VIBRATION_MODE]: DeviceVibrationMode;
[PrefKey.BLOCK_TRACKING]: boolean, [StreamPref.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID]: number;
[PrefKey.CONTROLLER_POLLING_RATE]: number, [StreamPref.LOCAL_CO_OP_ENABLED]: boolean;
[PrefKey.DEVICE_VIBRATION_INTENSITY]: number, [StreamPref.MKB_P1_MAPPING_PRESET_ID]: number;
[PrefKey.DEVICE_VIBRATION_MODE]: DeviceVibrationMode, [StreamPref.MKB_P1_SLOT]: number;
[PrefKey.GAME_BAR_POSITION]: GameBarPosition, [StreamPref.MKB_P2_MAPPING_PRESET_ID]: number;
[PrefKey.GAME_FORTNITE_FORCE_CONSOLE]: boolean, [StreamPref.MKB_P2_SLOT]: number;
[PrefKey.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID]: number, [StreamPref.NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY]: number;
[PrefKey.LOADING_SCREEN_GAME_ART]: boolean, [StreamPref.NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY]: number;
[PrefKey.LOADING_SCREEN_ROCKET]: LoadingScreenRocket, [StreamPref.STATS_CONDITIONAL_FORMATTING]: boolean;
[PrefKey.LOADING_SCREEN_SHOW_WAIT_TIME]: boolean, [StreamPref.STATS_ITEMS]: StreamStat[];
[PrefKey.LOCAL_CO_OP_ENABLED]: boolean, [StreamPref.STATS_OPACITY_ALL]: number;
[PrefKey.MKB_ENABLED]: boolean, [StreamPref.STATS_OPACITY_BACKGROUND]: number;
[PrefKey.MKB_HIDE_IDLE_CURSOR]: boolean, [StreamPref.STATS_POSITION]: StreamStatPosition;
[PrefKey.MKB_P1_MAPPING_PRESET_ID]: number, [StreamPref.STATS_QUICK_GLANCE_ENABLED]: boolean;
[PrefKey.MKB_P1_SLOT]: number, [StreamPref.STATS_SHOW_WHEN_PLAYING]: boolean;
[PrefKey.NATIVE_MKB_FORCED_GAMES]: string[], [StreamPref.STATS_TEXT_SIZE]: string;
[PrefKey.NATIVE_MKB_MODE]: NativeMkbMode, [StreamPref.VIDEO_BRIGHTNESS]: number;
[PrefKey.NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY]: number, [StreamPref.VIDEO_CONTRAST]: number;
[PrefKey.NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY]: number, [StreamPref.VIDEO_MAX_FPS]: number;
[PrefKey.REMOTE_PLAY_ENABLED]: boolean, [StreamPref.VIDEO_PLAYER_TYPE]: StreamPlayerType;
[PrefKey.REMOTE_PLAY_STREAM_RESOLUTION]: StreamResolution, [StreamPref.VIDEO_POSITION]: VideoPosition;
[PrefKey.SCREENSHOT_APPLY_FILTERS]: boolean, [StreamPref.VIDEO_POWER_PREFERENCE]: VideoPowerPreference;
[PrefKey.SERVER_BYPASS_RESTRICTION]: string, [StreamPref.VIDEO_PROCESSING]: StreamVideoProcessing;
[PrefKey.SERVER_PREFER_IPV6]: boolean, [StreamPref.VIDEO_PROCESSING_MODE]: StreamVideoProcessingMode;
[PrefKey.SERVER_REGION]: string, [StreamPref.VIDEO_RATIO]: VideoRatio;
[PrefKey.STATS_CONDITIONAL_FORMATTING]: boolean, [StreamPref.VIDEO_SATURATION]: number;
[PrefKey.STATS_ITEMS]: StreamStat[], [StreamPref.VIDEO_SHARPNESS]: number;
[PrefKey.STATS_OPACITY_ALL]: number,
[PrefKey.STATS_OPACITY_BACKGROUND]: number,
[PrefKey.STATS_POSITION]: StreamStatPosition,
[PrefKey.STATS_QUICK_GLANCE_ENABLED]: boolean,
[PrefKey.STATS_SHOW_WHEN_PLAYING]: boolean,
[PrefKey.STATS_TEXT_SIZE]: string,
[PrefKey.STREAM_CODEC_PROFILE]: CodecProfile,
[PrefKey.STREAM_COMBINE_SOURCES]: boolean,
[PrefKey.STREAM_MAX_VIDEO_BITRATE]: number,
[PrefKey.STREAM_PREFERRED_LOCALE]: StreamPreferredLocale,
[PrefKey.STREAM_RESOLUTION]: StreamResolution,
[PrefKey.TOUCH_CONTROLLER_AUTO_OFF]: boolean,
[PrefKey.TOUCH_CONTROLLER_DEFAULT_OPACITY]: number,
[PrefKey.TOUCH_CONTROLLER_MODE]: TouchControllerMode,
[PrefKey.TOUCH_CONTROLLER_STYLE_CUSTOM]: TouchControllerStyleCustom,
[PrefKey.TOUCH_CONTROLLER_STYLE_STANDARD]: TouchControllerStyleStandard,
[PrefKey.UI_CONTROLLER_FRIENDLY]: boolean,
[PrefKey.UI_CONTROLLER_SHOW_STATUS]: boolean,
[PrefKey.UI_DISABLE_FEEDBACK_DIALOG]: boolean,
[PrefKey.UI_GAME_CARD_SHOW_WAIT_TIME]: boolean,
[PrefKey.UI_HIDE_SECTIONS]: UiSection[],
[PrefKey.UI_HIDE_SYSTEM_MENU_ICON]: boolean,
[PrefKey.UI_LAYOUT]: UiLayout,
[PrefKey.UI_REDUCE_ANIMATIONS]: boolean,
[PrefKey.UI_SCROLLBAR_HIDE]: boolean,
[PrefKey.UI_SIMPLIFY_STREAM_MENU]: boolean,
[PrefKey.UI_SKIP_SPLASH_VIDEO]: boolean,
[PrefKey.VERSION_CURRENT]: string,
[PrefKey.VERSION_LAST_CHECK]: number,
[PrefKey.VERSION_LATEST]: string,
[PrefKey.VIDEO_BRIGHTNESS]: number,
[PrefKey.VIDEO_CONTRAST]: number,
[PrefKey.VIDEO_MAX_FPS]: number,
[PrefKey.VIDEO_PLAYER_TYPE]: StreamPlayerType,
[PrefKey.VIDEO_POSITION]: VideoPosition,
[PrefKey.VIDEO_POWER_PREFERENCE]: VideoPowerPreference,
[PrefKey.VIDEO_PROCESSING]: StreamVideoProcessing,
[PrefKey.VIDEO_RATIO]: VideoRatio,
[PrefKey.VIDEO_SATURATION]: number,
[PrefKey.VIDEO_SHARPNESS]: number,
} }
export type AllPrefs = GlobalPref | StreamPref;
export const ALL_PREFS: {
global: GlobalPref[],
stream: StreamPref[],
} = {
global: [
GlobalPref.AUDIO_MIC_ON_PLAYING,
GlobalPref.AUDIO_VOLUME_CONTROL_ENABLED,
GlobalPref.BLOCK_FEATURES,
GlobalPref.BLOCK_TRACKING,
GlobalPref.GAME_BAR_POSITION,
GlobalPref.GAME_FORTNITE_FORCE_CONSOLE,
GlobalPref.LOADING_SCREEN_GAME_ART,
GlobalPref.LOADING_SCREEN_ROCKET,
GlobalPref.LOADING_SCREEN_SHOW_WAIT_TIME,
GlobalPref.MKB_ENABLED,
GlobalPref.MKB_HIDE_IDLE_CURSOR,
GlobalPref.NATIVE_MKB_FORCED_GAMES,
GlobalPref.NATIVE_MKB_MODE,
GlobalPref.REMOTE_PLAY_STREAM_RESOLUTION,
GlobalPref.REMOTE_PLAY_PREFER_IPV6,
GlobalPref.SCREENSHOT_APPLY_FILTERS,
GlobalPref.SERVER_BYPASS_RESTRICTION,
GlobalPref.SERVER_PREFER_IPV6,
GlobalPref.SERVER_REGION,
GlobalPref.STREAM_CODEC_PROFILE,
GlobalPref.STREAM_COMBINE_SOURCES,
GlobalPref.STREAM_MAX_VIDEO_BITRATE,
GlobalPref.STREAM_PREFERRED_LOCALE,
GlobalPref.STREAM_RESOLUTION,
GlobalPref.TOUCH_CONTROLLER_AUTO_OFF,
GlobalPref.TOUCH_CONTROLLER_DEFAULT_OPACITY,
GlobalPref.TOUCH_CONTROLLER_MODE,
GlobalPref.TOUCH_CONTROLLER_STYLE_CUSTOM,
GlobalPref.TOUCH_CONTROLLER_STYLE_STANDARD,
GlobalPref.UI_CONTROLLER_FRIENDLY,
GlobalPref.UI_CONTROLLER_SHOW_STATUS,
GlobalPref.UI_DISABLE_FEEDBACK_DIALOG,
GlobalPref.UI_GAME_CARD_SHOW_WAIT_TIME,
GlobalPref.UI_HIDE_SECTIONS,
GlobalPref.UI_HIDE_SYSTEM_MENU_ICON,
GlobalPref.UI_IMAGE_QUALITY,
GlobalPref.UI_LAYOUT,
GlobalPref.UI_REDUCE_ANIMATIONS,
GlobalPref.UI_SCROLLBAR_HIDE,
GlobalPref.UI_SIMPLIFY_STREAM_MENU,
GlobalPref.UI_SKIP_SPLASH_VIDEO,
GlobalPref.UI_THEME,
GlobalPref.VERSION_CURRENT,
GlobalPref.VERSION_LAST_CHECK,
GlobalPref.VERSION_LATEST,
GlobalPref.SCRIPT_LOCALE,
GlobalPref.USER_AGENT_PROFILE,
],
stream: [
StreamPref.AUDIO_VOLUME,
StreamPref.CONTROLLER_POLLING_RATE,
StreamPref.CONTROLLER_SETTINGS,
StreamPref.DEVICE_VIBRATION_INTENSITY,
StreamPref.DEVICE_VIBRATION_MODE,
StreamPref.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID,
StreamPref.LOCAL_CO_OP_ENABLED,
StreamPref.MKB_P1_MAPPING_PRESET_ID,
StreamPref.MKB_P1_SLOT,
StreamPref.MKB_P2_MAPPING_PRESET_ID,
StreamPref.MKB_P2_SLOT,
StreamPref.NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY,
StreamPref.NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY,
StreamPref.STATS_CONDITIONAL_FORMATTING,
StreamPref.STATS_ITEMS,
StreamPref.STATS_OPACITY_ALL,
StreamPref.STATS_OPACITY_BACKGROUND,
StreamPref.STATS_POSITION,
StreamPref.STATS_QUICK_GLANCE_ENABLED,
StreamPref.STATS_SHOW_WHEN_PLAYING,
StreamPref.STATS_TEXT_SIZE,
StreamPref.VIDEO_BRIGHTNESS,
StreamPref.VIDEO_CONTRAST,
StreamPref.VIDEO_MAX_FPS,
StreamPref.VIDEO_PLAYER_TYPE,
StreamPref.VIDEO_POSITION,
StreamPref.VIDEO_POWER_PREFERENCE,
StreamPref.VIDEO_PROCESSING,
StreamPref.VIDEO_PROCESSING_MODE,
StreamPref.VIDEO_RATIO,
StreamPref.VIDEO_SATURATION,
StreamPref.VIDEO_SHARPNESS,
],
} as const;
export type AnySettingsStorage = BaseSettingsStorage<GlobalPref> | BaseSettingsStorage<StreamPref>;
export type AnyPref = GlobalPref | StreamPref;
export type PrefTypeMap<Key> = Key extends GlobalPref
? GlobalPrefTypeMap
: Key extends StreamPref
? StreamPrefTypeMap
: never;

View File

@ -6,6 +6,9 @@ export const enum UiSection {
NEWS = 'news', NEWS = 'news',
TOUCH = 'touch', TOUCH = 'touch',
BOYG = 'byog', BOYG = 'byog',
RECENTLY_ADDED = 'recently-added',
LEAVING_SOON = 'leaving-soon',
GENRES = 'genres',
} }
export const enum GameBarPosition { export const enum GameBarPosition {
@ -92,10 +95,13 @@ export const enum StreamStatPosition {
export const enum VideoRatio { export const enum VideoRatio {
'16:9' = '16:9', '16:9' = '16:9',
'18:9' = '18:9',
'21:9' = '21:9',
'16:10' = '16:10', '16:10' = '16:10',
'18:9' = '18:9',
'20:9' = '20:9',
'21:9' = '21:9',
'3:2' = '3:2',
'4:3' = '4:3', '4:3' = '4:3',
'5:4' = '5:4',
FILL = 'fill', FILL = 'fill',
} }
@ -116,6 +122,7 @@ export const enum VideoPowerPreference {
export const enum StreamPlayerType { export const enum StreamPlayerType {
VIDEO = 'default', VIDEO = 'default',
WEBGL2 = 'webgl2', WEBGL2 = 'webgl2',
WEBGPU = 'webgpu',
} }
export const enum StreamVideoProcessing { export const enum StreamVideoProcessing {
@ -123,10 +130,21 @@ export const enum StreamVideoProcessing {
CAS = 'cas', CAS = 'cas',
} }
export const enum StreamVideoProcessingMode {
QUALITY = 'quality',
PERFORMANCE = 'performance',
}
export const enum BlockFeature { export const enum BlockFeature {
CHAT = 'chat', CHAT = 'chat',
FRIENDS = 'friends', FRIENDS = 'friends',
BYOG = 'byog', BYOG = 'byog',
NOTIFICATIONS_INVITES = 'notifications-invites', NOTIFICATIONS_INVITES = 'notifications-invites',
NOTIFICATIONS_ACHIEVEMENTS = 'notifications-achievements', NOTIFICATIONS_ACHIEVEMENTS = 'notifications-achievements',
REMOTE_PLAY = 'remote-play',
}
export const enum UiTheme {
DEFAULT = 'default',
DARK_OLED = 'dark-oled',
} }

View File

@ -32,19 +32,25 @@ import { HeaderSection } from "./modules/ui/header";
import { GameTile } from "./modules/ui/game-tile"; import { GameTile } from "./modules/ui/game-tile";
import { ProductDetailsPage } from "./modules/ui/product-details"; 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 { GlobalPref, StreamPref } from "./enums/pref-keys";
import { getPref } from "./utils/settings-storages/global-settings-storage";
import { SettingsDialog } from "./modules/ui/dialog/settings-dialog";
import { StreamUiHandler } from "./modules/stream/stream-ui";
import { UserAgent } from "./utils/user-agent"; import { UserAgent } from "./utils/user-agent";
import { XboxApi } from "./utils/xbox-api"; import { XboxApi } from "./utils/xbox-api";
import { StreamStatsCollector } from "./utils/stream-stats-collector"; import { StreamStatsCollector } from "./utils/stream-stats-collector";
import { RootDialogObserver } from "./utils/root-dialog-observer";
import { StreamSettings } from "./utils/stream-settings"; import { StreamSettings } from "./utils/stream-settings";
import { KeyboardShortcutHandler } from "./modules/mkb/keyboard-shortcut-handler"; import { KeyboardShortcutHandler } from "./modules/mkb/keyboard-shortcut-handler";
import { GhPagesUtils } from "./utils/gh-pages"; import { GhPagesUtils } from "./utils/gh-pages";
import { DeviceVibrationManager } from "./modules/device-vibration-manager"; import { DeviceVibrationManager } from "./modules/device-vibration-manager";
import { BxEventBus } from "./utils/bx-event-bus"; import { BxEventBus } from "./utils/bx-event-bus";
import { getGlobalPref, getStreamPref } from "./utils/pref-utils";
import { SettingsManager } from "./modules/settings-manager";
import { Toast } from "./utils/toast";
import { WebGPUPlayer } from "./modules/player/webgpu/webgpu-player";
import { StreamUiHandler } from "./modules/stream/stream-ui";
import { TrueAchievements } from "./utils/true-achievements";
import { localRedirect } from "./modules/ui/ui";
import { handleDeepLink } from "./utils/deep-link";
SettingsManager.getInstance();
// Handle login page // Handle login page
if (window.location.pathname.includes('/auth/msa')) { if (window.location.pathname.includes('/auth/msa')) {
@ -143,6 +149,12 @@ if (isFullVersion() && BX_FLAGS.SafariWorkaround && document.readyState !== 'loa
throw new Error('[Better xCloud] Executing workaround for Safari'); throw new Error('[Better xCloud] Executing workaround for Safari');
} }
// Make sure it only run on /play
if (!window.location.pathname.match(/^\/[a-zA-Z]{2}-[a-zA-Z]{2}\/play/)) {
throw new Error('[Better xCloud] Not xCloud page');
}
window.addEventListener('load', e => { window.addEventListener('load', e => {
// Automatically reload the page when running into the "We are sorry..." error message // Automatically reload the page when running into the "We are sorry..." error message
window.setTimeout(() => { window.setTimeout(() => {
@ -164,21 +176,34 @@ document.addEventListener('readystatechange', e => {
if (STATES.isSignedIn) { if (STATES.isSignedIn) {
// Preload Remote Play // Preload Remote Play
RemotePlayManager.getInstance()?.initialize(); if (isFullVersion()) {
RemotePlayManager.getInstance()?.initialize();
}
} else { } else {
// Show Settings button in the header when not signed in // Show Settings button in the header when not signed in
window.setTimeout(HeaderSection.watchHeader, 2000); // window.setTimeout(HeaderSection.watchHeader, 2000);
} }
// Hide "Play with Friends" skeleton section // Hide "Play with Friends" skeleton section
if (getPref(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.FRIENDS) || getPref(PrefKey.BLOCK_FEATURES).includes(BlockFeature.FRIENDS)) { if (getGlobalPref(GlobalPref.UI_HIDE_SECTIONS).includes(UiSection.FRIENDS) || getGlobalPref(GlobalPref.BLOCK_FEATURES).includes(BlockFeature.FRIENDS)) {
const $parent = document.querySelector('div[class*=PlayWithFriendsSkeleton]')?.closest<HTMLElement>('div[class*=HomePage-module]'); const $parent = document.querySelector('div[class*=PlayWithFriendsSkeleton]')?.closest<HTMLElement>('div[class*=HomePage-module]');
$parent && ($parent.style.display = 'none'); $parent && ($parent.style.display = 'none');
} }
// Preload fonts // Preload fonts
preloadFonts(); preloadFonts();
}) });
// Deep link
if (AppInterface) {
window.addEventListener(BxEvent.XCLOUD_ROUTER_HISTORY_READY, e => {
if (window.location.pathname.includes('/fireos-browser-update')) {
localRedirect('/play');
} else {
handleDeepLink();
}
}, { once: true });
}
window.BX_EXPOSED = BxExposed; window.BX_EXPOSED = BxExposed;
@ -191,33 +216,21 @@ window.addEventListener('popstate', onHistoryChanged);
window.history.pushState = patchHistoryMethod('pushState'); window.history.pushState = patchHistoryMethod('pushState');
window.history.replaceState = patchHistoryMethod('replaceState'); window.history.replaceState = patchHistoryMethod('replaceState');
BxEventBus.Script.once('xcloud.server.unavailable', () => { BxEventBus.Script.on('ui.header.rendered', () => {
STATES.supportedRegion = false; HeaderSection.getInstance().checkHeader();
window.setTimeout(HeaderSection.watchHeader, 2000);
// Open Settings dialog on Unsupported page
const $unsupportedPage = document.querySelector<HTMLElement>('div[class^=UnsupportedMarketPage-module__container]');
if ($unsupportedPage) {
SettingsDialog.getInstance().show();
}
});
BxEventBus.Script.on('xcloud.server.ready', () => {
STATES.isSignedIn = true;
window.setTimeout(HeaderSection.watchHeader, 2000);
}); });
BxEventBus.Stream.on('state.loading', () => { BxEventBus.Stream.on('state.loading', () => {
// Get title ID for screenshot's name // Get title ID for screenshot's name
if (window.location.pathname.includes('/launch/') && STATES.currentStream.titleInfo) { if (window.location.pathname.includes('/launch/') && STATES.currentStream.titleInfo) {
STATES.currentStream.titleSlug = productTitleToSlug(STATES.currentStream.titleInfo.product.title); STATES.currentStream.titleSlug = productTitleToSlug(STATES.currentStream.titleInfo.productInfo.title);
} else { } else {
STATES.currentStream.titleSlug = 'remote-play'; STATES.currentStream.titleSlug = 'remote-play';
} }
}); });
// Setup loading screen // Setup loading screen
getPref(PrefKey.LOADING_SCREEN_GAME_ART) && BxEventBus.Script.on('titleInfo.ready', LoadingScreen.setup); getGlobalPref(GlobalPref.LOADING_SCREEN_GAME_ART) && BxEventBus.Script.on('titleInfo.ready', LoadingScreen.setup);
BxEventBus.Stream.on('state.starting', () => { BxEventBus.Stream.on('state.starting', () => {
// Hide loading screen // Hide loading screen
@ -234,11 +247,12 @@ BxEventBus.Stream.on('state.starting', () => {
}); });
BxEventBus.Stream.on('state.playing', payload => { BxEventBus.Stream.on('state.playing', payload => {
window.BX_STREAM_SETTINGS = StreamSettings.settings; if (isFullVersion()) {
StreamSettings.refreshAllSettings(); window.BX_STREAM_SETTINGS = StreamSettings.settings;
StreamSettings.refreshAllSettings();
}
STATES.isPlaying = true; STATES.isPlaying = true;
StreamUiHandler.observe();
if (isFullVersion()) { if (isFullVersion()) {
const gameBar = GameBar.getInstance(); const gameBar = GameBar.getInstance();
@ -256,17 +270,48 @@ BxEventBus.Stream.on('state.playing', payload => {
ScreenshotManager.getInstance().updateCanvasSize($video.videoWidth, $video.videoHeight); ScreenshotManager.getInstance().updateCanvasSize($video.videoWidth, $video.videoHeight);
// Setup local co-op // Setup local co-op
getPref(PrefKey.LOCAL_CO_OP_ENABLED) && BxExposed.toggleLocalCoOp(getPref(PrefKey.LOCAL_CO_OP_ENABLED)); if (getStreamPref(StreamPref.LOCAL_CO_OP_ENABLED)) {
BxExposed.toggleLocalCoOp(true);
Toast.show(t('local-co-op'), t('enabled'));
}
} }
updateVideoPlayer(); updateVideoPlayer();
}); });
BxEventBus.Stream.on('state.error', () => { BxEventBus.Script.on('ui.error.rendered', () => {
BxEventBus.Stream.emit('state.stopped', {}); BxEventBus.Stream.emit('state.stopped', {});
}); });
BxEventBus.Script.on('ui.guideHome.rendered', () => {
const $root = document.querySelector<HTMLElement>('#gamepass-dialog-root div[role=dialog] div[role=tabpanel] div[class*=HomeLandingPage]');
$root && GuideMenu.getInstance().injectHome($root, STATES.isPlaying);
});
BxEventBus.Script.on('ui.guideAchievementProgress.rendered', () => {
const $elm = document.querySelector('#gamepass-dialog-root button[class*=AchievementsButton-module__progressBarContainer]');
if ($elm) {
TrueAchievements.getInstance().injectAchievementsProgress($elm as HTMLElement);
}
});
BxEventBus.Script.on('ui.guideAchievementDetail.rendered', () => {
const $elm = document.querySelector('#gamepass-dialog-root div[class^=AchievementDetailPage-module]');
if ($elm) {
TrueAchievements.getInstance().injectAchievementDetailPage($elm as HTMLElement);
}
});
BxEventBus.Stream.on('ui.streamMenu.rendered', async () => {
await StreamUiHandler.handleStreamMenu();
});
BxEventBus.Stream.on('ui.streamHud.rendered', async () => {
const $elm = document.querySelector<HTMLElement>('#StreamHud');
$elm && StreamUiHandler.handleSystemMenu($elm);
});
isFullVersion() && window.addEventListener(BxEvent.XCLOUD_RENDERING_COMPONENT, e => { isFullVersion() && window.addEventListener(BxEvent.XCLOUD_RENDERING_COMPONENT, e => {
const component = (e as any).component; const component = (e as any).component;
if (component === 'product-detail') { if (component === 'product-detail') {
@ -291,20 +336,32 @@ BxEventBus.Stream.on('dataChannelCreated', payload => {
} }
// Get xboxTitleId from message // Get xboxTitleId from message
const currentStream = STATES.currentStream;
const json = JSON.parse(JSON.parse(msg.data).content); const json = JSON.parse(JSON.parse(msg.data).content);
const xboxTitleId = parseInt(json.titleid, 16); const currentId = currentStream.xboxTitleId ?? null;
STATES.currentStream.xboxTitleId = xboxTitleId; let newId: number = parseInt(json.titleid, 16);
// Get titleSlug for Remote Play // Get titleSlug for Remote Play
if (STATES.remotePlay.isPlaying) { if (window.location.pathname.includes('/play/consoles/launch/')) {
STATES.currentStream.titleSlug = 'remote-play'; currentStream.titleSlug = 'remote-play';
if (json.focused) { if (json.focused) {
const productTitle = await XboxApi.getProductTitle(xboxTitleId); const productTitle = await XboxApi.getProductTitle(newId);
if (productTitle) { if (productTitle) {
STATES.currentStream.titleSlug = productTitleToSlug(productTitle); currentStream.titleSlug = productTitleToSlug(productTitle);
} else {
newId = -1;
} }
} else {
newId = 0;
} }
} }
if (currentId !== newId) {
currentStream.xboxTitleId = newId;
BxEventBus.Stream.emit('xboxTitleId.changed', {
id: newId,
});
}
}); });
}); });
@ -314,6 +371,7 @@ function unload() {
return; return;
} }
BxLogger.warning('Unloading');
if (isFullVersion()) { if (isFullVersion()) {
KeyboardShortcutHandler.getInstance().stop(); KeyboardShortcutHandler.getInstance().stop();
@ -325,7 +383,7 @@ function unload() {
} }
// Destroy StreamPlayer // Destroy StreamPlayer
STATES.currentStream.streamPlayer?.destroy(); STATES.currentStream.streamPlayerManager?.destroy();
STATES.isPlaying = false; STATES.isPlaying = false;
STATES.currentStream = {}; STATES.currentStream = {};
@ -341,6 +399,8 @@ function unload() {
TouchController.reset(); TouchController.reset();
GameBar.getInstance()?.disable(); GameBar.getInstance()?.disable();
BxEventBus.Stream.emit('xboxTitleId.changed', { id: -1 });
} }
} }
@ -357,9 +417,11 @@ isFullVersion() && window.addEventListener(BxEvent.CAPTURE_SCREENSHOT, e => {
function main() { function main() {
GhPagesUtils.fetchLatestCommit(); GhPagesUtils.fetchLatestCommit();
if (getPref(PrefKey.NATIVE_MKB_MODE) !== NativeMkbMode.OFF) { if (isFullVersion()) {
const customList = getPref(PrefKey.NATIVE_MKB_FORCED_GAMES); if (getGlobalPref(GlobalPref.NATIVE_MKB_MODE) !== NativeMkbMode.OFF) {
BX_FLAGS.ForceNativeMkbTitles.push(...customList); const customList = getGlobalPref(GlobalPref.NATIVE_MKB_FORCED_GAMES);
BX_FLAGS.ForceNativeMkbTitles.push(...customList);
}
} }
StreamSettings.setup(); StreamSettings.setup();
@ -372,24 +434,23 @@ function main() {
patchCanvasContext(); patchCanvasContext();
isFullVersion() && AppInterface && patchPointerLockApi(); isFullVersion() && AppInterface && patchPointerLockApi();
getPref(PrefKey.AUDIO_VOLUME_CONTROL_ENABLED) && patchAudioContext(); getGlobalPref(GlobalPref.AUDIO_VOLUME_CONTROL_ENABLED) && patchAudioContext();
if (getPref(PrefKey.BLOCK_TRACKING)) { if (getGlobalPref(GlobalPref.BLOCK_TRACKING)) {
patchMeControl(); patchMeControl();
disableAdobeAudienceManager(); disableAdobeAudienceManager();
} }
RootDialogObserver.waitForRootDialog();
// Setup UI // Setup UI
addCss(); addCss();
GuideMenu.getInstance().addEventListeners();
StreamStatsCollector.setupEvents(); StreamStatsCollector.setupEvents();
StreamBadges.setupEvents(); StreamBadges.setupEvents();
StreamStats.setupEvents(); StreamStats.setupEvents();
if (isFullVersion()) { if (isFullVersion()) {
WebGPUPlayer.prepare();
STATES.userAgent.capabilities.touch && TouchController.updateCustomList(); STATES.userAgent.capabilities.touch && TouchController.updateCustomList();
DeviceVibrationManager.getInstance(); DeviceVibrationManager.getInstance();
@ -400,29 +461,24 @@ function main() {
Patcher.init(); Patcher.init();
disablePwa(); disablePwa();
// Preload Remote Play if (getGlobalPref(GlobalPref.TOUCH_CONTROLLER_MODE) === TouchControllerMode.ALL) {
if (getPref(PrefKey.REMOTE_PLAY_ENABLED)) {
RemotePlayManager.detect();
}
if (getPref(PrefKey.TOUCH_CONTROLLER_MODE) === TouchControllerMode.ALL) {
TouchController.setup(); TouchController.setup();
} }
// Start PointerProviderServer // Start PointerProviderServer
if (AppInterface && (getPref(PrefKey.MKB_ENABLED) || getPref(PrefKey.NATIVE_MKB_MODE) === NativeMkbMode.ON)) { if (AppInterface && (getGlobalPref(GlobalPref.MKB_ENABLED) || getGlobalPref(GlobalPref.NATIVE_MKB_MODE) === NativeMkbMode.ON)) {
STATES.pointerServerPort = AppInterface.startPointerServer() || 9269; STATES.pointerServerPort = AppInterface.startPointerServer() || 9269;
BxLogger.info('startPointerServer', 'Port', STATES.pointerServerPort.toString()); BxLogger.info('startPointerServer', 'Port', STATES.pointerServerPort.toString());
} }
// Show wait time in game card // Show wait time in game card
getPref(PrefKey.UI_GAME_CARD_SHOW_WAIT_TIME) && GameTile.setup(); getGlobalPref(GlobalPref.UI_GAME_CARD_SHOW_WAIT_TIME) && GameTile.setup();
EmulatedMkbHandler.setupEvents(); EmulatedMkbHandler.setupEvents();
} }
// Show a toast when connecting/disconecting controller // Show a toast when connecting/disconecting controller
if (getPref(PrefKey.UI_CONTROLLER_SHOW_STATUS)) { if (getGlobalPref(GlobalPref.UI_CONTROLLER_SHOW_STATUS)) {
window.addEventListener('gamepadconnected', e => showGamepadToast(e.gamepad)); window.addEventListener('gamepadconnected', e => showGamepadToast(e.gamepad));
window.addEventListener('gamepaddisconnected', e => showGamepadToast(e.gamepad)); window.addEventListener('gamepaddisconnected', e => showGamepadToast(e.gamepad));
} }

View File

@ -25,3 +25,17 @@ export const renderStylus = async () => {
export const compressCss = (css: string) => { export const compressCss = (css: string) => {
return (stylus(css, {}).set('compress', true)).render(); return (stylus(css, {}).set('compress', true)).render();
}; };
export const compressCode = (code: string): string => {
return code.split('\n') // Split into lines
.map(line => line.startsWith('#') || line.startsWith('@') ? line + '\n' : line.trim()) // Trim spaces, with exceptions for shader files
.filter(line => line && !line.startsWith('//')) // Remove empty and commented lines
.join(''); // Join into a single line
};
export const compressCodeFile = async (path: string) => {
const file = Bun.file(path);
const code = await file.text();
return compressCode(code);
};

View File

@ -47,7 +47,7 @@ export class DeviceVibrationManager {
} }
}); });
BxEventBus.Script.on('deviceVibration.updated', () => this.setupDataChannel()); BxEventBus.Stream.on('deviceVibration.updated', () => this.setupDataChannel());
} }
private setupDataChannel() { private setupDataChannel() {

View File

@ -6,21 +6,21 @@ import { BxIcon } from "@utils/bx-icon";
import type { BaseGameBarAction } from "./base-action"; import type { BaseGameBarAction } from "./base-action";
import { STATES } from "@utils/global"; import { STATES } from "@utils/global";
import { MicrophoneAction } from "./microphone-action"; import { MicrophoneAction } from "./microphone-action";
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref } from "@/enums/pref-keys";
import { getPref } from "@/utils/settings-storages/global-settings-storage";
import { TrueAchievementsAction } from "./true-achievements-action"; import { TrueAchievementsAction } from "./true-achievements-action";
import { SpeakerAction } from "./speaker-action"; import { SpeakerAction } from "./speaker-action";
import { RendererAction } from "./renderer-action"; import { RendererAction } from "./renderer-action";
import { BxLogger } from "@/utils/bx-logger"; import { BxLogger } from "@/utils/bx-logger";
import { GameBarPosition, TouchControllerMode } from "@/enums/pref-values"; import { GameBarPosition, TouchControllerMode } from "@/enums/pref-values";
import { BxEventBus } from "@/utils/bx-event-bus"; import { BxEventBus } from "@/utils/bx-event-bus";
import { getGlobalPref } from "@/utils/pref-utils";
export class GameBar { export class GameBar {
private static instance: GameBar | null | undefined; private static instance: GameBar | null | undefined;
public static getInstance(): typeof GameBar['instance'] { public static getInstance(): typeof GameBar['instance'] {
if (typeof GameBar.instance === 'undefined') { if (typeof GameBar.instance === 'undefined') {
if (getPref(PrefKey.GAME_BAR_POSITION) !== GameBarPosition.OFF) { if (getGlobalPref(GlobalPref.GAME_BAR_POSITION) !== GameBarPosition.OFF) {
GameBar.instance = new GameBar(); GameBar.instance = new GameBar();
} else { } else {
GameBar.instance = null; GameBar.instance = null;
@ -46,7 +46,7 @@ export class GameBar {
let $container; let $container;
const position = getPref(PrefKey.GAME_BAR_POSITION); const position = getGlobalPref(GlobalPref.GAME_BAR_POSITION);
const $gameBar = CE('div', { id: 'bx-game-bar', class: 'bx-gone', 'data-position': position }, const $gameBar = CE('div', { id: 'bx-game-bar', class: 'bx-gone', 'data-position': position },
$container = CE('div', { class: 'bx-game-bar-container bx-offscreen' }), $container = CE('div', { class: 'bx-game-bar-container bx-offscreen' }),
@ -55,7 +55,7 @@ export class GameBar {
this.actions = [ this.actions = [
new ScreenshotAction(), new ScreenshotAction(),
...(STATES.userAgent.capabilities.touch && (getPref(PrefKey.TOUCH_CONTROLLER_MODE) !== TouchControllerMode.OFF) ? [new TouchControlAction()] : []), ...(STATES.userAgent.capabilities.touch && (getGlobalPref(GlobalPref.TOUCH_CONTROLLER_MODE) !== TouchControllerMode.OFF) ? [new TouchControlAction()] : []),
new SpeakerAction(), new SpeakerAction(),
new RendererAction(), new RendererAction(),
new MicrophoneAction(), new MicrophoneAction(),

View File

@ -2,8 +2,8 @@ import { CE } from "@utils/html";
import { getPreferredServerRegion } from "@utils/region"; import { getPreferredServerRegion } from "@utils/region";
import { t } from "@utils/translation"; import { t } from "@utils/translation";
import { STATES } from "@utils/global"; import { STATES } from "@utils/global";
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref } from "@/enums/pref-keys";
import { getPref } from "@/utils/settings-storages/global-settings-storage"; import { getGlobalPref } from "@/utils/pref-utils";
import { compressCss } from "@macros/build" with { type: "macro" }; import { compressCss } from "@macros/build" with { type: "macro" };
import { LoadingScreenRocket } from "@/enums/pref-values"; import { LoadingScreenRocket } from "@/enums/pref-values";
@ -35,9 +35,11 @@ export class LoadingScreen {
LoadingScreen.$bgStyle = $bgStyle; LoadingScreen.$bgStyle = $bgStyle;
} }
LoadingScreen.setBackground(titleInfo.product.heroImageUrl || titleInfo.product.titledHeroImageUrl || titleInfo.product.tileImageUrl); if (titleInfo.productInfo) {
LoadingScreen.setBackground(titleInfo.productInfo.heroImageUrl || titleInfo.productInfo.titledHeroImageUrl || titleInfo.productInfo.tileImageUrl);
}
if (getPref(PrefKey.LOADING_SCREEN_ROCKET) === LoadingScreenRocket.HIDE) { if (getGlobalPref(GlobalPref.LOADING_SCREEN_ROCKET) === LoadingScreenRocket.HIDE) {
LoadingScreen.hideRocket(); LoadingScreen.hideRocket();
} }
} }
@ -63,6 +65,11 @@ export class LoadingScreen {
// Limit max width to reduce image size // Limit max width to reduce image size
imageUrl = imageUrl + '?w=1920'; imageUrl = imageUrl + '?w=1920';
const imageQuality = getGlobalPref(GlobalPref.UI_IMAGE_QUALITY);
if (imageQuality !== 90) {
imageUrl += '&q=' + imageQuality;
}
$bgStyle.textContent! += compressCss(` $bgStyle.textContent! += compressCss(`
#game-stream { #game-stream {
background-color: transparent !important; background-color: transparent !important;
@ -89,7 +96,7 @@ export class LoadingScreen {
static setupWaitTime(waitTime: number) { static setupWaitTime(waitTime: number) {
// Hide rocket when queing // Hide rocket when queing
if (getPref(PrefKey.LOADING_SCREEN_ROCKET) === LoadingScreenRocket.HIDE_QUEUE) { if (getGlobalPref(GlobalPref.LOADING_SCREEN_ROCKET) === LoadingScreenRocket.HIDE_QUEUE) {
LoadingScreen.hideRocket(); LoadingScreen.hideRocket();
} }
@ -146,7 +153,7 @@ export class LoadingScreen {
LoadingScreen.orgWebTitle && (document.title = LoadingScreen.orgWebTitle); LoadingScreen.orgWebTitle && (document.title = LoadingScreen.orgWebTitle);
LoadingScreen.$waitTimeBox && LoadingScreen.$waitTimeBox.classList.add('bx-gone'); LoadingScreen.$waitTimeBox && LoadingScreen.$waitTimeBox.classList.add('bx-gone');
if (getPref(PrefKey.LOADING_SCREEN_GAME_ART) && LoadingScreen.$bgStyle) { if (getGlobalPref(GlobalPref.LOADING_SCREEN_GAME_ART) && LoadingScreen.$bgStyle) {
const $rocketBg = document.querySelector('#game-stream rect[width="800"]'); const $rocketBg = document.querySelector('#game-stream rect[width="800"]');
$rocketBg && $rocketBg.addEventListener('transitionend', e => { $rocketBg && $rocketBg.addEventListener('transitionend', e => {
LoadingScreen.$bgStyle.textContent += compressCss(` LoadingScreen.$bgStyle.textContent += compressCss(`

View File

@ -1,4 +1,4 @@
import { MouseButtonCode, WheelCode, type KeyCode } from "@/enums/mkb"; import { MouseButtonCode, WheelCode } from "@/enums/mkb";
export const enum KeyModifier { export const enum KeyModifier {
CTRL = 1, CTRL = 1,

View File

@ -11,14 +11,15 @@ import { BxLogger } from "@utils/bx-logger";
import { PointerClient } from "./pointer-client"; import { PointerClient } from "./pointer-client";
import { NativeMkbHandler } from "./native-mkb-handler"; import { NativeMkbHandler } from "./native-mkb-handler";
import { MkbHandler, MouseDataProvider } from "./base-mkb-handler"; import { MkbHandler, MouseDataProvider } from "./base-mkb-handler";
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref, StreamPref } from "@/enums/pref-keys";
import { getPref } from "@/utils/settings-storages/global-settings-storage"; import { getGlobalPref, getStreamPref } from "@/utils/pref-utils";
import { GamepadKey, GamepadStick } from "@/enums/gamepad"; import { GamepadKey, GamepadStick } from "@/enums/gamepad";
import { MkbPopup } from "./mkb-popup"; import { MkbPopup } from "./mkb-popup";
import type { MkbConvertedPresetData } from "@/types/presets"; import type { MkbConvertedPresetData } from "@/types/presets";
import { StreamSettings } from "@/utils/stream-settings"; import { StreamSettings } from "@/utils/stream-settings";
import { ShortcutAction } from "@/enums/shortcut-actions"; import { ShortcutAction } from "@/enums/shortcut-actions";
import { BxEventBus } from "@/utils/bx-event-bus"; import { BxEventBus } from "@/utils/bx-event-bus";
import { generateVirtualControllerMapping, toXcloudGamepadKey } from "@/utils/gamepad";
const PointerToMouseButton = { const PointerToMouseButton = {
1: 0, 1: 0,
@ -133,7 +134,7 @@ export class EmulatedMkbHandler extends MkbHandler {
private static readonly LOG_TAG = 'EmulatedMkbHandler'; private static readonly LOG_TAG = 'EmulatedMkbHandler';
static isAllowed() { static isAllowed() {
return getPref(PrefKey.MKB_ENABLED) && (AppInterface || !UserAgent.isMobile()); return getGlobalPref(GlobalPref.MKB_ENABLED) && (AppInterface || !UserAgent.isMobile());
} }
private PRESET!: MkbConvertedPresetData | null; private PRESET!: MkbConvertedPresetData | null;
@ -152,6 +153,8 @@ export class EmulatedMkbHandler extends MkbHandler {
}; };
private nativeGetGamepads: Navigator['getGamepads']; private nativeGetGamepads: Navigator['getGamepads'];
private xCloudGamepad: XcloudGamepad = generateVirtualControllerMapping(0);
private initialized = false; private initialized = false;
private enabled = false; private enabled = false;
private mouseDataProvider: MouseDataProvider | undefined; private mouseDataProvider: MouseDataProvider | undefined;
@ -171,16 +174,16 @@ export class EmulatedMkbHandler extends MkbHandler {
private popup: MkbPopup; private popup: MkbPopup;
private STICK_MAP: { [key in GamepadKey]?: [GamepadKey[], number, number] } = { private STICK_MAP: { [key in GamepadKey]?: [GamepadKey[], number] } = {
[GamepadKey.LS_LEFT]: [this.LEFT_STICK_X, 0, -1], [GamepadKey.LS_LEFT]: [this.LEFT_STICK_X, -1],
[GamepadKey.LS_RIGHT]: [this.LEFT_STICK_X, 0, 1], [GamepadKey.LS_RIGHT]: [this.LEFT_STICK_X, 1],
[GamepadKey.LS_UP]: [this.LEFT_STICK_Y, 1, -1], [GamepadKey.LS_UP]: [this.LEFT_STICK_Y, 1],
[GamepadKey.LS_DOWN]: [this.LEFT_STICK_Y, 1, 1], [GamepadKey.LS_DOWN]: [this.LEFT_STICK_Y, -1],
[GamepadKey.RS_LEFT]: [this.RIGHT_STICK_X, 2, -1], [GamepadKey.RS_LEFT]: [this.RIGHT_STICK_X, -1],
[GamepadKey.RS_RIGHT]: [this.RIGHT_STICK_X, 2, 1], [GamepadKey.RS_RIGHT]: [this.RIGHT_STICK_X, 1],
[GamepadKey.RS_UP]: [this.RIGHT_STICK_Y, 3, -1], [GamepadKey.RS_UP]: [this.RIGHT_STICK_Y, 1],
[GamepadKey.RS_DOWN]: [this.RIGHT_STICK_Y, 3, 1], [GamepadKey.RS_DOWN]: [this.RIGHT_STICK_Y, -1],
}; };
private constructor() { private constructor() {
@ -205,11 +208,16 @@ export class EmulatedMkbHandler extends MkbHandler {
private getVirtualGamepad = () => this.VIRTUAL_GAMEPAD; private getVirtualGamepad = () => this.VIRTUAL_GAMEPAD;
private updateStick(stick: GamepadStick, x: number, y: number) { private updateStick(stick: GamepadStick, x: number, y: number) {
const virtualGamepad = this.getVirtualGamepad(); const gamepad = this.xCloudGamepad;
virtualGamepad.axes[stick * 2] = x; if (stick === GamepadStick.LEFT) {
virtualGamepad.axes[stick * 2 + 1] = y; gamepad.LeftThumbXAxis = x;
gamepad.LeftThumbYAxis = -y;
} else {
gamepad.RightThumbXAxis = x;
gamepad.RightThumbYAxis = -y;
}
virtualGamepad.timestamp = performance.now(); window.BX_EXPOSED.inputChannel?.sendGamepadInput(performance.now(), [this.xCloudGamepad]);
} }
/* /*
@ -224,29 +232,20 @@ export class EmulatedMkbHandler extends MkbHandler {
private vectorLength = (x: number, y: number): number => Math.sqrt(x ** 2 + y ** 2); private vectorLength = (x: number, y: number): number => Math.sqrt(x ** 2 + y ** 2);
private resetGamepad() { resetXcloudGamepads() {
const gamepad = this.getVirtualGamepad(); const index = getStreamPref(StreamPref.MKB_P1_SLOT) - 1;
// Reset axes this.xCloudGamepad = generateVirtualControllerMapping(0, {
gamepad.axes = [0, 0, 0, 0]; GamepadIndex: getStreamPref(StreamPref.LOCAL_CO_OP_ENABLED) ? index : 0,
Dirty: true,
// Reset buttons });
for (const button of gamepad.buttons) { this.VIRTUAL_GAMEPAD.index = index;
button.pressed = false;
button.value = 0;
}
gamepad.timestamp = performance.now();
} }
private pressButton(buttonIndex: GamepadKey, pressed: boolean) { private pressButton(buttonIndex: GamepadKey, pressed: boolean) {
const virtualGamepad = this.getVirtualGamepad(); const xCloudKey = toXcloudGamepadKey(buttonIndex)!;
if (buttonIndex >= 100) { if (buttonIndex >= 100) {
let [valueArr, axisIndex] = this.STICK_MAP[buttonIndex]!; let [valueArr]: [GamepadKey[], number] = this.STICK_MAP[buttonIndex]!;
valueArr = valueArr as number[];
axisIndex = axisIndex as number;
// Remove old index of the array // Remove old index of the array
for (let i = valueArr.length - 1; i >= 0; i--) { for (let i = valueArr.length - 1; i >= 0; i--) {
if (valueArr[i] === buttonIndex) { if (valueArr[i] === buttonIndex) {
@ -259,18 +258,19 @@ export class EmulatedMkbHandler extends MkbHandler {
let value; let value;
if (valueArr.length) { if (valueArr.length) {
// Get value of the last key of the axis // Get value of the last key of the axis
value = this.STICK_MAP[valueArr[valueArr.length - 1]]![2] as number; value = this.STICK_MAP[valueArr[valueArr.length - 1]]![1] as number;
} else { } else {
value = 0; value = 0;
} }
virtualGamepad.axes[axisIndex] = value; // @ts-ignore
this.xCloudGamepad[xCloudKey] = value;
} else { } else {
virtualGamepad.buttons[buttonIndex].pressed = pressed; // @ts-ignore
virtualGamepad.buttons[buttonIndex].value = pressed ? 1 : 0; this.xCloudGamepad[xCloudKey] = pressed ? 1 : 0;
} }
virtualGamepad.timestamp = performance.now(); window.BX_EXPOSED.inputChannel?.sendGamepadInput(performance.now(), [this.xCloudGamepad]);
} }
private onKeyboardEvent = (e: KeyboardEvent) => { private onKeyboardEvent = (e: KeyboardEvent) => {
@ -428,7 +428,7 @@ export class EmulatedMkbHandler extends MkbHandler {
return true; return true;
} }
toggle(force?: boolean) { async toggle(force?: boolean) {
if (!this.initialized) { if (!this.initialized) {
return; return;
} }
@ -440,9 +440,12 @@ export class EmulatedMkbHandler extends MkbHandler {
} }
if (this.enabled) { if (this.enabled) {
document.body.requestPointerLock({ try {
unadjustedMovement: true, await document.body.requestPointerLock({ unadjustedMovement: true });
}); } catch (e) {
document.body.requestPointerLock();
console.log(e);
}
} else { } else {
document.pointerLockElement && document.exitPointerLock(); document.pointerLockElement && document.exitPointerLock();
} }
@ -450,7 +453,7 @@ export class EmulatedMkbHandler extends MkbHandler {
refreshPresetData() { refreshPresetData() {
this.PRESET = window.BX_STREAM_SETTINGS.mkbPreset; this.PRESET = window.BX_STREAM_SETTINGS.mkbPreset;
this.resetGamepad(); this.resetXcloudGamepads();
} }
waitForMouseData(showPopup: boolean) { waitForMouseData(showPopup: boolean) {
@ -578,11 +581,6 @@ export class EmulatedMkbHandler extends MkbHandler {
window.removeEventListener(BxEvent.XCLOUD_POLLING_MODE_CHANGED, this.onPollingModeChanged); window.removeEventListener(BxEvent.XCLOUD_POLLING_MODE_CHANGED, this.onPollingModeChanged);
} }
updateGamepadSlots() {
// Set gamepad slot
this.VIRTUAL_GAMEPAD.index = getPref(PrefKey.MKB_P1_SLOT) - 1;
}
start() { start() {
if (!this.enabled) { if (!this.enabled) {
this.enabled = true; this.enabled = true;
@ -592,8 +590,8 @@ export class EmulatedMkbHandler extends MkbHandler {
this.isPolling = true; this.isPolling = true;
this.escKeyDownTime = -1; this.escKeyDownTime = -1;
this.resetGamepad(); window.BX_EXPOSED.toggleLocalCoOp(getStreamPref(StreamPref.LOCAL_CO_OP_ENABLED));
this.updateGamepadSlots(); this.resetXcloudGamepads();
window.navigator.getGamepads = this.patchedGetGamepads; window.navigator.getGamepads = this.patchedGetGamepads;
this.waitForMouseData(false); this.waitForMouseData(false);
@ -622,7 +620,7 @@ export class EmulatedMkbHandler extends MkbHandler {
const virtualGamepad = this.getVirtualGamepad(); const virtualGamepad = this.getVirtualGamepad();
if (virtualGamepad.connected) { if (virtualGamepad.connected) {
// Dispatch "gamepaddisconnected" event // Dispatch "gamepaddisconnected" event
this.resetGamepad(); this.resetXcloudGamepads();
virtualGamepad.connected = false; virtualGamepad.connected = false;
virtualGamepad.timestamp = performance.now(); virtualGamepad.timestamp = performance.now();
@ -652,7 +650,7 @@ export class EmulatedMkbHandler extends MkbHandler {
}); });
if (EmulatedMkbHandler.isAllowed()) { if (EmulatedMkbHandler.isAllowed()) {
BxEventBus.Script.on('mkb.setting.updated', () => { BxEventBus.Stream.on('mkb.setting.updated', () => {
EmulatedMkbHandler.getInstance()?.refreshPresetData(); EmulatedMkbHandler.getInstance()?.refreshPresetData();
}); });
} }

View File

@ -25,7 +25,7 @@ export class MkbPopup {
constructor() { constructor() {
this.render(); this.render();
BxEventBus.Script.on('keyboardShortcuts.updated', () => { BxEventBus.Stream.on('keyboardShortcuts.updated', () => {
const $newButton = this.createActivateButton(); const $newButton = this.createActivateButton();
this.$btnActivate.replaceWith($newButton); this.$btnActivate.replaceWith($newButton);
this.$btnActivate = $newButton; this.$btnActivate = $newButton;

View File

@ -1,11 +1,11 @@
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref } from "@/enums/pref-keys";
import { getPref } from "@/utils/settings-storages/global-settings-storage"; import { getGlobalPref } from "@/utils/pref-utils";
export class MouseCursorHider { export class MouseCursorHider {
private static instance: MouseCursorHider | null | undefined; private static instance: MouseCursorHider | null | undefined;
public static getInstance(): typeof MouseCursorHider['instance'] { public static getInstance(): typeof MouseCursorHider['instance'] {
if (typeof MouseCursorHider.instance === 'undefined') { if (typeof MouseCursorHider.instance === 'undefined') {
if (!getPref(PrefKey.MKB_ENABLED) && getPref(PrefKey.MKB_HIDE_IDLE_CURSOR)) { if (!getGlobalPref(GlobalPref.MKB_ENABLED) && getGlobalPref(GlobalPref.MKB_HIDE_IDLE_CURSOR)) {
MouseCursorHider.instance = new MouseCursorHider(); MouseCursorHider.instance = new MouseCursorHider();
} else { } else {
MouseCursorHider.instance = null; MouseCursorHider.instance = null;

View File

@ -4,8 +4,7 @@ import { AppInterface, STATES } from "@/utils/global";
import { MkbHandler } from "./base-mkb-handler"; import { MkbHandler } from "./base-mkb-handler";
import { t } from "@/utils/translation"; import { t } from "@/utils/translation";
import { BxEvent } from "@/utils/bx-event"; import { BxEvent } from "@/utils/bx-event";
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref, StreamPref } from "@/enums/pref-keys";
import { getPref } from "@/utils/settings-storages/global-settings-storage";
import { BxLogger } from "@/utils/bx-logger"; import { BxLogger } from "@/utils/bx-logger";
import { MkbPopup } from "./mkb-popup"; import { MkbPopup } from "./mkb-popup";
import { KeyHelper } from "./key-helper"; import { KeyHelper } from "./key-helper";
@ -13,19 +12,7 @@ import { StreamSettings } from "@/utils/stream-settings";
import { ShortcutAction } from "@/enums/shortcut-actions"; import { ShortcutAction } from "@/enums/shortcut-actions";
import { NativeMkbMode } from "@/enums/pref-values"; import { NativeMkbMode } from "@/enums/pref-values";
import { BxEventBus } from "@/utils/bx-event-bus"; import { BxEventBus } from "@/utils/bx-event-bus";
import { getStreamPref, getGlobalPref } from "@/utils/pref-utils";
type NativeMouseData = {
X: number,
Y: number,
Buttons: number,
WheelX: number,
WheelY: number,
Type?: 0, // 0: Relative, 1: Absolute
}
type XcloudInputSink = {
onMouseInput: (data: NativeMouseData) => void;
}
export class NativeMkbHandler extends MkbHandler { export class NativeMkbHandler extends MkbHandler {
private static instance: NativeMkbHandler | null | undefined; private static instance: NativeMkbHandler | null | undefined;
@ -43,7 +30,7 @@ export class NativeMkbHandler extends MkbHandler {
private readonly LOG_TAG = 'NativeMkbHandler'; private readonly LOG_TAG = 'NativeMkbHandler';
static isAllowed = () => { static isAllowed = () => {
return STATES.browser.capabilities.emulatedNativeMkb && getPref(PrefKey.NATIVE_MKB_MODE) === NativeMkbMode.ON; return STATES.browser.capabilities.emulatedNativeMkb && getGlobalPref(GlobalPref.NATIVE_MKB_MODE) === NativeMkbMode.ON;
} }
private pointerClient: PointerClient | undefined; private pointerClient: PointerClient | undefined;
@ -54,7 +41,7 @@ export class NativeMkbHandler extends MkbHandler {
private mouseVerticalMultiply = 0; private mouseVerticalMultiply = 0;
private mouseHorizontalMultiply = 0; private mouseHorizontalMultiply = 0;
private inputSink: XcloudInputSink | undefined; private inputChannel: XcloudInputChannel | undefined;
private popup!: MkbPopup; private popup!: MkbPopup;
@ -114,7 +101,7 @@ export class NativeMkbHandler extends MkbHandler {
init() { init() {
this.pointerClient = PointerClient.getInstance(); this.pointerClient = PointerClient.getInstance();
this.inputSink = window.BX_EXPOSED.inputSink; this.inputChannel = window.BX_EXPOSED.inputChannel;
// Stop keyboard input at startup // Stop keyboard input at startup
this.updateInputConfigurationAsync(false); this.updateInputConfigurationAsync(false);
@ -125,8 +112,8 @@ export class NativeMkbHandler extends MkbHandler {
Toast.show('Cannot enable Mouse & Keyboard feature'); Toast.show('Cannot enable Mouse & Keyboard feature');
} }
this.mouseVerticalMultiply = getPref(PrefKey.NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY); this.mouseVerticalMultiply = getStreamPref(StreamPref.NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY);
this.mouseHorizontalMultiply = getPref(PrefKey.NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY); this.mouseHorizontalMultiply = getStreamPref(StreamPref.NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY);
window.addEventListener('keyup', this); window.addEventListener('keyup', this);
@ -274,7 +261,7 @@ export class NativeMkbHandler extends MkbHandler {
private sendMouseInput(data: NativeMouseData) { private sendMouseInput(data: NativeMouseData) {
data.Type = 0; // Relative data.Type = 0; // Relative
this.inputSink?.onMouseInput(data); this.inputChannel?.queueMouseInput(data);
} }
private resetMouseInput() { private resetMouseInput() {

View File

@ -1,3 +1,4 @@
import type { ScriptEvents, StreamEvents } from "@/utils/bx-event-bus";
import type { PatchArray, PatchName, PatchPage } from "./patcher"; import type { PatchArray, PatchName, PatchPage } from "./patcher";
export class PatcherUtils { export class PatcherUtils {
@ -35,19 +36,115 @@ export class PatcherUtils {
return txt.substring(0, index) + toString + txt.substring(index + fromString.length); return txt.substring(0, index) + toString + txt.substring(index + fromString.length);
} }
static filterPatches(patches: Array<string | false>): PatchArray { static replaceAfterIndex(txt: string, search: string, replaceWith: string, index: number) {
const before = txt.slice(0, index);
const after = txt.slice(index).replace(search, replaceWith);
return before + after;
}
static filterPatches(patches: Array<PatchName | false>): PatchArray {
return patches.filter((item): item is PatchName => !!item); return patches.filter((item): item is PatchName => !!item);
} }
static patchBeforePageLoad(str: string, page: PatchPage): string | false { static patchBeforePageLoad(str: string, page: PatchPage): string | false {
let text = `chunkName:()=>"${page}-page",`; const index = str.indexOf(`chunkName:()=>"${page}-page",`);
if (!str.includes(text)) { if (index < 0) {
return false; return false;
} }
str = str.replace('requireAsync(e){', `requireAsync(e){window.BX_EXPOSED.beforePageLoad("${page}");`); str = PatcherUtils.replaceAfterIndex(str, 'requireAsync(e){', `requireAsync(e){window.BX_EXPOSED.beforePageLoad("${page}");`, index);
str = str.replace('requireSync(e){', `requireSync(e){window.BX_EXPOSED.beforePageLoad("${page}");`); str = PatcherUtils.replaceAfterIndex(str, 'requireSync(e){', `requireSync(e){window.BX_EXPOSED.beforePageLoad("${page}");`, index);
return str; return str;
} }
private static isVarCharacter(char: string) {
const code = char.charCodeAt(0);
// Check for uppercase letters (A-Z)
const isUppercase = code >= 65 && code <= 90;
// Check for lowercase letters (a-z)
const isLowercase = code >= 97 && code <= 122;
// Check for digits (0-9)
const isDigit = code >= 48 && code <= 57;
// Check for special characters '_' and '$'
const isSpecial = char === '_' || char === '$';
return isUppercase || isLowercase || isDigit || isSpecial;
}
static getVariableNameBefore(str: string, index: number) {
if (index < 0) {
return null;
}
const end = index;
let start = end - 1;
while (PatcherUtils.isVarCharacter(str[start])) {
start -= 1;
}
return str.substring(start + 1, end);
}
static getVariableNameAfter(str: string, index: number) {
if (index < 0) {
return null;
}
const start = index;
let end = start + 1;
while (PatcherUtils.isVarCharacter(str[end])) {
end += 1;
}
return str.substring(start, end);
}
static injectUseEffect<T extends 'Stream' | 'Script'>(str: string, index: number, group: T, eventName: T extends 'Stream' ? keyof StreamEvents : keyof ScriptEvents, separator: string = ';') {
const newCode = `window.BX_EXPOSED.reactUseEffect(() => window.BxEventBus.${group}.emit('${eventName}', {}), [])${separator}`;
str = PatcherUtils.insertAt(str, index, newCode);
return str;
}
static findAndParseParams(str: string, index: number, maxRange: number) {
const substr = str.substring(index, index + maxRange);
let startIndex = substr.indexOf('({');
if (startIndex < 0) {
return false;
}
startIndex += 1;
let endIndex = substr.indexOf('})', startIndex);
if (endIndex < 0) {
return false;
}
endIndex += 1;
try {
const input = substr.substring(startIndex, endIndex);
return PatcherUtils.parseObjectVariables(input);
} catch {
return null;
}
}
static parseObjectVariables(input: string) {
try {
const pairs = [...input.matchAll(/(\w+)\s*:\s*([a-zA-Z_$][\w$]*)/g)];
const result: Record<string, string> = {};
for (const [_, key, value] of pairs) {
result[key] = value;
}
return result;
} catch {
return null;
}
}
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
// @ts-ignore
declare const arguments: any;
const $dom = arguments[1];
if ($dom && $dom instanceof HTMLElement && $dom.id === 'gamepass-dialog-root') {
let showing = false;
const $child = $dom.firstElementChild;
const $dialog = $child?.firstElementChild;
if ($dialog) {
showing = !$dialog.className.includes('pageChangeExit');
}
window.BxEventBus.Script.emit(showing ? 'dialog.shown' : 'dialog.dismissed', {});
}

View File

@ -0,0 +1,12 @@
declare const $supportedInputIcons$: Array<any>;
declare const $productId$: string;
const supportedInputIcons = $supportedInputIcons$;
const productId = $productId$;
// Remove controller icon
supportedInputIcons.shift();
if (window.BX_EXPOSED.localCoOpManager!.isSupported(productId)) {
supportedInputIcons.push(window.BX_EXPOSED.createReactLocalCoOpIcon);
}

View File

@ -53,6 +53,9 @@ $this$.toggleLocalCoOp = (enable: boolean) => {
continue; continue;
} }
// Don't show toast
(gamepad as any)._noToast = true;
window.dispatchEvent(new GamepadEvent('gamepaddisconnected', { gamepad })); window.dispatchEvent(new GamepadEvent('gamepaddisconnected', { gamepad }));
window.dispatchEvent(new GamepadEvent('gamepadconnected', { gamepad })); window.dispatchEvent(new GamepadEvent('gamepadconnected', { gamepad }));
} }

View File

@ -3,7 +3,7 @@ declare const e: string;
try { try {
const msg = JSON.parse(e); const msg = JSON.parse(e);
if (msg.reason === 'WarningForBeingIdle' && !window.location.pathname.includes('/launch/')) { if (msg.reason === 'WarningForBeingIdle' && window.location.pathname.includes('/play/consoles/launch/')) {
$this$.sendKeepAlive(); $this$.sendKeepAlive();
// @ts-ignore // @ts-ignore
return; return;

View File

@ -0,0 +1,13 @@
// @ts-ignore
declare let $guideUI$: any;
declare const $onShowStreamMenu$: any;
declare const $offset$: any;
// Expose onShowStreamMenu
window.BX_EXPOSED.showStreamMenu = $onShowStreamMenu$;
// Restore the "..." button
$guideUI$ = null;
window.BX_EXPOSED.reactUseEffect(() => {
window.BxEventBus.Stream.emit('ui.streamHud.rendered', { expanded: $offset$.x === 0 });
});

View File

@ -0,0 +1,119 @@
import { BxLogger } from "@/utils/bx-logger";
import { BaseStreamPlayer, StreamPlayerElement, StreamPlayerFilter } from "./base-stream-player";
import { StreamVideoProcessing, type StreamPlayerType } from "@/enums/pref-values";
export abstract class BaseCanvasPlayer extends BaseStreamPlayer {
protected $canvas: HTMLCanvasElement;
protected targetFps = 60;
protected frameInterval = 0;
protected lastFrameTime = 0;
protected animFrameId: number | null = null;
protected frameCallback: any;
private boundDrawFrame: () => void;
constructor(playerType: StreamPlayerType, $video: HTMLVideoElement, logTag: string) {
super(playerType, StreamPlayerElement.CANVAS, $video, logTag);
const $canvas = document.createElement('canvas');
$canvas.width = $video.videoWidth;
$canvas.height = $video.videoHeight;
this.$canvas = $canvas;
$video.insertAdjacentElement('afterend', this.$canvas);
let frameCallback: any;
if ('requestVideoFrameCallback' in HTMLVideoElement.prototype) {
const $video = this.$video;
frameCallback = $video.requestVideoFrameCallback.bind($video);
} else {
frameCallback = requestAnimationFrame;
}
this.frameCallback = frameCallback;
this.boundDrawFrame = this.drawFrame.bind(this);
}
async init(): Promise<void> {
super.init();
await this.setupShaders();
this.setupRendering();
}
setTargetFps(target: number) {
this.targetFps = target;
this.lastFrameTime = 0;
this.frameInterval = target ? Math.floor(1000 / target) : 0;
}
getCanvas() {
return this.$canvas;
}
destroy() {
BxLogger.info(this.logTag, 'Destroy');
this.isStopped = true;
if (this.animFrameId) {
if ('requestVideoFrameCallback' in HTMLVideoElement.prototype) {
this.$video.cancelVideoFrameCallback(this.animFrameId);
} else {
cancelAnimationFrame(this.animFrameId);
}
this.animFrameId = null;
}
if (this.$canvas.isConnected) {
this.$canvas.remove();
}
this.$canvas.width = 1;
this.$canvas.height = 1;
}
toFilterId(processing: StreamVideoProcessing) {
return processing === StreamVideoProcessing.CAS ? StreamPlayerFilter.CAS : StreamPlayerFilter.USM;
}
protected shouldDraw() {
if (this.targetFps >= 60) {
// Always draw
return true;
} else if (this.targetFps === 0) {
// Don't draw when FPS is 0
return false;
}
const currentTime = performance.now();
const timeSinceLastFrame = currentTime - this.lastFrameTime;
if (timeSinceLastFrame < this.frameInterval) {
// Skip frame to limit FPS
return false;
}
this.lastFrameTime = currentTime;
return true;
}
private drawFrame() {
if (this.isStopped) {
return;
}
this.animFrameId = this.frameCallback(this.boundDrawFrame);
if (!this.shouldDraw()) {
return;
}
this.updateFrame();
}
protected setupRendering(): void {
this.animFrameId = this.frameCallback(this.boundDrawFrame);
}
protected abstract setupShaders(): void;
abstract updateFrame(): void;
}

View File

@ -0,0 +1,48 @@
import { StreamVideoProcessing, type StreamPlayerType } from "@/enums/pref-values";
import type { StreamPlayerOptions } from "@/types/stream";
import { BxLogger } from "@/utils/bx-logger";
export const enum StreamPlayerElement {
VIDEO = 'video',
CANVAS = 'canvas',
}
export const enum StreamPlayerFilter {
USM = 1,
CAS = 2,
}
export abstract class BaseStreamPlayer {
protected logTag: string;
protected playerType: StreamPlayerType;
protected elementType: StreamPlayerElement;
protected $video: HTMLVideoElement;
protected options: StreamPlayerOptions = {
processing: StreamVideoProcessing.USM,
sharpness: 0,
brightness: 1.0,
contrast: 1.0,
saturation: 1.0,
};
protected isStopped = false;
constructor(playerType: StreamPlayerType, elementType: StreamPlayerElement, $video: HTMLVideoElement, logTag: string) {
this.playerType = playerType;
this.elementType = elementType;
this.$video = $video;
this.logTag = logTag;
}
init() {
BxLogger.info(this.logTag, 'Initialize');
}
updateOptions(newOptions: Partial<StreamPlayerOptions>, refresh=false) {
this.options = Object.assign(this.options, newOptions);
refresh && this.refreshPlayer();
}
abstract refreshPlayer(): void;
}

View File

@ -0,0 +1,102 @@
import { CE } from "@/utils/html";
import { BaseStreamPlayer, StreamPlayerElement } from "../base-stream-player";
import { StreamPlayerType, StreamVideoProcessing } from "@/enums/pref-values";
import { GlobalPref } from "@/enums/pref-keys";
import { getGlobalPref } from "@/utils/pref-utils";
import { ScreenshotManager } from "@/utils/screenshot-manager";
export class VideoPlayer extends BaseStreamPlayer {
private $videoCss!: HTMLStyleElement;
private $usmMatrix!: SVGFEConvolveMatrixElement;
constructor($video: HTMLVideoElement, logTag: string) {
super(StreamPlayerType.VIDEO, StreamPlayerElement.VIDEO, $video, logTag);
}
init(): void {
super.init();
// Setup SVG filters
const xmlns = 'http://www.w3.org/2000/svg';
const $svg = CE('svg', {
id: 'bx-video-filters',
class: 'bx-gone',
xmlns,
},
CE('defs', { xmlns: 'http://www.w3.org/2000/svg' },
CE('filter', {
id: 'bx-filter-usm',
xmlns,
}, this.$usmMatrix = CE('feConvolveMatrix', {
id: 'bx-filter-usm-matrix',
order: '3',
xmlns,
}) as unknown as SVGFEConvolveMatrixElement),
),
);
this.$videoCss = CE('style', { id: 'bx-video-css' });
const $fragment = document.createDocumentFragment();
$fragment.append(this.$videoCss, $svg);
document.documentElement.appendChild($fragment);
}
protected setupRendering(): void {}
forceDrawFrame(): void {}
updateCanvas(): void {}
refreshPlayer() {
let filters = this.getVideoPlayerFilterStyle();
let videoCss = '';
if (filters) {
videoCss += `filter: ${filters} !important;`;
}
// Apply video filters to screenshots
if (getGlobalPref(GlobalPref.SCREENSHOT_APPLY_FILTERS)) {
ScreenshotManager.getInstance().updateCanvasFilters(filters);
}
let css = '';
if (videoCss) {
css = `#game-stream video { ${videoCss} }`;
}
this.$videoCss.textContent = css;
}
clearFilters() {
this.$videoCss.textContent = '';
}
private getVideoPlayerFilterStyle() {
const filters = [];
const sharpness = this.options.sharpness || 0;
if (this.options.processing === StreamVideoProcessing.USM && sharpness != 0) {
const level = (7 - ((sharpness / 2) - 1) * 0.5).toFixed(1); // 5, 5.5, 6, 6.5, 7
const matrix = `0 -1 0 -1 ${level} -1 0 -1 0`;
this.$usmMatrix?.setAttributeNS(null, 'kernelMatrix', matrix);
filters.push(`url(#bx-filter-usm)`);
}
const saturation = this.options.saturation || 100;
if (saturation != 100) {
filters.push(`saturate(${saturation}%)`);
}
const contrast = this.options.contrast || 100;
if (contrast != 100) {
filters.push(`contrast(${contrast}%)`);
}
const brightness = this.options.brightness || 100;
if (brightness != 100) {
filters.push(`brightness(${brightness}%)`);
}
return filters.join(' ');
}
}

View File

@ -1,268 +0,0 @@
import vertClarityBoost from "./shaders/clarity_boost.vert" with { type: "text" };
import fsClarityBoost from "./shaders/clarity_boost.fs" with { type: "text" };
import { BxLogger } from "@/utils/bx-logger";
import { PrefKey } from "@/enums/pref-keys";
import { getPref } from "@/utils/settings-storages/global-settings-storage";
export class WebGL2Player {
private readonly LOG_TAG = 'WebGL2Player';
private $video: HTMLVideoElement;
private $canvas: HTMLCanvasElement;
private gl: WebGL2RenderingContext | null = null;
private resources: Array<any> = [];
private program: WebGLProgram | null = null;
private stopped: boolean = false;
private options = {
filterId: 1,
sharpenFactor: 0,
brightness: 0.0,
contrast: 0.0,
saturation: 0.0,
};
private targetFps = 60;
private frameInterval = 0;
private lastFrameTime = 0;
private animFrameId: number | null = null;
constructor($video: HTMLVideoElement) {
BxLogger.info(this.LOG_TAG, 'Initialize');
this.$video = $video;
const $canvas = document.createElement('canvas');
$canvas.width = $video.videoWidth;
$canvas.height = $video.videoHeight;
this.$canvas = $canvas;
this.setupShaders();
this.setupRendering();
$video.insertAdjacentElement('afterend', $canvas);
}
setFilter(filterId: number, update = true) {
this.options.filterId = filterId;
update && this.updateCanvas();
}
setSharpness(sharpness: number, update = true) {
this.options.sharpenFactor = sharpness;
update && this.updateCanvas();
}
setBrightness(brightness: number, update = true) {
this.options.brightness = 1 + (brightness - 100) / 100;
update && this.updateCanvas();
}
setContrast(contrast: number, update = true) {
this.options.contrast = 1 + (contrast - 100) / 100;
update && this.updateCanvas();
}
setSaturation(saturation: number, update = true) {
this.options.saturation = 1 + (saturation - 100) / 100;
update && this.updateCanvas();
}
setTargetFps(target: number) {
this.targetFps = target;
this.lastFrameTime = 0;
this.frameInterval = target ? Math.floor(1000 / target) : 0;
}
getCanvas() {
return this.$canvas;
}
updateCanvas() {
const gl = this.gl!;
const program = this.program!;
gl.uniform2f(gl.getUniformLocation(program, 'iResolution'), this.$canvas.width, this.$canvas.height);
gl.uniform1i(gl.getUniformLocation(program, 'filterId'), this.options.filterId);
gl.uniform1f(gl.getUniformLocation(program, 'sharpenFactor'), this.options.sharpenFactor);
gl.uniform1f(gl.getUniformLocation(program, 'brightness'), this.options.brightness);
gl.uniform1f(gl.getUniformLocation(program, 'contrast'), this.options.contrast);
gl.uniform1f(gl.getUniformLocation(program, 'saturation'), this.options.saturation);
}
forceDrawFrame() {
const gl = this.gl!;
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, this.$video);
gl.drawArrays(gl.TRIANGLES, 0, 6);
}
private setupRendering() {
let frameCallback: any;
if ('requestVideoFrameCallback' in HTMLVideoElement.prototype) {
const $video = this.$video;
frameCallback = $video.requestVideoFrameCallback.bind($video);
} else {
frameCallback = requestAnimationFrame;
}
let animate = () => {
if (this.stopped) {
return;
}
this.animFrameId = frameCallback(animate);
let draw = true;
// Don't draw when FPS is 0
if (this.targetFps === 0) {
draw = false;
} else if (this.targetFps < 60) {
// Limit FPS
const currentTime = performance.now();
const timeSinceLastFrame = currentTime - this.lastFrameTime;
if (timeSinceLastFrame < this.frameInterval) {
draw = false;
} else {
this.lastFrameTime = currentTime;
}
}
if (draw) {
const gl = this.gl!;
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, this.$video);
gl.drawArrays(gl.TRIANGLES, 0, 6);
}
}
this.animFrameId = frameCallback(animate);
}
private setupShaders() {
BxLogger.info(this.LOG_TAG, 'Setting up', getPref(PrefKey.VIDEO_POWER_PREFERENCE));
const gl = this.$canvas.getContext('webgl2', {
isBx: true,
antialias: true,
alpha: false,
powerPreference: getPref(PrefKey.VIDEO_POWER_PREFERENCE),
}) as WebGL2RenderingContext;
this.gl = gl;
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferWidth);
// Vertex shader: Identity map
const vShader = gl.createShader(gl.VERTEX_SHADER)!;
gl.shaderSource(vShader, vertClarityBoost);
gl.compileShader(vShader);
const fShader = gl.createShader(gl.FRAGMENT_SHADER)!;
gl.shaderSource(fShader, fsClarityBoost);
gl.compileShader(fShader);
// Create and link program
const program = gl.createProgram()!;
this.program = program;
gl.attachShader(program, vShader);
gl.attachShader(program, fShader);
gl.linkProgram(program);
gl.useProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
console.error(`Link failed: ${gl.getProgramInfoLog(program)}`);
console.error(`vs info-log: ${gl.getShaderInfoLog(vShader)}`);
console.error(`fs info-log: ${gl.getShaderInfoLog(fShader)}`);
}
this.updateCanvas();
// Vertices: A screen-filling quad made from two triangles
const buffer = gl.createBuffer();
this.resources.push(buffer);
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
// Texture to contain the video data
const texture = gl.createTexture();
this.resources.push(texture);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
// Bind texture to the "data" argument to the fragment shader
gl.uniform1i(gl.getUniformLocation(program, 'data'), 0);
gl.activeTexture(gl.TEXTURE0);
// gl.bindTexture(gl.TEXTURE_2D, texture);
}
resume() {
this.stop();
this.stopped = false;
BxLogger.info(this.LOG_TAG, 'Resume');
this.$canvas.classList.remove('bx-gone');
this.setupRendering();
}
stop() {
BxLogger.info(this.LOG_TAG, 'Stop');
this.$canvas.classList.add('bx-gone');
this.stopped = true;
if (this.animFrameId) {
if ('requestVideoFrameCallback' in HTMLVideoElement.prototype) {
this.$video.cancelVideoFrameCallback(this.animFrameId);
} else {
cancelAnimationFrame(this.animFrameId);
}
this.animFrameId = null;
}
}
destroy() {
BxLogger.info(this.LOG_TAG, 'Destroy');
this.stop();
const gl = this.gl;
if (gl) {
gl.getExtension('WEBGL_lose_context')?.loseContext();
gl.useProgram(null);
for (const resource of this.resources) {
if (resource instanceof WebGLProgram) {
gl.deleteProgram(resource);
} else if (resource instanceof WebGLShader) {
gl.deleteShader(resource);
} else if (resource instanceof WebGLTexture) {
gl.deleteTexture(resource);
} else if (resource instanceof WebGLBuffer) {
gl.deleteBuffer(resource);
}
}
this.gl = null;
}
if (this.$canvas.isConnected) {
this.$canvas.parentElement?.removeChild(this.$canvas);
}
this.$canvas.width = 1;
this.$canvas.height = 1;
}
}

View File

@ -5,15 +5,16 @@ uniform sampler2D data;
uniform vec2 iResolution; uniform vec2 iResolution;
const int FILTER_UNSHARP_MASKING = 1; const int FILTER_UNSHARP_MASKING = 1;
// const int FILTER_CAS = 2; const int FILTER_CAS = 2;
// constrast = 0.8 // constrast = 0.8
const float CAS_CONTRAST_PEAK = 0.8 * -3.0 + 8.0; const float CAS_CONTRAST_PEAK = 0.8 * -3.0 + 8.0;
// Luminosity factor // Luminosity factor: https://www.w3.org/TR/AERT/#color-contrast
const vec3 LUMINOSITY_FACTOR = vec3(0.2126, 0.7152, 0.0722); const vec3 LUMINOSITY_FACTOR = vec3(0.299, 0.587, 0.114);
uniform int filterId; uniform int filterId;
uniform bool qualityMode;
uniform float sharpenFactor; uniform float sharpenFactor;
uniform float brightness; uniform float brightness;
uniform float contrast; uniform float contrast;
@ -28,16 +29,22 @@ vec3 clarityBoost(sampler2D tex, vec2 coord, vec3 e) {
// a b c // a b c
// d e f // d e f
// g h i // g h i
vec3 a = texture(tex, coord + texelSize * vec2(-1, 1)).rgb;
vec3 b = texture(tex, coord + texelSize * vec2(0, 1)).rgb; vec3 b = texture(tex, coord + texelSize * vec2(0, 1)).rgb;
vec3 c = texture(tex, coord + texelSize * vec2(1, 1)).rgb;
vec3 d = texture(tex, coord + texelSize * vec2(-1, 0)).rgb; vec3 d = texture(tex, coord + texelSize * vec2(-1, 0)).rgb;
vec3 f = texture(tex, coord + texelSize * vec2(1, 0)).rgb; vec3 f = texture(tex, coord + texelSize * vec2(1, 0)).rgb;
vec3 g = texture(tex, coord + texelSize * vec2(-1, -1)).rgb;
vec3 h = texture(tex, coord + texelSize * vec2(0, -1)).rgb; vec3 h = texture(tex, coord + texelSize * vec2(0, -1)).rgb;
vec3 i = texture(tex, coord + texelSize * vec2(1, -1)).rgb;
vec3 a;
vec3 c;
vec3 g;
vec3 i;
if (filterId == FILTER_UNSHARP_MASKING || qualityMode) {
a = texture(tex, coord + texelSize * vec2(-1, 1)).rgb;
c = texture(tex, coord + texelSize * vec2(1, 1)).rgb;
g = texture(tex, coord + texelSize * vec2(-1, -1)).rgb;
i = texture(tex, coord + texelSize * vec2(1, -1)).rgb;
}
// USM // USM
if (filterId == FILTER_UNSHARP_MASKING) { if (filterId == FILTER_UNSHARP_MASKING) {
@ -55,10 +62,12 @@ vec3 clarityBoost(sampler2D tex, vec2 coord, vec3 e) {
// g h i h // g h i h
// These are 2.0x bigger (factored out the extra multiply). // These are 2.0x bigger (factored out the extra multiply).
vec3 minRgb = min(min(min(d, e), min(f, b)), h); vec3 minRgb = min(min(min(d, e), min(f, b)), h);
minRgb += min(min(a, c), min(g, i));
vec3 maxRgb = max(max(max(d, e), max(f, b)), h); vec3 maxRgb = max(max(max(d, e), max(f, b)), h);
maxRgb += max(max(a, c), max(g, i));
if (qualityMode) {
minRgb += min(min(a, c), min(g, i));
maxRgb += max(max(a, c), max(g, i));
}
// Smooth minimum distance to signal limit divided by smooth max. // Smooth minimum distance to signal limit divided by smooth max.
vec3 reciprocalMaxRgb = 1.0 / maxRgb; vec3 reciprocalMaxRgb = 1.0 / maxRgb;
@ -85,10 +94,12 @@ void main() {
vec3 color = texture(data, uv).rgb; vec3 color = texture(data, uv).rgb;
// Clarity boost // Clarity boost
color = sharpenFactor > 0.0 ? clarityBoost(data, uv, color) : color; if (sharpenFactor > 0.0) {
color = clarityBoost(data, uv, color);
}
// Saturation // Saturation
color = saturation != 1.0 ? mix(vec3(dot(color, LUMINOSITY_FACTOR)), color, saturation) : color; color = mix(vec3(dot(color, LUMINOSITY_FACTOR)), color, saturation);
// Contrast // Contrast
color = contrast * (color - 0.5) + 0.5; color = contrast * (color - 0.5) + 0.5;

View File

@ -0,0 +1,142 @@
import { compressCodeFile } from "@macros/build" with { type: "macro" };
import { StreamPref } from "@/enums/pref-keys";
import { getStreamPref } from "@/utils/pref-utils";
import { BaseCanvasPlayer } from "../base-canvas-player";
import { StreamPlayerType, StreamVideoProcessingMode } from "@/enums/pref-values";
export class WebGL2Player extends BaseCanvasPlayer {
private gl: WebGL2RenderingContext | null = null;
private resources: Array<WebGLBuffer | WebGLTexture | WebGLProgram | WebGLShader> = [];
private program: WebGLProgram | null = null;
constructor($video: HTMLVideoElement) {
super(StreamPlayerType.WEBGL2, $video, 'WebGL2Player');
}
private updateCanvas() {
console.log('updateCanvas', this.options);
const gl = this.gl!;
const program = this.program!;
const filterId = this.toFilterId(this.options.processing);
gl.uniform2f(gl.getUniformLocation(program, 'iResolution'), this.$canvas.width, this.$canvas.height);
gl.uniform1i(gl.getUniformLocation(program, 'filterId'), filterId);
gl.uniform1i(gl.getUniformLocation(program, 'qualityMode'), this.options.processingMode === StreamVideoProcessingMode.QUALITY ? 1 : 0);
gl.uniform1f(gl.getUniformLocation(program, 'sharpenFactor'), this.options.sharpness / (this.options.processingMode === StreamVideoProcessingMode.QUALITY ? 1 : 1.2));
gl.uniform1f(gl.getUniformLocation(program, 'brightness'), this.options.brightness / 100);
gl.uniform1f(gl.getUniformLocation(program, 'contrast'), this.options.contrast / 100);
gl.uniform1f(gl.getUniformLocation(program, 'saturation'), this.options.saturation / 100);
}
updateFrame() {
const gl = this.gl!;
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, this.$video);
gl.drawArrays(gl.TRIANGLES, 0, 3);
}
protected async setupShaders(): Promise<void> {
const gl = this.$canvas.getContext('webgl2', {
isBx: true,
antialias: true,
alpha: false,
depth: false,
preserveDrawingBuffer: false,
stencil: false,
powerPreference: getStreamPref(StreamPref.VIDEO_POWER_PREFERENCE),
} as WebGLContextAttributes) as WebGL2RenderingContext;
this.gl = gl;
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferWidth);
// Vertex shader: Identity map
const vShader = gl.createShader(gl.VERTEX_SHADER)!;
gl.shaderSource(vShader, compressCodeFile('./src/modules/player/webgl2/shaders/clarity-boost.vert') as any as string);
gl.compileShader(vShader);
const fShader = gl.createShader(gl.FRAGMENT_SHADER)!;
gl.shaderSource(fShader, compressCodeFile('./src/modules/player/webgl2/shaders/clarity-boost.fs') as any as string);
gl.compileShader(fShader);
// Create and link program
const program = gl.createProgram()!;
this.program = program;
gl.attachShader(program, vShader);
gl.attachShader(program, fShader);
gl.linkProgram(program);
gl.useProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
console.error(`Link failed: ${gl.getProgramInfoLog(program)}`);
console.error(`vs info-log: ${gl.getShaderInfoLog(vShader)}`);
console.error(`fs info-log: ${gl.getShaderInfoLog(fShader)}`);
}
this.updateCanvas();
// Vertices: A screen-filling quad made from two triangles
const buffer = gl.createBuffer();
this.resources.push(buffer);
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
-1.0, -1.0, // Bottom-left
3.0, -1.0, // Bottom-right
-1.0, 3.0, // Top-left
]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
// Texture to contain the video data
const texture = gl.createTexture();
this.resources.push(texture);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
// Bind texture to the "data" argument to the fragment shader
gl.uniform1i(gl.getUniformLocation(program, 'data'), 0);
gl.activeTexture(gl.TEXTURE0);
// gl.bindTexture(gl.TEXTURE_2D, texture);
}
destroy() {
super.destroy();
const gl = this.gl;
if (!gl) {
return;
}
gl.getExtension('WEBGL_lose_context')?.loseContext();
gl.useProgram(null);
for (const resource of this.resources) {
if (resource instanceof WebGLProgram) {
gl.deleteProgram(resource);
} else if (resource instanceof WebGLShader) {
gl.deleteShader(resource);
} else if (resource instanceof WebGLTexture) {
gl.deleteTexture(resource);
} else if (resource instanceof WebGLBuffer) {
gl.deleteBuffer(resource);
}
}
this.gl = null;
}
refreshPlayer(): void {
this.updateCanvas();
}
}

View File

@ -0,0 +1,93 @@
struct Params {
filterId: f32,
sharpness: f32,
brightness: f32,
contrast: f32,
saturation: f32,
};
struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) uv: vec2<f32>,
};
@group(0) @binding(0) var ourSampler: sampler;
@group(0) @binding(1) var ourTexture: texture_external;
@group(0) @binding(2) var<uniform> ourParams: Params;
const FILTER_UNSHARP_MASKING: f32 = 1.0;
const CAS_CONTRAST_PEAK: f32 = 0.8 * -3.0 + 8.0;
// Luminosity factor: https://www.w3.org/TR/AERT/#color-contrast
const LUMINOSITY_FACTOR = vec3(0.299, 0.587, 0.114);
@vertex
fn vsMain(@location(0) pos: vec2<f32>) -> VertexOutput {
var out: VertexOutput;
out.position = vec4(pos, 0.0, 1.0);
// Flip the Y-coordinate of UVs
out.uv = (vec2(pos.x, 1.0 - (pos.y + 1.0)) + vec2(1.0, 1.0)) * 0.5;
return out;
}
fn clarityBoost(coord: vec2<f32>, texSize: vec2<f32>, e: vec3<f32>) -> vec3<f32> {
let texelSize = 1.0 / texSize;
// Load 3x3 neighborhood samples
let a = textureSampleBaseClampToEdge(ourTexture, ourSampler, coord + texelSize * vec2(-1.0, 1.0)).rgb;
let b = textureSampleBaseClampToEdge(ourTexture, ourSampler, coord + texelSize * vec2( 0.0, 1.0)).rgb;
let c = textureSampleBaseClampToEdge(ourTexture, ourSampler, coord + texelSize * vec2( 1.0, 1.0)).rgb;
let d = textureSampleBaseClampToEdge(ourTexture, ourSampler, coord + texelSize * vec2(-1.0, 0.0)).rgb;
let f = textureSampleBaseClampToEdge(ourTexture, ourSampler, coord + texelSize * vec2( 1.0, 0.0)).rgb;
let g = textureSampleBaseClampToEdge(ourTexture, ourSampler, coord + texelSize * vec2(-1.0, -1.0)).rgb;
let h = textureSampleBaseClampToEdge(ourTexture, ourSampler, coord + texelSize * vec2( 0.0, -1.0)).rgb;
let i = textureSampleBaseClampToEdge(ourTexture, ourSampler, coord + texelSize * vec2( 1.0, -1.0)).rgb;
// Unsharp Masking (USM)
if ourParams.filterId == FILTER_UNSHARP_MASKING {
let gaussianBlur = (a + c + g + i) * 1.0 + (b + d + f + h) * 2.0 + e * 4.0;
let blurred = gaussianBlur / 16.0;
return e + (e - blurred) * (ourParams.sharpness / 3.0);
}
// Contrast Adaptive Sharpening (CAS)
let minRgb = min(min(min(d, e), min(f, b)), h) + min(min(a, c), min(g, i));
let maxRgb = max(max(max(d, e), max(f, b)), h) + max(max(a, c), max(g, i));
let reciprocalMaxRgb = 1.0 / maxRgb;
var amplifyRgb = clamp(min(minRgb, 2.0 - maxRgb) * reciprocalMaxRgb, vec3(0.0), vec3(1.0));
amplifyRgb = 1.0 / sqrt(amplifyRgb);
let weightRgb = -(1.0 / (amplifyRgb * CAS_CONTRAST_PEAK));
let reciprocalWeightRgb = 1.0 / (4.0 * weightRgb + 1.0);
let window = b + d + f + h;
let outColor = clamp((window * weightRgb + e) * reciprocalWeightRgb, vec3(0.0), vec3(1.0));
return mix(e, outColor, ourParams.sharpness / 2.0);
}
@fragment
fn fsMain(input: VertexOutput) -> @location(0) vec4<f32> {
let texSize = vec2<f32>(textureDimensions(ourTexture));
let center = textureSampleBaseClampToEdge(ourTexture, ourSampler, input.uv);
var adjustedRgb = clarityBoost(input.uv, texSize, center.rgb);
// Compute grayscale intensity
let gray = dot(adjustedRgb, LUMINOSITY_FACTOR);
// Interpolate between grayscale and color
adjustedRgb = mix(vec3(gray), adjustedRgb, ourParams.saturation);
// Adjust contrast
adjustedRgb = (adjustedRgb - 0.5) * ourParams.contrast + 0.5;
// Adjust brightness
adjustedRgb *= ourParams.brightness;
return vec4(adjustedRgb, 1.0);
}

View File

@ -0,0 +1,188 @@
import { compressCodeFile } from "@macros/build" with { type: "macro" };
import { BaseCanvasPlayer } from "../base-canvas-player";
import { StreamPlayerType } from "@/enums/pref-values";
import { BxEventBus } from "@/utils/bx-event-bus";
import { BX_FLAGS } from "@/utils/bx-flags";
export class WebGPUPlayer extends BaseCanvasPlayer {
static device: GPUDevice;
context!: GPUCanvasContext | null;
pipeline!: GPURenderPipeline | null;
sampler!: GPUSampler | null;
bindGroup!: GPUBindGroup | null;
optionsUpdated: boolean = false;
paramsBuffer!: GPUBuffer | null;
vertexBuffer!: GPUBuffer | null;
static async prepare(): Promise<void> {
if (!BX_FLAGS.EnableWebGPURenderer || !navigator.gpu) {
BxEventBus.Script.emit('webgpu.ready', {});
return;
}
try {
const adapter = await navigator.gpu.requestAdapter();
if (adapter) {
WebGPUPlayer.device = await adapter.requestDevice();
WebGPUPlayer.device?.addEventListener('uncapturederror', e => {
console.error((e as GPUUncapturedErrorEvent).error.message);
});
}
} catch (ex) {
alert(ex);
}
BxEventBus.Script.emit('webgpu.ready', {});
}
constructor($video: HTMLVideoElement) {
super(StreamPlayerType.WEBGPU, $video, 'WebGPUPlayer');
}
protected setupShaders(): void {
this.context = this.$canvas.getContext('webgpu')!;
if (!this.context) {
alert('Can\'t initiate context');
return;
}
const format = navigator.gpu.getPreferredCanvasFormat();
this.context.configure({
device: WebGPUPlayer.device,
format,
alphaMode: 'opaque',
});
this.vertexBuffer = WebGPUPlayer.device.createBuffer({
label: 'vertex buffer',
size: 6 * 4, // 6 floats (2 per vertex)
usage: GPUBufferUsage.VERTEX,
mappedAtCreation: true,
});
const mappedRange = this.vertexBuffer.getMappedRange();
new Float32Array(mappedRange).set([
-1, 3, // Vertex 1
-1, -1, // Vertex 2
3, -1, // Vertex 3
]);
this.vertexBuffer.unmap();
const shaderModule = WebGPUPlayer.device.createShaderModule({ code: compressCodeFile('./src/modules/player/webgpu/shaders/clarity-boost.wgsl') as any as string });
this.pipeline = WebGPUPlayer.device.createRenderPipeline({
layout: 'auto',
vertex: {
module: shaderModule,
entryPoint: 'vsMain',
buffers: [{
arrayStride: 8,
attributes: [{
format: 'float32x2',
offset: 0,
shaderLocation: 0,
}],
}],
},
fragment: {
module: shaderModule,
entryPoint: 'fsMain',
targets: [{ format }],
},
primitive: { topology: 'triangle-list' },
});
this.sampler = WebGPUPlayer.device.createSampler({ magFilter: 'linear', minFilter: 'linear' });
this.updateCanvas();
}
private prepareUniformBuffer(value: any, classType: any) {
const uniform = new classType(value);
const uniformBuffer = WebGPUPlayer.device.createBuffer({
size: uniform.byteLength,
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
});
WebGPUPlayer.device.queue.writeBuffer(uniformBuffer, 0, uniform);
return uniformBuffer;
}
private updateCanvas() {
const externalTexture = WebGPUPlayer.device.importExternalTexture({ source: this.$video });
if (!this.optionsUpdated) {
this.paramsBuffer = this.prepareUniformBuffer([
this.toFilterId(this.options.processing),
this.options.sharpness,
this.options.brightness / 100,
this.options.contrast / 100,
this.options.saturation / 100,
], Float32Array);
this.optionsUpdated = true;
}
this.bindGroup = WebGPUPlayer.device.createBindGroup({
layout: this.pipeline!.getBindGroupLayout(0),
entries: [
{ binding: 0, resource: this.sampler },
{ binding: 1, resource: externalTexture as any },
{ binding: 2, resource: { buffer: this.paramsBuffer } },
],
});
}
updateFrame(): void {
this.updateCanvas();
const commandEncoder = WebGPUPlayer.device.createCommandEncoder();
const passEncoder = commandEncoder.beginRenderPass({
colorAttachments: [{
view: this.context!.getCurrentTexture().createView(),
loadOp: 'clear',
storeOp: 'store',
clearValue: [0.0, 0.0, 0.0, 1.0],
}]
});
passEncoder.setPipeline(this.pipeline!);
passEncoder.setBindGroup(0, this.bindGroup);
passEncoder.setVertexBuffer(0, this.vertexBuffer);
passEncoder.draw(3);
passEncoder.end();
WebGPUPlayer.device.queue.submit([commandEncoder.finish()]);
}
refreshPlayer(): void {
this.optionsUpdated = false;
this.updateCanvas();
}
destroy(): void {
super.destroy();
this.isStopped = true;
// Unset GPU resources
this.pipeline = null;
this.bindGroup = null;
this.sampler = null;
this.paramsBuffer?.destroy();
this.paramsBuffer = null;
this.vertexBuffer?.destroy();
this.vertexBuffer = null;
// Reset the WebGPU context (force garbage collection)
if (this.context) {
this.context.unconfigure();
this.context = null;
}
console.log('WebGPU context successfully freed.');
}
}

View File

@ -5,9 +5,10 @@ import { t } from "@utils/translation";
import { localRedirect } from "@modules/ui/ui"; import { localRedirect } from "@modules/ui/ui";
import { BxLogger } from "@utils/bx-logger"; import { BxLogger } from "@utils/bx-logger";
import { HeaderSection } from "./ui/header"; import { HeaderSection } from "./ui/header";
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref } from "@/enums/pref-keys";
import { getPref, setPref } from "@/utils/settings-storages/global-settings-storage"; import { getGlobalPref, setGlobalPref } from "@/utils/pref-utils";
import { RemotePlayDialog } from "./ui/dialog/remote-play-dialog"; import { RemotePlayDialog } from "./ui/dialog/remote-play-dialog";
import { BlockFeature } from "@/enums/pref-values";
export const enum RemotePlayConsoleState { export const enum RemotePlayConsoleState {
ON = 'On', ON = 'On',
@ -37,7 +38,7 @@ export class RemotePlayManager {
private static instance: RemotePlayManager | null | undefined; private static instance: RemotePlayManager | null | undefined;
public static getInstance(): typeof RemotePlayManager['instance'] { public static getInstance(): typeof RemotePlayManager['instance'] {
if (typeof RemotePlayManager.instance === 'undefined') { if (typeof RemotePlayManager.instance === 'undefined') {
if (getPref(PrefKey.REMOTE_PLAY_ENABLED)) { if (!getGlobalPref(GlobalPref.BLOCK_FEATURES).includes(BlockFeature.REMOTE_PLAY)) {
RemotePlayManager.instance = new RemotePlayManager(); RemotePlayManager.instance = new RemotePlayManager();
} else { } else {
RemotePlayManager.instance = null; RemotePlayManager.instance = null;
@ -156,6 +157,11 @@ export class RemotePlayManager {
}, },
}; };
// Start with "isDefault" = true first
this.regions.sort((a: RemotePlayRegion, b: RemotePlayRegion) => {
return a.isDefault ? -1 : 0;
})
// Test servers one by one // Test servers one by one
for (const region of this.regions) { for (const region of this.regions) {
try { try {
@ -186,15 +192,10 @@ export class RemotePlayManager {
play(serverId: string, resolution?: string) { play(serverId: string, resolution?: string) {
if (resolution) { if (resolution) {
setPref(PrefKey.REMOTE_PLAY_STREAM_RESOLUTION, resolution); setGlobalPref(GlobalPref.REMOTE_PLAY_STREAM_RESOLUTION, resolution, 'ui');
} }
STATES.remotePlay.config = { localRedirect('/consoles/launch/' + serverId);
serverId: serverId,
};
window.BX_REMOTE_PLAY_CONFIG = STATES.remotePlay.config;
localRedirect('/launch/fortnite/BT5P2X999VH2#remote-play');
} }
togglePopup(force = null) { togglePopup(force = null) {
@ -208,33 +209,9 @@ export class RemotePlayManager {
return; return;
} }
/*
// Show native dialog in Android app
if (AppInterface && AppInterface.showRemotePlayDialog) {
AppInterface.showRemotePlayDialog(JSON.stringify(this.consoles));
(document.activeElement as HTMLElement).blur();
return;
}
*/
RemotePlayDialog.getInstance().show(); RemotePlayDialog.getInstance().show();
} }
static detect() {
if (!getPref(PrefKey.REMOTE_PLAY_ENABLED)) {
return;
}
STATES.remotePlay.isPlaying = window.location.pathname.includes('/launch/') && window.location.hash.startsWith('#remote-play');
if (STATES.remotePlay?.isPlaying) {
window.BX_REMOTE_PLAY_CONFIG = STATES.remotePlay.config;
// Remove /launch/... from URL
window.history.replaceState({origin: 'better-xcloud'}, '', 'https://www.xbox.com/' + location.pathname.substring(1, 6) + '/play');
} else {
window.BX_REMOTE_PLAY_CONFIG = null;
}
}
isReady() { isReady() {
return this.consoles !== null; return this.consoles !== null;
} }

View File

@ -0,0 +1,356 @@
import { GlobalPref, StreamPref, type AnyPref } from "@/enums/pref-keys";
import { limitVideoPlayerFps, onChangeVideoPlayerType, updateVideoPlayer } from "./stream/stream-settings-utils";
import { StreamStats } from "./stream/stream-stats";
import { SoundShortcut } from "./shortcuts/sound-shortcut";
import { STATES } from "@/utils/global";
import { getGamePref, getStreamPref, hasGamePref, isStreamPref, setGameIdPref, STORAGE } from "@/utils/pref-utils";
import { BxExposed } from "@/utils/bx-exposed";
import { StreamSettings } from "@/utils/stream-settings";
import { NativeMkbHandler } from "./mkb/native-mkb-handler";
import { BxEventBus } from "@/utils/bx-event-bus";
import { SettingElement } from "@/utils/setting-element";
import { CE } from "@/utils/html";
import { t } from "@/utils/translation";
import { BxSelectElement } from "@/web-components/bx-select";
import { XboxApi } from "@/utils/xbox-api";
import { EmulatedMkbHandler } from "./mkb/mkb-handler";
type SettingType = Partial<{
hidden: true;
onChange: () => void;
onChangeUi: () => void;
$element: HTMLElement;
}>;
export class SettingsManager {
private static instance: SettingsManager;
public static getInstance = () => SettingsManager.instance ?? (SettingsManager.instance = new SettingsManager());
private $streamSettingsSelection!: HTMLElement;
private $tips!: HTMLElement;
private playingGameId: number = -1;
private targetGameId: number = -1;
// @ts-ignore
private SETTINGS: Record<GlobalPref | StreamPref, SettingType> = {
// [GlobalPref.VERSION_LATEST]: { hidden: true },
// [GlobalPref.VERSION_LAST_CHECK]: { hidden: true },
// [GlobalPref.VERSION_CURRENT]: { hidden: true },
[StreamPref.LOCAL_CO_OP_ENABLED]: {
onChange: () => {
BxExposed.toggleLocalCoOp(getStreamPref(StreamPref.LOCAL_CO_OP_ENABLED));
},
},
[StreamPref.DEVICE_VIBRATION_MODE]: {
onChange: StreamSettings.refreshControllerSettings,
},
[StreamPref.DEVICE_VIBRATION_INTENSITY]: {
onChange: StreamSettings.refreshControllerSettings,
},
[StreamPref.CONTROLLER_POLLING_RATE]: {
onChange: StreamSettings.refreshControllerSettings,
},
[StreamPref.CONTROLLER_SETTINGS]: {
onChange: StreamSettings.refreshControllerSettings,
},
[StreamPref.NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY]: {
onChange: () => {
const value = getStreamPref(StreamPref.NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY);
NativeMkbHandler.getInstance()?.setHorizontalScrollMultiplier(value / 100);
},
},
[StreamPref.NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY]: {
onChange: () => {
const value = getStreamPref(StreamPref.NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY);
NativeMkbHandler.getInstance()?.setVerticalScrollMultiplier(value / 100);
},
},
[StreamPref.VIDEO_PLAYER_TYPE]: {
onChange: updateVideoPlayer,
onChangeUi: onChangeVideoPlayerType,
},
[StreamPref.VIDEO_POWER_PREFERENCE]: {
onChange: () => {
const streamPlayer = STATES.currentStream.streamPlayerManager;
if (!streamPlayer) {
return;
}
updateVideoPlayer();
},
},
[StreamPref.VIDEO_PROCESSING]: {
onChange: updateVideoPlayer,
onChangeUi: onChangeVideoPlayerType,
},
[StreamPref.VIDEO_PROCESSING_MODE]: {
onChange: updateVideoPlayer,
},
[StreamPref.VIDEO_SHARPNESS]: {
onChange: updateVideoPlayer,
},
[StreamPref.VIDEO_MAX_FPS]: {
onChange: () => {
const value = getStreamPref(StreamPref.VIDEO_MAX_FPS);
limitVideoPlayerFps(value);
},
},
[StreamPref.VIDEO_RATIO]: {
onChange: updateVideoPlayer,
},
[StreamPref.VIDEO_BRIGHTNESS]: {
onChange: updateVideoPlayer,
},
[StreamPref.VIDEO_CONTRAST]: {
onChange: updateVideoPlayer,
},
[StreamPref.VIDEO_SATURATION]: {
onChange: updateVideoPlayer,
},
[StreamPref.VIDEO_POSITION]: {
onChange: updateVideoPlayer,
},
[StreamPref.AUDIO_VOLUME]: {
onChange: () => {
const value = getStreamPref(StreamPref.AUDIO_VOLUME);
SoundShortcut.setGainNodeVolume(value);
},
},
[StreamPref.STATS_ITEMS]: {
onChange: StreamStats.refreshStyles,
},
[StreamPref.STATS_QUICK_GLANCE_ENABLED]: {
onChange: () => {
const value = getStreamPref(StreamPref.STATS_QUICK_GLANCE_ENABLED);
if (!value) {
StreamStats.getInstance().stop(true);
}
},
},
[StreamPref.STATS_POSITION]: {
onChange: StreamStats.refreshStyles,
},
[StreamPref.STATS_TEXT_SIZE]: {
onChange: StreamStats.refreshStyles,
},
[StreamPref.STATS_OPACITY_ALL]: {
onChange: StreamStats.refreshStyles,
},
[StreamPref.STATS_OPACITY_BACKGROUND]: {
onChange: StreamStats.refreshStyles,
},
[StreamPref.STATS_CONDITIONAL_FORMATTING]: {
onChange: StreamStats.refreshStyles,
},
[StreamPref.MKB_P1_MAPPING_PRESET_ID]: {
onChange: StreamSettings.refreshMkbSettings,
},
[StreamPref.MKB_P1_SLOT]: {
onChange: () => {
EmulatedMkbHandler.getInstance()?.resetXcloudGamepads();
},
},
[StreamPref.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID]: {
onChange: StreamSettings.refreshKeyboardShortcuts,
},
};
constructor() {
// Trigger onChange event when a setting value is modified
BxEventBus.Stream.on('setting.changed', data => {
if (isStreamPref(data.settingKey)) {
this.updateStreamElement(data.settingKey);
}
});
BxEventBus.Stream.on('gameSettings.switched', ({ id }) => {
this.switchGameSettings(id);
});
this.renderStreamSettingsSelection();
}
private updateStreamElement(key: StreamPref, onChanges?: Set<SettingType['onChange']>, onChangeUis?: Set<SettingType['onChangeUi']>) {
const info = this.SETTINGS[key];
// Add events
if (info.onChangeUi) {
if (onChangeUis) {
// Save to a Set()
onChangeUis.add(info.onChangeUi);
} else {
// Trigger onChangeUi()
info.onChangeUi();
}
}
if (info.onChange && STATES.isPlaying) {
if (onChanges) {
// Save to a Set()
onChanges.add(info.onChange);
} else {
// Trigger onChange()
info.onChange();
}
}
// Update element
const $elm = info.$element;
if (!$elm) {
return;
}
const value = getGamePref(this.targetGameId, key, true)!;
if ('setValue' in $elm) {
($elm as any).setValue(value);
} else {
($elm as HTMLInputElement).value = value.toString();
}
this.updateDataset($elm, key as StreamPref);
}
private switchGameSettings(id: number) {
setGameIdPref(id);
// Don't re-apply settings if the game is the same
if (this.targetGameId === id) {
return;
}
// Re-apply all stream settings
const onChanges: Set<SettingType['onChange']> = new Set();
const onChangeUis: Set<SettingType['onChangeUi']> = new Set();
const oldGameId = this.targetGameId;
this.targetGameId = id;
let key: AnyPref;
for (key in this.SETTINGS) {
if (!isStreamPref(key)) {
continue;
}
const oldValue = getGamePref(oldGameId, key, true);
const newValue = getGamePref(this.targetGameId, key, true);
if (oldValue === newValue) {
continue;
}
// Only apply Stream settings
this.updateStreamElement(key, onChanges, onChangeUis);
}
// Trigger onChange callbacks
onChangeUis.forEach(fn => fn && fn());
onChanges.forEach(fn => fn && fn());
// Toggle tips if not playing anything
this.$tips.classList.toggle('bx-gone', id < 0);
}
setElement(pref: AnyPref, $elm: HTMLElement) {
// Set empty object
if (!this.SETTINGS[pref]) {
this.SETTINGS[pref] = {};
}
this.updateDataset($elm, pref as StreamPref);
this.SETTINGS[pref].$element = $elm;
}
getElement(pref: AnyPref, params?: any) {
// Set empty object
if (!this.SETTINGS[pref]) {
this.SETTINGS[pref] = {};
}
let $elm = this.SETTINGS[pref].$element;
if (!$elm) {
// Render element
$elm = SettingElement.fromPref(pref, null, params)!;
this.SETTINGS[pref].$element = $elm;
}
this.updateDataset($elm, pref as StreamPref);
return $elm;
}
hasElement(pref: AnyPref) {
return !!this.SETTINGS[pref]?.$element;
}
private updateDataset($elm: HTMLElement, pref: StreamPref) {
if (this.targetGameId === this.playingGameId && hasGamePref(this.playingGameId, pref)) {
$elm.dataset.override = 'true';
} else {
delete $elm.dataset['override'];
}
}
private renderStreamSettingsSelection() {
this.$tips = CE('p', { class: 'bx-gone' }, ` ⟶: ${t('reset-highlighted-setting')}`);
const $select = BxSelectElement.create(CE('select', false,
CE('optgroup', { label: t('settings-for') },
CE('option', { value: -1 }, t('all-games')),
),
), true);
$select.addEventListener('input', e => {
const id = parseInt($select.value);
// $btn.disabled = id < 0;
BxEventBus.Stream.emit('gameSettings.switched', { id });
});
this.$streamSettingsSelection = CE('div', {
class: 'bx-stream-settings-selection bx-gone',
_nearby: { orientation: 'vertical' },
},
CE('div', false, $select ),
this.$tips,
);
BxEventBus.Stream.on('xboxTitleId.changed', async ({ id }) => {
this.playingGameId = id;
// Only switch to game settings if it's not empty
const gameSettings = STORAGE.Stream.getGameSettings(id);
const selectedId = (gameSettings && !gameSettings.isEmpty()) ? id : -1;
setGameIdPref(selectedId);
// Remove every options except the first one (All games)
const $optGroup = $select.querySelector('optgroup')!;
while ($optGroup.childElementCount > 1) {
$optGroup.lastElementChild?.remove();
}
// Add current game to the selection
if (id >= 0) {
const title = id === 0 ? 'Xbox' : await XboxApi.getProductTitle(id);
$optGroup.appendChild(CE('option', {
value: id,
}, title));
}
// Activate custom settings
$select.value = selectedId.toString();
BxEventBus.Stream.emit('gameSettings.switched', { id: selectedId });
});
}
getStreamSettingsSelection() {
return this.$streamSettingsSelection;
}
getTargetGameId() {
return this.targetGameId;
}
}

View File

@ -1,7 +1,7 @@
import { PrefKey } from "@/enums/pref-keys"; import { StreamPref } from "@/enums/pref-keys";
import { getPref } from "@/utils/settings-storages/global-settings-storage";
import { limitVideoPlayerFps } from "../stream/stream-settings-utils"; import { limitVideoPlayerFps } from "../stream/stream-settings-utils";
import { BxEventBus } from "@/utils/bx-event-bus"; import { BxEventBus } from "@/utils/bx-event-bus";
import { getStreamPref } from "@/utils/pref-utils";
export class RendererShortcut { export class RendererShortcut {
static toggleVisibility() { static toggleVisibility() {
@ -15,7 +15,7 @@ export class RendererShortcut {
const isVisible = !$mediaContainer.classList.contains('bx-gone'); const isVisible = !$mediaContainer.classList.contains('bx-gone');
// Switch FPS // Switch FPS
limitVideoPlayerFps(isVisible ? getPref(PrefKey.VIDEO_MAX_FPS) : 0); limitVideoPlayerFps(isVisible ? getStreamPref(StreamPref.VIDEO_MAX_FPS) : 0);
BxEventBus.Stream.emit('video.visibility.changed', { isVisible }); BxEventBus.Stream.emit('video.visibility.changed', { isVisible });
} }
} }

View File

@ -1,7 +1,7 @@
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref } from "@/enums/pref-keys";
import { ShortcutAction } from "@/enums/shortcut-actions"; import { ShortcutAction } from "@/enums/shortcut-actions";
import { AppInterface, STATES } from "@/utils/global"; import { AppInterface, STATES } from "@/utils/global";
import { getPref } from "@/utils/settings-storages/global-settings-storage"; import { getGlobalPref } from "@/utils/pref-utils";
import { t } from "@/utils/translation"; import { t } from "@/utils/translation";
type ShortcutActions = { type ShortcutActions = {
@ -46,7 +46,7 @@ export const SHORTCUT_ACTIONS: ShortcutActions = {
[ShortcutAction.STREAM_SOUND_TOGGLE]: [t('sound'), t('toggle')], [ShortcutAction.STREAM_SOUND_TOGGLE]: [t('sound'), t('toggle')],
...(getPref(PrefKey.AUDIO_VOLUME_CONTROL_ENABLED) ? { ...(getGlobalPref(GlobalPref.AUDIO_VOLUME_CONTROL_ENABLED) ? {
[ShortcutAction.STREAM_VOLUME_INC]: [t('volume'), t('increase')], [ShortcutAction.STREAM_VOLUME_INC]: [t('volume'), t('increase')],
[ShortcutAction.STREAM_VOLUME_DEC]: [t('volume'), t('decrease')], [ShortcutAction.STREAM_VOLUME_DEC]: [t('volume'), t('decrease')],
} : {}), } : {}),

View File

@ -2,9 +2,10 @@ import { t } from "@utils/translation";
import { STATES } from "@utils/global"; import { STATES } from "@utils/global";
import { Toast } from "@utils/toast"; import { Toast } from "@utils/toast";
import { ceilToNearest, floorToNearest } from "@/utils/utils"; import { ceilToNearest, floorToNearest } from "@/utils/utils";
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref, StreamPref } from "@/enums/pref-keys";
import { getPref, setPref } from "@/utils/settings-storages/global-settings-storage"; import { getGlobalPref } from "@/utils/pref-utils";
import { BxEventBus } from "@/utils/bx-event-bus"; import { BxEventBus } from "@/utils/bx-event-bus";
import { getStreamPref, setStreamPref } from "@/utils/pref-utils";
export enum SpeakerState { export enum SpeakerState {
ENABLED, ENABLED,
@ -13,11 +14,11 @@ export enum SpeakerState {
export class SoundShortcut { export class SoundShortcut {
static adjustGainNodeVolume(amount: number): number { static adjustGainNodeVolume(amount: number): number {
if (!getPref(PrefKey.AUDIO_VOLUME_CONTROL_ENABLED)) { if (!getGlobalPref(GlobalPref.AUDIO_VOLUME_CONTROL_ENABLED)) {
return 0; return 0;
} }
const currentValue = getPref(PrefKey.AUDIO_VOLUME); const currentValue = getStreamPref(StreamPref.AUDIO_VOLUME);
let nearestValue: number; let nearestValue: number;
if (amount > 0) { // Increase if (amount > 0) { // Increase
@ -33,7 +34,7 @@ export class SoundShortcut {
newValue = currentValue + amount; newValue = currentValue + amount;
} }
newValue = setPref(PrefKey.AUDIO_VOLUME, newValue, true); newValue = setStreamPref(StreamPref.AUDIO_VOLUME, newValue, 'direct');
SoundShortcut.setGainNodeVolume(newValue); SoundShortcut.setGainNodeVolume(newValue);
// Show toast // Show toast
@ -47,14 +48,14 @@ export class SoundShortcut {
} }
static muteUnmute() { static muteUnmute() {
if (getPref(PrefKey.AUDIO_VOLUME_CONTROL_ENABLED) && STATES.currentStream.audioGainNode) { if (getGlobalPref(GlobalPref.AUDIO_VOLUME_CONTROL_ENABLED) && STATES.currentStream.audioGainNode) {
const gainValue = STATES.currentStream.audioGainNode.gain.value; const gainValue = STATES.currentStream.audioGainNode.gain.value;
const settingValue = getPref(PrefKey.AUDIO_VOLUME); const settingValue = getStreamPref(StreamPref.AUDIO_VOLUME);
let targetValue: number; let targetValue: number;
if (settingValue === 0) { // settingValue is 0 => set to 100 if (settingValue === 0) { // settingValue is 0 => set to 100
targetValue = 100; targetValue = 100;
setPref(PrefKey.AUDIO_VOLUME, targetValue, true); setStreamPref(StreamPref.AUDIO_VOLUME, targetValue, 'direct');
} else if (gainValue === 0) { // is being muted => set to settingValue } else if (gainValue === 0) { // is being muted => set to settingValue
targetValue = settingValue; targetValue = settingValue;
} else { // not being muted => mute } else { // not being muted => mute

View File

@ -7,8 +7,8 @@ export class VirtualControllerShortcut {
return; return;
} }
const released = generateVirtualControllerMapping(); const released = generateVirtualControllerMapping(0);
const pressed = generateVirtualControllerMapping({ const pressed = generateVirtualControllerMapping(0, {
Nexus: 1, Nexus: 1,
VirtualPhysicality: 1024, // Home VirtualPhysicality: 1024, // Home
}); });

View File

@ -0,0 +1,191 @@
import { WebGL2Player } from "./player/webgl2/webgl2-player";
import { ScreenshotManager } from "@/utils/screenshot-manager";
import { STATES } from "@/utils/global";
import { StreamPref } from "@/enums/pref-keys";
import { BX_FLAGS } from "@/utils/bx-flags";
import { StreamPlayerType, VideoPosition } from "@/enums/pref-values";
import { getStreamPref } from "@/utils/pref-utils";
import type { BaseCanvasPlayer } from "./player/base-canvas-player";
import { VideoPlayer } from "./player/video/video-player";
import { StreamPlayerElement } from "./player/base-stream-player";
import { WebGPUPlayer } from "./player/webgpu/webgpu-player";
import type { StreamPlayerOptions } from "@/types/stream";
export class StreamPlayerManager {
private static instance: StreamPlayerManager;
public static getInstance = () => StreamPlayerManager.instance ?? (StreamPlayerManager.instance = new StreamPlayerManager());
private $video!: HTMLVideoElement;
private videoPlayer!: VideoPlayer;
private canvasPlayer: BaseCanvasPlayer | null | undefined;
private playerType: StreamPlayerType = StreamPlayerType.VIDEO;
private constructor() {}
setVideoElement($video: HTMLVideoElement) {
this.$video = $video;
this.videoPlayer = new VideoPlayer($video, 'VideoPlayer');
this.videoPlayer.init();
}
resizePlayer() {
const PREF_RATIO = getStreamPref(StreamPref.VIDEO_RATIO);
const $video = this.$video;
const isNativeTouchGame = STATES.currentStream.titleInfo?.details.hasNativeTouchSupport;
let targetWidth;
let targetHeight;
let targetObjectFit;
if (PREF_RATIO.includes(':')) {
const tmp = PREF_RATIO.split(':');
// Get preferred ratio
const videoRatio = parseFloat(tmp[0]) / parseFloat(tmp[1]);
let width = 0;
let height = 0;
// Get parent's ratio
const parentRect = $video.parentElement!.getBoundingClientRect();
const parentRatio = parentRect.width / parentRect.height;
// Get target width & height
if (parentRatio > videoRatio) {
height = parentRect.height;
width = height * videoRatio;
} else {
width = parentRect.width;
height = width / videoRatio;
}
// Avoid floating points
width = Math.ceil(Math.min(parentRect.width, width));
height = Math.ceil(Math.min(parentRect.height, height));
$video.dataset.width = width.toString();
$video.dataset.height = height.toString();
// Set position
const $parent = $video.parentElement!;
const position = getStreamPref(StreamPref.VIDEO_POSITION);
$parent.style.removeProperty('padding-top');
$parent.dataset.position = position;
if (position === VideoPosition.TOP_HALF || position === VideoPosition.BOTTOM_HALF) {
let padding = Math.floor((window.innerHeight - height) / 4);
if (padding > 0) {
if (position === VideoPosition.BOTTOM_HALF) {
padding *= 3;
}
$parent.style.paddingTop = padding + 'px';
}
}
// Update size
targetWidth = `${width}px`;
targetHeight = `${height}px`;
targetObjectFit = PREF_RATIO === '16:9' ? 'contain' : 'fill';
} else {
targetWidth = '100%';
targetHeight = '100%';
targetObjectFit = PREF_RATIO;
$video.dataset.width = window.innerWidth.toString();
$video.dataset.height = window.innerHeight.toString();
}
$video.style.width = targetWidth;
$video.style.height = targetHeight;
$video.style.objectFit = targetObjectFit;
if (this.canvasPlayer) {
const $canvas = this.canvasPlayer.getCanvas();
$canvas.style.width = targetWidth;
$canvas.style.height = targetHeight;
$canvas.style.objectFit = targetObjectFit;
$video.dispatchEvent(new Event('resize'));
}
// Update video dimensions
if (isNativeTouchGame && this.playerType !== StreamPlayerType.VIDEO) {
window.BX_EXPOSED.streamSession.updateDimensions();
}
}
switchPlayerType(type: StreamPlayerType, refreshPlayer: boolean = false) {
if (this.playerType !== type) {
const videoClass = BX_FLAGS.DeviceInfo.deviceType === 'android-tv' ? 'bx-pixel' : 'bx-gone';
// Destroy old player
this.cleanUpCanvasPlayer();
if (type === StreamPlayerType.VIDEO) {
// Switch from Canvas -> Video
this.$video.classList.remove(videoClass);
} else {
// Switch from Video -> Canvas
if (BX_FLAGS.EnableWebGPURenderer && type === StreamPlayerType.WEBGPU) {
this.canvasPlayer = new WebGPUPlayer(this.$video);
} else {
this.canvasPlayer = new WebGL2Player(this.$video);
}
this.canvasPlayer.init();
this.videoPlayer.clearFilters();
this.$video.classList.add(videoClass);
}
this.playerType = type;
}
refreshPlayer && this.refreshPlayer();
}
updateOptions(options: StreamPlayerOptions, refreshPlayer: boolean = false) {
(this.canvasPlayer || this.videoPlayer).updateOptions(options, refreshPlayer);
}
getPlayerElement(elementType?: StreamPlayerElement) {
if (typeof elementType === 'undefined') {
elementType = this.playerType === StreamPlayerType.VIDEO ? StreamPlayerElement.VIDEO : StreamPlayerElement.CANVAS;
}
if (elementType !== StreamPlayerElement.VIDEO) {
return this.canvasPlayer?.getCanvas();
}
return this.$video;
}
getCanvasPlayer() {
return this.canvasPlayer;
}
refreshPlayer() {
if (this.playerType === StreamPlayerType.VIDEO) {
this.videoPlayer.refreshPlayer();
} else {
ScreenshotManager.getInstance().updateCanvasFilters('none');
this.canvasPlayer?.refreshPlayer();
}
this.resizePlayer();
}
getVideoPlayerFilterStyle() {
throw new Error("Method not implemented.");
}
private cleanUpCanvasPlayer() {
this.canvasPlayer?.destroy();
this.canvasPlayer = null;
}
destroy() {
this.cleanUpCanvasPlayer();
}
}

View File

@ -1,303 +0,0 @@
import { isFullVersion } from "@macros/build" with { type: "macro" };
import { CE } from "@/utils/html";
import { WebGL2Player } from "./player/webgl2-player";
import { ScreenshotManager } from "@/utils/screenshot-manager";
import { STATES } from "@/utils/global";
import { PrefKey } from "@/enums/pref-keys";
import { getPref } from "@/utils/settings-storages/global-settings-storage";
import { BX_FLAGS } from "@/utils/bx-flags";
import { StreamPlayerType, StreamVideoProcessing, VideoPosition } from "@/enums/pref-values";
export type StreamPlayerOptions = Partial<{
processing: string,
sharpness: number,
saturation: number,
contrast: number,
brightness: number,
}>;
export class StreamPlayer {
private $video: HTMLVideoElement;
private playerType: StreamPlayerType = StreamPlayerType.VIDEO;
private options: StreamPlayerOptions = {};
private webGL2Player: WebGL2Player | null = null;
private $videoCss: HTMLStyleElement | null = null;
private $usmMatrix: SVGFEConvolveMatrixElement | null = null;
constructor($video: HTMLVideoElement, type: StreamPlayerType, options: StreamPlayerOptions) {
this.setupVideoElements();
this.$video = $video;
this.options = options || {};
this.setPlayerType(type);
}
private setupVideoElements() {
this.$videoCss = document.getElementById('bx-video-css') as HTMLStyleElement;
if (this.$videoCss) {
return;
}
const $fragment = document.createDocumentFragment();
this.$videoCss = CE('style', { id: 'bx-video-css' });
$fragment.appendChild(this.$videoCss);
// Setup SVG filters
const $svg = CE('svg', {
id: 'bx-video-filters',
xmlns: 'http://www.w3.org/2000/svg',
class: 'bx-gone',
}, CE('defs', { xmlns: 'http://www.w3.org/2000/svg' },
CE('filter', {
id: 'bx-filter-usm',
xmlns: 'http://www.w3.org/2000/svg',
}, this.$usmMatrix = CE('feConvolveMatrix', {
id: 'bx-filter-usm-matrix',
order: '3',
xmlns: 'http://www.w3.org/2000/svg',
}) as unknown as SVGFEConvolveMatrixElement),
),
);
$fragment.appendChild($svg);
document.documentElement.appendChild($fragment);
}
private getVideoPlayerFilterStyle() {
const filters = [];
const sharpness = this.options.sharpness || 0;
if (this.options.processing === StreamVideoProcessing.USM && sharpness != 0) {
const level = (7 - ((sharpness / 2) - 1) * 0.5).toFixed(1); // 5, 5.5, 6, 6.5, 7
const matrix = `0 -1 0 -1 ${level} -1 0 -1 0`;
this.$usmMatrix?.setAttributeNS(null, 'kernelMatrix', matrix);
filters.push(`url(#bx-filter-usm)`);
}
const saturation = this.options.saturation || 100;
if (saturation != 100) {
filters.push(`saturate(${saturation}%)`);
}
const contrast = this.options.contrast || 100;
if (contrast != 100) {
filters.push(`contrast(${contrast}%)`);
}
const brightness = this.options.brightness || 100;
if (brightness != 100) {
filters.push(`brightness(${brightness}%)`);
}
return filters.join(' ');
}
private resizePlayer() {
const PREF_RATIO = getPref(PrefKey.VIDEO_RATIO);
const $video = this.$video;
const isNativeTouchGame = STATES.currentStream.titleInfo?.details.hasNativeTouchSupport;
let $webGL2Canvas;
if (this.playerType == StreamPlayerType.WEBGL2) {
$webGL2Canvas = this.webGL2Player?.getCanvas()!;
}
let targetWidth;
let targetHeight;
let targetObjectFit;
if (PREF_RATIO.includes(':')) {
const tmp = PREF_RATIO.split(':');
// Get preferred ratio
const videoRatio = parseFloat(tmp[0]) / parseFloat(tmp[1]);
let width = 0;
let height = 0;
// Get parent's ratio
const parentRect = $video.parentElement!.getBoundingClientRect();
const parentRatio = parentRect.width / parentRect.height;
// Get target width & height
if (parentRatio > videoRatio) {
height = parentRect.height;
width = height * videoRatio;
} else {
width = parentRect.width;
height = width / videoRatio;
}
// Prevent floating points
width = Math.ceil(Math.min(parentRect.width, width));
height = Math.ceil(Math.min(parentRect.height, height));
$video.dataset.width = width.toString();
$video.dataset.height = height.toString();
// Set position
const $parent = $video.parentElement!;
const position = getPref(PrefKey.VIDEO_POSITION);
$parent.style.removeProperty('padding-top');
$parent.dataset.position = position;
if (position === VideoPosition.TOP_HALF || position === VideoPosition.BOTTOM_HALF) {
let padding = Math.floor((window.innerHeight - height) / 4);
if (padding > 0) {
if (position === VideoPosition.BOTTOM_HALF) {
padding *= 3;
}
$parent.style.paddingTop = padding + 'px';
}
}
// Update size
targetWidth = `${width}px`;
targetHeight = `${height}px`;
targetObjectFit = PREF_RATIO === '16:9' ? 'contain' : 'fill';
} else {
targetWidth = '100%';
targetHeight = '100%';
targetObjectFit = PREF_RATIO;
$video.dataset.width = window.innerWidth.toString();
$video.dataset.height = window.innerHeight.toString();
}
$video.style.width = targetWidth;
$video.style.height = targetHeight;
$video.style.objectFit = targetObjectFit;
// $video.style.padding = padding;
if ($webGL2Canvas) {
$webGL2Canvas.style.width = targetWidth;
$webGL2Canvas.style.height = targetHeight;
$webGL2Canvas.style.objectFit = targetObjectFit;
$video.dispatchEvent(new Event('resize'));
}
// Update video dimensions
if (isNativeTouchGame && this.playerType == StreamPlayerType.WEBGL2) {
window.BX_EXPOSED.streamSession.updateDimensions();
}
}
setPlayerType(type: StreamPlayerType, refreshPlayer: boolean = false) {
if (this.playerType !== type) {
const videoClass = BX_FLAGS.DeviceInfo.deviceType === 'android-tv' ? 'bx-pixel' : 'bx-gone';
// Switch from Video -> WebGL2
if (type === StreamPlayerType.WEBGL2) {
// Initialize WebGL2 player
if (!this.webGL2Player) {
this.webGL2Player = new WebGL2Player(this.$video);
} else {
this.webGL2Player.resume();
}
this.$videoCss!.textContent = '';
this.$video.classList.add(videoClass);
} else {
// Cleanup WebGL2 Player
this.webGL2Player?.stop();
this.$video.classList.remove(videoClass);
}
}
this.playerType = type;
refreshPlayer && this.refreshPlayer();
}
setOptions(options: StreamPlayerOptions, refreshPlayer: boolean = false) {
this.options = options;
refreshPlayer && this.refreshPlayer();
}
updateOptions(options: StreamPlayerOptions, refreshPlayer: boolean = false) {
this.options = Object.assign(this.options, options);
refreshPlayer && this.refreshPlayer();
}
getPlayerElement(playerType?: StreamPlayerType) {
if (typeof playerType === 'undefined') {
playerType = this.playerType;
}
if (playerType === StreamPlayerType.WEBGL2) {
return this.webGL2Player?.getCanvas();
}
return this.$video;
}
getWebGL2Player() {
return this.webGL2Player;
}
refreshPlayer() {
if (this.playerType === StreamPlayerType.WEBGL2) {
const options = this.options;
const webGL2Player = this.webGL2Player!;
if (options.processing === StreamVideoProcessing.USM) {
webGL2Player.setFilter(1);
} else {
webGL2Player.setFilter(2);
}
isFullVersion() && ScreenshotManager.getInstance().updateCanvasFilters('none');
webGL2Player.setSharpness(options.sharpness || 0);
webGL2Player.setSaturation(options.saturation || 100);
webGL2Player.setContrast(options.contrast || 100);
webGL2Player.setBrightness(options.brightness || 100);
} else {
let filters = this.getVideoPlayerFilterStyle();
let videoCss = '';
if (filters) {
videoCss += `filter: ${filters} !important;`;
}
// Apply video filters to screenshots
if (isFullVersion() && getPref(PrefKey.SCREENSHOT_APPLY_FILTERS)) {
ScreenshotManager.getInstance().updateCanvasFilters(filters);
}
let css = '';
if (videoCss) {
css = `#game-stream video { ${videoCss} }`;
}
this.$videoCss!.textContent = css;
}
this.resizePlayer();
}
reloadPlayer() {
this.cleanUpWebGL2Player();
this.playerType = StreamPlayerType.VIDEO;
this.setPlayerType(StreamPlayerType.WEBGL2, false);
}
private cleanUpWebGL2Player() {
// Clean up WebGL2 Player
this.webGL2Player?.destroy();
this.webGL2Player = null;
}
destroy() {
this.cleanUpWebGL2Player();
}
}

View File

@ -1,76 +1,83 @@
import { STATES } from "@utils/global"; import { STATES } from "@utils/global";
import { UserAgent } from "@utils/user-agent"; import { UserAgent } from "@utils/user-agent";
import type { StreamPlayerOptions } from "../stream-player"; import { StreamPref } from "@/enums/pref-keys";
import { PrefKey } from "@/enums/pref-keys";
import { getPref, setPref } from "@/utils/settings-storages/global-settings-storage";
import { StreamVideoProcessing, StreamPlayerType } from "@/enums/pref-values"; import { StreamVideoProcessing, StreamPlayerType } from "@/enums/pref-values";
import { escapeCssSelector } from "@/utils/html"; import { getStreamPref, setStreamPref } from "@/utils/pref-utils";
import { SettingsManager } from "../settings-manager";
import type { StreamPlayerOptions } from "@/types/stream";
export function onChangeVideoPlayerType() { export function onChangeVideoPlayerType() {
const playerType = getPref(PrefKey.VIDEO_PLAYER_TYPE); const playerType = getStreamPref(StreamPref.VIDEO_PLAYER_TYPE);
const $videoProcessing = document.getElementById(`bx_setting_${escapeCssSelector(PrefKey.VIDEO_PROCESSING)}`) as HTMLSelectElement; const processing = getStreamPref(StreamPref.VIDEO_PROCESSING);
const $videoSharpness = document.getElementById(`bx_setting_${escapeCssSelector(PrefKey.VIDEO_SHARPNESS)}`) as HTMLElement; const settingsManager = SettingsManager.getInstance();
const $videoPowerPreference = document.getElementById(`bx_setting_${escapeCssSelector(PrefKey.VIDEO_POWER_PREFERENCE)}`) as HTMLElement; if (!settingsManager.hasElement(StreamPref.VIDEO_PROCESSING)) {
const $videoMaxFps = document.getElementById(`bx_setting_${escapeCssSelector(PrefKey.VIDEO_MAX_FPS)}`) as HTMLElement;
if (!$videoProcessing) {
return; return;
} }
let isDisabled = false; let isDisabled = false;
const $videoProcessing = settingsManager.getElement(StreamPref.VIDEO_PROCESSING) as HTMLSelectElement;
const $videoProcessingMode = settingsManager.getElement(StreamPref.VIDEO_PROCESSING_MODE) as HTMLSelectElement;
const $videoSharpness = settingsManager.getElement(StreamPref.VIDEO_SHARPNESS);
const $videoPowerPreference = settingsManager.getElement(StreamPref.VIDEO_POWER_PREFERENCE);
const $videoMaxFps = settingsManager.getElement(StreamPref.VIDEO_MAX_FPS);
const $optCas = $videoProcessing.querySelector<HTMLOptionElement>(`option[value=${StreamVideoProcessing.CAS}]`); const $optCas = $videoProcessing.querySelector<HTMLOptionElement>(`option[value=${StreamVideoProcessing.CAS}]`);
if (playerType === StreamPlayerType.WEBGL2) { if (playerType === StreamPlayerType.VIDEO) {
$optCas && ($optCas.disabled = false);
} else {
// Only allow USM when player type is Video // Only allow USM when player type is Video
$videoProcessing.value = StreamVideoProcessing.USM; $videoProcessing.value = StreamVideoProcessing.USM;
setPref(PrefKey.VIDEO_PROCESSING, StreamVideoProcessing.USM); setStreamPref(StreamPref.VIDEO_PROCESSING, StreamVideoProcessing.USM, 'direct');
$optCas && ($optCas.disabled = true); $optCas && ($optCas.disabled = true);
if (UserAgent.isSafari()) { if (UserAgent.isSafari()) {
isDisabled = true; isDisabled = true;
} }
} else {
$optCas && ($optCas.disabled = false);
} }
$videoProcessing.disabled = isDisabled; $videoProcessing.disabled = isDisabled;
$videoSharpness.dataset.disabled = isDisabled.toString(); $videoSharpness.dataset.disabled = isDisabled.toString();
// Hide Power Preference setting if renderer isn't WebGL2 // Hide Power Preference setting if renderer isn't WebGL2
$videoProcessingMode.closest('.bx-settings-row')!.classList.toggle('bx-gone', !(playerType === StreamPlayerType.WEBGL2 && processing === StreamVideoProcessing.CAS));
$videoPowerPreference.closest('.bx-settings-row')!.classList.toggle('bx-gone', playerType !== StreamPlayerType.WEBGL2); $videoPowerPreference.closest('.bx-settings-row')!.classList.toggle('bx-gone', playerType !== StreamPlayerType.WEBGL2);
$videoMaxFps.closest('.bx-settings-row')!.classList.toggle('bx-gone', playerType !== StreamPlayerType.WEBGL2); $videoMaxFps.closest('.bx-settings-row')!.classList.toggle('bx-gone', playerType === StreamPlayerType.VIDEO);
updateVideoPlayer();
} }
export function limitVideoPlayerFps(targetFps: number) { export function limitVideoPlayerFps(targetFps: number) {
const streamPlayer = STATES.currentStream.streamPlayer; const streamPlayer = STATES.currentStream.streamPlayerManager;
streamPlayer?.getWebGL2Player()?.setTargetFps(targetFps); streamPlayer?.getCanvasPlayer()?.setTargetFps(targetFps);
} }
export function updateVideoPlayer() { export function updateVideoPlayer() {
const streamPlayer = STATES.currentStream.streamPlayer; const streamPlayerManager = STATES.currentStream.streamPlayerManager;
if (!streamPlayer) { if (!streamPlayerManager) {
return; return;
} }
limitVideoPlayerFps(getPref(PrefKey.VIDEO_MAX_FPS));
const options = { const options = {
processing: getPref(PrefKey.VIDEO_PROCESSING), processing: getStreamPref(StreamPref.VIDEO_PROCESSING),
sharpness: getPref(PrefKey.VIDEO_SHARPNESS), processingMode: getStreamPref(StreamPref.VIDEO_PROCESSING_MODE),
saturation: getPref(PrefKey.VIDEO_SATURATION), sharpness: getStreamPref(StreamPref.VIDEO_SHARPNESS),
contrast: getPref(PrefKey.VIDEO_CONTRAST), saturation: getStreamPref(StreamPref.VIDEO_SATURATION),
brightness: getPref(PrefKey.VIDEO_BRIGHTNESS), contrast: getStreamPref(StreamPref.VIDEO_CONTRAST),
brightness: getStreamPref(StreamPref.VIDEO_BRIGHTNESS),
} satisfies StreamPlayerOptions; } satisfies StreamPlayerOptions;
streamPlayer.setPlayerType(getPref(PrefKey.VIDEO_PLAYER_TYPE)); streamPlayerManager.switchPlayerType(getStreamPref(StreamPref.VIDEO_PLAYER_TYPE));
streamPlayer.updateOptions(options); limitVideoPlayerFps(getStreamPref(StreamPref.VIDEO_MAX_FPS));
streamPlayer.refreshPlayer(); streamPlayerManager.updateOptions(options);
streamPlayerManager.refreshPlayer();
} }
window.addEventListener('resize', updateVideoPlayer); function resizeVideoPlayer() {
const streamPlayerManager = STATES.currentStream.streamPlayerManager;
streamPlayerManager?.resizePlayer();
}
window.addEventListener('resize', resizeVideoPlayer);

View File

@ -1,12 +1,12 @@
import { CE } from "@utils/html" import { CE } from "@utils/html"
import { t } from "@utils/translation" import { t } from "@utils/translation"
import { STATES } from "@utils/global" import { STATES } from "@utils/global"
import { PrefKey } from "@/enums/pref-keys" import { StreamPref } from "@/enums/pref-keys"
import { getPref } from "@/utils/settings-storages/global-settings-storage" import { StreamStatsCollector } from "@/utils/stream-stats-collector"
import { StreamStatsCollector, type StreamStatGrade } from "@/utils/stream-stats-collector"
import { BxLogger } from "@/utils/bx-logger" import { BxLogger } from "@/utils/bx-logger"
import { StreamStat } from "@/enums/pref-values" import { StreamStat } from "@/enums/pref-values"
import { BxEventBus } from "@/utils/bx-event-bus" import { BxEventBus } from "@/utils/bx-event-bus"
import { getStreamPref } from "@/utils/pref-utils";
export class StreamStats { export class StreamStats {
@ -14,6 +14,7 @@ export class StreamStats {
public static getInstance = () => StreamStats.instance ?? (StreamStats.instance = new StreamStats()); public static getInstance = () => StreamStats.instance ?? (StreamStats.instance = new StreamStats());
private readonly LOG_TAG = 'StreamStats'; private readonly LOG_TAG = 'StreamStats';
private isRunning = false;
private intervalId?: number | null; private intervalId?: number | null;
private readonly REFRESH_INTERVAL = 1 * 1000; private readonly REFRESH_INTERVAL = 1 * 1000;
@ -69,19 +70,23 @@ export class StreamStats {
}; };
private $container!: HTMLElement; private $container!: HTMLElement;
private boundOnStreamHudStateChanged: typeof this.onStreamHudStateChanged;
quickGlanceObserver?: MutationObserver | null;
private constructor() { private constructor() {
BxLogger.info(this.LOG_TAG, 'constructor()'); BxLogger.info(this.LOG_TAG, 'constructor()');
this.boundOnStreamHudStateChanged = this.onStreamHudStateChanged.bind(this);
BxEventBus.Stream.on('ui.streamHud.rendered', this.boundOnStreamHudStateChanged);
this.render(); this.render();
} }
async start(glancing=false) { async start(glancing=false) {
if (!this.isHidden() || (glancing && this.isGlancing())) { if (this.isRunning || !this.isHidden() || (glancing && this.isGlancing())) {
return; return;
} }
this.isRunning = true;
this.intervalId && clearInterval(this.intervalId); this.intervalId && clearInterval(this.intervalId);
await this.update(true); await this.update(true);
@ -96,6 +101,7 @@ export class StreamStats {
return; return;
} }
this.isRunning = false;
this.intervalId && clearInterval(this.intervalId); this.intervalId && clearInterval(this.intervalId);
this.intervalId = null; this.intervalId = null;
@ -113,49 +119,22 @@ export class StreamStats {
destroy() { destroy() {
this.stop(); this.stop();
this.quickGlanceStop();
this.hideSettingsUi(); this.hideSettingsUi();
} }
isHidden = () => this.$container.classList.contains('bx-gone'); isHidden = () => this.$container.classList.contains('bx-gone');
isGlancing = () => this.$container.dataset.display === 'glancing'; isGlancing = () => this.$container.dataset.display === 'glancing';
quickGlanceSetup() { onStreamHudStateChanged({ expanded }: { expanded: boolean }) {
if (!STATES.isPlaying || this.quickGlanceObserver) { if (!getStreamPref(StreamPref.STATS_QUICK_GLANCE_ENABLED)) {
return; return;
} }
const $uiContainer = document.querySelector('div[data-testid=ui-container]')!; if (expanded) {
if (!$uiContainer) { this.isHidden() && this.start(true);
return; } else {
this.stop(true);
} }
this.quickGlanceObserver = new MutationObserver((mutationList, observer) => {
for (const record of mutationList) {
const $target = record.target as HTMLElement;
if (!$target.className || !$target.className.startsWith('GripHandle')) {
continue;
}
const expanded = (record.target as HTMLElement).ariaExpanded;
if (expanded === 'true') {
this.isHidden() && this.start(true);
} else {
this.stop(true);
}
}
});
this.quickGlanceObserver.observe($uiContainer, {
attributes: true,
attributeFilter: ['aria-expanded'],
subtree: true,
});
}
quickGlanceStop() {
this.quickGlanceObserver && this.quickGlanceObserver.disconnect();
this.quickGlanceObserver = null;
} }
private update = async (forceUpdate=false) => { private update = async (forceUpdate=false) => {
@ -164,7 +143,7 @@ export class StreamStats {
return; return;
} }
const PREF_STATS_CONDITIONAL_FORMATTING = getPref(PrefKey.STATS_CONDITIONAL_FORMATTING); const PREF_STATS_CONDITIONAL_FORMATTING = getStreamPref(StreamPref.STATS_CONDITIONAL_FORMATTING);
let grade: StreamStatGrade = ''; let grade: StreamStatGrade = '';
// Collect stats // Collect stats
@ -192,12 +171,12 @@ export class StreamStats {
} }
refreshStyles() { refreshStyles() {
const PREF_ITEMS = getPref(PrefKey.STATS_ITEMS); const PREF_ITEMS = getStreamPref(StreamPref.STATS_ITEMS);
const PREF_OPACITY_BG = getPref(PrefKey.STATS_OPACITY_BACKGROUND); const PREF_OPACITY_BG = getStreamPref(StreamPref.STATS_OPACITY_BACKGROUND);
const $container = this.$container; const $container = this.$container;
$container.dataset.stats = '[' + PREF_ITEMS.join('][') + ']'; $container.dataset.stats = '[' + PREF_ITEMS.join('][') + ']';
$container.dataset.position = getPref(PrefKey.STATS_POSITION); $container.dataset.position = getStreamPref(StreamPref.STATS_POSITION);
if (PREF_OPACITY_BG === 0) { if (PREF_OPACITY_BG === 0) {
$container.style.removeProperty('background-color'); $container.style.removeProperty('background-color');
@ -207,12 +186,12 @@ export class StreamStats {
$container.style.backgroundColor = `rgba(0, 0, 0, ${PREF_OPACITY_BG}%)`; $container.style.backgroundColor = `rgba(0, 0, 0, ${PREF_OPACITY_BG}%)`;
} }
$container.style.opacity = getPref(PrefKey.STATS_OPACITY_ALL) + '%'; $container.style.opacity = getStreamPref(StreamPref.STATS_OPACITY_ALL) + '%';
$container.style.fontSize = getPref(PrefKey.STATS_TEXT_SIZE); $container.style.fontSize = getStreamPref(StreamPref.STATS_TEXT_SIZE);
} }
hideSettingsUi() { hideSettingsUi() {
if (this.isGlancing() && !getPref(PrefKey.STATS_QUICK_GLANCE_ENABLED)) { if (this.isGlancing() && !getStreamPref(StreamPref.STATS_QUICK_GLANCE_ENABLED)) {
this.stop(); this.stop();
} }
} }
@ -240,8 +219,8 @@ export class StreamStats {
static setupEvents() { static setupEvents() {
BxEventBus.Stream.on('state.playing', () => { BxEventBus.Stream.on('state.playing', () => {
const PREF_STATS_QUICK_GLANCE = getPref(PrefKey.STATS_QUICK_GLANCE_ENABLED); const PREF_STATS_QUICK_GLANCE = getStreamPref(StreamPref.STATS_QUICK_GLANCE_ENABLED);
const PREF_STATS_SHOW_WHEN_PLAYING = getPref(PrefKey.STATS_SHOW_WHEN_PLAYING); const PREF_STATS_SHOW_WHEN_PLAYING = getStreamPref(StreamPref.STATS_SHOW_WHEN_PLAYING);
const streamStats = StreamStats.getInstance(); const streamStats = StreamStats.getInstance();
@ -249,7 +228,6 @@ export class StreamStats {
if (PREF_STATS_SHOW_WHEN_PLAYING) { if (PREF_STATS_SHOW_WHEN_PLAYING) {
streamStats.start(); streamStats.start();
} else if (PREF_STATS_QUICK_GLANCE) { } else if (PREF_STATS_QUICK_GLANCE) {
streamStats.quickGlanceSetup();
// Show stats bar // Show stats bar
!PREF_STATS_SHOW_WHEN_PLAYING && streamStats.start(true); !PREF_STATS_SHOW_WHEN_PLAYING && streamStats.start(true);
} }

View File

@ -5,7 +5,6 @@ import { t } from "@utils/translation.ts";
import { StreamBadges } from "./stream-badges.ts"; import { StreamBadges } from "./stream-badges.ts";
import { StreamStats } from "./stream-stats.ts"; import { StreamStats } from "./stream-stats.ts";
import { SettingsDialog } from "../ui/dialog/settings-dialog.ts"; import { SettingsDialog } from "../ui/dialog/settings-dialog.ts";
import { BxEventBus } from "@/utils/bx-event-bus.ts";
export class StreamUiHandler { export class StreamUiHandler {
@ -13,7 +12,6 @@ export class StreamUiHandler {
private static $btnStreamStats: HTMLElement | null | undefined; private static $btnStreamStats: HTMLElement | null | undefined;
private static $btnRefresh: HTMLElement | null | undefined; private static $btnRefresh: HTMLElement | null | undefined;
private static $btnHome: HTMLElement | null | undefined; private static $btnHome: HTMLElement | null | undefined;
private static observer: MutationObserver | undefined;
private static cloneStreamHudButton($btnOrg: HTMLElement, label: string, svgIcon: BxIconRaw): HTMLElement | null { private static cloneStreamHudButton($btnOrg: HTMLElement, label: string, svgIcon: BxIconRaw): HTMLElement | null {
if (!$btnOrg) { if (!$btnOrg) {
@ -101,7 +99,7 @@ export class StreamUiHandler {
return $btn; return $btn;
} }
private static async handleStreamMenu() { static async handleStreamMenu() {
const $btnCloseHud = document.querySelector<HTMLElement>('button[class*=StreamMenu-module__backButton]'); const $btnCloseHud = document.querySelector<HTMLElement>('button[class*=StreamMenu-module__backButton]');
if (!$btnCloseHud) { if (!$btnCloseHud) {
return; return;
@ -134,13 +132,17 @@ export class StreamUiHandler {
$menu?.appendChild(await StreamBadges.getInstance().render()); $menu?.appendChild(await StreamBadges.getInstance().render());
} }
private static handleSystemMenu($streamHud: HTMLElement) { static handleSystemMenu($streamHud: HTMLElement) {
// Get the last button // Get the last button
const $orgButton = $streamHud.querySelector<HTMLElement>('div[class^=HUDButton]'); const $orgButton = $streamHud.querySelector<HTMLElement>('div[class^=HUDButton]');
if (!$orgButton) { if (!$orgButton) {
return; return;
} }
if (StreamUiHandler.$btnStreamSettings && $streamHud.contains(StreamUiHandler.$btnStreamSettings)) {
return;
}
const hideGripHandle = () => { const hideGripHandle = () => {
// Grip handle // Grip handle
const $gripHandle = document.querySelector<HTMLElement>('#StreamHud button[class^=GripHandle]'); const $gripHandle = document.querySelector<HTMLElement>('#StreamHud button[class^=GripHandle]');
@ -207,67 +209,5 @@ export class StreamUiHandler {
StreamUiHandler.$btnStreamStats = undefined; StreamUiHandler.$btnStreamStats = undefined;
StreamUiHandler.$btnRefresh = undefined; StreamUiHandler.$btnRefresh = undefined;
StreamUiHandler.$btnHome = undefined; StreamUiHandler.$btnHome = undefined;
StreamUiHandler.observer && StreamUiHandler.observer.disconnect();
StreamUiHandler.observer = undefined;
}
static observe() {
StreamUiHandler.reset();
const $screen = document.querySelector('#PageContent section[class*=PureScreens]');
if (!$screen) {
return;
}
const observer = new MutationObserver(mutationList => {
let item: MutationRecord;
for (item of mutationList) {
if (item.type !== 'childList') {
continue;
}
item.addedNodes.forEach(async $node => {
if (!$node || $node.nodeType !== Node.ELEMENT_NODE) {
return;
}
let $elm: HTMLElement | null = $node as HTMLElement;
// Ignore non-HTML elements
if (!($elm instanceof HTMLElement)) {
return;
}
const className = $elm.className || '';
// Error Page: .PureErrorPage.ErrorScreen
if (className.includes('PureErrorPage')) {
BxEventBus.Stream.emit('state.error', {});
return;
}
// Render badges
if (className.startsWith('StreamMenu-module__container')) {
StreamUiHandler.handleStreamMenu();
return;
}
if (className.startsWith('Overlay-module_') || className.startsWith('InProgressScreen')) {
$elm = $elm.querySelector('#StreamHud');
}
if (!$elm || ($elm.id || '') !== 'StreamHud') {
return;
}
// Handle System Menu bar
StreamUiHandler.handleSystemMenu($elm);
});
};
});
observer.observe($screen, { subtree: true, childList: true });
StreamUiHandler.observer = observer;
} }
} }

View File

@ -4,8 +4,8 @@ import { BxEvent } from "@utils/bx-event";
import { NATIVE_FETCH } from "@utils/bx-flags"; import { NATIVE_FETCH } from "@utils/bx-flags";
import { t } from "@utils/translation"; import { t } from "@utils/translation";
import { BxLogger } from "@utils/bx-logger"; import { BxLogger } from "@utils/bx-logger";
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref } from "@/enums/pref-keys";
import { getPref } from "@/utils/settings-storages/global-settings-storage"; import { getGlobalPref } from "@/utils/pref-utils";
import { TouchControllerStyleCustom, TouchControllerStyleStandard } from "@/enums/pref-values"; import { TouchControllerStyleCustom, TouchControllerStyleStandard } from "@/enums/pref-values";
import { GhPagesUtils } from "@/utils/gh-pages"; import { GhPagesUtils } from "@/utils/gh-pages";
import { BxEventBus } from "@/utils/bx-event-bus"; import { BxEventBus } from "@/utils/bx-event-bus";
@ -209,7 +209,7 @@ export class TouchController {
} }
if (!layoutId) { if (!layoutId) {
BxLogger.error(LOG_TAG, 'Invalid layoutId, show default controller'); BxLogger.warning(LOG_TAG, 'Invalid layoutId, show default controller');
TouchController.#enabled && TouchController.#showDefault(); TouchController.#enabled && TouchController.#showDefault();
return; return;
} }
@ -267,6 +267,10 @@ export class TouchController {
return TouchController.#customList; return TouchController.#customList;
} }
static hasCustomControl(productId: string): boolean {
return TouchController.#customList?.includes(productId);
}
static setup() { static setup() {
// Function for testing touch control // Function for testing touch control
window.testTouchLayout = (layout: any) => { window.testTouchLayout = (layout: any) => {
@ -289,8 +293,8 @@ export class TouchController {
TouchController.#$style = $style; TouchController.#$style = $style;
const PREF_STYLE_STANDARD = getPref(PrefKey.TOUCH_CONTROLLER_STYLE_STANDARD); const PREF_STYLE_STANDARD = getGlobalPref(GlobalPref.TOUCH_CONTROLLER_STYLE_STANDARD);
const PREF_STYLE_CUSTOM = getPref(PrefKey.TOUCH_CONTROLLER_STYLE_CUSTOM); const PREF_STYLE_CUSTOM = getGlobalPref(GlobalPref.TOUCH_CONTROLLER_STYLE_CUSTOM);
BxEventBus.Stream.on('dataChannelCreated', payload => { BxEventBus.Stream.on('dataChannelCreated', payload => {
const { dataChannel } = payload; const { dataChannel } = payload;

View File

@ -1,3 +1,5 @@
import { isFullVersion } from "@macros/build" with { type: "macro" };
import { GamepadKey } from "@/enums/gamepad"; import { GamepadKey } from "@/enums/gamepad";
import { VIRTUAL_GAMEPAD_ID } from "@/modules/mkb/mkb-handler"; import { VIRTUAL_GAMEPAD_ID } from "@/modules/mkb/mkb-handler";
import { BxEvent } from "@/utils/bx-event"; import { BxEvent } from "@/utils/bx-event";
@ -641,7 +643,9 @@ export class NavigationDialogManager {
private startGamepadPolling() { private startGamepadPolling() {
this.stopGamepadPolling(); this.stopGamepadPolling();
this.gamepadPollingIntervalId = window.setInterval(this.pollGamepad, NavigationDialogManager.GAMEPAD_POLLING_INTERVAL); if (isFullVersion()) {
this.gamepadPollingIntervalId = window.setInterval(this.pollGamepad, NavigationDialogManager.GAMEPAD_POLLING_INTERVAL);
}
} }
private stopGamepadPolling() { private stopGamepadPolling() {

View File

@ -5,8 +5,8 @@ import { t } from "@/utils/translation";
import { GamepadKey, GamepadKeyName } from "@/enums/gamepad"; import { GamepadKey, GamepadKeyName } from "@/enums/gamepad";
import { ButtonStyle, CE, createButton, createSettingRow } from "@/utils/html"; import { ButtonStyle, CE, createButton, createSettingRow } from "@/utils/html";
import { BxSelectElement } from "@/web-components/bx-select"; import { BxSelectElement } from "@/web-components/bx-select";
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref } from "@/enums/pref-keys";
import { getPref } from "@/utils/settings-storages/global-settings-storage"; import { getGlobalPref } from "@/utils/pref-utils";
import { BxEvent } from "@/utils/bx-event"; import { BxEvent } from "@/utils/bx-event";
import { deepClone } from "@/utils/global"; import { deepClone } from "@/utils/global";
import { StreamSettings } from "@/utils/stream-settings"; import { StreamSettings } from "@/utils/stream-settings";
@ -58,7 +58,7 @@ export class ControllerCustomizationsManagerDialog extends BaseProfileManagerDia
} }
private render() { private render() {
const isControllerFriendly = getPref(PrefKey.UI_CONTROLLER_FRIENDLY); const isControllerFriendly = getGlobalPref(GlobalPref.UI_CONTROLLER_FRIENDLY);
const $rows = CE('div', { class: 'bx-buttons-grid' }); const $rows = CE('div', { class: 'bx-buttons-grid' });
const $baseSelect = CE('select', { class: 'bx-full-width' }, const $baseSelect = CE('select', { class: 'bx-full-width' },
@ -117,7 +117,7 @@ export class ControllerCustomizationsManagerDialog extends BaseProfileManagerDia
} }
// Map nearby elenemts for controller-friendly UI // Map nearby elenemts for controller-friendly UI
if (getPref(PrefKey.UI_CONTROLLER_FRIENDLY)) { if (getGlobalPref(GlobalPref.UI_CONTROLLER_FRIENDLY)) {
for (let i = 0; i < this.selectsOrder.length; i++) { for (let i = 0; i < this.selectsOrder.length; i++) {
const $select = this.selectsMap[this.selectsOrder[i] as unknown as GamepadKey] as NavigationElement; const $select = this.selectsMap[this.selectsOrder[i] as unknown as GamepadKey] as NavigationElement;
const directions = { const directions = {
@ -257,7 +257,7 @@ export class ControllerCustomizationsManagerDialog extends BaseProfileManagerDia
$label.classList.add('bx-horizontal-shaking'); $label.classList.add('bx-horizontal-shaking');
// Focus select // Focus select
if (getPref(PrefKey.UI_CONTROLLER_FRIENDLY)) { if (getGlobalPref(GlobalPref.UI_CONTROLLER_FRIENDLY)) {
this.dialogManager.focus($select); this.dialogManager.focus($select);
} }
} }

View File

@ -4,7 +4,7 @@ import { t } from "@/utils/translation";
import { MkbMappingPresetsTable } from "@/utils/local-db/mkb-mapping-presets-table"; import { MkbMappingPresetsTable } from "@/utils/local-db/mkb-mapping-presets-table";
import { GamepadKey, GamepadKeyName } from "@/enums/gamepad"; import { GamepadKey, GamepadKeyName } from "@/enums/gamepad";
import { CE, createSettingRow } from "@/utils/html"; import { CE, createSettingRow } from "@/utils/html";
import { MouseMapTo, type KeyCode } from "@/enums/mkb"; import { MouseMapTo } from "@/enums/mkb";
import { BxKeyBindingButton, BxKeyBindingButtonFlag } from "@/web-components/bx-key-binding-button"; import { BxKeyBindingButton, BxKeyBindingButtonFlag } from "@/web-components/bx-key-binding-button";
import { StreamSettings } from "@/utils/stream-settings"; import { StreamSettings } from "@/utils/stream-settings";
import { BxNumberStepper } from "@/web-components/bx-number-stepper"; import { BxNumberStepper } from "@/web-components/bx-number-stepper";

View File

@ -1,14 +1,17 @@
import { ButtonStyle, CE, createButton } from "@/utils/html"; import { ButtonStyle, CE, createButton, escapeCssSelector } from "@/utils/html";
import { NavigationDialog, type NavigationElement } from "./navigation-dialog"; import { NavigationDialog, type NavigationElement } from "./navigation-dialog";
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref } from "@/enums/pref-keys";
import { BxIcon } from "@/utils/bx-icon"; import { BxIcon } from "@/utils/bx-icon";
import { getPref, setPref } from "@/utils/settings-storages/global-settings-storage"; import { getGlobalPref, setGlobalPref } from "@/utils/pref-utils";
import { t } from "@/utils/translation"; import { t } from "@/utils/translation";
import { RemotePlayConsoleState, RemotePlayManager } from "@/modules/remote-play-manager"; import { RemotePlayConsoleState, RemotePlayManager } from "@/modules/remote-play-manager";
import { BxSelectElement } from "@/web-components/bx-select"; import { BxSelectElement } from "@/web-components/bx-select";
import { BxEvent } from "@/utils/bx-event"; import { BxEvent } from "@/utils/bx-event";
import { BxLogger } from "@/utils/bx-logger"; import { BxLogger } from "@/utils/bx-logger";
import { StreamResolution } from "@/enums/pref-values"; import { StreamResolution } from "@/enums/pref-values";
import { setNearby } from "@/utils/navigation-utils";
import { AppInterface } from "@/utils/global";
import { SettingElement } from "@/utils/setting-element";
export class RemotePlayDialog extends NavigationDialog { export class RemotePlayDialog extends NavigationDialog {
@ -32,23 +35,27 @@ export class RemotePlayDialog extends NavigationDialog {
} }
private setupDialog() { private setupDialog() {
const $fragment = CE('div', { class: 'bx-remote-play-container' }); const $fragment = CE('div', { class: 'bx-centered-dialog' },
CE('div', { class: 'bx-dialog-title' },
CE('p', false, t('remote-play')),
),
);
const $settingNote = CE('p', {}); const $settingNote = CE('p', {});
const currentResolution = getPref(PrefKey.REMOTE_PLAY_STREAM_RESOLUTION); const currentResolution = getGlobalPref(GlobalPref.REMOTE_PLAY_STREAM_RESOLUTION);
let $resolutions : HTMLSelectElement | NavigationElement = CE('select', false, let $resolutions : HTMLSelectElement | NavigationElement = CE('select', false,
CE('option', { value: StreamResolution.DIM_720P }, '720p'), CE('option', { value: StreamResolution.DIM_720P }, '720p'),
CE('option', { value: StreamResolution.DIM_1080P }, '1080p'), CE('option', { value: StreamResolution.DIM_1080P }, '1080p'),
// CE('option', { value: StreamResolution.DIM_1080P_HQ }, `1080p (HQ)`), CE('option', { value: StreamResolution.DIM_1080P_HQ }, `1080p (HQ)`),
); );
$resolutions = BxSelectElement.create($resolutions as HTMLSelectElement); $resolutions = BxSelectElement.create($resolutions as HTMLSelectElement);
$resolutions.addEventListener('input', (e: Event) => { $resolutions.addEventListener('input', (e: Event) => {
const value = (e.target as HTMLSelectElement).value; const value = (e.target as HTMLSelectElement).value;
$settingNote.textContent = value === '1080p' ? '✅ ' + t('can-stream-xbox-360-games') : '❌ ' + t('cant-stream-xbox-360-games'); $settingNote.textContent = `${t('xbox-360-games')} ${value === StreamResolution.DIM_1080P_HQ ? '❌' : '✅'} ${t('xbox-apps')}`;
setPref(PrefKey.REMOTE_PLAY_STREAM_RESOLUTION, value); setGlobalPref(GlobalPref.REMOTE_PLAY_STREAM_RESOLUTION, value, 'ui');
}); });
($resolutions as any).value = currentResolution; ($resolutions as any).value = currentResolution;
@ -61,6 +68,9 @@ export class RemotePlayDialog extends NavigationDialog {
}, CE('div', false, }, CE('div', false,
CE('label', false, t('target-resolution'), $settingNote), CE('label', false, t('target-resolution'), $settingNote),
$resolutions, $resolutions,
), CE('div', false,
CE('label', { 'for': `bx_setting_${escapeCssSelector(GlobalPref.REMOTE_PLAY_PREFER_IPV6)}` }, t('prefer-ipv6-server')),
SettingElement.fromPref(GlobalPref.REMOTE_PLAY_PREFER_IPV6),
)); ));
$fragment.appendChild($qualitySettings); $fragment.appendChild($qualitySettings);
@ -69,8 +79,20 @@ export class RemotePlayDialog extends NavigationDialog {
const manager = RemotePlayManager.getInstance()!; const manager = RemotePlayManager.getInstance()!;
const consoles = manager.getConsoles(); const consoles = manager.getConsoles();
const createConsoleShortcut = (e: Event) => {
const { serverId, deviceName } = (e.target as HTMLElement).dataset;
const optionsJson = JSON.stringify({
'resolution': getGlobalPref(GlobalPref.REMOTE_PLAY_STREAM_RESOLUTION),
});
AppInterface?.createConsoleShortcut(serverId!, deviceName!, optionsJson);
};
for (let con of consoles) { for (let con of consoles) {
const $child = CE('div', { class: 'bx-remote-play-device-wrapper' }, let $connect;
const $child = CE('div', {
class: 'bx-remote-play-device-wrapper',
},
CE('div', { class: 'bx-remote-play-device-info' }, CE('div', { class: 'bx-remote-play-device-info' },
CE('div', false, CE('div', false,
CE('span', { class: 'bx-remote-play-device-name' }, con.deviceName), CE('span', { class: 'bx-remote-play-device-name' }, con.deviceName),
@ -79,8 +101,20 @@ export class RemotePlayDialog extends NavigationDialog {
CE('div', { class: 'bx-remote-play-power-state' }, this.STATE_LABELS[con.powerState]), CE('div', { class: 'bx-remote-play-power-state' }, this.STATE_LABELS[con.powerState]),
), ),
// Shortcut button
AppInterface ? createButton({
attributes: {
'data-server-id': con.serverId,
'data-device-name': con.deviceName,
},
icon: BxIcon.CREATE_SHORTCUT,
style: ButtonStyle.GHOST | ButtonStyle.FOCUSABLE,
title: t('create-shortcut'),
onClick: createConsoleShortcut,
}) : null,
// Connect button // Connect button
createButton({ $connect = createButton({
classes: ['bx-remote-play-connect-button'], classes: ['bx-remote-play-connect-button'],
label: t('console-connect'), label: t('console-connect'),
style: ButtonStyle.PRIMARY | ButtonStyle.FOCUSABLE, style: ButtonStyle.PRIMARY | ButtonStyle.FOCUSABLE,
@ -88,6 +122,10 @@ export class RemotePlayDialog extends NavigationDialog {
}), }),
); );
setNearby($child, {
orientation: 'horizontal',
focus: $connect,
})
$fragment.appendChild($child); $fragment.appendChild($child);
} }
@ -126,7 +164,7 @@ export class RemotePlayDialog extends NavigationDialog {
} }
focusIfNeeded(): void { focusIfNeeded(): void {
const $btnConnect = this.$container.querySelector<HTMLElement>('.bx-remote-play-device-wrapper button'); const $btnConnect = this.$container.querySelector<HTMLElement>('.bx-remote-play-device-wrapper button:last-of-type');
$btnConnect && $btnConnect.focus(); $btnConnect && $btnConnect.focus();
} }
} }

View File

@ -1,14 +1,12 @@
import { isFullVersion } from "@macros/build" with { type: "macro" }; import { isFullVersion } from "@macros/build" with { type: "macro" };
import { limitVideoPlayerFps, onChangeVideoPlayerType, updateVideoPlayer } from "@/modules/stream/stream-settings-utils"; import { onChangeVideoPlayerType } from "@/modules/stream/stream-settings-utils";
import { ButtonStyle, calculateSelectBoxes, CE, createButton, createSettingRow, createSvgIcon, escapeCssSelector, type BxButtonOptions } from "@/utils/html"; import { ButtonStyle, calculateSelectBoxes, CE, createButton, createSettingRow, createSvgIcon, escapeCssSelector, type BxButtonOptions } from "@/utils/html";
import { NavigationDialog, NavigationDirection } from "./navigation-dialog"; import { NavigationDialog, NavigationDirection } from "./navigation-dialog";
import { SoundShortcut } from "@/modules/shortcuts/sound-shortcut";
import { StreamStats } from "@/modules/stream/stream-stats";
import { TouchController } from "@/modules/touch-controller"; import { TouchController } from "@/modules/touch-controller";
import { BxEvent } from "@/utils/bx-event"; import { BxEvent } from "@/utils/bx-event";
import { BxIcon, type BxIconRaw } from "@/utils/bx-icon"; import { BxIcon, type BxIconRaw } from "@/utils/bx-icon";
import { STATES, AppInterface, deepClone, SCRIPT_VERSION, STORAGE, SCRIPT_VARIANT } from "@/utils/global"; import { STATES, AppInterface, deepClone, SCRIPT_VERSION, SCRIPT_VARIANT } from "@/utils/global";
import { t, Translations } from "@/utils/translation"; import { t, Translations } from "@/utils/translation";
import { BxSelectElement } from "@/web-components/bx-select"; import { BxSelectElement } from "@/web-components/bx-select";
import { setNearby } from "@/utils/navigation-utils"; import { setNearby } from "@/utils/navigation-utils";
@ -17,8 +15,7 @@ import { UserAgentProfile } from "@/enums/user-agent";
import { UserAgent } from "@/utils/user-agent"; import { UserAgent } from "@/utils/user-agent";
import { BX_FLAGS } from "@/utils/bx-flags"; import { BX_FLAGS } from "@/utils/bx-flags";
import { clearAllData, copyToClipboard } from "@/utils/utils"; import { clearAllData, copyToClipboard } from "@/utils/utils";
import { PrefKey, StorageKey } from "@/enums/pref-keys"; import { GlobalPref, StorageKey, StreamPref, type AnyPref } from "@/enums/pref-keys";
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, SuggestedSettingProfile } from "@/types/setting-definition"; import type { SettingDefinition, SuggestedSettingProfile } from "@/types/setting-definition";
import { FullscreenText } from "../fullscreen-text"; import { FullscreenText } from "../fullscreen-text";
@ -27,14 +24,14 @@ import { GamepadKey } from "@/enums/gamepad";
import { NativeMkbHandler } from "@/modules/mkb/native-mkb-handler"; import { NativeMkbHandler } from "@/modules/mkb/native-mkb-handler";
import { ControllerExtraSettings } from "./settings/controller-extra"; import { ControllerExtraSettings } from "./settings/controller-extra";
import { SuggestionsSetting } from "./settings/suggestions"; import { SuggestionsSetting } from "./settings/suggestions";
import { StreamSettings } from "@/utils/stream-settings";
import { MkbExtraSettings } from "./settings/mkb-extra"; import { MkbExtraSettings } from "./settings/mkb-extra";
import { BxExposed } from "@/utils/bx-exposed";
import { BxEventBus } from "@/utils/bx-event-bus"; import { BxEventBus } from "@/utils/bx-event-bus";
import { getGlobalPref, getPrefInfo, getStreamPref, isStreamPref, setGlobalPref, STORAGE } from "@/utils/pref-utils";
import { SettingsManager } from "@/modules/settings-manager";
type SettingTabSectionItem = Partial<{ type SettingTabSectionItem = Partial<{
pref: PrefKey; pref: AnyPref;
multiLines: boolean; multiLines: boolean;
label: string; label: string;
note: string | (() => HTMLElement) | HTMLElement; note: string | (() => HTMLElement) | HTMLElement;
@ -43,7 +40,7 @@ type SettingTabSectionItem = Partial<{
options: { [key: string]: string }; options: { [key: string]: string };
unsupported: boolean; unsupported: boolean;
unsupportedNote: string; unsupportedNote: string;
onChange: (e: any, value: number) => void; // onChange: (e: any, value: number) => void;
onCreated: (setting: SettingTabSectionItem, $control: any) => void; onCreated: (setting: SettingTabSectionItem, $control: any) => void;
params: any; params: any;
requiredVariants?: BuildVariant | Array<BuildVariant>; requiredVariants?: BuildVariant | Array<BuildVariant>;
@ -59,17 +56,15 @@ type SettingTabSection = {
unsupportedNote?: HTMLElement | string | Text | null; unsupportedNote?: HTMLElement | string | Text | null;
helpUrl?: string; helpUrl?: string;
content?: HTMLElement; content?: HTMLElement;
lazyContent?: boolean | (() => HTMLElement); items?: Array<SettingTabSectionItem | AnyPref | (($parent: HTMLElement) => void) | false>;
items?: Array<SettingTabSectionItem | PrefKey | (($parent: HTMLElement) => void) | false>;
requiredVariants?: BuildVariant | Array<BuildVariant>; requiredVariants?: BuildVariant | Array<BuildVariant>;
}; };
type SettingTab = { type SettingTab = {
icon: BxIconRaw; icon: BxIconRaw;
group: SettingTabGroup, group: SettingTabGroup,
items: Array<SettingTabSection | HTMLElement | false> | (() => Array<SettingTabSection | false>); items: Array<SettingTabSection | HTMLElement | false>;
requiredVariants?: BuildVariant | Array<BuildVariant>; requiredVariants?: BuildVariant | Array<BuildVariant>;
lazyContent?: boolean;
}; };
type SettingTabGroup = 'global' | 'stream' | 'controller' | 'mkb' | 'stats'; type SettingTabGroup = 'global' | 'stream' | 'controller' | 'mkb' | 'stats';
@ -87,17 +82,20 @@ export class SettingsDialog extends NavigationDialog {
private $btnGlobalReload!: HTMLButtonElement; private $btnGlobalReload!: HTMLButtonElement;
private $noteGlobalReload!: HTMLElement; private $noteGlobalReload!: HTMLElement;
private $btnSuggestion!: HTMLDivElement; private $btnSuggestion!: HTMLDivElement;
private $streamSettingsSelection!: HTMLElement;
private renderFullSettings: boolean; private renderFullSettings: boolean;
protected boundOnContextMenu: any;
protected suggestedSettings: Record<SuggestedSettingProfile, PartialRecord<PrefKey, any>> = { protected suggestedSettings: Record<SuggestedSettingProfile, PartialRecord<AnyPref, any>> = {
recommended: {}, recommended: {},
default: {}, default: {},
lowest: {}, lowest: {},
highest: {}, highest: {},
}; };
protected suggestedSettingLabels: PartialRecord<PrefKey, string> = {}; protected settingLabels: PartialRecord<AnyPref, string> = {};
protected settingElements: PartialRecord<PrefKey, HTMLElement> = {};
protected settingsManager: SettingsManager;
private readonly TAB_GLOBAL_ITEMS: Array<SettingTabSection | false> = [{ private readonly TAB_GLOBAL_ITEMS: Array<SettingTabSection | false> = [{
group: 'general', group: 'general',
@ -106,7 +104,7 @@ export class SettingsDialog extends NavigationDialog {
items: [ items: [
// Top buttons // Top buttons
($parent) => { ($parent) => {
const PREF_LATEST_VERSION = getPref(PrefKey.VERSION_LATEST); const PREF_LATEST_VERSION = getGlobalPref(GlobalPref.VERSION_LATEST);
const topButtons = []; const topButtons = [];
// "New version available" button // "New version available" button
@ -188,57 +186,56 @@ export class SettingsDialog extends NavigationDialog {
}, },
{ {
pref: PrefKey.SCRIPT_LOCALE, pref: GlobalPref.SCRIPT_LOCALE,
multiLines: true, multiLines: true,
}, },
PrefKey.SERVER_BYPASS_RESTRICTION, GlobalPref.SERVER_BYPASS_RESTRICTION,
PrefKey.UI_CONTROLLER_FRIENDLY, GlobalPref.UI_CONTROLLER_FRIENDLY,
PrefKey.REMOTE_PLAY_ENABLED,
], ],
}, { }, {
group: 'server', group: 'server',
label: t('server'), label: t('server'),
items: [ items: [
{ {
pref: PrefKey.SERVER_REGION, pref: GlobalPref.SERVER_REGION,
multiLines: true, multiLines: true,
}, },
{ {
pref: PrefKey.STREAM_PREFERRED_LOCALE, pref: GlobalPref.STREAM_PREFERRED_LOCALE,
multiLines: true, multiLines: true,
}, },
PrefKey.SERVER_PREFER_IPV6, GlobalPref.SERVER_PREFER_IPV6,
], ],
}, { }, {
group: 'stream', group: 'stream',
label: t('stream'), label: t('stream'),
items: [ items: [
PrefKey.STREAM_RESOLUTION, GlobalPref.STREAM_RESOLUTION,
PrefKey.STREAM_CODEC_PROFILE, GlobalPref.STREAM_CODEC_PROFILE,
PrefKey.STREAM_MAX_VIDEO_BITRATE, GlobalPref.STREAM_MAX_VIDEO_BITRATE,
PrefKey.AUDIO_VOLUME_CONTROL_ENABLED, GlobalPref.AUDIO_VOLUME_CONTROL_ENABLED,
PrefKey.SCREENSHOT_APPLY_FILTERS, GlobalPref.SCREENSHOT_APPLY_FILTERS,
PrefKey.AUDIO_MIC_ON_PLAYING, GlobalPref.AUDIO_MIC_ON_PLAYING,
PrefKey.GAME_FORTNITE_FORCE_CONSOLE, GlobalPref.GAME_FORTNITE_FORCE_CONSOLE,
PrefKey.STREAM_COMBINE_SOURCES, GlobalPref.STREAM_COMBINE_SOURCES,
], ],
}, { }, {
requiredVariants: 'full', requiredVariants: 'full',
group: 'mkb', group: 'mkb',
label: t('mouse-and-keyboard'), label: t('mouse-and-keyboard'),
items: [ items: [
PrefKey.NATIVE_MKB_MODE, GlobalPref.NATIVE_MKB_MODE,
{ {
pref: PrefKey.NATIVE_MKB_FORCED_GAMES, pref: GlobalPref.NATIVE_MKB_FORCED_GAMES,
multiLines: true, multiLines: true,
note: CE('a', { href: 'https://github.com/redphx/better-xcloud/discussions/574', target: '_blank' }, t('unofficial-game-list')), note: CE('a', { href: 'https://github.com/redphx/better-xcloud/discussions/574', target: '_blank' }, t('unofficial-game-list')),
}, },
PrefKey.MKB_ENABLED, GlobalPref.MKB_ENABLED,
PrefKey.MKB_HIDE_IDLE_CURSOR, GlobalPref.MKB_HIDE_IDLE_CURSOR,
], ],
// Unsupported // Unsupported
@ -255,13 +252,13 @@ export class SettingsDialog extends NavigationDialog {
label: t('touch-controller'), label: t('touch-controller'),
items: [ items: [
{ {
pref: PrefKey.TOUCH_CONTROLLER_MODE, pref: GlobalPref.TOUCH_CONTROLLER_MODE,
note: CE('a', { href: 'https://github.com/redphx/better-xcloud/discussions/241', target: '_blank' }, t('unofficial-game-list')), note: CE('a', { href: 'https://github.com/redphx/better-xcloud/discussions/241', target: '_blank' }, t('unofficial-game-list')),
}, },
PrefKey.TOUCH_CONTROLLER_AUTO_OFF, GlobalPref.TOUCH_CONTROLLER_AUTO_OFF,
PrefKey.TOUCH_CONTROLLER_DEFAULT_OPACITY, GlobalPref.TOUCH_CONTROLLER_DEFAULT_OPACITY,
PrefKey.TOUCH_CONTROLLER_STYLE_STANDARD, GlobalPref.TOUCH_CONTROLLER_STYLE_STANDARD,
PrefKey.TOUCH_CONTROLLER_STYLE_CUSTOM, GlobalPref.TOUCH_CONTROLLER_STYLE_CUSTOM,
], ],
// Unsupported // Unsupported
@ -273,21 +270,23 @@ export class SettingsDialog extends NavigationDialog {
group: 'ui', group: 'ui',
label: t('ui'), label: t('ui'),
items: [ items: [
PrefKey.UI_LAYOUT, GlobalPref.UI_LAYOUT,
PrefKey.UI_GAME_CARD_SHOW_WAIT_TIME, GlobalPref.UI_THEME,
PrefKey.UI_CONTROLLER_SHOW_STATUS, GlobalPref.UI_IMAGE_QUALITY,
PrefKey.UI_SIMPLIFY_STREAM_MENU, GlobalPref.UI_GAME_CARD_SHOW_WAIT_TIME,
PrefKey.UI_SKIP_SPLASH_VIDEO, GlobalPref.UI_CONTROLLER_SHOW_STATUS,
!AppInterface && PrefKey.UI_SCROLLBAR_HIDE, GlobalPref.UI_SIMPLIFY_STREAM_MENU,
PrefKey.UI_HIDE_SYSTEM_MENU_ICON, GlobalPref.UI_SKIP_SPLASH_VIDEO,
PrefKey.UI_DISABLE_FEEDBACK_DIALOG, !AppInterface && GlobalPref.UI_SCROLLBAR_HIDE,
PrefKey.UI_REDUCE_ANIMATIONS, GlobalPref.UI_HIDE_SYSTEM_MENU_ICON,
GlobalPref.UI_DISABLE_FEEDBACK_DIALOG,
GlobalPref.UI_REDUCE_ANIMATIONS,
{ {
pref: PrefKey.UI_HIDE_SECTIONS, pref: GlobalPref.UI_HIDE_SECTIONS,
multiLines: true, multiLines: true,
}, },
{ {
pref: PrefKey.BLOCK_FEATURES, pref: GlobalPref.BLOCK_FEATURES,
multiLines: true, multiLines: true,
}, },
], ],
@ -296,28 +295,28 @@ export class SettingsDialog extends NavigationDialog {
group: 'game-bar', group: 'game-bar',
label: t('game-bar'), label: t('game-bar'),
items: [ items: [
PrefKey.GAME_BAR_POSITION, GlobalPref.GAME_BAR_POSITION,
], ],
}, { }, {
group: 'loading-screen', group: 'loading-screen',
label: t('loading-screen'), label: t('loading-screen'),
items: [ items: [
PrefKey.LOADING_SCREEN_GAME_ART, GlobalPref.LOADING_SCREEN_GAME_ART,
PrefKey.LOADING_SCREEN_SHOW_WAIT_TIME, GlobalPref.LOADING_SCREEN_SHOW_WAIT_TIME,
PrefKey.LOADING_SCREEN_ROCKET, GlobalPref.LOADING_SCREEN_ROCKET,
], ],
}, { }, {
group: 'other', group: 'other',
label: t('other'), label: t('other'),
items: [ items: [
PrefKey.BLOCK_TRACKING, GlobalPref.BLOCK_TRACKING,
], ],
}, { }, isFullVersion() && {
group: 'advanced', group: 'advanced',
label: t('advanced'), label: t('advanced'),
items: [ items: [
{ {
pref: PrefKey.USER_AGENT_PROFILE, pref: GlobalPref.USER_AGENT_PROFILE,
multiLines: true, multiLines: true,
onCreated: (setting, $control) => { onCreated: (setting, $control) => {
const defaultUserAgent = window.navigator.orgUserAgent || window.navigator.userAgent; const defaultUserAgent = window.navigator.orgUserAgent || window.navigator.userAgent;
@ -374,7 +373,7 @@ export class SettingsDialog extends NavigationDialog {
$parent => { $parent => {
$parent.appendChild(createButton({ $parent.appendChild(createButton({
label: t('clear-data'), label: t('clear-data'),
style: ButtonStyle.GHOST | ButtonStyle.FULL_WIDTH | ButtonStyle.FOCUSABLE, style: ButtonStyle.DANGER | ButtonStyle.FROSTED | ButtonStyle.FULL_WIDTH | ButtonStyle.FOCUSABLE,
onClick: e => { onClick: e => {
if (confirm(t('clear-data-confirm'))) { if (confirm(t('clear-data-confirm'))) {
clearAllData(); clearAllData();
@ -428,20 +427,17 @@ export class SettingsDialog extends NavigationDialog {
label: t('audio'), label: t('audio'),
helpUrl: 'https://better-xcloud.github.io/ingame-features/#audio', helpUrl: 'https://better-xcloud.github.io/ingame-features/#audio',
items: [{ items: [{
pref: PrefKey.AUDIO_VOLUME, pref: StreamPref.AUDIO_VOLUME,
onChange: (e: any, value: number) => {
SoundShortcut.setGainNodeVolume(value);
},
params: { params: {
disabled: !getPref(PrefKey.AUDIO_VOLUME_CONTROL_ENABLED), disabled: !getGlobalPref(GlobalPref.AUDIO_VOLUME_CONTROL_ENABLED),
}, },
onCreated: (setting: SettingTabSectionItem, $elm: HTMLElement) => { onCreated: (setting: SettingTabSectionItem, $elm: HTMLElement) => {
const $range = $elm.querySelector<HTMLInputElement>('input[type=range')!; const $range = $elm.querySelector<HTMLInputElement>('input[type=range')!;
BxEventBus.Script.on('setting.changed', payload => { BxEventBus.Stream.on('setting.changed', payload => {
const { storageKey, settingKey, settingValue } = payload; const { settingKey } = payload;
if (storageKey === StorageKey.GLOBAL && settingKey === PrefKey.AUDIO_VOLUME) { if (settingKey === StreamPref.AUDIO_VOLUME) {
$range.value = settingValue; $range.value = getStreamPref(settingKey).toString();
BxEvent.dispatch($range, 'input', { ignoreOnChange: true }); BxEvent.dispatch($range, 'input', { ignoreOnChange: true });
} }
}); });
@ -451,67 +447,35 @@ export class SettingsDialog extends NavigationDialog {
group: 'video', group: 'video',
label: t('video'), label: t('video'),
helpUrl: 'https://better-xcloud.github.io/ingame-features/#video', helpUrl: 'https://better-xcloud.github.io/ingame-features/#video',
items: [{ items: [
pref: PrefKey.VIDEO_PLAYER_TYPE, StreamPref.VIDEO_PLAYER_TYPE,
onChange: onChangeVideoPlayerType, StreamPref.VIDEO_MAX_FPS,
}, { StreamPref.VIDEO_POWER_PREFERENCE,
pref: PrefKey.VIDEO_MAX_FPS, StreamPref.VIDEO_PROCESSING,
onChange: e => { StreamPref.VIDEO_PROCESSING_MODE,
limitVideoPlayerFps(parseInt(e.target.value)); StreamPref.VIDEO_RATIO,
}, StreamPref.VIDEO_POSITION,
}, { StreamPref.VIDEO_SHARPNESS,
pref: PrefKey.VIDEO_POWER_PREFERENCE, StreamPref.VIDEO_SATURATION,
onChange: () => { StreamPref.VIDEO_CONTRAST,
const streamPlayer = STATES.currentStream.streamPlayer; StreamPref.VIDEO_BRIGHTNESS,
if (!streamPlayer) { ],
return;
}
streamPlayer.reloadPlayer();
updateVideoPlayer();
},
}, {
pref: PrefKey.VIDEO_PROCESSING,
onChange: updateVideoPlayer,
}, {
pref: PrefKey.VIDEO_RATIO,
onChange: updateVideoPlayer,
}, {
pref: PrefKey.VIDEO_POSITION,
onChange: updateVideoPlayer,
}, {
pref: PrefKey.VIDEO_SHARPNESS,
onChange: updateVideoPlayer,
}, {
pref: PrefKey.VIDEO_SATURATION,
onChange: updateVideoPlayer,
}, {
pref: PrefKey.VIDEO_CONTRAST,
onChange: updateVideoPlayer,
}, {
pref: PrefKey.VIDEO_BRIGHTNESS,
onChange: updateVideoPlayer,
}],
}]; }];
private readonly TAB_CONTROLLER_ITEMS: Array<SettingTabSection | HTMLElement | false> = [{ private readonly TAB_CONTROLLER_ITEMS: Array<SettingTabSection | HTMLElement | false> = isFullVersion() ? [{
group: 'controller', group: 'controller',
label: t('controller'), label: t('controller'),
helpUrl: 'https://better-xcloud.github.io/ingame-features/#controller', helpUrl: 'https://better-xcloud.github.io/ingame-features/#controller',
items: [ items: [
isFullVersion() && { StreamPref.LOCAL_CO_OP_ENABLED,
pref: PrefKey.LOCAL_CO_OP_ENABLED, StreamPref.CONTROLLER_POLLING_RATE,
onChange: () => { BxExposed.toggleLocalCoOp(getPref(PrefKey.LOCAL_CO_OP_ENABLED)); }, ($parent => {
}, $parent.appendChild(ControllerExtraSettings.renderSettings.apply(this));
isFullVersion() && { }),
pref: PrefKey.CONTROLLER_POLLING_RATE, ],
onChange: () => StreamSettings.refreshControllerSettings(),
}, isFullVersion() && ($parent => {
$parent.appendChild(ControllerExtraSettings.renderSettings.apply(this));
})],
}, },
isFullVersion() && STATES.userAgent.capabilities.touch && { STATES.userAgent.capabilities.touch && {
group: 'touch-control', group: 'touch-control',
label: t('touch-controller'), label: t('touch-controller'),
items: [{ items: [{
@ -563,82 +527,57 @@ export class SettingsDialog extends NavigationDialog {
}); });
}, },
}], }],
}, isFullVersion() && STATES.browser.capabilities.deviceVibration && { },
STATES.browser.capabilities.deviceVibration && {
group: 'device', group: 'device',
label: t('device'), label: t('device'),
items: [{ items: [{
pref: PrefKey.DEVICE_VIBRATION_MODE, pref: StreamPref.DEVICE_VIBRATION_MODE,
multiLines: true, multiLines: true,
unsupported: !STATES.browser.capabilities.deviceVibration, unsupported: !STATES.browser.capabilities.deviceVibration,
onChange: () => StreamSettings.refreshControllerSettings(),
}, { }, {
pref: PrefKey.DEVICE_VIBRATION_INTENSITY, pref: StreamPref.DEVICE_VIBRATION_INTENSITY,
unsupported: !STATES.browser.capabilities.deviceVibration, unsupported: !STATES.browser.capabilities.deviceVibration,
onChange: () => StreamSettings.refreshControllerSettings(),
}], }],
}]; }] : [];
private readonly TAB_MKB_ITEMS: (() => Array<SettingTabSection | false>) = () => [ private readonly TAB_MKB_ITEMS: Array<SettingTabSection | false> = isFullVersion() ? [
isFullVersion() && { {
requiredVariants: 'full', requiredVariants: 'full',
group: 'mkb', group: 'mkb',
label: t('mouse-and-keyboard'), label: t('mouse-and-keyboard'),
helpUrl: 'https://better-xcloud.github.io/mouse-and-keyboard/', helpUrl: 'https://better-xcloud.github.io/mouse-and-keyboard/',
items: [ items: [
isFullVersion() && (($parent: HTMLElement) => { ($parent: HTMLElement) => {
$parent.appendChild(MkbExtraSettings.renderSettings.apply(this)); $parent.appendChild(MkbExtraSettings.renderSettings.apply(this));
}) },
], ],
}, },
isFullVersion() && NativeMkbHandler.isAllowed() && { NativeMkbHandler.isAllowed() && {
requiredVariants: 'full', requiredVariants: 'full',
group: 'native-mkb', group: 'native-mkb',
label: t('native-mkb'), label: t('native-mkb'),
items: isFullVersion() ? [{ items: [
pref: PrefKey.NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY, StreamPref.NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY,
onChange: (e: any, value: number) => { StreamPref.NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY,
NativeMkbHandler.getInstance()?.setVerticalScrollMultiplier(value / 100); ],
}, }] : [];
}, {
pref: PrefKey.NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY,
onChange: (e: any, value: number) => {
NativeMkbHandler.getInstance()?.setHorizontalScrollMultiplier(value / 100);
},
}] : [],
}];
private readonly TAB_STATS_ITEMS: Array<SettingTabSection | false> = [{ private readonly TAB_STATS_ITEMS: Array<SettingTabSection | false> = [{
group: 'stats', group: 'stats',
label: t('stream-stats'), label: t('stream-stats'),
helpUrl: 'https://better-xcloud.github.io/stream-stats/', helpUrl: 'https://better-xcloud.github.io/stream-stats/',
items: [{ items: [
pref: PrefKey.STATS_SHOW_WHEN_PLAYING, StreamPref.STATS_SHOW_WHEN_PLAYING,
}, { StreamPref.STATS_QUICK_GLANCE_ENABLED,
pref: PrefKey.STATS_QUICK_GLANCE_ENABLED, StreamPref.STATS_ITEMS,
onChange: (e: InputEvent) => { StreamPref.STATS_POSITION,
const streamStats = StreamStats.getInstance(); StreamPref.STATS_TEXT_SIZE,
(e.target! as HTMLInputElement).checked ? streamStats.quickGlanceSetup() : streamStats.quickGlanceStop(); StreamPref.STATS_OPACITY_ALL,
}, StreamPref.STATS_OPACITY_BACKGROUND,
}, { StreamPref.STATS_CONDITIONAL_FORMATTING,
pref: PrefKey.STATS_ITEMS,
onChange: StreamStats.refreshStyles,
}, {
pref: PrefKey.STATS_POSITION,
onChange: StreamStats.refreshStyles,
}, {
pref: PrefKey.STATS_TEXT_SIZE,
onChange: StreamStats.refreshStyles,
}, {
pref: PrefKey.STATS_OPACITY_ALL,
onChange: StreamStats.refreshStyles,
}, {
pref: PrefKey.STATS_OPACITY_BACKGROUND,
onChange: StreamStats.refreshStyles,
}, {
pref: PrefKey.STATS_CONDITIONAL_FORMATTING,
onChange: StreamStats.refreshStyles,
},
], ],
}]; }];
@ -666,7 +605,6 @@ export class SettingsDialog extends NavigationDialog {
group: 'mkb', group: 'mkb',
icon: BxIcon.NATIVE_MKB, icon: BxIcon.NATIVE_MKB,
items: this.TAB_MKB_ITEMS, items: this.TAB_MKB_ITEMS,
lazyContent: true,
requiredVariants: 'full', requiredVariants: 'full',
}, },
@ -681,6 +619,8 @@ export class SettingsDialog extends NavigationDialog {
super(); super();
BxLogger.info(this.LOG_TAG, 'constructor()'); BxLogger.info(this.LOG_TAG, 'constructor()');
this.boundOnContextMenu = this.onContextMenu.bind(this);
this.settingsManager = SettingsManager.getInstance();
this.renderFullSettings = STATES.supportedRegion && STATES.isSignedIn; this.renderFullSettings = STATES.supportedRegion && STATES.isSignedIn;
this.setupDialog(); this.setupDialog();
@ -694,13 +634,17 @@ export class SettingsDialog extends NavigationDialog {
} }
// Trigger event // Trigger event
const $selectUserAgent = document.querySelector<HTMLSelectElement>(`#bx_setting_${escapeCssSelector(PrefKey.USER_AGENT_PROFILE)}`); const $selectUserAgent = document.querySelector<HTMLSelectElement>(`#bx_setting_${escapeCssSelector(GlobalPref.USER_AGENT_PROFILE)}`);
if ($selectUserAgent) { if ($selectUserAgent) {
$selectUserAgent.disabled = true; $selectUserAgent.disabled = true;
BxEvent.dispatch($selectUserAgent, 'input', {}); BxEvent.dispatch($selectUserAgent, 'input', {});
$selectUserAgent.disabled = false; $selectUserAgent.disabled = false;
} }
}); });
BxEventBus.Stream.on('gameSettings.switched', ({ id }) => {
this.$tabContents.dataset.gameId = id.toString();
});
} }
getDialog(): NavigationDialog { getDialog(): NavigationDialog {
@ -740,21 +684,6 @@ export class SettingsDialog extends NavigationDialog {
private onTabClicked = (e: Event) => { private onTabClicked = (e: Event) => {
const $svg = (e.target as SVGElement).closest('svg')!; const $svg = (e.target as SVGElement).closest('svg')!;
// Render tab content lazily
if (!!$svg.dataset.lazy) {
// Remove attribute
delete $svg.dataset.lazy;
// Render data
const settingTab = this.SETTINGS_UI[$svg.dataset.group as SettingTabGroup];
if (!settingTab) {
return;
}
const items = (settingTab.items as Function)();
const $tabContent = this.renderSettingsSection.call(this, settingTab, items);
this.$tabContents.appendChild($tabContent);
}
// Switch tab // Switch tab
let $child: HTMLElement; let $child: HTMLElement;
const children = Array.from(this.$tabContents.children) as HTMLElement[]; const children = Array.from(this.$tabContents.children) as HTMLElement[];
@ -765,12 +694,15 @@ export class SettingsDialog extends NavigationDialog {
// Calculate size of controller-friendly select boxes // Calculate size of controller-friendly select boxes
calculateSelectBoxes($child as HTMLElement); calculateSelectBoxes($child as HTMLElement);
} else { } else if ($child.dataset.tabGroup) {
// Hide tab content // Hide tab content
$child.classList.add('bx-gone'); $child.classList.add('bx-gone');
} }
} }
// Toggle stream settings selection
this.$streamSettingsSelection.classList.toggle('bx-gone', $svg.dataset.group === 'global');
// Highlight current tab button // Highlight current tab button
for (const $child of Array.from(this.$tabs.children)) { for (const $child of Array.from(this.$tabs.children)) {
$child.classList.remove('bx-active'); $child.classList.remove('bx-active');
@ -783,10 +715,8 @@ export class SettingsDialog extends NavigationDialog {
const $svg = createSvgIcon(settingTab.icon as any); const $svg = createSvgIcon(settingTab.icon as any);
$svg.dataset.group = settingTab.group; $svg.dataset.group = settingTab.group;
$svg.tabIndex = 0; $svg.tabIndex = 0;
settingTab.lazyContent && ($svg.dataset.lazy = settingTab.lazyContent.toString());
$svg.addEventListener('click', this.onTabClicked); $svg.addEventListener('click', this.onTabClicked);
return $svg; return $svg;
} }
@ -801,8 +731,14 @@ export class SettingsDialog extends NavigationDialog {
this.$btnGlobalReload.classList.add('bx-danger'); this.$btnGlobalReload.classList.add('bx-danger');
} }
private onContextMenu(e: Event) {
e.preventDefault();
const $elm = e.target;
$elm instanceof HTMLElement && this.resetHighlightedSetting($elm);
}
private renderServerSetting(setting: SettingTabSectionItem): HTMLElement { private renderServerSetting(setting: SettingTabSectionItem): HTMLElement {
let selectedValue = getPref(PrefKey.SERVER_REGION); let selectedValue = getGlobalPref(GlobalPref.SERVER_REGION);
const continents: Record<ServerContinent, { const continents: Record<ServerContinent, {
label: string, label: string,
@ -835,7 +771,7 @@ export class SettingsDialog extends NavigationDialog {
$control.name = $control.id; $control.name = $control.id;
$control.addEventListener('input', (e: Event) => { $control.addEventListener('input', (e: Event) => {
setPref(setting.pref!, (e.target as HTMLSelectElement).value); setGlobalPref(setting.pref! as GlobalPref, (e.target as HTMLSelectElement).value, 'ui');
this.onGlobalSettingChanged(e); this.onGlobalSettingChanged(e);
}); });
@ -887,13 +823,14 @@ export class SettingsDialog extends NavigationDialog {
} }
private renderSettingRow(settingTab: SettingTab, $tabContent: HTMLElement, settingTabContent: SettingTabSection, setting: SettingTabSectionItem | string) { private renderSettingRow(settingTab: SettingTab, $tabContent: HTMLElement, settingTabContent: SettingTabSection, setting: SettingTabSectionItem | string) {
// Convert pref key to object
if (typeof setting === 'string') { if (typeof setting === 'string') {
setting = { setting = {
pref: setting as PrefKey, pref: setting as AnyPref,
} satisfies SettingTabSectionItem; } satisfies SettingTabSectionItem;
} }
const pref = setting.pref; const pref = setting.pref!;
let $control; let $control;
if (setting.content) { if (setting.content) {
@ -903,13 +840,13 @@ export class SettingsDialog extends NavigationDialog {
$control = setting.content; $control = setting.content;
} }
} else if (!setting.unsupported) { } else if (!setting.unsupported) {
if (pref === PrefKey.SERVER_REGION) { if (pref === GlobalPref.SERVER_REGION) {
$control = this.renderServerSetting(setting); $control = this.renderServerSetting(setting);
} else if (pref === PrefKey.SCRIPT_LOCALE) { } else if (pref === GlobalPref.SCRIPT_LOCALE) {
$control = SettingElement.fromPref(pref, STORAGE.Global, async (e: Event) => { $control = SettingElement.fromPref(pref, async (e: Event) => {
const newLocale = (e.target as HTMLSelectElement).value; const newLocale = (e.target as HTMLSelectElement).value;
if (getPref(PrefKey.UI_CONTROLLER_FRIENDLY)) { if (getGlobalPref(GlobalPref.UI_CONTROLLER_FRIENDLY)) {
let timeoutId = (e.target as any).timeoutId; let timeoutId = (e.target as any).timeoutId;
timeoutId && window.clearTimeout(timeoutId); timeoutId && window.clearTimeout(timeoutId);
(e.target as any).timeoutId = window.setTimeout(() => { (e.target as any).timeoutId = window.setTimeout(() => {
@ -924,8 +861,8 @@ export class SettingsDialog extends NavigationDialog {
this.onGlobalSettingChanged(e); this.onGlobalSettingChanged(e);
}); });
} else if (pref === PrefKey.USER_AGENT_PROFILE) { } else if (pref === GlobalPref.USER_AGENT_PROFILE) {
$control = SettingElement.fromPref(PrefKey.USER_AGENT_PROFILE, STORAGE.Global, (e: Event) => { $control = SettingElement.fromPref(GlobalPref.USER_AGENT_PROFILE, (e: Event) => {
const $target = e.target as HTMLSelectElement; const $target = e.target as HTMLSelectElement;
const value = $target.value as UserAgentProfile; const value = $target.value as UserAgentProfile;
let isCustom = value === UserAgentProfile.CUSTOM; let isCustom = value === UserAgentProfile.CUSTOM;
@ -941,25 +878,21 @@ export class SettingsDialog extends NavigationDialog {
!(e.target as HTMLInputElement).disabled && this.onGlobalSettingChanged(e); !(e.target as HTMLInputElement).disabled && this.onGlobalSettingChanged(e);
}); });
} else { } else {
let onChange = setting.onChange; $control = this.settingsManager.getElement(pref, setting.params);
if (!onChange && settingTab.group === 'global') { if (settingTab.group === 'global') {
onChange = this.onGlobalSettingChanged; $control.addEventListener('input', this.onGlobalSettingChanged);
} }
$control = SettingElement.fromPref(pref as PrefKey, STORAGE.Global, onChange, setting.params);
} }
// Replace <select> with controller-friendly one // Replace <select> with controller-friendly one
if ($control instanceof HTMLSelectElement) { if ($control instanceof HTMLSelectElement) {
$control = BxSelectElement.create($control); $control = BxSelectElement.create($control);
} }
pref && (this.settingElements[pref] = $control);
} }
let prefDefinition: SettingDefinition | null = null; let prefDefinition: SettingDefinition | null = null;
if (pref) { if (pref) {
prefDefinition = getPrefDefinition(pref); prefDefinition = getPrefInfo(pref).definition;
} }
if (prefDefinition && !this.isSupportedVariant(prefDefinition.requiredVariants)) { if (prefDefinition && !this.isSupportedVariant(prefDefinition.requiredVariants)) {
@ -1007,12 +940,20 @@ export class SettingsDialog extends NavigationDialog {
const $row = createSettingRow(label, !prefDefinition?.unsupported && $control, { const $row = createSettingRow(label, !prefDefinition?.unsupported && $control, {
$note, $note,
multiLines: setting.multiLines, multiLines: setting.multiLines,
icon: prefDefinition?.labelIcon,
onContextMenu: this.boundOnContextMenu,
pref: pref,
}); });
if (pref) { if (pref) {
$row.htmlFor = `bx_setting_${escapeCssSelector(pref)}`; $row.htmlFor = `bx_setting_${escapeCssSelector(pref)}`;
} }
$row.dataset.type = settingTabContent.group; $row.dataset.type = settingTabContent.group;
// Highlight "Bypass region" row
if (!STATES.supportedRegion && setting.pref === GlobalPref.SERVER_BYPASS_RESTRICTION) {
$row.classList.add('bx-settings-important-row');
}
$tabContent.appendChild($row); $tabContent.appendChild($row);
!prefDefinition?.unsupported && setting.onCreated && setting.onCreated(setting, $control); !prefDefinition?.unsupported && setting.onCreated && setting.onCreated(setting, $control);
} }
@ -1020,7 +961,9 @@ export class SettingsDialog extends NavigationDialog {
private renderSettingsSection(settingTab: SettingTab, sections: Array<SettingTabSection | HTMLElement | false>): HTMLElement { private renderSettingsSection(settingTab: SettingTab, sections: Array<SettingTabSection | HTMLElement | false>): HTMLElement {
const $tabContent = CE('div', { const $tabContent = CE('div', {
class: 'bx-gone', class: 'bx-gone',
'data-tab-group': settingTab.group, _dataset: {
tabGroup: settingTab.group,
},
}); });
for (const section of sections) { for (const section of sections) {
@ -1165,21 +1108,31 @@ export class SettingsDialog extends NavigationDialog {
), ),
), ),
$tabContents = CE('div', { CE('div', {
class: 'bx-settings-tab-contents', class: 'bx-settings-tab-contents',
_nearby: { _nearby: {
orientation: 'vertical', orientation: 'vertical',
focus: () => this.jumpToSettingGroup('next'), loop: direction => {
loop: direction => { if (direction === NavigationDirection.UP || direction === NavigationDirection.DOWN) {
if (direction === NavigationDirection.UP || direction === NavigationDirection.DOWN) { this.focusVisibleSetting(direction === NavigationDirection.UP ? 'last' : 'first');
this.focusVisibleSetting(direction === NavigationDirection.UP ? 'last' : 'first'); return true;
return true; }
}
return false; return false;
}, },
}
}, },
}), // Render global/per-game settings selection
this.$streamSettingsSelection = SettingsManager.getInstance().getStreamSettingsSelection(),
$tabContents = CE('div', {
class: 'bx-settings-tab-content',
_nearby: {
orientation: 'vertical',
focus: () => this.jumpToSettingGroup('next'),
},
}),
),
); );
this.$container = $container; this.$container = $container;
@ -1195,6 +1148,7 @@ export class SettingsDialog extends NavigationDialog {
} }
}); });
// Render tab contents
let settingTabGroup: keyof typeof this.SETTINGS_UI let settingTabGroup: keyof typeof this.SETTINGS_UI
for (settingTabGroup in this.SETTINGS_UI) { for (settingTabGroup in this.SETTINGS_UI) {
const settingTab = this.SETTINGS_UI[settingTabGroup]; const settingTab = this.SETTINGS_UI[settingTabGroup];
@ -1216,11 +1170,6 @@ export class SettingsDialog extends NavigationDialog {
const $svg = this.renderTab(settingTab); const $svg = this.renderTab(settingTab);
$tabs.appendChild($svg); $tabs.appendChild($svg);
// Don't render lazy tab content
if (typeof settingTab.items === 'function') {
continue;
}
const $tabContent = this.renderSettingsSection.call(this, settingTab, settingTab.items); const $tabContent = this.renderSettingsSection.call(this, settingTab, settingTab.items);
$tabContents.appendChild($tabContent); $tabContents.appendChild($tabContent);
} }
@ -1341,6 +1290,43 @@ export class SettingsDialog extends NavigationDialog {
return false; return false;
} }
private resetHighlightedSetting($elm?: HTMLElement) {
const targetGameId = SettingsManager.getInstance().getTargetGameId();
if (targetGameId < 0) {
return;
}
if (!$elm) {
// Get focusing element
$elm = document.activeElement instanceof HTMLElement ? document.activeElement : undefined;
}
const $row = $elm?.closest('div[data-tab-group] > .bx-settings-row');
if (!$row) {
return;
}
const pref = ($row as any).prefKey;
if (!pref) {
alert('Pref not found: ' + $row.id);
}
if (!isStreamPref(pref)) {
return;
}
// Delete settings
const deleted = STORAGE.Stream.deleteSettingByGame(targetGameId, pref);
if (deleted) {
BxEventBus.Stream.emit('setting.changed', {
storageKey: `${StorageKey.STREAM}.${targetGameId}`,
settingKey: pref,
});
}
return deleted;
}
handleKeyPress(key: string): boolean { handleKeyPress(key: string): boolean {
let handled = true; let handled = true;
switch (key) { switch (key) {
@ -1359,6 +1345,9 @@ export class SettingsDialog extends NavigationDialog {
case 'PageDown': case 'PageDown':
this.jumpToSettingGroup('next'); this.jumpToSettingGroup('next');
break; break;
case 'KeyQ':
this.resetHighlightedSetting();
break;
default: default:
handled = false; handled = false;
break; break;
@ -1391,6 +1380,9 @@ export class SettingsDialog extends NavigationDialog {
case GamepadKey.RT: case GamepadKey.RT:
this.jumpToSettingGroup('next'); this.jumpToSettingGroup('next');
break; break;
case GamepadKey.X:
this.resetHighlightedSetting();
break;
default: default:
handled = false; handled = false;
break; break;

View File

@ -1,16 +1,17 @@
import { BxEvent } from "@/utils/bx-event"; import { BxEvent } from "@/utils/bx-event";
import { getUniqueGamepadNames } from "@/utils/gamepad"; import { getUniqueGamepadNames, simplifyGamepadName } from "@/utils/gamepad";
import { CE, removeChildElements, createButton, ButtonStyle, createSettingRow, renderPresetsList, calculateSelectBoxes } from "@/utils/html"; import { CE, removeChildElements, createButton, ButtonStyle, createSettingRow, renderPresetsList, calculateSelectBoxes } from "@/utils/html";
import { t } from "@/utils/translation"; import { t } from "@/utils/translation";
import { BxSelectElement } from "@/web-components/bx-select"; import { BxSelectElement } from "@/web-components/bx-select";
import { ControllerShortcutsManagerDialog } from "../profile-manger/controller-shortcuts-manager-dialog"; import { ControllerShortcutsManagerDialog } from "../profile-manger/controller-shortcuts-manager-dialog";
import type { SettingsDialog } from "../settings-dialog"; import type { SettingsDialog } from "../settings-dialog";
import { ControllerShortcutsTable } from "@/utils/local-db/controller-shortcuts-table"; import { ControllerShortcutsTable } from "@/utils/local-db/controller-shortcuts-table";
import { ControllerSettingsTable } from "@/utils/local-db/controller-settings-table";
import { StreamSettings } from "@/utils/stream-settings"; import { StreamSettings } from "@/utils/stream-settings";
import { ControllerCustomizationsTable } from "@/utils/local-db/controller-customizations-table"; import { ControllerCustomizationsTable } from "@/utils/local-db/controller-customizations-table";
import { ControllerCustomizationsManagerDialog } from "../profile-manger/controller-customizations-manager-dialog"; import { ControllerCustomizationsManagerDialog } from "../profile-manger/controller-customizations-manager-dialog";
import { BxIcon } from "@/utils/bx-icon"; import { BxIcon } from "@/utils/bx-icon";
import { getStreamPref, setStreamPref, STORAGE } from "@/utils/pref-utils";
import { StreamPref } from "@/enums/pref-keys";
export class ControllerExtraSettings extends HTMLElement { export class ControllerExtraSettings extends HTMLElement {
currentControllerId!: string; currentControllerId!: string;
@ -26,16 +27,23 @@ export class ControllerExtraSettings extends HTMLElement {
getCurrentControllerId!: typeof ControllerExtraSettings['getCurrentControllerId']; getCurrentControllerId!: typeof ControllerExtraSettings['getCurrentControllerId'];
saveSettings!: typeof ControllerExtraSettings['saveSettings']; saveSettings!: typeof ControllerExtraSettings['saveSettings'];
updateCustomizationSummary!: typeof ControllerExtraSettings['updateCustomizationSummary']; updateCustomizationSummary!: typeof ControllerExtraSettings['updateCustomizationSummary'];
setValue!: typeof ControllerExtraSettings['setValue'];
static renderSettings(this: SettingsDialog): HTMLElement { static renderSettings(this: SettingsDialog): HTMLElement {
const $container = CE('label', { const $container = CE('label', {
class: 'bx-settings-row bx-controller-extra-settings', class: 'bx-settings-row bx-controller-extra-settings',
}) as unknown as ControllerExtraSettings; }) as unknown as ControllerExtraSettings;
// Setting up for Settings Manager
($container as any).prefKey = StreamPref.CONTROLLER_SETTINGS;
$container.addEventListener('contextmenu', this.boundOnContextMenu);
this.settingsManager.setElement(StreamPref.CONTROLLER_SETTINGS, $container);
$container.updateLayout = ControllerExtraSettings.updateLayout.bind($container); $container.updateLayout = ControllerExtraSettings.updateLayout.bind($container);
$container.switchController = ControllerExtraSettings.switchController.bind($container); $container.switchController = ControllerExtraSettings.switchController.bind($container);
$container.getCurrentControllerId = ControllerExtraSettings.getCurrentControllerId.bind($container); $container.getCurrentControllerId = ControllerExtraSettings.getCurrentControllerId.bind($container);
$container.saveSettings = ControllerExtraSettings.saveSettings.bind($container); $container.saveSettings = ControllerExtraSettings.saveSettings.bind($container);
$container.setValue = ControllerExtraSettings.setValue.bind($container);
const $selectControllers = BxSelectElement.create(CE('select', { const $selectControllers = BxSelectElement.create(CE('select', {
class: 'bx-full-width', class: 'bx-full-width',
@ -80,9 +88,7 @@ export class ControllerExtraSettings extends HTMLElement {
}), }),
}), }),
), ),
{ { multiLines: true },
multiLines: true,
},
); );
$rowCustomization.appendChild( $rowCustomization.appendChild(
$container.$summaryCustomization = CE('div'), $container.$summaryCustomization = CE('div'),
@ -162,7 +168,7 @@ export class ControllerExtraSettings extends HTMLElement {
// Render controller list // Render controller list
for (const name of this.controllerIds) { for (const name of this.controllerIds) {
const $option = CE('option', { value: name }, name); const $option = CE('option', { value: name }, simplifyGamepadName(name));
$fragment.appendChild($option); $fragment.appendChild($option);
} }
@ -191,14 +197,8 @@ export class ControllerExtraSettings extends HTMLElement {
return; return;
} }
const controllerSettings = await ControllerSettingsTable.getInstance().getControllerData(this.currentControllerId); const controllerSetting = STORAGE.Stream.getControllerSetting(this.currentControllerId);
ControllerExtraSettings.updateElements.call(this, controllerSetting);
// Update UI
this.$selectShortcuts.value = controllerSettings.shortcutPresetId.toString();
this.$selectCustomization.value = controllerSettings.customizationPresetId.toString();
// Update summary
ControllerExtraSettings.updateCustomizationSummary.call(this);
} }
private static getCurrentControllerId(this: ControllerExtraSettings) { private static getCurrentControllerId(this: ControllerExtraSettings) {
@ -228,16 +228,30 @@ export class ControllerExtraSettings extends HTMLElement {
return; return;
} }
const data: ControllerSettingsRecord = { const controllerSettings = getStreamPref(StreamPref.CONTROLLER_SETTINGS);
id: this.currentControllerId, controllerSettings[this.currentControllerId] = {
data: { shortcutPresetId: parseInt(this.$selectShortcuts.value),
shortcutPresetId: parseInt(this.$selectShortcuts.value), customizationPresetId: parseInt(this.$selectCustomization.value),
customizationPresetId: parseInt(this.$selectCustomization.value),
},
}; };
await ControllerSettingsTable.getInstance().put(data); setStreamPref(StreamPref.CONTROLLER_SETTINGS, controllerSettings, 'ui');
StreamSettings.refreshControllerSettings(); StreamSettings.refreshControllerSettings();
} }
private static setValue(this: ControllerExtraSettings, value: ControllerSettings) {
ControllerExtraSettings.updateElements.call(this, value[this.currentControllerId]);
}
private static updateElements(this: ControllerExtraSettings, controllerSetting: ControllerSetting) {
if (!controllerSetting) {
return;
}
// Update UI
this.$selectShortcuts.value = controllerSetting.shortcutPresetId.toString();
this.$selectCustomization.value = controllerSetting.customizationPresetId.toString();
// Update summary
ControllerExtraSettings.updateCustomizationSummary.call(this);
}
} }

View File

@ -3,15 +3,11 @@ import type { SettingsDialog } from "../settings-dialog";
import { MkbMappingPresetsTable } from "@/utils/local-db/mkb-mapping-presets-table"; import { MkbMappingPresetsTable } from "@/utils/local-db/mkb-mapping-presets-table";
import { BxSelectElement } from "@/web-components/bx-select"; import { BxSelectElement } from "@/web-components/bx-select";
import { t } from "@/utils/translation"; import { t } from "@/utils/translation";
import { getPref, setPref } from "@/utils/settings-storages/global-settings-storage"; import { getGlobalPref, getStreamPref, setStreamPref } from "@/utils/pref-utils";
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref, StreamPref } from "@/enums/pref-keys";
import { StreamSettings } from "@/utils/stream-settings";
import { MkbMappingManagerDialog } from "../profile-manger/mkb-mapping-manager-dialog"; import { MkbMappingManagerDialog } from "../profile-manger/mkb-mapping-manager-dialog";
import { KeyboardShortcutsManagerDialog } from "../profile-manger/keyboard-shortcuts-manager-dialog"; import { KeyboardShortcutsManagerDialog } from "../profile-manger/keyboard-shortcuts-manager-dialog";
import { KeyboardShortcutsTable } from "@/utils/local-db/keyboard-shortcuts-table"; import { KeyboardShortcutsTable } from "@/utils/local-db/keyboard-shortcuts-table";
import { SettingElement } from "@/utils/setting-element";
import { STORAGE } from "@/utils/global";
import { EmulatedMkbHandler } from "@/modules/mkb/mkb-handler";
import { BxIcon } from "@/utils/bx-icon"; import { BxIcon } from "@/utils/bx-icon";
export class MkbExtraSettings extends HTMLElement { export class MkbExtraSettings extends HTMLElement {
@ -44,7 +40,7 @@ export class MkbExtraSettings extends HTMLElement {
})); }));
$container.append( $container.append(
...(getPref(PrefKey.MKB_ENABLED) ? [ ...(getGlobalPref(GlobalPref.MKB_ENABLED) ? [
createSettingRow( createSettingRow(
t('virtual-controller'), t('virtual-controller'),
CE('div', { CE('div', {
@ -63,14 +59,20 @@ export class MkbExtraSettings extends HTMLElement {
}), }),
}), }),
), ),
{ multiLines: true }, {
multiLines: true,
onContextMenu: this.boundOnContextMenu,
pref: StreamPref.MKB_P1_MAPPING_PRESET_ID,
},
), ),
createSettingRow( createSettingRow(
t('virtual-controller-slot'), t('virtual-controller-slot'),
SettingElement.fromPref(PrefKey.MKB_P1_SLOT, STORAGE.Global, () => { this.settingsManager.getElement(StreamPref.MKB_P1_SLOT),
EmulatedMkbHandler.getInstance()?.updateGamepadSlots(); {
}), onContextMenu: this.boundOnContextMenu,
pref: StreamPref.MKB_P1_SLOT,
},
), ),
] : []), ] : []),
@ -92,13 +94,20 @@ export class MkbExtraSettings extends HTMLElement {
}), }),
}), }),
), ),
{ multiLines: true }, {
multiLines: true,
onContextMenu: this.boundOnContextMenu,
pref: StreamPref.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID,
},
), ),
); );
$container.$mappingPresets = $mappingPresets; $container.$mappingPresets = $mappingPresets;
$container.$shortcutsPresets = $shortcutsPresets; $container.$shortcutsPresets = $shortcutsPresets;
this.settingsManager.setElement(StreamPref.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID, $shortcutsPresets);
this.settingsManager.setElement(StreamPref.MKB_P1_MAPPING_PRESET_ID, $mappingPresets);
$container.updateLayout(); $container.updateLayout();
// Refresh layout when parent dialog is shown // Refresh layout when parent dialog is shown
this.onMountedCallbacks.push(() => { this.onMountedCallbacks.push(() => {
@ -111,24 +120,20 @@ export class MkbExtraSettings extends HTMLElement {
private static async updateLayout(this: MkbExtraSettings) { private static async updateLayout(this: MkbExtraSettings) {
// Render shortcut presets // Render shortcut presets
const mappingPresets = await MkbMappingPresetsTable.getInstance().getPresets(); const mappingPresets = await MkbMappingPresetsTable.getInstance().getPresets();
renderPresetsList(this.$mappingPresets, mappingPresets, getPref(PrefKey.MKB_P1_MAPPING_PRESET_ID)); renderPresetsList(this.$mappingPresets, mappingPresets, getStreamPref(StreamPref.MKB_P1_MAPPING_PRESET_ID));
// Render shortcut presets // Render shortcut presets
const shortcutsPresets = await KeyboardShortcutsTable.getInstance().getPresets(); const shortcutsPresets = await KeyboardShortcutsTable.getInstance().getPresets();
renderPresetsList(this.$shortcutsPresets, shortcutsPresets, getPref(PrefKey.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID), { addOffValue: true }); renderPresetsList(this.$shortcutsPresets, shortcutsPresets, getStreamPref(StreamPref.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID), { addOffValue: true });
} }
private static async saveMkbSettings(this: MkbExtraSettings) { private static async saveMkbSettings(this: MkbExtraSettings) {
const presetId = parseInt(this.$mappingPresets.value); const presetId = parseInt(this.$mappingPresets.value);
setPref(PrefKey.MKB_P1_MAPPING_PRESET_ID, presetId); setStreamPref(StreamPref.MKB_P1_MAPPING_PRESET_ID, presetId, 'ui');
StreamSettings.refreshMkbSettings();
} }
private static async saveShortcutsSettings(this: MkbExtraSettings) { private static async saveShortcutsSettings(this: MkbExtraSettings) {
const presetId = parseInt(this.$shortcutsPresets.value); const presetId = parseInt(this.$shortcutsPresets.value);
setPref(PrefKey.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID, presetId); setStreamPref(StreamPref.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID, presetId, 'ui');
StreamSettings.refreshKeyboardShortcuts();
} }
} }

View File

@ -1,16 +1,16 @@
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref, StreamPref, type AnyPref } from "@/enums/pref-keys";
import { BxEvent } from "@/utils/bx-event"; import { BxEvent } from "@/utils/bx-event";
import { BX_FLAGS, NATIVE_FETCH, type BxFlags } from "@/utils/bx-flags"; import { BX_FLAGS, NATIVE_FETCH } from "@/utils/bx-flags";
import { STORAGE } from "@/utils/global";
import { CE, removeChildElements, createButton, ButtonStyle, escapeCssSelector } from "@/utils/html"; import { CE, removeChildElements, createButton, ButtonStyle, escapeCssSelector } from "@/utils/html";
import type { BxHtmlSettingElement } from "@/utils/setting-element"; import type { BxHtmlSettingElement } from "@/utils/setting-element";
import { getPref, setPref, getPrefDefinition } from "@/utils/settings-storages/global-settings-storage";
import { t } from "@/utils/translation"; import { t } from "@/utils/translation";
import { BxSelectElement } from "@/web-components/bx-select"; import { BxSelectElement } from "@/web-components/bx-select";
import type { SettingsDialog } from "../settings-dialog"; import type { SettingsDialog } from "../settings-dialog";
import type { RecommendedSettings, SuggestedSettingProfile } from "@/types/setting-definition"; import type { RecommendedSettings, SuggestedSettingProfile } from "@/types/setting-definition";
import { DeviceVibrationMode, TouchControllerMode } from "@/enums/pref-values"; import { DeviceVibrationMode, TouchControllerMode } from "@/enums/pref-values";
import { GhPagesUtils } from "@/utils/gh-pages"; import { GhPagesUtils } from "@/utils/gh-pages";
import { STORAGE, getPrefInfo, setPref } from "@/utils/pref-utils";
import { SettingsManager } from "@/modules/settings-manager";
export class SuggestionsSetting { export class SuggestionsSetting {
static async renderSuggestions(this: SettingsDialog, e: Event) { static async renderSuggestions(this: SettingsDialog, e: Event) {
@ -38,16 +38,16 @@ export class SuggestionsSetting {
} }
for (const setting of settingTabContent.items) { for (const setting of settingTabContent.items) {
let prefKey: PrefKey | undefined; let prefKey: AnyPref | undefined;
if (typeof setting === 'string') { if (typeof setting === 'string') {
prefKey = setting; prefKey = setting;
} else if (typeof setting === 'object') { } else if (typeof setting === 'object') {
prefKey = setting.pref as PrefKey; prefKey = setting.pref as GlobalPref;
} }
if (prefKey) { if (prefKey) {
this.suggestedSettingLabels[prefKey] = settingTabContent.label; this.settingLabels[prefKey] = settingTabContent.label;
} }
} }
} }
@ -76,15 +76,15 @@ export class SuggestionsSetting {
const deviceType = BX_FLAGS.DeviceInfo.deviceType; const deviceType = BX_FLAGS.DeviceInfo.deviceType;
if (deviceType === 'android-handheld') { if (deviceType === 'android-handheld') {
// Disable touch // Disable touch
SuggestionsSetting.addDefaultSuggestedSetting.call(this, PrefKey.TOUCH_CONTROLLER_MODE, TouchControllerMode.OFF); SuggestionsSetting.addDefaultSuggestedSetting.call(this, GlobalPref.TOUCH_CONTROLLER_MODE, TouchControllerMode.OFF);
// Enable device vibration // Enable device vibration
SuggestionsSetting.addDefaultSuggestedSetting.call(this, PrefKey.DEVICE_VIBRATION_MODE, DeviceVibrationMode.ON); SuggestionsSetting.addDefaultSuggestedSetting.call(this, StreamPref.DEVICE_VIBRATION_MODE, DeviceVibrationMode.ON);
} else if (deviceType === 'android') { } else if (deviceType === 'android') {
// Enable device vibration // Enable device vibration
SuggestionsSetting.addDefaultSuggestedSetting.call(this, PrefKey.DEVICE_VIBRATION_MODE, DeviceVibrationMode.AUTO); SuggestionsSetting.addDefaultSuggestedSetting.call(this, StreamPref.DEVICE_VIBRATION_MODE, DeviceVibrationMode.AUTO);
} else if (deviceType === 'android-tv') { } else if (deviceType === 'android-tv') {
// Disable touch // Disable touch
SuggestionsSetting.addDefaultSuggestedSetting.call(this, PrefKey.TOUCH_CONTROLLER_MODE, TouchControllerMode.OFF); SuggestionsSetting.addDefaultSuggestedSetting.call(this, GlobalPref.TOUCH_CONTROLLER_MODE, TouchControllerMode.OFF);
} }
// Set value for Default profile // Set value for Default profile
@ -116,10 +116,17 @@ export class SuggestionsSetting {
note && fragment.appendChild(CE('div', { class: 'bx-suggest-note' }, note)); note && fragment.appendChild(CE('div', { class: 'bx-suggest-note' }, note));
const settings = this.suggestedSettings[profile]; const settings = this.suggestedSettings[profile];
let prefKey: PrefKey; for (const key in settings) {
for (prefKey in settings) { const { storage, definition } = getPrefInfo(key as AnyPref);
let prefKey;
if (storage === STORAGE.Stream) {
prefKey = key as StreamPref;
} else {
prefKey = key as GlobalPref;
}
let suggestedValue; let suggestedValue;
const definition = getPrefDefinition(prefKey);
if (definition && definition.transformValue) { if (definition && definition.transformValue) {
suggestedValue = definition.transformValue.get.call(definition, settings[prefKey]); suggestedValue = definition.transformValue.get.call(definition, settings[prefKey]);
} else { } else {
@ -127,8 +134,9 @@ export class SuggestionsSetting {
} }
// @ts-ignore // @ts-ignore
const currentValue = getPref(prefKey, false); const currentValue = storage.getSetting(prefKey, false);
const currentValueText = STORAGE.Global.getValueText(prefKey, currentValue); // @ts-ignore
const currentValueText = storage.getValueText(prefKey, currentValue);
const isSameValue = currentValue === suggestedValue; const isSameValue = currentValue === suggestedValue;
let $child: HTMLElement; let $child: HTMLElement;
@ -137,12 +145,14 @@ export class SuggestionsSetting {
// No changes // No changes
$value = currentValueText; $value = currentValueText;
} else { } else {
const suggestedValueText = STORAGE.Global.getValueText(prefKey, suggestedValue); // @ts-ignore
const suggestedValueText = storage.getValueText(prefKey, suggestedValue);
$value = currentValueText + ' ➔ ' + suggestedValueText; $value = currentValueText + ' ➔ ' + suggestedValueText;
} }
let $checkbox: HTMLInputElement; let $checkbox: HTMLInputElement;
const breadcrumb = this.suggestedSettingLabels[prefKey] + ' ' + STORAGE.Global.getLabel(prefKey); // @ts-ignore
const breadcrumb = this.settingLabels[prefKey] + ' ' + storage.getLabel(prefKey);
const id = escapeCssSelector(`bx_suggest_${prefKey}`); const id = escapeCssSelector(`bx_suggest_${prefKey}`);
$child = CE('div', { $child = CE('div', {
@ -183,7 +193,8 @@ export class SuggestionsSetting {
const profile = $select.value as SuggestedSettingProfile; const profile = $select.value as SuggestedSettingProfile;
const settings = this.suggestedSettings[profile]; const settings = this.suggestedSettings[profile];
let prefKey: PrefKey; let prefKey: AnyPref;
const settingsManager = SettingsManager.getInstance();
for (prefKey in settings) { for (prefKey in settings) {
let suggestedValue = settings[prefKey]; let suggestedValue = settings[prefKey];
@ -192,17 +203,17 @@ export class SuggestionsSetting {
continue; continue;
} }
const $control = this.settingElements[prefKey] as HTMLElement; const $control = settingsManager.getElement(prefKey);
// Set value directly if the control element is not available // Set value directly if the control element is not available
if (!$control) { if (!$control) {
setPref(prefKey, suggestedValue); setPref(prefKey, suggestedValue, 'direct');
continue; continue;
} }
// Transform value // Transform value
const settingDefinition = getPrefDefinition(prefKey); const { definition: settingDefinition } = getPrefInfo(prefKey);
if (settingDefinition.transformValue) { if (settingDefinition?.transformValue) {
suggestedValue = settingDefinition.transformValue.get.call(settingDefinition, suggestedValue); suggestedValue = settingDefinition.transformValue.get.call(settingDefinition, suggestedValue);
} }
@ -274,7 +285,7 @@ export class SuggestionsSetting {
const url = GhPagesUtils.getUrl(`devices/${brand}/${board}-${model}.json`); const url = GhPagesUtils.getUrl(`devices/${brand}/${board}-${model}.json`);
const response = await NATIVE_FETCH(url); const response = await NATIVE_FETCH(url);
const json = (await response.json()) as RecommendedSettings; const json = (await response.json()) as RecommendedSettings;
const recommended: PartialRecord<PrefKey, any> = {}; const recommended: PartialRecord<GlobalPref, any> = {};
// Only supports schema version 2 // Only supports schema version 2
if (json.schema_version !== 2) { if (json.schema_version !== 2) {
@ -311,7 +322,7 @@ export class SuggestionsSetting {
return null; return null;
} }
private static addDefaultSuggestedSetting(this: SettingsDialog, prefKey: PrefKey, value: any) { private static addDefaultSuggestedSetting(this: SettingsDialog, prefKey: AnyPref, value: any) {
let key: keyof typeof this.suggestedSettings; let key: keyof typeof this.suggestedSettings;
for (key in this.suggestedSettings) { for (key in this.suggestedSettings) {
if (key !== 'default' && !(prefKey in this.suggestedSettings)) { if (key !== 'default' && !(prefKey in this.suggestedSettings)) {
@ -327,10 +338,10 @@ export class SuggestionsSetting {
continue; continue;
} }
let prefKey: PrefKey; let prefKey: AnyPref;
for (prefKey in this.suggestedSettings[key]) { for (prefKey in this.suggestedSettings[key]) {
if (!(prefKey in this.suggestedSettings.default)) { if (!(prefKey in this.suggestedSettings.default)) {
this.suggestedSettings.default[prefKey] = getPrefDefinition(prefKey).default; this.suggestedSettings.default[prefKey] = getPrefInfo(prefKey).definition.default;
} }
} }
} }

View File

@ -1,16 +1,12 @@
import { isFullVersion } from "@macros/build" with { type: "macro" };
import { BxEvent } from "@/utils/bx-event";
import { AppInterface, STATES } from "@/utils/global"; import { AppInterface, STATES } from "@/utils/global";
import { createButton, ButtonStyle, CE } from "@/utils/html"; import { createButton, ButtonStyle, CE } from "@/utils/html";
import { t } from "@/utils/translation"; import { t } from "@/utils/translation";
import { SettingsDialog } from "./dialog/settings-dialog"; import { SettingsDialog } from "./dialog/settings-dialog";
import { TrueAchievements } from "@/utils/true-achievements";
import { BxIcon } from "@/utils/bx-icon"; import { BxIcon } from "@/utils/bx-icon";
import { BxEventBus } from "@/utils/bx-event-bus"; import { BxEventBus } from "@/utils/bx-event-bus";
import { getPref } from "@/utils/settings-storages/global-settings-storage"; import { getGlobalPref } from "@/utils/pref-utils";
import { UiLayout } from "@/enums/pref-values"; import { UiLayout } from "@/enums/pref-values";
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref } from "@/enums/pref-keys";
export enum GuideMenuTab { export enum GuideMenuTab {
HOME = 'home', HOME = 'home',
@ -41,6 +37,7 @@ export class GuideMenu {
const buttons = { const buttons = {
scriptSettings: createButton({ scriptSettings: createButton({
label: t('better-xcloud'), label: t('better-xcloud'),
icon: BxIcon.BETTER_XCLOUD,
style: ButtonStyle.FULL_WIDTH | ButtonStyle.FOCUSABLE | ButtonStyle.PRIMARY, style: ButtonStyle.FULL_WIDTH | ButtonStyle.FOCUSABLE | ButtonStyle.PRIMARY,
onClick: () => { onClick: () => {
// Wait until the Guide dialog is closed // Wait until the Guide dialog is closed
@ -115,7 +112,7 @@ export class GuideMenu {
}); });
// Set TV tag // Set TV tag
if (STATES.userAgent.isTv || getPref(PrefKey.UI_LAYOUT) === UiLayout.TV) { if (STATES.userAgent.isTv || getGlobalPref(GlobalPref.UI_LAYOUT) === UiLayout.TV) {
document.body.dataset.bxMediaType = 'tv'; document.body.dataset.bxMediaType = 'tv';
} }
@ -140,11 +137,9 @@ export class GuideMenu {
} }
injectHome($root: HTMLElement, isPlaying = false) { injectHome($root: HTMLElement, isPlaying = false) {
if (isFullVersion()) { const $buttons = this.renderButtons();
const $achievementsProgress = $root.querySelector('button[class*=AchievementsButton-module__progressBarContainer]'); if ($root.contains($buttons)) {
if ($achievementsProgress) { return;
TrueAchievements.getInstance().injectAchievementsProgress($achievementsProgress as HTMLElement);
}
} }
// Find the element to add buttons to // Find the element to add buttons to
@ -168,67 +163,7 @@ export class GuideMenu {
return false; return false;
} }
const $buttons = this.renderButtons();
$buttons.dataset.isPlaying = isPlaying.toString(); $buttons.dataset.isPlaying = isPlaying.toString();
$target.insertAdjacentElement('afterend', $buttons); $target.insertAdjacentElement('afterend', $buttons);
} }
private onShown = async (e: Event) => {
const where = (e as any).where as GuideMenuTab;
if (where === GuideMenuTab.HOME) {
const $root = document.querySelector<HTMLElement>('#gamepass-dialog-root div[role=dialog] div[role=tabpanel] div[class*=HomeLandingPage]');
$root && this.injectHome($root, STATES.isPlaying);
}
}
addEventListeners() {
window.addEventListener(BxEvent.XCLOUD_GUIDE_MENU_SHOWN, this.onShown);
}
observe($addedElm: HTMLElement) {
let className = $addedElm.className;
// Fix custom buttons disappearing in Guide Menu (#551)
if (!className) {
className = $addedElm.firstElementChild?.className ?? '';
}
if (!className || className.startsWith('bx-')) {
return;
}
// TrueAchievements
if (isFullVersion() && className.includes('AchievementsButton-module__progressBarContainer')) {
TrueAchievements.getInstance().injectAchievementsProgress($addedElm);
return;
}
if (!className.startsWith('NavigationAnimation') &&
!className.startsWith('DialogRoutes') &&
!className.startsWith('Dialog-module__container')) {
return;
}
// Achievement Details page
if (isFullVersion()) {
const $achievDetailPage = $addedElm.querySelector('div[class*=AchievementDetailPage]');
if ($achievDetailPage) {
TrueAchievements.getInstance().injectAchievementDetailPage($achievDetailPage as HTMLElement);
return;
}
}
// Find navigation bar
const $selectedTab = $addedElm.querySelector('div[class^=NavigationMenu] button[aria-selected=true');
if ($selectedTab) {
let $elm: Element | null = $selectedTab;
let index;
for (index = 0; ($elm = $elm?.previousElementSibling); index++);
if (index === 0) {
BxEvent.dispatch(window, BxEvent.XCLOUD_GUIDE_MENU_SHOWN, { where: GuideMenuTab.HOME });
}
}
}
} }

View File

@ -1,107 +1,102 @@
import { SCRIPT_VERSION } from "@utils/global"; import { isFullVersion } from "@macros/build" with { type: "macro" };
import { createButton, ButtonStyle, CE, isElementVisible } from "@utils/html";
import { SCRIPT_VERSION, STATES } from "@utils/global";
import { createButton, ButtonStyle, CE } from "@utils/html";
import { BxIcon } from "@utils/bx-icon"; import { BxIcon } from "@utils/bx-icon";
import { getPreferredServerRegion } from "@utils/region"; import { getPreferredServerRegion } from "@utils/region";
import { RemotePlayManager } from "@/modules/remote-play-manager"; import { RemotePlayManager } from "@/modules/remote-play-manager";
import { t } from "@utils/translation"; import { t } from "@utils/translation";
import { SettingsDialog } from "./dialog/settings-dialog"; import { SettingsDialog } from "./dialog/settings-dialog";
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref } from "@/enums/pref-keys";
import { getPref } from "@/utils/settings-storages/global-settings-storage"; import { getGlobalPref } from "@/utils/pref-utils";
import { BxLogger } from "@/utils/bx-logger"; import { BxLogger } from "@/utils/bx-logger";
import { BxEventBus } from "@/utils/bx-event-bus";
import { BlockFeature } from "@/enums/pref-values";
import { Toast } from "@/utils/toast";
export class HeaderSection { export class HeaderSection {
private static instance: HeaderSection; private static instance: HeaderSection;
public static getInstance = () => HeaderSection.instance ?? (HeaderSection.instance = new HeaderSection()); public static getInstance = () => HeaderSection.instance ?? (HeaderSection.instance = new HeaderSection());
private readonly LOG_TAG = 'HeaderSection'; private readonly LOG_TAG = 'HeaderSection';
private $btnRemotePlay: HTMLElement; private $btnRemotePlay: HTMLElement | null;
private $btnSettings: HTMLElement; private $btnSettings: HTMLElement;
private $buttonsWrapper: HTMLElement; private $buttonsWrapper: HTMLElement;
private observer?: MutationObserver;
private timeoutId?: number | null;
constructor() { constructor() {
BxLogger.info(this.LOG_TAG, 'constructor()'); BxLogger.info(this.LOG_TAG, 'constructor()');
this.$btnRemotePlay = createButton({ if (isFullVersion()) {
classes: ['bx-header-remote-play-button', 'bx-gone'], this.$btnRemotePlay = createButton({
icon: BxIcon.REMOTE_PLAY, classes: ['bx-header-remote-play-button', 'bx-gone'],
title: t('remote-play'), icon: BxIcon.REMOTE_PLAY,
style: ButtonStyle.GHOST | ButtonStyle.FOCUSABLE | ButtonStyle.CIRCULAR, title: t('remote-play'),
onClick: e => RemotePlayManager.getInstance()?.togglePopup(), style: ButtonStyle.GHOST | ButtonStyle.FOCUSABLE | ButtonStyle.CIRCULAR,
}); onClick: e => RemotePlayManager.getInstance()?.togglePopup(),
});
} else {
this.$btnRemotePlay = null;
}
this.$btnSettings = createButton({ let $btnSettings = this.$btnSettings = createButton({
classes: ['bx-header-settings-button'], classes: ['bx-header-settings-button', 'bx-gone'],
label: '???', label: t('better-xcloud'),
style: ButtonStyle.FROSTED | ButtonStyle.DROP_SHADOW | ButtonStyle.FOCUSABLE | ButtonStyle.FULL_HEIGHT, style: ButtonStyle.FROSTED | ButtonStyle.DROP_SHADOW | ButtonStyle.FOCUSABLE | ButtonStyle.FULL_HEIGHT,
onClick: e => SettingsDialog.getInstance().show(), onClick: e => SettingsDialog.getInstance().show(),
}); });
this.$buttonsWrapper = CE('div', false, this.$buttonsWrapper = CE('div', false,
getPref(PrefKey.REMOTE_PLAY_ENABLED) ? this.$btnRemotePlay : null, !getGlobalPref(GlobalPref.BLOCK_FEATURES).includes(BlockFeature.REMOTE_PLAY) ? this.$btnRemotePlay : null,
this.$btnSettings, this.$btnSettings,
); );
BxEventBus.Script.on('xcloud.server', ({status}) => {
if (status === 'ready') {
STATES.isSignedIn = true;
// Show server name
$btnSettings.querySelector('span')!.textContent = getPreferredServerRegion(true) || t('better-xcloud');
const PREF_LATEST_VERSION = getGlobalPref(GlobalPref.VERSION_LATEST);
// Show new update status
if (!SCRIPT_VERSION.includes('beta') && PREF_LATEST_VERSION && PREF_LATEST_VERSION !== SCRIPT_VERSION) {
$btnSettings.setAttribute('data-update-available', 'true');
}
} else if (status === 'error') {
Toast.show(t('server-list-error'), '❌', { instant: true });
} else if (status === 'unavailable') {
STATES.supportedRegion = false;
// Open Settings dialog on Unsupported page
const $unsupportedPage = document.querySelector<HTMLElement>('div[class^=UnsupportedMarketPage-module__container]');
if ($unsupportedPage) {
SettingsDialog.getInstance().show();
}
}
$btnSettings.classList.remove('bx-gone');
});
} }
private injectSettingsButton($parent?: HTMLElement) { checkHeader = () => {
if (!$parent) { const $header = document.querySelector('#gamepass-root header[class^=Header-module__header]');
if (!$header) {
return; return;
} }
const PREF_LATEST_VERSION = getPref(PrefKey.VERSION_LATEST); let $target = $header.querySelector('div[class*=EdgewaterHeader-module__rightSectionSpacing], div[class*=RemotePlayHeader-module__rightSectionSpacing]');
// Setup Settings button
const $btnSettings = this.$btnSettings;
if (isElementVisible(this.$buttonsWrapper)) {
return;
}
$btnSettings.querySelector('span')!.textContent = getPreferredServerRegion(true) || t('better-xcloud');
// Show new update status
if (!SCRIPT_VERSION.includes('beta') && PREF_LATEST_VERSION && PREF_LATEST_VERSION !== SCRIPT_VERSION) {
$btnSettings.setAttribute('data-update-available', 'true');
}
// Add the Settings button to the web page
$parent.appendChild(this.$buttonsWrapper);
}
private checkHeader = () => {
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 && this.injectSettingsButton($target as HTMLElement); // Add the Settings button to the web page
} $target?.appendChild(this.$buttonsWrapper);
private watchHeader() { if (!STATES.isSignedIn) {
const $root = document.querySelector('#PageContent header') || document.querySelector('#root'); BxEventBus.Script.emit('xcloud.server', { status: 'signed-out' });
if (!$root) {
return;
} }
this.timeoutId && clearTimeout(this.timeoutId);
this.timeoutId = null;
this.observer && this.observer.disconnect();
this.observer = new MutationObserver(mutationList => {
this.timeoutId && clearTimeout(this.timeoutId);
this.timeoutId = window.setTimeout(this.checkHeader, 2000);
});
this.observer.observe($root, { subtree: true, childList: true });
this.checkHeader();
} }
showRemotePlayButton() { showRemotePlayButton() {
this.$btnRemotePlay.classList.remove('bx-gone'); this.$btnRemotePlay?.classList.remove('bx-gone');
}
static watchHeader() {
HeaderSection.getInstance().watchHeader();
} }
} }

View File

@ -1,7 +1,8 @@
import { BX_FLAGS } from "@/utils/bx-flags"; import { BX_FLAGS } from "@/utils/bx-flags";
import { BxIcon } from "@/utils/bx-icon"; import { BxIcon } from "@/utils/bx-icon";
import { AppInterface } from "@/utils/global"; import { AppInterface } from "@/utils/global";
import { ButtonStyle, CE, createButton } from "@/utils/html"; import { ButtonStyle, CE, createButton, createSvgIcon } from "@/utils/html";
import { LocalCoOpManager } from "@/utils/local-co-op-manager";
import { t } from "@/utils/translation"; import { t } from "@/utils/translation";
import { parseDetailsPath } from "@/utils/utils"; import { parseDetailsPath } from "@/utils/utils";
@ -28,21 +29,33 @@ export class ProductDetailsPage {
private static injectTimeoutId: number | null = null; private static injectTimeoutId: number | null = null;
static injectButtons() { static injectButtons() {
if (!AppInterface) {
return;
}
ProductDetailsPage.injectTimeoutId && clearTimeout(ProductDetailsPage.injectTimeoutId); ProductDetailsPage.injectTimeoutId && clearTimeout(ProductDetailsPage.injectTimeoutId);
ProductDetailsPage.injectTimeoutId = window.setTimeout(() => { ProductDetailsPage.injectTimeoutId = window.setTimeout(() => {
// Find action buttons container // Inputs
const $container = document.querySelector('div[class*=ActionButtons-module__container]'); const $inputsContainer = document.querySelector<HTMLElement>('div[class*="Header-module__gamePassAndInputsContainer"]');
if ($container && $container.parentElement) { if ($inputsContainer && !$inputsContainer.dataset.bxInjected) {
$container.parentElement.appendChild(CE('div', { $inputsContainer.dataset.bxInjected = 'true';
class: 'bx-product-details-buttons',
}, const { productId } = parseDetailsPath(window.location.pathname);
['android-handheld', 'android'].includes(BX_FLAGS.DeviceInfo.deviceType) && ProductDetailsPage.$btnShortcut, if (LocalCoOpManager.getInstance().isSupported(productId || '')) {
ProductDetailsPage.$btnWallpaper, $inputsContainer.insertAdjacentElement('afterend', CE('div', {
)); class: 'bx-product-details-icons bx-frosted',
}, createSvgIcon(BxIcon.LOCAL_CO_OP), t('local-co-op')));
}
}
// Inject buttons for Android app
if (AppInterface) {
// Find action buttons container
const $container = document.querySelector('div[class*=ActionButtons-module__container]');
if ($container && $container.parentElement) {
$container.parentElement.appendChild(CE('div', {
class: 'bx-product-details-buttons',
},
['android-handheld', 'android'].includes(BX_FLAGS.DeviceInfo.deviceType) && ProductDetailsPage.$btnShortcut,
ProductDetailsPage.$btnWallpaper,
));
}
} }
}, 500); }, 500);
} }

8
src/types/db.d.ts vendored
View File

@ -2,11 +2,3 @@ interface BaseRecord {
id: any; id: any;
data: any; data: any;
}; };
interface ControllerSettingsRecord extends BaseRecord {
id: string;
data: {
shortcutPresetId: number;
customizationPresetId: number;
};
};

29
src/types/global.d.ts vendored
View File

@ -1,16 +1,38 @@
import type { BxExposed } from "@/utils/bx-exposed"; import type { BxExposed } from "@/utils/bx-exposed";
import type { AllPresets, ControllerShortcutPresetRecord } from "./presets"; import type { AllPresets, ControllerShortcutPresetRecord } from "./presets";
import type { PrefKey } from "@/enums/pref-keys"; import type { GlobalPref } from "@/enums/pref-keys";
import type { StreamSettings, type StreamSettingsData } from "@/utils/stream-settings"; import type { StreamSettings, type StreamSettingsData } from "@/utils/stream-settings";
import type { BxEvent } from "@/utils/bx-event"; import type { BxEvent } from "@/utils/bx-event";
import type { BxEventBus } from "@/utils/bx-event-bus"; import type { BxEventBus } from "@/utils/bx-event-bus";
import type { BxLogger } from "@/utils/bx-logger"; import type { BxLogger } from "@/utils/bx-logger";
import type { XcloudInputChannel } from "@/utils/gamepad";
export {}; export {};
declare global { declare global {
interface Window { interface Window {
AppInterface: any; AppInterface: {
startPointerServer(),
requestPointerCapture(),
releasePointerCapture(),
runShortcut?(action: string),
saveScreenshot(name: string | undefined, data: string),
vibrate(dataJson: string, intensity: number),
openTrueAchievementsLink(override: boolean, xboxTitleId?: string | undefined, id?: string | undefined),
openAppSettings?(),
updateLatestScript(),
closeApp(),
getDeepLinkData(): string,
createShortcut(path: string),
createConsoleShortcut(serverId: string, deviceName: string, optionsJson: string),
downloadWallpapers(titleSlug: string | undefined, productId: string | undefined),
onEvent(event: String),
onEventBus(event: String),
};
BX_FLAGS?: BxFlags; BX_FLAGS?: BxFlags;
BX_CE: (elmName: string, props: { [index: string]: any }={}) => HTMLElement; BX_CE: (elmName: string, props: { [index: string]: any }={}) => HTMLElement;
BX_EXPOSED: typeof BxExposed & Partial<{ BX_EXPOSED: typeof BxExposed & Partial<{
@ -20,12 +42,11 @@ declare global {
closeAll: () => void; closeAll: () => void;
}; };
showStreamMenu: () => void; showStreamMenu: () => void;
inputSink: any; inputChannel: XcloudInputChannel | undefined;
streamSession: any; streamSession: any;
touchLayoutManager: any; touchLayoutManager: any;
}>; }>;
BX_REMOTE_PLAY_CONFIG: BxStates.remotePlay.config;
BX_STREAM_SETTINGS: StreamSettingsData; BX_STREAM_SETTINGS: StreamSettingsData;
BX_FETCH: typeof window['fetch']; BX_FETCH: typeof window['fetch'];

88
src/types/index.d.ts vendored
View File

@ -22,57 +22,6 @@ type ServerRegion = {
contintent: ServerContinent; contintent: ServerContinent;
}; };
type BxStates = {
supportedRegion: boolean;
serverRegions: Record<string, ServerRegion>;
selectedRegion: any;
gsToken: string;
isSignedIn: boolean;
isPlaying: boolean;
browser: {
capabilities: {
touch: boolean;
batteryApi: boolean;
deviceVibration: boolean;
mkb: boolean;
emulatedNativeMkb: boolean;
};
};
userAgent: {
isTv: boolean;
capabilities: {
touch: boolean;
mkb: boolean;
};
};
currentStream: Partial<{
titleSlug: string;
titleInfo: XcloudTitleInfo;
xboxTitleId: number;
streamPlayer: StreamPlayer | null;
peerConnection: RTCPeerConnection;
audioContext: AudioContext | null;
audioGainNode: GainNode | null;
}>;
remotePlay: Partial<{
isPlaying: boolean;
server: string;
config: {
serverId: string;
};
titleId?: string;
}>;
pointerServerPort: number;
}
type XcloudTitleInfo = { type XcloudTitleInfo = {
titleId: string, titleId: string,
@ -87,7 +36,7 @@ type XcloudTitleInfo = {
hasMkbSupport: boolean; hasMkbSupport: boolean;
}; };
product: { productInfo: {
title: string; title: string;
heroImageUrl: string; heroImageUrl: string;
titledHeroImageUrl: string; titledHeroImageUrl: string;
@ -105,10 +54,12 @@ declare module '*.js' {
const content: string; const content: string;
export default content; export default content;
} }
declare module '*.svg' { declare module '*.svg' {
const content: string; const content: string;
export default content; export default content;
} }
declare module '*.styl' { declare module '*.styl' {
const content: string; const content: string;
export default content; export default content;
@ -118,11 +69,17 @@ declare module '*.fs' {
const content: string; const content: string;
export default content; export default content;
} }
declare module '*.vert' { declare module '*.vert' {
const content: string; const content: string;
export default content; export default content;
} }
declare module '*.wgsl' {
const content: string;
export default content;
}
type MkbMouseMove = { type MkbMouseMove = {
movementX: number; movementX: number;
movementY: number; movementY: number;
@ -178,7 +135,7 @@ type XboxAchievement = {
} }
}; };
type OsName = 'windows' | 'tizen' | 'android'; type OsName = 'windows' | 'tizen' | 'webOS' | 'xboxOS' | 'android';
type XcloudGamepad = { type XcloudGamepad = {
GamepadIndex: number; GamepadIndex: number;
@ -213,3 +170,28 @@ type XcloudGamepad = {
RightStickAxes?: any; RightStickAxes?: any;
Share?: any; Share?: any;
}; };
type BxFlags = {
Debug: boolean;
CheckForUpdate: boolean;
EnableXcloudLogging: boolean;
SafariWorkaround: boolean;
EnableWebGPURenderer: boolean;
ForceNativeMkbTitles: string[];
FeatureGates: { [key: string]: boolean } | null,
DeviceInfo: {
deviceType: 'android' | 'android-tv' | 'android-handheld' | 'webos' | 'unknown',
userAgent?: string,
androidInfo?: {
manufacturer: string,
brand: string,
board: string,
model: string,
},
}
}

140
src/types/mkb.d.ts vendored Normal file
View File

@ -0,0 +1,140 @@
type NativeMouseData = {
X: number,
Y: number,
Buttons: number,
WheelX: number,
WheelY: number,
Type?: 0, // 0: Relative, 1: Absolute
}
type XcloudInputChannel = {
sendGamepadInput: (timestamp: number, gamepads: XcloudGamepad[]) => void;
queueMouseInput: (data: NativeMouseData) => void;
}
type KeyCode =
| 'Backspace'
| 'Tab'
| 'Enter'
| 'ShiftLeft'
| 'ShiftRight'
| 'ControlLeft'
| 'ControlRight'
| 'AltLeft'
| 'AltRight'
| 'Pause'
| 'CapsLock'
| 'Escape'
| 'Space'
| 'PageUp'
| 'PageDown'
| 'End'
| 'Home'
| 'ArrowLeft'
| 'ArrowUp'
| 'ArrowRight'
| 'ArrowDown'
| 'PrintScreen'
| 'Insert'
| 'Delete'
| 'Digit0'
| 'Digit1'
| 'Digit2'
| 'Digit3'
| 'Digit4'
| 'Digit5'
| 'Digit6'
| 'Digit7'
| 'Digit8'
| 'Digit9'
| 'KeyA'
| 'KeyB'
| 'KeyC'
| 'KeyD'
| 'KeyE'
| 'KeyF'
| 'KeyG'
| 'KeyH'
| 'KeyI'
| 'KeyJ'
| 'KeyK'
| 'KeyL'
| 'KeyM'
| 'KeyN'
| 'KeyO'
| 'KeyP'
| 'KeyQ'
| 'KeyR'
| 'KeyS'
| 'KeyT'
| 'KeyU'
| 'KeyV'
| 'KeyW'
| 'KeyX'
| 'KeyY'
| 'KeyZ'
| 'MetaLeft'
| 'MetaRight'
| 'ContextMenu'
| 'F1'
| 'F2'
| 'F3'
| 'F4'
| 'F5'
| 'F6'
| 'F7'
| 'F8'
| 'F9'
| 'F10'
| 'F11'
| 'F12'
| 'NumLock'
| 'ScrollLock'
| 'AudioVolumeMute'
| 'AudioVolumeDown'
| 'AudioVolumeUp'
| 'MediaTrackNext'
| 'MediaTrackPrevious'
| 'MediaStop'
| 'MediaPlayPause'
| 'LaunchMail'
| 'LaunchMediaPlayer'
| 'LaunchApplication1'
| 'LaunchApplication2'
| 'Semicolon'
| 'Equal'
| 'Comma'
| 'Minus'
| 'Period'
| 'Slash'
| 'Backquote'
| 'BracketLeft'
| 'Backslash'
| 'BracketRight'
| 'Quote'
| 'Numpad0'
| 'Numpad1'
| 'Numpad2'
| 'Numpad3'
| 'Numpad4'
| 'Numpad5'
| 'Numpad6'
| 'Numpad7'
| 'Numpad8'
| 'Numpad9'
| 'NumpadMultiply'
| 'NumpadAdd'
| 'NumpadSubtract'
| 'NumpadDecimal'
| 'NumpadDivide';
type KeyCodeExcludeModifiers = Exclude<KeyCode,
'ShiftLeft'
| 'ShiftRight'
| 'ControlLeft'
| 'ControlRight'
| 'AltLeft'
| 'AltRight'
>

8
src/types/network.d.ts vendored Executable file
View File

@ -0,0 +1,8 @@
type RemotePlayConsoleAddresses = {
[key: string]: number[],
}
type ForceNativeMkbResponse = {
$schemaVersion: number;
data: { [key: string]: string };
}

View File

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

View File

@ -1,4 +1,4 @@
export type PreferenceSetting = { type PreferenceSetting = {
default: any; default: any;
optionsGroup?: string; optionsGroup?: string;
options?: { [index: string]: string }; options?: { [index: string]: string };
@ -17,4 +17,13 @@ export type PreferenceSetting = {
label?: string; label?: string;
}; };
export type PreferenceSettings = { [index in PrefKey]: PreferenceSetting }; type PreferenceSettings = { [index in PrefKey]: PreferenceSetting };
type StreamPreferredLocale = 'default' | string;
type ControllerSetting = {
shortcutPresetId: number;
customizationPresetId: number;
}
type ControllerSettings = Record<string, ControllerSetting>;

View File

@ -1 +0,0 @@
type StreamPreferredLocale = 'default' | string;

View File

@ -1,8 +1,8 @@
import type { PrefKey } from "@/enums/pref-keys"; import type { AnyPref, AnySettingsStorage, GlobalPref, StreamPref } from "@/enums/pref-keys";
import type { SettingElementType } from "@/utils/setting-element"; import type { SettingElementType } from "@/utils/setting-element";
export type SuggestedSettingProfile = 'recommended' | 'lowest' | 'highest' | 'default'; type SuggestedSettingProfile = 'recommended' | 'lowest' | 'highest' | 'default';
export type RecommendedSettings = { type RecommendedSettings = {
schema_version: 2, schema_version: 2,
device_name: string, device_name: string,
device_type: 'android' | 'android-tv' | 'android-handheld' | 'webos', device_type: 'android' | 'android-tv' | 'android-handheld' | 'webos',
@ -10,16 +10,18 @@ export type RecommendedSettings = {
app: any, app: any,
script: { script: {
_base?: 'lowest' | 'highest', _base?: 'lowest' | 'highest',
} & PartialRecord<PrefKey, any>, } & PartialRecord<GlobalPref, any>,
}, },
}; };
export type SettingAction = 'get' | 'set'; type SettingAction = 'get' | 'set';
type SettingActionOrigin = 'direct' | 'ui';
interface BaseSettingDefinition { interface BaseSettingDefinition {
default: any; default: any;
label?: string; label?: string;
labelIcon?: BxIconRaw,
note?: string | (() => HTMLElement) | HTMLElement; note?: string | (() => HTMLElement) | HTMLElement;
experimental?: boolean; experimental?: boolean;
unsupported?: boolean; unsupported?: boolean;
@ -55,15 +57,22 @@ interface NumberStepperSettingDefinition extends BaseSettingDefinition {
}; };
} }
export type SettingDefinition = BaseSettingDefinition | OptionsSettingDefinition | MultipleOptionsSettingDefinition | NumberStepperSettingDefinition; type SettingDefinition = BaseSettingDefinition | OptionsSettingDefinition | MultipleOptionsSettingDefinition | NumberStepperSettingDefinition;
type PrefInfo = {
storage: AnySettingsStorage,
definition: SettingDefinition,
// value: unknown,
};
export type SettingDefinitions = { [index in PrefKey]: SettingDefinition }; type SettingDefinitions<T extends AnyPref> = {
[key in T]: SettingDefinition;
};
export type MultipleOptionsParams = Partial<{ type MultipleOptionsParams = Partial<{
size?: number; size?: number;
}> }>
export type NumberStepperParams = Partial<{ type NumberStepperParams = Partial<{
steps: number; steps: number;
suffix: string; suffix: string;
@ -77,7 +86,7 @@ export type NumberStepperParams = Partial<{
reverse: boolean; reverse: boolean;
}> }>
export type DualNumberStepperParams = { type DualNumberStepperParams = {
min: number; min: number;
minDiff: number; minDiff: number;
max: number; max: number;

49
src/types/states.d.ts vendored Normal file
View File

@ -0,0 +1,49 @@
import type { StreamPlayerManager } from "@/modules/stream-player-manager";
type BxStates = {
supportedRegion: boolean;
serverRegions: Record<string, ServerRegion>;
selectedRegion: any;
gsToken: string;
isSignedIn: boolean;
isPlaying: boolean;
browser: {
capabilities: {
touch: boolean;
batteryApi: boolean;
deviceVibration: boolean;
mkb: boolean;
emulatedNativeMkb: boolean;
};
};
userAgent: {
isTv: boolean;
capabilities: {
touch: boolean;
mkb: boolean;
};
};
currentStream: Partial<{
titleSlug: string;
titleInfo: XcloudTitleInfo;
xboxTitleId: number | null;
gameSpecificSettings: boolean;
streamPlayerManager: StreamPlayerManager | null;
peerConnection: RTCPeerConnection;
audioContext: AudioContext | null;
audioGainNode: GainNode | null;
}>;
remotePlay: Partial<{
server: string;
titleId?: string;
}>;
pointerServerPort: number;
}

View File

@ -18,3 +18,6 @@ type RTCBasicStat = {
totalDecodeTime: number, totalDecodeTime: number,
type: string, type: string,
} }
type StreamStatGrade = '' | 'bad' | 'ok' | 'good';

10
src/types/stream.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
import type { StreamVideoProcessing, StreamVideoProcessingMode } from "@/enums/pref-values";
type StreamPlayerOptions = {
processing: StreamVideoProcessing,
processingMode: StreamVideoProcessingMode,
sharpness: number,
saturation: number,
contrast: number,
brightness: number,
};

View File

@ -1,4 +1,4 @@
import type { PrefKey, StorageKey } from "@/enums/pref-keys"; import type { GlobalPref, StorageKey, StreamPref } from "@/enums/pref-keys";
import { BX_FLAGS } from "./bx-flags"; import { BX_FLAGS } from "./bx-flags";
import { BxLogger } from "./bx-logger"; import { BxLogger } from "./bx-logger";
import { AppInterface } from "./global"; import { AppInterface } from "./global";
@ -7,23 +7,21 @@ import type { SpeakerState } from "@/modules/shortcuts/sound-shortcut";
type EventCallback<T = any> = (payload: T) => void; type EventCallback<T = any> = (payload: T) => void;
type ScriptEvents = { export type ScriptEvents = {
'xcloud.server.ready': {}; 'xcloud.server': {
'xcloud.server.unavailable': {}; status: 'ready' | 'unavailable' | 'signed-out' | 'error',
'dialog.shown': {},
'dialog.dismissed': {},
'titleInfo.ready': {};
'setting.changed': {
storageKey: StorageKey;
settingKey: PrefKey;
settingValue: any;
}; };
'mkb.setting.updated': {}; 'dialog.shown': {};
'keyboardShortcuts.updated': {}; 'dialog.dismissed': {};
'deviceVibration.updated': {};
'titleInfo.ready': {};
'setting.changed': {
storageKey: Omit<StorageKey, StorageKey.STREAM>;
settingKey: GlobalPref;
// settingValue: any;
};
// GH pages // GH pages
'list.forcedNativeMkb.updated': { 'list.forcedNativeMkb.updated': {
@ -31,20 +29,51 @@ type ScriptEvents = {
data: any; data: any;
}; };
}; };
'list.localCoOp.updated': {
ids: Set<string>;
};
'webgpu.ready': {},
'ui.header.rendered': {},
'ui.error.rendered': {},
'ui.guideHome.rendered': {},
'ui.guideAchievementProgress.rendered': {},
'ui.guideAchievementDetail.rendered': {},
}; };
type StreamEvents = { export type StreamEvents = {
'state.loading': {}; 'state.loading': {};
'state.starting': {}; 'state.starting': {};
'state.playing': { $video?: HTMLVideoElement }; 'state.playing': { $video?: HTMLVideoElement };
'state.stopped': {}; 'state.stopped': {};
'state.error': {};
'gameBar.activated': {}, 'xboxTitleId.changed': {
'speaker.state.changed': { state: SpeakerState }, id: number;
'video.visibility.changed': { isVisible: boolean }, };
'gameSettings.switched': {
id: number;
};
'setting.changed': {
storageKey: StorageKey.STREAM | `${StorageKey.STREAM}.${number}`;
settingKey: StreamPref;
// settingValue: any;
};
'mkb.setting.updated': {};
'keyboardShortcuts.updated': {};
'deviceVibration.updated': {};
'gameBar.activated': {};
'speaker.state.changed': { state: SpeakerState };
'video.visibility.changed': { isVisible: boolean };
// Inside patch // Inside patch
'microphone.state.changed': { state: MicrophoneState }, 'microphone.state.changed': { state: MicrophoneState };
'ui.streamHud.rendered': { expanded: boolean },
'ui.streamMenu.rendered': {},
dataChannelCreated: { dataChannel: RTCDataChannel }; dataChannelCreated: { dataChannel: RTCDataChannel };
}; };
@ -123,7 +152,10 @@ export class BxEventBus<TEvents extends Record<string, any>> {
try { try {
if (event in this.appJsInterfaces) { if (event in this.appJsInterfaces) {
const method = this.appJsInterfaces[event]; const method = this.appJsInterfaces[event];
AppInterface[method] && AppInterface[method](); if (method && method in AppInterface) {
// @ts-ignore
AppInterface[method]();
}
} else { } else {
AppInterface.onEventBus(this.group + '.' + (event as string)); AppInterface.onEventBus(this.group + '.' + (event as string));
} }
@ -132,7 +164,7 @@ export class BxEventBus<TEvents extends Record<string, any>> {
} }
} }
BX_FLAGS.Debug && BxLogger.warning('EventBus', 'emit', event, payload); BX_FLAGS.Debug && BxLogger.warning('EventBus', 'emit', `${this.group}.${event as string}`, payload);
} }
} }

View File

@ -14,6 +14,7 @@ export namespace BxEvent {
export const TOUCH_LAYOUT_MANAGER_READY = 'bx-touch-layout-manager-ready'; export const TOUCH_LAYOUT_MANAGER_READY = 'bx-touch-layout-manager-ready';
// Inside app // Inside app
// TODO: Use EventBus
export const REMOTE_PLAY_READY = 'bx-remote-play-ready'; export const REMOTE_PLAY_READY = 'bx-remote-play-ready';
export const REMOTE_PLAY_FAILED = 'bx-remote-play-failed'; export const REMOTE_PLAY_FAILED = 'bx-remote-play-failed';

View File

@ -5,14 +5,15 @@ import { deepClone, STATES } from "@utils/global";
import { BxLogger } from "./bx-logger"; import { BxLogger } from "./bx-logger";
import { BX_FLAGS } from "./bx-flags"; import { BX_FLAGS } from "./bx-flags";
import { NavigationDialogManager } from "@/modules/ui/dialog/navigation-dialog"; import { NavigationDialogManager } from "@/modules/ui/dialog/navigation-dialog";
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref } from "@/enums/pref-keys";
import { getPref } from "./settings-storages/global-settings-storage";
import { GamePassCloudGallery } from "@/enums/game-pass-gallery"; import { GamePassCloudGallery } from "@/enums/game-pass-gallery";
import { TouchController } from "@/modules/touch-controller"; import { TouchController } from "@/modules/touch-controller";
import { NativeMkbMode, TouchControllerMode } from "@/enums/pref-values"; import { NativeMkbMode, TouchControllerMode } from "@/enums/pref-values";
import { Patcher, type PatchPage } from "@/modules/patcher/patcher"; import { Patcher, type PatchPage } from "@/modules/patcher/patcher";
import { BxEventBus } from "./bx-event-bus"; import { BxEventBus } from "./bx-event-bus";
import { FeatureGates } from "./feature-gates"; import { FeatureGates } from "./feature-gates";
import { getGlobalPref } from "./pref-utils";
import { LocalCoOpManager } from "./local-co-op-manager";
export enum SupportedInputType { export enum SupportedInputType {
CONTROLLER = 'Controller', CONTROLLER = 'Controller',
@ -80,6 +81,14 @@ export const BxExposed = {
BxLogger.error(LOG_TAG, e); BxLogger.error(LOG_TAG, e);
} }
// Disable header & footer
try {
state.uhf.headerMode = 'Off';
state.uhf.footerMode = 'Off';
} catch (e) {
BxLogger.error(LOG_TAG, e);
}
// Redirect to /en-US/play if visiting from an unsupported region // Redirect to /en-US/play if visiting from an unsupported region
try { try {
const xCloud = state.xcloud.authentication.authStatusByStrategy.XCloud; const xCloud = state.xcloud.authentication.authStatusByStrategy.XCloud;
@ -106,17 +115,17 @@ export const BxExposed = {
} }
// Remove native MKB support on mobile browsers or by user's choice // Remove native MKB support on mobile browsers or by user's choice
if (getPref(PrefKey.NATIVE_MKB_MODE) === NativeMkbMode.OFF) { if (getGlobalPref(GlobalPref.NATIVE_MKB_MODE) === NativeMkbMode.OFF) {
supportedInputTypes = supportedInputTypes.filter(i => i !== SupportedInputType.MKB); supportedInputTypes = supportedInputTypes.filter(i => i !== SupportedInputType.MKB);
} }
titleInfo.details.hasMkbSupport = supportedInputTypes.includes(SupportedInputType.MKB); titleInfo.details.hasMkbSupport = supportedInputTypes.includes(SupportedInputType.MKB);
if (STATES.userAgent.capabilities.touch) { if (STATES.userAgent.capabilities.touch) {
let touchControllerAvailability = getPref(PrefKey.TOUCH_CONTROLLER_MODE); let touchControllerAvailability = getGlobalPref(GlobalPref.TOUCH_CONTROLLER_MODE);
// Disable touch control when gamepad found // Disable touch control when gamepad found
if (touchControllerAvailability !== TouchControllerMode.OFF && getPref(PrefKey.TOUCH_CONTROLLER_AUTO_OFF)) { if (touchControllerAvailability !== TouchControllerMode.OFF && getGlobalPref(GlobalPref.TOUCH_CONTROLLER_AUTO_OFF)) {
const gamepads = window.navigator.getGamepads(); const gamepads = window.navigator.getGamepads();
let gamepadFound = false; let gamepadFound = false;
@ -230,4 +239,31 @@ export const BxExposed = {
BxLogger.info('beforePageLoad', page); BxLogger.info('beforePageLoad', page);
Patcher.patchPage(page); Patcher.patchPage(page);
} : () => {}, } : () => {},
localCoOpManager: isFullVersion() ? LocalCoOpManager.getInstance() : null,
reactCreateElement: function(...args: any[]) {},
reactUseEffect: function(...args: any[]) {},
createReactLocalCoOpIcon: isFullVersion() ? (attrs: any): any => {
const reactCE = window.BX_EXPOSED.reactCreateElement;
// local-co-op.svg
return reactCE(
'svg',
{ xmlns: 'http://www.w3.org/2000/svg', width: '1em', height: '1em', viewBox: '0 0 32 32', 'fill-rule': 'evenodd', 'stroke-linecap': 'round', 'stroke-linejoin': 'round', ...attrs },
reactCE(
'g',
null,
reactCE('path', { d: 'M24.272 11.165h-3.294l-3.14 3.564c-.391.391-.922.611-1.476.611a2.1 2.1 0 0 1-2.087-2.088 2.09 2.09 0 0 1 .031-.362l1.22-6.274a3.89 3.89 0 0 1 3.81-3.206h6.57c1.834 0 3.439 1.573 3.833 3.295l1.205 6.185a2.09 2.09 0 0 1 .031.362 2.1 2.1 0 0 1-2.087 2.088c-.554 0-1.085-.22-1.476-.611l-3.14-3.564', fill: 'none', stroke: '#fff', 'stroke-width': '2' }),
reactCE('circle', { cx: '22.625', cy: '5.874', r: '.879' }),
reactCE('path', { d: 'M11.022 24.415H7.728l-3.14 3.564c-.391.391-.922.611-1.476.611a2.1 2.1 0 0 1-2.087-2.088 2.09 2.09 0 0 1 .031-.362l1.22-6.274a3.89 3.89 0 0 1 3.81-3.206h6.57c1.834 0 3.439 1.573 3.833 3.295l1.205 6.185a2.09 2.09 0 0 1 .031.362 2.1 2.1 0 0 1-2.087 2.088c-.554 0-1.085-.22-1.476-.611l-3.14-3.564', fill: 'none', stroke: '#fff', 'stroke-width': '2' }),
reactCE('circle', { cx: '9.375', cy: '19.124', r: '.879' })
),
);
} : () => {},
hasCustomTouchControl: TouchController.hasCustomControl,
hasCustomNativeMkb: (productId: string) => {
return BX_FLAGS.ForceNativeMkbTitles?.includes(productId);
}
}; };

View File

@ -1,28 +1,5 @@
import { BxLogger } from "./bx-logger"; import { BxLogger } from "./bx-logger";
export type BxFlags = {
Debug: boolean;
CheckForUpdate: boolean;
EnableXcloudLogging: boolean;
SafariWorkaround: boolean;
ForceNativeMkbTitles: string[];
FeatureGates: { [key: string]: boolean } | null,
DeviceInfo: {
deviceType: 'android' | 'android-tv' | 'android-handheld' | 'webos' | 'unknown',
userAgent?: string,
androidInfo?: {
manufacturer: string,
brand: string,
board: string,
model: string,
},
}
}
// Setup flags // Setup flags
const DEFAULT_FLAGS: BxFlags = { const DEFAULT_FLAGS: BxFlags = {
Debug: false, Debug: false,
@ -31,6 +8,8 @@ const DEFAULT_FLAGS: BxFlags = {
EnableXcloudLogging: false, EnableXcloudLogging: false,
SafariWorkaround: true, SafariWorkaround: true,
EnableWebGPURenderer: false,
ForceNativeMkbTitles: [], ForceNativeMkbTitles: [],
FeatureGates: null, FeatureGates: null,

View File

@ -9,7 +9,9 @@ import iconCursorText from "@assets/svg/cursor-text.svg" with { type: "text" };
import iconDisplay from "@assets/svg/display.svg" with { type: "text" }; import iconDisplay from "@assets/svg/display.svg" with { type: "text" };
import iconEye from "@assets/svg/eye.svg" with { type: "text" }; import iconEye from "@assets/svg/eye.svg" with { type: "text" };
import iconEyeSlash from "@assets/svg/eye-slash.svg" with { type: "text" }; import iconEyeSlash from "@assets/svg/eye-slash.svg" with { type: "text" };
// import iconGlobalRestore from "@assets/svg/global-restore.svg" with { type: "text" };
import iconHome from "@assets/svg/home.svg" with { type: "text" }; import iconHome from "@assets/svg/home.svg" with { type: "text" };
import iconLocalCoOp from "@assets/svg/local-co-op.svg" with { type: "text" };
import iconNativeMkb from "@assets/svg/native-mkb.svg" with { type: "text" }; import iconNativeMkb from "@assets/svg/native-mkb.svg" with { type: "text" };
import iconNew from "@assets/svg/new.svg" with { type: "text" }; import iconNew from "@assets/svg/new.svg" with { type: "text" };
import iconPencil from "@assets/svg/pencil-simple-line.svg" with { type: "text" }; import iconPencil from "@assets/svg/pencil-simple-line.svg" with { type: "text" };
@ -51,7 +53,9 @@ export const BxIcon = {
DISPLAY: iconDisplay, DISPLAY: iconDisplay,
EYE: iconEye, EYE: iconEye,
EYE_SLASH: iconEyeSlash, EYE_SLASH: iconEyeSlash,
// GLOBAL_RESTORE: iconGlobalRestore,
HOME: iconHome, HOME: iconHome,
LOCAL_CO_OP: iconLocalCoOp,
NATIVE_MKB: iconNativeMkb, NATIVE_MKB: iconNativeMkb,
NEW: iconNew, NEW: iconNew,
MANAGE: iconPencil, MANAGE: iconPencil,

View File

@ -1,24 +1,31 @@
import { CE } from "@utils/html"; import { CE } from "@utils/html";
import { compressCss, renderStylus } from "@macros/build" with { type: "macro" }; import { compressCss, isLiteVersion, renderStylus } from "@macros/build" with { type: "macro" };
import { BlockFeature, UiSection } from "@/enums/pref-values"; import { BlockFeature, UiSection, UiTheme } from "@/enums/pref-values";
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref } from "@/enums/pref-keys";
import { getPref } from "./settings-storages/global-settings-storage"; import { getGlobalPref } from "./pref-utils";
import { containsAll } from "./utils";
export function addCss() { export function addCss() {
const STYLUS_CSS = renderStylus() as unknown as string; 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 = getGlobalPref(GlobalPref.UI_HIDE_SECTIONS);
const selectorToHide = []; const selectorToHide = [];
if (isLiteVersion()) {
// Hide Controller icon in Game tiles
selectorToHide.push('div[role=img][class*=SupportedInputsBadge] svg:first-of-type');
selectorToHide.push('div[role=img][class*=SupportedInputsBadge]:not(:has(:nth-child(2)))');
}
// Hide "News" section // Hide "News" section
if (PREF_HIDE_SECTIONS.includes(UiSection.NEWS)) { if (PREF_HIDE_SECTIONS.includes(UiSection.NEWS)) {
selectorToHide.push('#BodyContent > div[class*=CarouselRow-module]'); selectorToHide.push('#BodyContent > div[class*=CarouselRow-module]');
} }
// Hide BYOG section // Hide BYOG section
if (getPref(PrefKey.BLOCK_FEATURES).includes(BlockFeature.BYOG)) { if (getGlobalPref(GlobalPref.BLOCK_FEATURES).includes(BlockFeature.BYOG) || getGlobalPref(GlobalPref.UI_HIDE_SECTIONS).includes(UiSection.BOYG)) {
selectorToHide.push('#BodyContent > div[class*=ByogRow-module__container___]'); selectorToHide.push('#BodyContent > div[class*=ByogRow-module__container___]');
} }
@ -38,8 +45,23 @@ export function addCss() {
selectorToHide.push('#BodyContent div[class*=HomePage-module__bottomSpacing]:has(a[href="/play/gallery/touch"])'); selectorToHide.push('#BodyContent div[class*=HomePage-module__bottomSpacing]:has(a[href="/play/gallery/touch"])');
} }
// Hide "Recently added" section
if (PREF_HIDE_SECTIONS.includes(UiSection.RECENTLY_ADDED)) {
selectorToHide.push('#BodyContent div[class*=HomePage-module__bottomSpacing]:has(a[href="/play/gallery/recently-added"])');
}
// Hide "Genres section"
if (PREF_HIDE_SECTIONS.includes(UiSection.GENRES)) {
selectorToHide.push('#BodyContent div[class*=HomePage-module__genresRow]');
}
// Hide "GamePassPromo"
if (containsAll(PREF_HIDE_SECTIONS, [UiSection.RECENTLY_ADDED, UiSection.LEAVING_SOON, UiSection.GENRES, UiSection.ALL_GAMES])) {
selectorToHide.push('#BodyContent div[class*=GamePassPromoSection-module__container]');
}
// Hide "Start a party" button in the Guide menu // Hide "Start a party" button in the Guide menu
if (getPref(PrefKey.BLOCK_FEATURES).includes(BlockFeature.FRIENDS)) { if (getGlobalPref(GlobalPref.BLOCK_FEATURES).includes(BlockFeature.FRIENDS)) {
selectorToHide.push('#gamepass-dialog-root div[class^=AchievementsPreview-module__container] + button[class*=HomeLandingPage-module__button]'); selectorToHide.push('#gamepass-dialog-root div[class^=AchievementsPreview-module__container] + button[class*=HomeLandingPage-module__button]');
} }
@ -47,54 +69,73 @@ export function addCss() {
css += selectorToHide.join(',') + '{ display: none; }'; css += selectorToHide.join(',') + '{ display: none; }';
} }
// Reduce animations // Change site's background
if (getPref(PrefKey.UI_REDUCE_ANIMATIONS)) { if (getGlobalPref(GlobalPref.UI_THEME) === UiTheme.DARK_OLED) {
css += compressCss(` css += compressCss(`
div[class*=GameCard-module__gameTitleInnerWrapper], body[data-theme=dark] {
div[class*=GameCard-module__card], --gds-containerSolidAppBackground: #000 !important;
div[class*=ScrollArrows-module] { }
div[aria-hidden=true][class^=BackgroundImageAbsoluteContainer][class*=ProductDetailPage-module__backgroundImageGradient]:after {
background: radial-gradient(ellipse 100% 100% at 50% 0, #1515178c 0, #1a1b1ea6 32%, #000000 100%) !important;
}
a[href="/play/gallery/all-games"][class*=AllGamesRow-module__seeAllCloudGames] {
background: none !important;
}
`);
}
// Reduce animations
if (getGlobalPref(GlobalPref.UI_REDUCE_ANIMATIONS)) {
css += compressCss(`
/*div[class*=GameCard-module__card],*/
div[class^=GameCard-module__gameTitleInnerWrapper],
div[class^=ScrollArrows-module],
div[class^=ContextMenu-module__][class*=Dropdown-module__dropdownWrapper] {
animation: none !important;
transition: none !important; transition: none !important;
} }
`); `);
} }
// Hide the top-left dots icon while playing // Hide the top-left dots icon while playing
if (getPref(PrefKey.UI_HIDE_SYSTEM_MENU_ICON)) { if (getGlobalPref(GlobalPref.UI_HIDE_SYSTEM_MENU_ICON)) {
css += compressCss(` css += compressCss(`
div[class*=Grip-module__container] { #StreamHud div[class^=Grip-module__container] {
visibility: hidden; visibility: hidden;
} }
@media (hover: hover) { @media (hover: hover) {
button[class*=GripHandle-module__container]:hover div[class*=Grip-module__container] { #StreamHud button[class^=GripHandle-module__container]:hover div[class^=Grip-module__container] {
visibility: visible; visibility: visible;
} }
} }
button[class*=GripHandle-module__container][aria-expanded=true] div[class*=Grip-module__container] { #StreamHud button[class^=GripHandle-module__container][aria-expanded=true] div[class^=Grip-module__container] {
visibility: visible; visibility: visible;
} }
button[class*=GripHandle-module__container][aria-expanded=false] { #StreamHud button[class^=GripHandle-module__container][aria-expanded=false] {
background-color: transparent !important; background-color: transparent !important;
} }
div[class*=StreamHUD-module__buttonsContainer] { #StreamHud div[class^=StreamHUD-module__buttonsContainer] {
padding: 0px !important; padding: 0px !important;
} }
`); `);
} }
css += compressCss(` css += compressCss(`
div[class*=StreamMenu-module__menu] { #game-stream div[class*=StreamMenu-module__menu] {
min-width: 100vw !important; min-width: 100vw !important;
} }
`); `);
// Simplify Stream's menu // Simplify Stream's menu
if (getPref(PrefKey.UI_SIMPLIFY_STREAM_MENU)) { if (getGlobalPref(GlobalPref.UI_SIMPLIFY_STREAM_MENU)) {
css += compressCss(` css += compressCss(`
div[class*=Menu-module__scrollable] { #game-stream div[class*=Menu-module__scrollable] {
--bxStreamMenuItemSize: 80px; --bxStreamMenuItemSize: 80px;
--streamMenuItemSize: calc(var(--bxStreamMenuItemSize) + 40px) !important; --streamMenuItemSize: calc(var(--bxStreamMenuItemSize) + 40px) !important;
} }
@ -107,18 +148,18 @@ body[data-media-type=tv] .bx-badges {
top: calc(var(--streamMenuItemSize) - 10px) !important; top: calc(var(--streamMenuItemSize) - 10px) !important;
} }
button[class*=MenuItem-module__container] { #game-stream button[class*=MenuItem-module__container] {
min-width: auto !important; min-width: auto !important;
min-height: auto !important; min-height: auto !important;
width: var(--bxStreamMenuItemSize) !important; width: var(--bxStreamMenuItemSize) !important;
height: var(--bxStreamMenuItemSize) !important; height: var(--bxStreamMenuItemSize) !important;
} }
div[class*=MenuItem-module__label] { #game-stream div[class*=MenuItem-module__label] {
display: none !important; display: none !important;
} }
svg[class*=MenuItem-module__icon] { #game-stream svg[class*=MenuItem-module__icon] {
width: 36px; width: 36px;
height: 100% !important; height: 100% !important;
padding: 0 !important; padding: 0 !important;
@ -152,7 +193,7 @@ body:not([data-media-type=tv]) div[class*=MenuItem-module__label] {
} }
// Hide scrollbar // Hide scrollbar
if (getPref(PrefKey.UI_SCROLLBAR_HIDE)) { if (getGlobalPref(GlobalPref.UI_SCROLLBAR_HIDE)) {
css += compressCss(` css += compressCss(`
html { html {
scrollbar-width: none; scrollbar-width: none;

56
src/utils/deep-link.ts Normal file
View File

@ -0,0 +1,56 @@
import { localRedirect } from "@/modules/ui/ui";
import { AppInterface } from "./global";
import { RemotePlayManager } from "@/modules/remote-play-manager";
import { BxEvent } from "./bx-event";
export function handleDeepLink() {
const deepLinkData = JSON.parse(AppInterface.getDeepLinkData());
console.log('deepLinkData', deepLinkData);
if (!deepLinkData.host) {
return;
}
const onReady = () => {
if (deepLinkData.host === 'PLAY') {
localRedirect('/launch/' + deepLinkData.data.join('/'));
} else if (deepLinkData.host === 'DEVICE_CODE') {
localRedirect('/login/deviceCode');
} else if (deepLinkData.host === 'REMOTE_PLAY') {
const serverId = deepLinkData.data[0];
const resolution = deepLinkData.data[1] || '1080p';
const manager = RemotePlayManager.getInstance();
if (!manager) {
return;
}
if (manager.isReady()) {
manager.play(serverId, resolution);
return;
}
window.addEventListener(BxEvent.REMOTE_PLAY_READY, () => {
manager.play(serverId, resolution);
});
}
}
let handled = false
const observer = new MutationObserver(mutationList => {
mutationList.forEach(mutation => {
if (handled || mutation.type !== 'childList') {
return;
}
const $target = mutation.target as HTMLElement;
if (!handled && $target.className && $target.className['startsWith'] && $target.className.includes('HomePage-module__homePage')) {
handled = true;
observer.disconnect();
setTimeout(onReady, 1000);
return;
}
});
});
observer.observe(document.documentElement, {subtree: true, childList: true});
}

View File

@ -1,7 +1,7 @@
import { PrefKey } from "@/enums/pref-keys"; import { GlobalPref } from "@/enums/pref-keys";
import { BX_FLAGS } from "./bx-flags"; import { BX_FLAGS } from "./bx-flags";
import { getPref } from "./settings-storages/global-settings-storage";
import { BlockFeature, NativeMkbMode } from "@/enums/pref-values"; import { BlockFeature, NativeMkbMode } from "@/enums/pref-values";
import { getGlobalPref } from "./pref-utils";
export let FeatureGates: { [key: string]: boolean } = { export let FeatureGates: { [key: string]: boolean } = {
PwaPrompt: false, PwaPrompt: false,
@ -9,16 +9,19 @@ export let FeatureGates: { [key: string]: boolean } = {
EnableUpdateRequiredPage: false, EnableUpdateRequiredPage: false,
ShowForcedUpdateScreen: false, ShowForcedUpdateScreen: false,
EnableTakControlResizing: true, // Experimenting EnableTakControlResizing: true, // Experimenting
EnableLazyLoadedHome: false,
EnableRemotePlay: !getGlobalPref(GlobalPref.BLOCK_FEATURES).includes(BlockFeature.REMOTE_PLAY),
EnableConsoles: !getGlobalPref(GlobalPref.BLOCK_FEATURES).includes(BlockFeature.REMOTE_PLAY),
}; };
// Enable Native Mouse & Keyboard // Enable Native Mouse & Keyboard
const nativeMkbMode = getPref(PrefKey.NATIVE_MKB_MODE); const nativeMkbMode = getGlobalPref(GlobalPref.NATIVE_MKB_MODE);
if (nativeMkbMode !== NativeMkbMode.DEFAULT) { if (nativeMkbMode !== NativeMkbMode.DEFAULT) {
FeatureGates.EnableMouseAndKeyboard = nativeMkbMode === NativeMkbMode.ON; FeatureGates.EnableMouseAndKeyboard = nativeMkbMode === NativeMkbMode.ON;
} }
// Disable chat feature // Disable chat feature
const blockFeatures = getPref(PrefKey.BLOCK_FEATURES); const blockFeatures = getGlobalPref(GlobalPref.BLOCK_FEATURES);
if (blockFeatures.includes(BlockFeature.CHAT)) { if (blockFeatures.includes(BlockFeature.CHAT)) {
FeatureGates.EnableGuideChatTab = false; FeatureGates.EnableGuideChatTab = false;
} }

View File

@ -2,21 +2,27 @@ import { VIRTUAL_GAMEPAD_ID } from "@modules/mkb/mkb-handler";
import { t } from "@utils/translation"; import { t } from "@utils/translation";
import { Toast } from "@utils/toast"; import { Toast } from "@utils/toast";
import { BxLogger } from "@utils/bx-logger"; import { BxLogger } from "@utils/bx-logger";
import { PrefKey } from "@/enums/pref-keys"; import { GamepadKey, GamepadKeyName } from "@/enums/gamepad";
import { getPref } from "./settings-storages/global-settings-storage"; import { getStreamPref } from "@/utils/pref-utils";
import { GamepadKeyName, type GamepadKey } from "@/enums/gamepad"; import { StreamPref } from "@/enums/pref-keys";
// Show a toast when connecting/disconecting controller // Show a toast when connecting/disconecting controller
export function showGamepadToast(gamepad: Gamepad) { export function showGamepadToast(gamepad: Gamepad) {
// Don't show Toast for virtual controller // Don't show toast for virtual controller
if (gamepad.id === VIRTUAL_GAMEPAD_ID) { if (gamepad.id === VIRTUAL_GAMEPAD_ID) {
return; return;
} }
// Don't show toast when toggling local co-op feature
if ((gamepad as any)._noToast) {
return;
}
BxLogger.info('Gamepad', gamepad); BxLogger.info('Gamepad', gamepad);
let text = '🎮'; let text = '🎮';
if (getPref(PrefKey.LOCAL_CO_OP_ENABLED)) { if (getStreamPref(StreamPref.LOCAL_CO_OP_ENABLED)) {
text += ` #${gamepad.index + 1}`; text += ` #${gamepad.index + 1}`;
} }
@ -35,6 +41,10 @@ export function showGamepadToast(gamepad: Gamepad) {
Toast.show(text, status, { instant: false }); Toast.show(text, status, { instant: false });
} }
export function simplifyGamepadName(name: string) {
return name.replace(/\s+\(.*Vendor: ([0-9a-f]{4}) Product: ([0-9a-f]{4})\)$/, ' ($1-$2)');
}
export function getUniqueGamepadNames() { export function getUniqueGamepadNames() {
const gamepads = window.navigator.getGamepads(); const gamepads = window.navigator.getGamepads();
const names: string[] = []; const names: string[] = [];
@ -59,9 +69,9 @@ export function hasGamepad() {
return false; return false;
} }
export function generateVirtualControllerMapping(override: {}={}) { export function generateVirtualControllerMapping(index: number, override: Partial<XcloudGamepad>={}) {
const mapping = { const mapping = {
GamepadIndex: 0, GamepadIndex: index,
A: 0, A: 0,
B: 0, B: 0,
X: 0, X: 0,
@ -95,3 +105,44 @@ export function generateVirtualControllerMapping(override: {}={}) {
export function getGamepadPrompt(gamepadKey: GamepadKey): string { export function getGamepadPrompt(gamepadKey: GamepadKey): string {
return GamepadKeyName[gamepadKey][1]; return GamepadKeyName[gamepadKey][1];
} }
const XCLOUD_GAMEPAD_KEY_MAPPING: { [key in GamepadKey]?: keyof XcloudGamepad } = {
[GamepadKey.A]: 'A',
[GamepadKey.B]: 'B',
[GamepadKey.X]: 'X',
[GamepadKey.Y]: 'Y',
[GamepadKey.UP]: 'DPadUp',
[GamepadKey.RIGHT]: 'DPadRight',
[GamepadKey.DOWN]: 'DPadDown',
[GamepadKey.LEFT]: 'DPadLeft',
[GamepadKey.LB]: 'LeftShoulder',
[GamepadKey.RB]: 'RightShoulder',
[GamepadKey.LT]: 'LeftTrigger',
[GamepadKey.RT]: 'RightTrigger',
[GamepadKey.L3]: 'LeftThumb',
[GamepadKey.R3]: 'RightThumb',
[GamepadKey.LS]: 'LeftStickAxes',
[GamepadKey.RS]: 'RightStickAxes',
[GamepadKey.SELECT]: 'View',
[GamepadKey.START]: 'Menu',
[GamepadKey.HOME]: 'Nexus',
[GamepadKey.SHARE]: 'Share',
[GamepadKey.LS_LEFT]: 'LeftThumbXAxis',
[GamepadKey.LS_RIGHT]: 'LeftThumbXAxis',
[GamepadKey.LS_UP]: 'LeftThumbYAxis',
[GamepadKey.LS_DOWN]: 'LeftThumbYAxis',
[GamepadKey.RS_LEFT]: 'RightThumbXAxis',
[GamepadKey.RS_RIGHT]: 'RightThumbXAxis',
[GamepadKey.RS_UP]: 'RightThumbYAxis',
[GamepadKey.RS_DOWN]: 'RightThumbYAxis',
};
export function toXcloudGamepadKey(gamepadKey: GamepadKey) {
return XCLOUD_GAMEPAD_KEY_MAPPING[gamepadKey];
}

View File

@ -4,11 +4,6 @@ import { BxLogger } from "./bx-logger";
import { BxEventBus } from "./bx-event-bus"; import { BxEventBus } from "./bx-event-bus";
export type ForceNativeMkbResponse = {
$schemaVersion: number;
data: { [key: string]: string };
}
export class GhPagesUtils { export class GhPagesUtils {
static fetchLatestCommit() { static fetchLatestCommit() {
const url = 'https://api.github.com/repos/redphx/better-xcloud/branches/gh-pages'; const url = 'https://api.github.com/repos/redphx/better-xcloud/branches/gh-pages';
@ -56,6 +51,8 @@ export class GhPagesUtils {
BxEventBus.Script.emit('list.forcedNativeMkb.updated', { BxEventBus.Script.emit('list.forcedNativeMkb.updated', {
data: json, data: json,
}); });
} else {
window.localStorage.removeItem(key);
} }
}); });
@ -70,6 +67,7 @@ export class GhPagesUtils {
} }
static getTouchControlCustomList() { static getTouchControlCustomList() {
// TODO: use Set()
const key = StorageKey.LIST_CUSTOM_TOUCH_LAYOUTS; const key = StorageKey.LIST_CUSTOM_TOUCH_LAYOUTS;
NATIVE_FETCH(GhPagesUtils.getUrl('touch-layouts/ids.json')) NATIVE_FETCH(GhPagesUtils.getUrl('touch-layouts/ids.json'))
@ -83,4 +81,31 @@ export class GhPagesUtils {
const customList = JSON.parse(window.localStorage.getItem(key) || '[]'); const customList = JSON.parse(window.localStorage.getItem(key) || '[]');
return customList; return customList;
} }
static getLocalCoOpList(): Set<string> {
const supportedSchema = 1;
const key = StorageKey.LIST_LOCAL_CO_OP;
NATIVE_FETCH(GhPagesUtils.getUrl('local-co-op/ids.json'))
.then(response => response.json())
.then(json => {
if (json.$schemaVersion === supportedSchema) {
window.localStorage.setItem(key, JSON.stringify(json));
const ids = new Set(Object.keys(json.data));
BxEventBus.Script.emit('list.localCoOp.updated', { ids });
} else {
window.localStorage.removeItem(key);
BxEventBus.Script.emit('list.localCoOp.updated', { ids: new Set() });
}
});
const info = JSON.parse(window.localStorage.getItem(key) || '{}');
if (info.$schemaVersion !== supportedSchema) {
// Delete storage;
window.localStorage.removeItem(key);
return new Set();
}
return new Set(Object.keys(info.data || {}));
}
} }

View File

@ -1,4 +1,4 @@
import type { BaseSettingsStore } from "./settings-storages/base-settings-storage"; import type { BxStates } from "@/types/states";
import { UserAgent } from "./user-agent"; import { UserAgent } from "./user-agent";
export const SCRIPT_VERSION = Bun.env.SCRIPT_VERSION!; export const SCRIPT_VERSION = Bun.env.SCRIPT_VERSION!;
@ -47,8 +47,6 @@ export const STATES: BxStates = {
pointerServerPort: 9269, pointerServerPort: 9269,
}; };
export const STORAGE: { [key: string]: BaseSettingsStore } = {};
export function deepClone(obj: any): typeof obj | {} { export function deepClone(obj: any): typeof obj | {} {
if (!obj) { if (!obj) {
return {}; return {};

Some files were not shown because too many files have changed in this diff Show More