mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-29 10:51:44 +02:00
Compare commits
109 Commits
Author | SHA1 | Date | |
---|---|---|---|
5d177bd76c | |||
f18c5c14ed | |||
d0ceed00f8 | |||
fce8af4b3b | |||
57686f9d8e | |||
f0e7272a82 | |||
b0ecc7171b | |||
17c08792e1 | |||
e8376b52fe | |||
f6581abe34 | |||
b090d325ae | |||
ec3daa09fd | |||
b2a2e4d27e | |||
4f3430c43c | |||
15c6d3c74b | |||
b170b95145 | |||
4217b89194 | |||
38211168e9 | |||
392dc2cf86 | |||
67de264aa9 | |||
3e2c1bb2a4 | |||
5653914d19 | |||
4a8f66f2a1 | |||
70f43ba8f2 | |||
4d49639622 | |||
22f1ebdd08 | |||
bae51eff3d | |||
adc9897210 | |||
53442557e1 | |||
5b67b4c37d | |||
5a06933143 | |||
6440c91cdf | |||
b06dc6e219 | |||
540a50fb3a | |||
e5178830cb | |||
75549bc477 | |||
8a3d48d4a3 | |||
33c3b2810a | |||
95881dd241 | |||
c89ebb78a4 | |||
222ad1c34e | |||
6cfff0274d | |||
01502363ab | |||
9ab63c4a53 | |||
89a968d688 | |||
5e98c756d4 | |||
831fd98d02 | |||
de76364a46 | |||
075b15aa48 | |||
9388d7fbf4 | |||
2d8361ba73 | |||
79c7af10d4 | |||
6bd658e8a6 | |||
7e6b89b357 | |||
4271583a5a | |||
1b2cf70248 | |||
87447df7fd | |||
8664c1a60f | |||
602c31dc7f | |||
bbaea5f629 | |||
03efa528c8 | |||
63aaca7d61 | |||
15ae88e9e6 | |||
7578671cc3 | |||
82cfb11a6d | |||
15700e736d | |||
b27cfc8215 | |||
1e644504ec | |||
7206d11825 | |||
fa19a5a68e | |||
3f834f74b6 | |||
749d5d720e | |||
b969d52a3c | |||
e5bd7e64a7 | |||
82ee00b4ae | |||
8e88af5f8c | |||
927eae3f2f | |||
9f440e9cf4 | |||
1acb30e3af | |||
34159fad22 | |||
741538ebcf | |||
6d2e04aff1 | |||
f2bc98229f | |||
49fb8e2818 | |||
d012d96675 | |||
c129feaf2d | |||
4f7b23912d | |||
e4d73f9e36 | |||
2eea9ce8f5 | |||
27abab8473 | |||
0c34173815 | |||
0164423e45 | |||
71dcaf4b07 | |||
8f49c48e74 | |||
6fa1f73702 | |||
728abced45 | |||
411e43ceb0 | |||
baa22dbefc | |||
97fb7a114f | |||
39b2f814b6 | |||
3d34bb3edf | |||
ab1c93eb3a | |||
739adfce41 | |||
2e77f19006 | |||
8a40d361d9 | |||
98fa273b48 | |||
1e6527413c | |||
b9134bc141 | |||
336a965653 |
39
build.ts
39
build.ts
@ -20,6 +20,8 @@ enum BuildTarget {
|
|||||||
|
|
||||||
type BuildVariant = 'full' | 'lite';
|
type BuildVariant = 'full' | 'lite';
|
||||||
|
|
||||||
|
const MINIFY_SYNTAX = true;
|
||||||
|
|
||||||
const postProcess = (str: string): string => {
|
const postProcess = (str: string): string => {
|
||||||
// Unescape unicode charaters
|
// Unescape unicode charaters
|
||||||
str = unescape((str.replace(/\\u/g, '%u')));
|
str = unescape((str.replace(/\\u/g, '%u')));
|
||||||
@ -55,7 +57,7 @@ const postProcess = (str: string): string => {
|
|||||||
|
|
||||||
// Minify SVG import code
|
// Minify SVG import code
|
||||||
const svgMap = {}
|
const svgMap = {}
|
||||||
str = str.replaceAll(/var ([\w_]+) = ("<svg.*?");\n\n/g, function(match, p1, p2) {
|
str = str.replaceAll(/var ([\w_]+) = ("<svg.*?");\n\n/g, (match, p1, p2) => {
|
||||||
// Remove new lines in SVG
|
// Remove new lines in SVG
|
||||||
p2 = p2.replaceAll(/\\n*\s*/g, '');
|
p2 = p2.replaceAll(/\\n*\s*/g, '');
|
||||||
|
|
||||||
@ -70,12 +72,37 @@ const postProcess = (str: string): string => {
|
|||||||
// Collapse empty brackets
|
// Collapse empty brackets
|
||||||
str = str.replaceAll(/\{[\s\n]+\}/g, '{}');
|
str = str.replaceAll(/\{[\s\n]+\}/g, '{}');
|
||||||
|
|
||||||
// Collapse if/else blocks without curly braces
|
|
||||||
str = str.replaceAll(/((if \(.*?\)|else)\n\s+)/g, '$2 ');
|
|
||||||
|
|
||||||
// Remove blank lines
|
// Remove blank lines
|
||||||
str = str.replaceAll(/\n([\s]*)\n/g, "\n");
|
str = str.replaceAll(/\n([\s]*)\n/g, "\n");
|
||||||
|
|
||||||
|
// Minify WebGL shaders & JS strings
|
||||||
|
// Replace "\n " with "\n"
|
||||||
|
str = str.replaceAll(/\\n+\s*/g, '\\n');
|
||||||
|
// Remove comment line
|
||||||
|
str = str.replaceAll(/\\n\/\/.*?(?=\\n)/g, '');
|
||||||
|
|
||||||
|
// Replace ${"time".toUpperCase()} with "TIME"
|
||||||
|
str = str.replaceAll(/\$\{"([^"]+)"\.toUpperCase\(\)\}/g, (match, p1) => {
|
||||||
|
return p1.toUpperCase();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Replace " (e) =>" to " e =>"
|
||||||
|
// str = str.replaceAll(/ \(([^\s,.$()]+)\) =>/g, ' $1 =>');
|
||||||
|
|
||||||
|
// Set indent to 1 space
|
||||||
|
if (MINIFY_SYNTAX) {
|
||||||
|
// Collapse if/else blocks without curly braces
|
||||||
|
str = str.replaceAll(/((if \(.*?\)|else)\n\s+)/g, '$2 ');
|
||||||
|
|
||||||
|
str = str.replaceAll(/\n(\s+)/g, (match, p1) => {
|
||||||
|
const len = p1.length / 2;
|
||||||
|
return '\n' + ' '.repeat(len);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fix unicode regex in Patcher.optimizeGameSlugGenerator
|
||||||
|
str = str.replaceAll('^\\™', '^\\\\u2122');
|
||||||
|
|
||||||
assert(str.includes('/* ADDITIONAL CODE */'));
|
assert(str.includes('/* ADDITIONAL CODE */'));
|
||||||
assert(str.includes('window.BX_EXPOSED = BxExposed'));
|
assert(str.includes('window.BX_EXPOSED = BxExposed'));
|
||||||
assert(str.includes('window.BxEvent = BxEvent'));
|
assert(str.includes('window.BxEvent = BxEvent'));
|
||||||
@ -108,7 +135,7 @@ const build = async (target: BuildTarget, version: string, variant: BuildVariant
|
|||||||
outdir: outDir,
|
outdir: outDir,
|
||||||
naming: outputScriptName,
|
naming: outputScriptName,
|
||||||
minify: {
|
minify: {
|
||||||
syntax: true,
|
syntax: MINIFY_SYNTAX,
|
||||||
},
|
},
|
||||||
define: {
|
define: {
|
||||||
'Bun.env.BUILD_TARGET': JSON.stringify(target),
|
'Bun.env.BUILD_TARGET': JSON.stringify(target),
|
||||||
@ -139,7 +166,7 @@ const build = async (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')) {
|
if (!version.includes('beta') && variant === 'full') {
|
||||||
await Bun.write(outDir + '/' + outputMetaName, txtMetaHeader.replace('[[VERSION]]', version));
|
await Bun.write(outDir + '/' + outputMetaName, txtMetaHeader.replace('[[VERSION]]', version));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
dist/better-xcloud.lite.meta.js
vendored
5
dist/better-xcloud.lite.meta.js
vendored
@ -1,5 +0,0 @@
|
|||||||
// ==UserScript==
|
|
||||||
// @name Better xCloud
|
|
||||||
// @namespace https://github.com/redphx
|
|
||||||
// @version 5.8.0
|
|
||||||
// ==/UserScript==
|
|
10993
dist/better-xcloud.lite.user.js
vendored
10993
dist/better-xcloud.lite.user.js
vendored
File diff suppressed because one or more lines are too long
2
dist/better-xcloud.meta.js
vendored
2
dist/better-xcloud.meta.js
vendored
@ -1,5 +1,5 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Better xCloud
|
// @name Better xCloud
|
||||||
// @namespace https://github.com/redphx
|
// @namespace https://github.com/redphx
|
||||||
// @version 5.8.0
|
// @version 5.9.5
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
14981
dist/better-xcloud.user.js
vendored
14981
dist/better-xcloud.user.js
vendored
File diff suppressed because one or more lines are too long
10
package.json
10
package.json
@ -10,14 +10,14 @@
|
|||||||
"build": "build.ts"
|
"build": "build.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bun": "^1.1.10",
|
"@types/bun": "^1.1.12",
|
||||||
"@types/node": "^22.7.4",
|
"@types/node": "^22.7.9",
|
||||||
"@types/stylus": "^0.48.43",
|
"@types/stylus": "^0.48.43",
|
||||||
"eslint": "^9.12.0",
|
"eslint": "^9.13.0",
|
||||||
"eslint-plugin-compat": "^6.0.1",
|
"eslint-plugin-compat": "^6.0.1",
|
||||||
"stylus": "^0.63.0"
|
"stylus": "^0.64.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"typescript": "^5.6.2"
|
"typescript": "^5.6.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,21 +76,21 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Touch controller buttons */
|
/* Touch controller buttons */
|
||||||
div[data-enabled] {
|
div[data-activated] {
|
||||||
button {
|
button {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show enabled button */
|
/* Show default button */
|
||||||
div[data-enabled='true'] {
|
div[data-activated='false'] {
|
||||||
button:first-of-type {
|
button:first-of-type {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show enable button */
|
/* Show activated button */
|
||||||
div[data-enabled='false'] {
|
div[data-activated='true'] {
|
||||||
button:last-of-type {
|
button:last-of-type {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
min-width: 40px;
|
min-width: 40px;
|
||||||
font-family: var(--bx-monospaced-font);
|
font-family: var(--bx-monospaced-font);
|
||||||
font-size: 12px;
|
font-size: 13px;
|
||||||
margin: 0 4px;
|
margin: 0 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +91,7 @@ div[class^=StreamMenu-module__container] .bx-badges {
|
|||||||
&[data-stats*="[batt]"] > .bx-stat-batt,
|
&[data-stats*="[batt]"] > .bx-stat-batt,
|
||||||
&[data-stats*="[fps]"] > .bx-stat-fps,
|
&[data-stats*="[fps]"] > .bx-stat-fps,
|
||||||
&[data-stats*="[ping]"] > .bx-stat-ping,
|
&[data-stats*="[ping]"] > .bx-stat-ping,
|
||||||
|
&[data-stats*="[jit]"] > .bx-stat-jit,
|
||||||
&[data-stats*="[btr]"] > .bx-stat-btr,
|
&[data-stats*="[btr]"] > .bx-stat-btr,
|
||||||
&[data-stats*="[dt]"] > .bx-stat-dt,
|
&[data-stats*="[dt]"] > .bx-stat-dt,
|
||||||
&[data-stats*="[pl]"] > .bx-stat-pl,
|
&[data-stats*="[pl]"] > .bx-stat-pl,
|
||||||
@ -106,6 +107,7 @@ div[class^=StreamMenu-module__container] .bx-badges {
|
|||||||
&[data-stats$="[batt]"] > .bx-stat-batt,
|
&[data-stats$="[batt]"] > .bx-stat-batt,
|
||||||
&[data-stats$="[fps]"] > .bx-stat-fps,
|
&[data-stats$="[fps]"] > .bx-stat-fps,
|
||||||
&[data-stats$="[ping]"] > .bx-stat-ping,
|
&[data-stats$="[ping]"] > .bx-stat-ping,
|
||||||
|
&[data-stats$="[jit]"] > .bx-stat-jit,
|
||||||
&[data-stats$="[btr]"] > .bx-stat-btr,
|
&[data-stats$="[btr]"] > .bx-stat-btr,
|
||||||
&[data-stats$="[dt]"] > .bx-stat-dt,
|
&[data-stats$="[dt]"] > .bx-stat-dt,
|
||||||
&[data-stats$="[pl]"] > .bx-stat-pl,
|
&[data-stats$="[pl]"] > .bx-stat-pl,
|
||||||
|
8
src/assets/svg/eye-slash.svg
Normal file
8
src/assets/svg/eye-slash.svg
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<svg xmlns='http://www.w3.org/2000/svg' fill='#fff' stroke='none ' fill-rule='evenodd' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' viewBox='0 0 32 32'>
|
||||||
|
<clipPath id='A'>
|
||||||
|
<path d='M0 0h32v32H0z'/>
|
||||||
|
</clipPath>
|
||||||
|
<g clip-path='url(#A)'>
|
||||||
|
<path d='M6.123 3.549a1.07 1.07 0 0 0-.798-.359c-.585 0-1.067.482-1.067 1.067 0 .27.102.53.286.727l2.565 2.823C2.267 10.779.184 15.36.092 15.568c-.123.276-.123.591 0 .867.047.105 1.176 2.609 3.687 5.12 3.345 3.344 7.57 5.112 12.221 5.112a16.97 16.97 0 0 0 6.943-1.444l2.933 3.228c.202.228.493.359.798.359.585 0 1.067-.482 1.067-1.067a1.07 1.07 0 0 0-.286-.727L6.123 3.549zm6.31 10.112l5.556 6.114c-.612.322-1.294.49-1.986.49a4.29 4.29 0 0 1-4.267-4.266c0-.831.242-1.643.697-2.338zM16 24.533c-4.104 0-7.689-1.492-10.657-4.433A17.73 17.73 0 0 1 2.267 16c.625-1.172 2.621-4.452 6.313-6.584l2.4 2.633c-.878 1.125-1.356 2.512-1.356 3.939 0 3.511 2.89 6.4 6.4 6.4 1.221 0 2.416-.349 3.444-1.005l1.964 2.16a14.92 14.92 0 0 1-5.432.99zm.8-12.724a1.07 1.07 0 0 1-.867-1.048c0-.585.482-1.067 1.067-1.067a1.12 1.12 0 0 1 .2.019c2.784.54 4.896 2.863 5.169 5.686a1.07 1.07 0 0 1-.962 1.161c-.034.002-.067.002-.1 0a1.07 1.07 0 0 1-1.067-.968 4.29 4.29 0 0 0-3.44-3.783zm15.104 4.626c-.056.125-1.407 3.116-4.448 5.84a1.07 1.07 0 0 1-.724.283c-.585 0-1.067-.482-1.067-1.067a1.07 1.07 0 0 1 .368-.806A17.7 17.7 0 0 0 29.74 16a17.73 17.73 0 0 0-3.083-4.103C23.689 8.959 20.104 7.467 16 7.467a15.82 15.82 0 0 0-2.581.209 1.06 1.06 0 0 1-.186.016 1.07 1.07 0 0 1-1.067-1.066 1.07 1.07 0 0 1 .901-1.054A17.89 17.89 0 0 1 16 5.333c4.651 0 8.876 1.768 12.221 5.114 2.511 2.51 3.64 5.016 3.687 5.121.123.276.123.591 0 .867h-.004z' fill-rule='nonzero'/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.7 KiB |
8
src/assets/svg/eye.svg
Normal file
8
src/assets/svg/eye.svg
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<svg xmlns='http://www.w3.org/2000/svg' fill='#fff' stroke='none ' fill-rule='evenodd' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' viewBox='0 0 32 32'>
|
||||||
|
<clipPath id='A'>
|
||||||
|
<path d='M0 0h32v32H0z'/>
|
||||||
|
</clipPath>
|
||||||
|
<g clip-path='url(#A)'>
|
||||||
|
<path d='M31.908 15.568c-.047-.105-1.176-2.611-3.687-5.121C24.876 7.101 20.651 5.333 16 5.333S7.124 7.101 3.779 10.447c-2.511 2.51-3.646 5.02-3.687 5.121-.123.276-.123.591 0 .867.047.105 1.176 2.609 3.687 5.12 3.345 3.344 7.57 5.112 12.221 5.112s8.876-1.768 12.221-5.112c2.511-2.511 3.64-5.015 3.687-5.12.123-.276.123-.591 0-.867zM16 24.533c-4.104 0-7.689-1.492-10.657-4.433-1.218-1.211-2.254-2.592-3.076-4.1.822-1.508 1.858-2.889 3.076-4.1C8.311 8.959 11.896 7.467 16 7.467s7.689 1.492 10.657 4.433c1.221 1.211 2.259 2.592 3.083 4.1-.961 1.795-5.149 8.533-13.74 8.533zM16 9.6c-3.511 0-6.4 2.889-6.4 6.4s2.889 6.4 6.4 6.4 6.4-2.889 6.4-6.4A6.44 6.44 0 0 0 16 9.6zm0 10.667A4.29 4.29 0 0 1 11.733 16 4.29 4.29 0 0 1 16 11.733 4.29 4.29 0 0 1 20.267 16 4.29 4.29 0 0 1 16 20.267z' fill-rule='nonzero'/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.1 KiB |
@ -37,11 +37,11 @@ export enum PrefKey {
|
|||||||
LOCAL_CO_OP_ENABLED = 'local_co_op_enabled',
|
LOCAL_CO_OP_ENABLED = 'local_co_op_enabled',
|
||||||
// LOCAL_CO_OP_SEPARATE_TOUCH_CONTROLLER = 'local_co_op_separate_touch_controller',
|
// LOCAL_CO_OP_SEPARATE_TOUCH_CONTROLLER = 'local_co_op_separate_touch_controller',
|
||||||
|
|
||||||
CONTROLLER_ENABLE_SHORTCUTS = 'controller_enable_shortcuts',
|
|
||||||
CONTROLLER_ENABLE_VIBRATION = 'controller_enable_vibration',
|
CONTROLLER_ENABLE_VIBRATION = 'controller_enable_vibration',
|
||||||
CONTROLLER_DEVICE_VIBRATION = 'controller_device_vibration',
|
CONTROLLER_DEVICE_VIBRATION = 'controller_device_vibration',
|
||||||
CONTROLLER_VIBRATION_INTENSITY = 'controller_vibration_intensity',
|
CONTROLLER_VIBRATION_INTENSITY = 'controller_vibration_intensity',
|
||||||
CONTROLLER_SHOW_CONNECTION_STATUS = 'controller_show_connection_status',
|
CONTROLLER_SHOW_CONNECTION_STATUS = 'controller_show_connection_status',
|
||||||
|
CONTROLLER_POLLING_RATE = 'controller_polling_rate',
|
||||||
|
|
||||||
NATIVE_MKB_ENABLED = 'native_mkb_enabled',
|
NATIVE_MKB_ENABLED = 'native_mkb_enabled',
|
||||||
NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY = 'native_mkb_scroll_x_sensitivity',
|
NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY = 'native_mkb_scroll_x_sensitivity',
|
||||||
@ -69,12 +69,12 @@ export enum PrefKey {
|
|||||||
UI_SCROLLBAR_HIDE = 'ui_scrollbar_hide',
|
UI_SCROLLBAR_HIDE = 'ui_scrollbar_hide',
|
||||||
UI_HIDE_SECTIONS = 'ui_hide_sections',
|
UI_HIDE_SECTIONS = 'ui_hide_sections',
|
||||||
|
|
||||||
UI_HOME_CONTEXT_MENU_DISABLED = 'ui_home_context_menu_disabled',
|
|
||||||
UI_GAME_CARD_SHOW_WAIT_TIME = 'ui_game_card_show_wait_time',
|
UI_GAME_CARD_SHOW_WAIT_TIME = 'ui_game_card_show_wait_time',
|
||||||
|
|
||||||
VIDEO_PLAYER_TYPE = 'video_player_type',
|
VIDEO_PLAYER_TYPE = 'video_player_type',
|
||||||
VIDEO_PROCESSING = 'video_processing',
|
VIDEO_PROCESSING = 'video_processing',
|
||||||
VIDEO_POWER_PREFERENCE = 'video_power_preference',
|
VIDEO_POWER_PREFERENCE = 'video_power_preference',
|
||||||
|
VIDEO_MAX_FPS = 'video_max_fps',
|
||||||
VIDEO_SHARPNESS = 'video_sharpness',
|
VIDEO_SHARPNESS = 'video_sharpness',
|
||||||
VIDEO_RATIO = 'video_ratio',
|
VIDEO_RATIO = 'video_ratio',
|
||||||
VIDEO_BRIGHTNESS = 'video_brightness',
|
VIDEO_BRIGHTNESS = 'video_brightness',
|
||||||
@ -98,4 +98,5 @@ export enum PrefKey {
|
|||||||
REMOTE_PLAY_RESOLUTION = 'xhome_resolution',
|
REMOTE_PLAY_RESOLUTION = 'xhome_resolution',
|
||||||
|
|
||||||
GAME_FORTNITE_FORCE_CONSOLE = 'game_fortnite_force_console',
|
GAME_FORTNITE_FORCE_CONSOLE = 'game_fortnite_force_console',
|
||||||
|
GAME_MSFS2020_FORCE_NATIVE_MKB = 'game_msfs2020_force_native_mkb',
|
||||||
}
|
}
|
||||||
|
83
src/index.ts
83
src/index.ts
@ -7,12 +7,11 @@ import { BxExposed } from "@utils/bx-exposed";
|
|||||||
import { t } from "@utils/translation";
|
import { t } from "@utils/translation";
|
||||||
import { interceptHttpRequests } from "@utils/network";
|
import { interceptHttpRequests } from "@utils/network";
|
||||||
import { CE } from "@utils/html";
|
import { CE } from "@utils/html";
|
||||||
import { showGamepadToast } from "@utils/gamepad";
|
import { showGamepadToast, updatePollingRate } from "@utils/gamepad";
|
||||||
import { EmulatedMkbHandler } from "@modules/mkb/mkb-handler";
|
import { EmulatedMkbHandler } from "@modules/mkb/mkb-handler";
|
||||||
import { StreamBadges } from "@modules/stream/stream-badges";
|
import { StreamBadges } from "@modules/stream/stream-badges";
|
||||||
import { StreamStats } from "@modules/stream/stream-stats";
|
import { StreamStats } from "@modules/stream/stream-stats";
|
||||||
import { addCss, preloadFonts } from "@utils/css";
|
import { addCss, preloadFonts } from "@utils/css";
|
||||||
import { Toast } from "@utils/toast";
|
|
||||||
import { LoadingScreen } from "@modules/loading-screen";
|
import { LoadingScreen } from "@modules/loading-screen";
|
||||||
import { MouseCursorHider } from "@modules/mkb/mouse-cursor-hider";
|
import { MouseCursorHider } from "@modules/mkb/mouse-cursor-hider";
|
||||||
import { TouchController } from "@modules/touch-controller";
|
import { TouchController } from "@modules/touch-controller";
|
||||||
@ -21,12 +20,11 @@ import { Patcher } from "@modules/patcher";
|
|||||||
import { RemotePlayManager } from "@/modules/remote-play-manager";
|
import { RemotePlayManager } from "@/modules/remote-play-manager";
|
||||||
import { onHistoryChanged, patchHistoryMethod } from "@utils/history";
|
import { onHistoryChanged, patchHistoryMethod } from "@utils/history";
|
||||||
import { VibrationManager } from "@modules/vibration-manager";
|
import { VibrationManager } from "@modules/vibration-manager";
|
||||||
import { overridePreloadState } from "@utils/preload-state";
|
|
||||||
import { disableAdobeAudienceManager, patchAudioContext, patchCanvasContext, patchMeControl, patchPointerLockApi, patchRtcCodecs, patchRtcPeerConnection, patchVideoApi } from "@utils/monkey-patches";
|
import { disableAdobeAudienceManager, patchAudioContext, patchCanvasContext, patchMeControl, patchPointerLockApi, patchRtcCodecs, patchRtcPeerConnection, patchVideoApi } from "@utils/monkey-patches";
|
||||||
import { AppInterface, STATES } from "@utils/global";
|
import { AppInterface, STATES } from "@utils/global";
|
||||||
import { BxLogger } from "@utils/bx-logger";
|
import { BxLogger } from "@utils/bx-logger";
|
||||||
import { GameBar } from "./modules/game-bar/game-bar";
|
import { GameBar } from "./modules/game-bar/game-bar";
|
||||||
import { Screenshot } from "./utils/screenshot";
|
import { ScreenshotManager } from "./utils/screenshot-manager";
|
||||||
import { NativeMkbHandler } from "./modules/mkb/native-mkb-handler";
|
import { NativeMkbHandler } from "./modules/mkb/native-mkb-handler";
|
||||||
import { GuideMenu } from "./modules/ui/guide-menu";
|
import { GuideMenu } from "./modules/ui/guide-menu";
|
||||||
import { updateVideoPlayer } from "./modules/stream/stream-settings-utils";
|
import { updateVideoPlayer } from "./modules/stream/stream-settings-utils";
|
||||||
@ -42,6 +40,7 @@ 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";
|
||||||
|
|
||||||
// Handle login page
|
// Handle login page
|
||||||
if (window.location.pathname.includes('/auth/msa')) {
|
if (window.location.pathname.includes('/auth/msa')) {
|
||||||
@ -169,7 +168,7 @@ document.addEventListener('readystatechange', e => {
|
|||||||
|
|
||||||
// Hide "Play with Friends" skeleton section
|
// Hide "Play with Friends" skeleton section
|
||||||
if (getPref(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.FRIENDS)) {
|
if (getPref(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.FRIENDS)) {
|
||||||
const $parent = document.querySelector('div[class*=PlayWithFriendsSkeleton]')?.closest('div[class*=HomePage-module]') as HTMLElement;
|
const $parent = document.querySelector('div[class*=PlayWithFriendsSkeleton]')?.closest<HTMLElement>('div[class*=HomePage-module]');
|
||||||
$parent && ($parent.style.display = 'none');
|
$parent && ($parent.style.display = 'none');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +192,7 @@ window.addEventListener(BxEvent.XCLOUD_SERVERS_UNAVAILABLE, e => {
|
|||||||
window.setTimeout(HeaderSection.watchHeader, 2000);
|
window.setTimeout(HeaderSection.watchHeader, 2000);
|
||||||
|
|
||||||
// Open Settings dialog on Unsupported page
|
// Open Settings dialog on Unsupported page
|
||||||
const $unsupportedPage = document.querySelector('div[class^=UnsupportedMarketPage-module__container]') as HTMLElement;
|
const $unsupportedPage = document.querySelector<HTMLElement>('div[class^=UnsupportedMarketPage-module__container]');
|
||||||
if ($unsupportedPage) {
|
if ($unsupportedPage) {
|
||||||
SettingsNavigationDialog.getInstance().show();
|
SettingsNavigationDialog.getInstance().show();
|
||||||
}
|
}
|
||||||
@ -240,7 +239,7 @@ window.addEventListener(BxEvent.STREAM_PLAYING, e => {
|
|||||||
|
|
||||||
if (isFullVersion()) {
|
if (isFullVersion()) {
|
||||||
const $video = (e as any).$video as HTMLVideoElement;
|
const $video = (e as any).$video as HTMLVideoElement;
|
||||||
Screenshot.updateCanvasSize($video.videoWidth, $video.videoHeight);
|
ScreenshotManager.getInstance().updateCanvasSize($video.videoWidth, $video.videoHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateVideoPlayer();
|
updateVideoPlayer();
|
||||||
@ -309,12 +308,13 @@ function unload() {
|
|||||||
window.BX_EXPOSED.stopTakRendering = false;
|
window.BX_EXPOSED.stopTakRendering = false;
|
||||||
|
|
||||||
NavigationDialogManager.getInstance().hide();
|
NavigationDialogManager.getInstance().hide();
|
||||||
StreamStats.getInstance().onStoppedPlaying();
|
StreamStats.getInstance().destroy();
|
||||||
|
StreamBadges.getInstance().destroy();
|
||||||
|
|
||||||
if (isFullVersion()) {
|
if (isFullVersion()) {
|
||||||
MouseCursorHider.stop();
|
MouseCursorHider.stop();
|
||||||
TouchController.reset();
|
TouchController.reset();
|
||||||
GameBar.getInstance().disable();
|
(getPref(PrefKey.GAME_BAR_POSITION) !== 'off') && GameBar.getInstance().disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,60 +324,15 @@ window.addEventListener('pagehide', e => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
isFullVersion() && window.addEventListener(BxEvent.CAPTURE_SCREENSHOT, e => {
|
isFullVersion() && window.addEventListener(BxEvent.CAPTURE_SCREENSHOT, e => {
|
||||||
Screenshot.takeScreenshot();
|
ScreenshotManager.getInstance().takeScreenshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function observeRootDialog($root: HTMLElement) {
|
|
||||||
let beingShown = false;
|
|
||||||
|
|
||||||
const observer = new MutationObserver(mutationList => {
|
|
||||||
for (const mutation of mutationList) {
|
|
||||||
if (mutation.type !== 'childList') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
BX_FLAGS.Debug && BxLogger.warning('RootDialog', 'added', mutation.addedNodes);
|
|
||||||
if (mutation.addedNodes.length === 1) {
|
|
||||||
const $addedElm = mutation.addedNodes[0];
|
|
||||||
if ($addedElm instanceof HTMLElement && $addedElm.className) {
|
|
||||||
// Make sure it's Guide dialog
|
|
||||||
if ($root.querySelector('div[class*=GuideDialog]')) {
|
|
||||||
GuideMenu.observe($addedElm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const shown = !!($root.firstElementChild && $root.firstElementChild.childElementCount > 0);
|
|
||||||
if (shown !== beingShown) {
|
|
||||||
beingShown = shown;
|
|
||||||
BxEvent.dispatch(window, shown ? BxEvent.XCLOUD_DIALOG_SHOWN : BxEvent.XCLOUD_DIALOG_DISMISSED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
observer.observe($root, {subtree: true, childList: true});
|
|
||||||
}
|
|
||||||
|
|
||||||
function waitForRootDialog() {
|
|
||||||
const observer = new MutationObserver(mutationList => {
|
|
||||||
for (const mutation of mutationList) {
|
|
||||||
if (mutation.type !== 'childList') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const $target = mutation.target as HTMLElement;
|
|
||||||
if ($target.id && $target.id === 'gamepass-dialog-root') {
|
|
||||||
observer.disconnect();
|
|
||||||
observeRootDialog($target);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
observer.observe(document.documentElement, {subtree: true, childList: true});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
|
if (getPref(PrefKey.GAME_MSFS2020_FORCE_NATIVE_MKB)) {
|
||||||
|
BX_FLAGS.ForceNativeMkbTitles.push('9PMQDM08SNK9');
|
||||||
|
}
|
||||||
|
|
||||||
// Monkey patches
|
// Monkey patches
|
||||||
patchRtcPeerConnection();
|
patchRtcPeerConnection();
|
||||||
patchRtcCodecs();
|
patchRtcCodecs();
|
||||||
@ -393,23 +348,19 @@ function main() {
|
|||||||
disableAdobeAudienceManager();
|
disableAdobeAudienceManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
waitForRootDialog();
|
RootDialogObserver.waitForRootDialog();
|
||||||
|
|
||||||
// Setup UI
|
// Setup UI
|
||||||
addCss();
|
addCss();
|
||||||
Toast.setup();
|
|
||||||
|
|
||||||
GuideMenu.addEventListeners();
|
GuideMenu.getInstance().addEventListeners();
|
||||||
StreamStatsCollector.setupEvents();
|
StreamStatsCollector.setupEvents();
|
||||||
StreamBadges.setupEvents();
|
StreamBadges.setupEvents();
|
||||||
StreamStats.setupEvents();
|
StreamStats.setupEvents();
|
||||||
|
|
||||||
if (isFullVersion()) {
|
if (isFullVersion()) {
|
||||||
(getPref(PrefKey.GAME_BAR_POSITION) !== 'off') && GameBar.getInstance();
|
updatePollingRate();
|
||||||
Screenshot.setup();
|
|
||||||
|
|
||||||
STATES.userAgent.capabilities.touch && TouchController.updateCustomList();
|
STATES.userAgent.capabilities.touch && TouchController.updateCustomList();
|
||||||
overridePreloadState();
|
|
||||||
|
|
||||||
VibrationManager.initialSetup();
|
VibrationManager.initialSetup();
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Screenshot } from "@utils/screenshot";
|
import { ScreenshotManager } from "@/utils/screenshot-manager";
|
||||||
import { GamepadKey } from "@enums/mkb";
|
import { GamepadKey } from "@enums/mkb";
|
||||||
import { PrompFont } from "@enums/prompt-font";
|
import { PrompFont } from "@enums/prompt-font";
|
||||||
import { CE, removeChildElements } from "@utils/html";
|
import { CE, removeChildElements } from "@utils/html";
|
||||||
@ -38,66 +38,67 @@ const enum ShortcutAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ControllerShortcut {
|
export class ControllerShortcut {
|
||||||
static readonly #STORAGE_KEY = 'better_xcloud_controller_shortcuts';
|
private static readonly STORAGE_KEY = 'better_xcloud_controller_shortcuts';
|
||||||
|
|
||||||
static #buttonsCache: {[key: string]: boolean[]} = {};
|
private static buttonsCache: {[key: string]: boolean[]} = {};
|
||||||
static #buttonsStatus: {[key: string]: boolean[]} = {};
|
private static buttonsStatus: {[key: string]: boolean[]} = {};
|
||||||
|
|
||||||
static #$selectProfile: HTMLSelectElement;
|
private static $selectProfile: HTMLSelectElement;
|
||||||
static #$selectActions: Partial<{[key in GamepadKey]: HTMLSelectElement}> = {};
|
private static $selectActions: Partial<{[key in GamepadKey]: HTMLSelectElement}> = {};
|
||||||
static #$container: HTMLElement;
|
private static $container: HTMLElement;
|
||||||
|
|
||||||
static #ACTIONS: {[key: string]: (ShortcutAction | null)[]} | null = null;
|
private static ACTIONS: {[key: string]: (ShortcutAction | null)[]} | null = null;
|
||||||
|
|
||||||
static reset(index: number) {
|
static reset(index: number) {
|
||||||
ControllerShortcut.#buttonsCache[index] = [];
|
ControllerShortcut.buttonsCache[index] = [];
|
||||||
ControllerShortcut.#buttonsStatus[index] = [];
|
ControllerShortcut.buttonsStatus[index] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
static handle(gamepad: Gamepad): boolean {
|
static handle(gamepad: Gamepad): boolean {
|
||||||
if (!ControllerShortcut.#ACTIONS) {
|
if (!ControllerShortcut.ACTIONS) {
|
||||||
ControllerShortcut.#ACTIONS = ControllerShortcut.#getActionsFromStorage();
|
ControllerShortcut.ACTIONS = ControllerShortcut.getActionsFromStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
const gamepadIndex = gamepad.index;
|
const gamepadIndex = gamepad.index;
|
||||||
const actions = ControllerShortcut.#ACTIONS![gamepad.id];
|
const actions = ControllerShortcut.ACTIONS![gamepad.id];
|
||||||
if (!actions) {
|
if (!actions) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move the buttons status from the previous frame to the cache
|
// Move the buttons status from the previous frame to the cache
|
||||||
ControllerShortcut.#buttonsCache[gamepadIndex] = ControllerShortcut.#buttonsStatus[gamepadIndex].slice(0);
|
ControllerShortcut.buttonsCache[gamepadIndex] = ControllerShortcut.buttonsStatus[gamepadIndex].slice(0);
|
||||||
// Clear the buttons status
|
// Clear the buttons status
|
||||||
ControllerShortcut.#buttonsStatus[gamepadIndex] = [];
|
ControllerShortcut.buttonsStatus[gamepadIndex] = [];
|
||||||
|
|
||||||
const pressed: boolean[] = [];
|
const pressed: boolean[] = [];
|
||||||
let otherButtonPressed = false;
|
let otherButtonPressed = false;
|
||||||
|
|
||||||
gamepad.buttons.forEach((button, index) => {
|
const entries = gamepad.buttons.entries();
|
||||||
|
for (const [index, button] of entries) {
|
||||||
// Only add the newly pressed button to the array (holding doesn't count)
|
// Only add the newly pressed button to the array (holding doesn't count)
|
||||||
if (button.pressed && index !== GamepadKey.HOME) {
|
if (button.pressed && index !== GamepadKey.HOME) {
|
||||||
otherButtonPressed = true;
|
otherButtonPressed = true;
|
||||||
pressed[index] = true;
|
pressed[index] = true;
|
||||||
|
|
||||||
// If this is newly pressed button -> run action
|
// If this is newly pressed button -> run action
|
||||||
if (actions[index] && !ControllerShortcut.#buttonsCache[gamepadIndex][index]) {
|
if (actions[index] && !ControllerShortcut.buttonsCache[gamepadIndex][index]) {
|
||||||
setTimeout(() => ControllerShortcut.#runAction(actions[index]!), 0);
|
setTimeout(() => ControllerShortcut.runAction(actions[index]!), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
ControllerShortcut.#buttonsStatus[gamepadIndex] = pressed;
|
ControllerShortcut.buttonsStatus[gamepadIndex] = pressed;
|
||||||
return otherButtonPressed;
|
return otherButtonPressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
static #runAction(action: ShortcutAction) {
|
private static runAction(action: ShortcutAction) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ShortcutAction.BETTER_XCLOUD_SETTINGS_SHOW:
|
case ShortcutAction.BETTER_XCLOUD_SETTINGS_SHOW:
|
||||||
SettingsNavigationDialog.getInstance().show();
|
SettingsNavigationDialog.getInstance().show();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ShortcutAction.STREAM_SCREENSHOT_CAPTURE:
|
case ShortcutAction.STREAM_SCREENSHOT_CAPTURE:
|
||||||
Screenshot.takeScreenshot();
|
ScreenshotManager.getInstance().takeScreenshot();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ShortcutAction.STREAM_STATS_TOGGLE:
|
case ShortcutAction.STREAM_STATS_TOGGLE:
|
||||||
@ -134,8 +135,8 @@ export class ControllerShortcut {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static #updateAction(profile: string, button: GamepadKey, action: ShortcutAction | null) {
|
private static updateAction(profile: string, button: GamepadKey, action: ShortcutAction | null) {
|
||||||
const actions = ControllerShortcut.#ACTIONS!;
|
const actions = ControllerShortcut.ACTIONS!;
|
||||||
if (!(profile in actions)) {
|
if (!(profile in actions)) {
|
||||||
actions[profile] = [];
|
actions[profile] = [];
|
||||||
}
|
}
|
||||||
@ -147,9 +148,9 @@ export class ControllerShortcut {
|
|||||||
actions[profile][button] = action;
|
actions[profile][button] = action;
|
||||||
|
|
||||||
// Remove empty profiles
|
// Remove empty profiles
|
||||||
for (const key in ControllerShortcut.#ACTIONS) {
|
for (const key in ControllerShortcut.ACTIONS) {
|
||||||
let empty = true;
|
let empty = true;
|
||||||
for (const value of ControllerShortcut.#ACTIONS[key]) {
|
for (const value of ControllerShortcut.ACTIONS[key]) {
|
||||||
if (!!value) {
|
if (!!value) {
|
||||||
empty = false;
|
empty = false;
|
||||||
break;
|
break;
|
||||||
@ -157,19 +158,17 @@ export class ControllerShortcut {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (empty) {
|
if (empty) {
|
||||||
delete ControllerShortcut.#ACTIONS[key];
|
delete ControllerShortcut.ACTIONS[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save to storage
|
// Save to storage
|
||||||
window.localStorage.setItem(ControllerShortcut.#STORAGE_KEY, JSON.stringify(ControllerShortcut.#ACTIONS));
|
window.localStorage.setItem(ControllerShortcut.STORAGE_KEY, JSON.stringify(ControllerShortcut.ACTIONS));
|
||||||
|
|
||||||
console.log(ControllerShortcut.#ACTIONS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static #updateProfileList(e?: GamepadEvent) {
|
private static updateProfileList(e?: GamepadEvent) {
|
||||||
const $select = ControllerShortcut.#$selectProfile;
|
const $select = ControllerShortcut.$selectProfile;
|
||||||
const $container = ControllerShortcut.#$container;
|
const $container = ControllerShortcut.$container;
|
||||||
|
|
||||||
const $fragment = document.createDocumentFragment();
|
const $fragment = document.createDocumentFragment();
|
||||||
|
|
||||||
@ -205,16 +204,16 @@ export class ControllerShortcut {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static #switchProfile(profile: string) {
|
private static switchProfile(profile: string) {
|
||||||
let actions = ControllerShortcut.#ACTIONS![profile];
|
let actions = ControllerShortcut.ACTIONS![profile];
|
||||||
if (!actions) {
|
if (!actions) {
|
||||||
actions = [];
|
actions = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset selects' values
|
// Reset selects' values
|
||||||
let button: any;
|
let button: any;
|
||||||
for (button in ControllerShortcut.#$selectActions) {
|
for (button in ControllerShortcut.$selectActions) {
|
||||||
const $select = ControllerShortcut.#$selectActions[button as GamepadKey]!;
|
const $select = ControllerShortcut.$selectActions[button as GamepadKey]!;
|
||||||
$select.value = actions[button] || '';
|
$select.value = actions[button] || '';
|
||||||
|
|
||||||
BxEvent.dispatch($select, 'input', {
|
BxEvent.dispatch($select, 'input', {
|
||||||
@ -224,15 +223,15 @@ export class ControllerShortcut {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static #getActionsFromStorage() {
|
private static getActionsFromStorage() {
|
||||||
return JSON.parse(window.localStorage.getItem(ControllerShortcut.#STORAGE_KEY) || '{}');
|
return JSON.parse(window.localStorage.getItem(ControllerShortcut.STORAGE_KEY) || '{}');
|
||||||
}
|
}
|
||||||
|
|
||||||
static renderSettings() {
|
static renderSettings() {
|
||||||
const PREF_CONTROLLER_FRIENDLY_UI = getPref(PrefKey.UI_CONTROLLER_FRIENDLY);
|
const PREF_CONTROLLER_FRIENDLY_UI = getPref(PrefKey.UI_CONTROLLER_FRIENDLY);
|
||||||
|
|
||||||
// Read actions from localStorage
|
// Read actions from localStorage
|
||||||
ControllerShortcut.#ACTIONS = ControllerShortcut.#getActionsFromStorage();
|
ControllerShortcut.ACTIONS = ControllerShortcut.getActionsFromStorage();
|
||||||
|
|
||||||
const buttons: Map<GamepadKey, PrompFont> = new Map();
|
const buttons: Map<GamepadKey, PrompFont> = new Map();
|
||||||
buttons.set(GamepadKey.Y, PrompFont.Y);
|
buttons.set(GamepadKey.Y, PrompFont.Y);
|
||||||
@ -340,7 +339,7 @@ export class ControllerShortcut {
|
|||||||
);
|
);
|
||||||
|
|
||||||
$selectProfile.addEventListener('input', e => {
|
$selectProfile.addEventListener('input', e => {
|
||||||
ControllerShortcut.#switchProfile($selectProfile.value);
|
ControllerShortcut.switchProfile($selectProfile.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
const onActionChanged = (e: Event) => {
|
const onActionChanged = (e: Event) => {
|
||||||
@ -361,7 +360,7 @@ export class ControllerShortcut {
|
|||||||
($fakeSelect.firstElementChild as HTMLOptionElement).text = fakeText;
|
($fakeSelect.firstElementChild as HTMLOptionElement).text = fakeText;
|
||||||
}
|
}
|
||||||
|
|
||||||
!(e as any).ignoreOnChange && ControllerShortcut.#updateAction(profile, button as GamepadKey, action);
|
!(e as any).ignoreOnChange && ControllerShortcut.updateAction(profile, button as GamepadKey, action);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -387,7 +386,7 @@ export class ControllerShortcut {
|
|||||||
$select.dataset.button = button.toString();
|
$select.dataset.button = button.toString();
|
||||||
$select.addEventListener('input', onActionChanged);
|
$select.addEventListener('input', onActionChanged);
|
||||||
|
|
||||||
ControllerShortcut.#$selectActions[button] = $select;
|
ControllerShortcut.$selectActions[button] = $select;
|
||||||
|
|
||||||
if (PREF_CONTROLLER_FRIENDLY_UI) {
|
if (PREF_CONTROLLER_FRIENDLY_UI) {
|
||||||
const $bxSelect = BxSelectElement.wrap($select);
|
const $bxSelect = BxSelectElement.wrap($select);
|
||||||
@ -412,14 +411,14 @@ export class ControllerShortcut {
|
|||||||
|
|
||||||
$container.appendChild($remap);
|
$container.appendChild($remap);
|
||||||
|
|
||||||
ControllerShortcut.#$selectProfile = $selectProfile;
|
ControllerShortcut.$selectProfile = $selectProfile;
|
||||||
ControllerShortcut.#$container = $container;
|
ControllerShortcut.$container = $container;
|
||||||
|
|
||||||
// Detect when gamepad connected/disconnect
|
// Detect when gamepad connected/disconnect
|
||||||
window.addEventListener('gamepadconnected', ControllerShortcut.#updateProfileList);
|
window.addEventListener('gamepadconnected', ControllerShortcut.updateProfileList);
|
||||||
window.addEventListener('gamepaddisconnected', ControllerShortcut.#updateProfileList);
|
window.addEventListener('gamepaddisconnected', ControllerShortcut.updateProfileList);
|
||||||
|
|
||||||
ControllerShortcut.#updateProfileList();
|
ControllerShortcut.updateProfileList();
|
||||||
|
|
||||||
return $container;
|
return $container;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ export class Dialog {
|
|||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
// Create dialog overlay
|
// Create dialog overlay
|
||||||
const $overlay = document.querySelector('.bx-dialog-overlay') as HTMLElement;
|
const $overlay = document.querySelector<HTMLElement>('.bx-dialog-overlay');
|
||||||
|
|
||||||
if (!$overlay) {
|
if (!$overlay) {
|
||||||
this.$overlay = CE('div', {'class': 'bx-dialog-overlay bx-gone'});
|
this.$overlay = CE('div', {'class': 'bx-dialog-overlay bx-gone'});
|
||||||
|
@ -1,6 +1,16 @@
|
|||||||
|
import { BxEvent } from "@/utils/bx-event";
|
||||||
|
|
||||||
export abstract class BaseGameBarAction {
|
export abstract class BaseGameBarAction {
|
||||||
|
abstract $content: HTMLElement;
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
reset() {}
|
reset() {}
|
||||||
|
|
||||||
abstract render(): HTMLElement;
|
onClick(e: Event) {
|
||||||
|
BxEvent.dispatch(window, BxEvent.GAME_BAR_ACTION_ACTIVATED);
|
||||||
|
};
|
||||||
|
|
||||||
|
render(): HTMLElement {
|
||||||
|
return this.$content;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -8,56 +8,42 @@ import { MicrophoneShortcut, MicrophoneState } from "../shortcuts/shortcut-micro
|
|||||||
export class MicrophoneAction extends BaseGameBarAction {
|
export class MicrophoneAction extends BaseGameBarAction {
|
||||||
$content: HTMLElement;
|
$content: HTMLElement;
|
||||||
|
|
||||||
visible: boolean = false;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
const onClick = (e: Event) => {
|
|
||||||
BxEvent.dispatch(window, BxEvent.GAME_BAR_ACTION_ACTIVATED);
|
|
||||||
|
|
||||||
const enabled = MicrophoneShortcut.toggle(false);
|
|
||||||
this.$content.setAttribute('data-enabled', enabled.toString());
|
|
||||||
};
|
|
||||||
|
|
||||||
const $btnDefault = createButton({
|
const $btnDefault = createButton({
|
||||||
style: ButtonStyle.GHOST,
|
style: ButtonStyle.GHOST,
|
||||||
icon: BxIcon.MICROPHONE,
|
icon: BxIcon.MICROPHONE,
|
||||||
onClick: onClick,
|
onClick: this.onClick.bind(this),
|
||||||
classes: ['bx-activated'],
|
classes: ['bx-activated'],
|
||||||
});
|
});
|
||||||
|
|
||||||
const $btnMuted = createButton({
|
const $btnMuted = createButton({
|
||||||
style: ButtonStyle.GHOST,
|
style: ButtonStyle.GHOST,
|
||||||
icon: BxIcon.MICROPHONE_MUTED,
|
icon: BxIcon.MICROPHONE_MUTED,
|
||||||
onClick: onClick,
|
onClick: this.onClick.bind(this),
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$content = CE('div', {},
|
this.$content = CE('div', {}, $btnMuted, $btnDefault);
|
||||||
$btnDefault,
|
|
||||||
$btnMuted,
|
|
||||||
);
|
|
||||||
|
|
||||||
this.reset();
|
|
||||||
|
|
||||||
window.addEventListener(BxEvent.MICROPHONE_STATE_CHANGED, e => {
|
window.addEventListener(BxEvent.MICROPHONE_STATE_CHANGED, e => {
|
||||||
const microphoneState = (e as any).microphoneState;
|
const microphoneState = (e as any).microphoneState;
|
||||||
const enabled = microphoneState === MicrophoneState.ENABLED;
|
const enabled = microphoneState === MicrophoneState.ENABLED;
|
||||||
|
this.$content.dataset.activated = enabled.toString();
|
||||||
this.$content.setAttribute('data-enabled', enabled.toString());
|
|
||||||
|
|
||||||
// Show the button in Game Bar if the mic is enabled
|
// Show the button in Game Bar if the mic is enabled
|
||||||
this.$content.classList.remove('bx-gone');
|
this.$content.classList.remove('bx-gone');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render(): HTMLElement {
|
onClick(e: Event) {
|
||||||
return this.$content;
|
super.onClick(e);
|
||||||
|
const enabled = MicrophoneShortcut.toggle(false);
|
||||||
|
this.$content.dataset.activated = enabled.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
reset(): void {
|
reset(): void {
|
||||||
this.visible = false;
|
|
||||||
this.$content.classList.add('bx-gone');
|
this.$content.classList.add('bx-gone');
|
||||||
this.$content.setAttribute('data-enabled', 'false');
|
this.$content.dataset.activated = 'false';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
38
src/modules/game-bar/action-renderer.ts
Normal file
38
src/modules/game-bar/action-renderer.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import { BxIcon } from "@utils/bx-icon";
|
||||||
|
import { createButton, ButtonStyle, CE } from "@utils/html";
|
||||||
|
import { BaseGameBarAction } from "./action-base";
|
||||||
|
import { RendererShortcut } from "../shortcuts/shortcut-renderer";
|
||||||
|
|
||||||
|
|
||||||
|
export class RendererAction extends BaseGameBarAction {
|
||||||
|
$content: HTMLElement;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
const $btnDefault = createButton({
|
||||||
|
style: ButtonStyle.GHOST,
|
||||||
|
icon: BxIcon.EYE,
|
||||||
|
onClick: this.onClick.bind(this),
|
||||||
|
});
|
||||||
|
|
||||||
|
const $btnActivated = createButton({
|
||||||
|
style: ButtonStyle.GHOST,
|
||||||
|
icon: BxIcon.EYE_SLASH,
|
||||||
|
onClick: this.onClick.bind(this),
|
||||||
|
classes: ['bx-activated'],
|
||||||
|
});
|
||||||
|
|
||||||
|
this.$content = CE('div', {}, $btnDefault, $btnActivated);
|
||||||
|
}
|
||||||
|
|
||||||
|
onClick(e: Event) {
|
||||||
|
super.onClick(e);
|
||||||
|
const isVisible = RendererShortcut.toggleVisibility();
|
||||||
|
this.$content.dataset.activated = (!isVisible).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
reset(): void {
|
||||||
|
this.$content.dataset.activated = 'false';
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,8 @@
|
|||||||
import { BxEvent } from "@utils/bx-event";
|
|
||||||
import { BxIcon } from "@utils/bx-icon";
|
import { BxIcon } from "@utils/bx-icon";
|
||||||
import { createButton, ButtonStyle } from "@utils/html";
|
import { createButton, ButtonStyle } from "@utils/html";
|
||||||
import { BaseGameBarAction } from "./action-base";
|
import { BaseGameBarAction } from "./action-base";
|
||||||
import { t } from "@utils/translation";
|
import { t } from "@utils/translation";
|
||||||
import { Screenshot } from "@/utils/screenshot";
|
import { ScreenshotManager } from "@/utils/screenshot-manager";
|
||||||
|
|
||||||
export class ScreenshotAction extends BaseGameBarAction {
|
export class ScreenshotAction extends BaseGameBarAction {
|
||||||
$content: HTMLElement;
|
$content: HTMLElement;
|
||||||
@ -11,20 +10,16 @@ export class ScreenshotAction extends BaseGameBarAction {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
const onClick = (e: Event) => {
|
|
||||||
BxEvent.dispatch(window, BxEvent.GAME_BAR_ACTION_ACTIVATED);
|
|
||||||
Screenshot.takeScreenshot();
|
|
||||||
};
|
|
||||||
|
|
||||||
this.$content = createButton({
|
this.$content = createButton({
|
||||||
style: ButtonStyle.GHOST,
|
style: ButtonStyle.GHOST,
|
||||||
icon: BxIcon.SCREENSHOT,
|
icon: BxIcon.SCREENSHOT,
|
||||||
title: t('take-screenshot'),
|
title: t('take-screenshot'),
|
||||||
onClick: onClick,
|
onClick: this.onClick.bind(this),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render(): HTMLElement {
|
onClick(e: Event): void {
|
||||||
return this.$content;
|
super.onClick(e);
|
||||||
|
ScreenshotManager.getInstance().takeScreenshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,44 +11,35 @@ export class SpeakerAction extends BaseGameBarAction {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
const onClick = (e: Event) => {
|
|
||||||
BxEvent.dispatch(window, BxEvent.GAME_BAR_ACTION_ACTIVATED);
|
|
||||||
SoundShortcut.muteUnmute();
|
|
||||||
};
|
|
||||||
|
|
||||||
const $btnEnable = createButton({
|
const $btnEnable = createButton({
|
||||||
style: ButtonStyle.GHOST,
|
style: ButtonStyle.GHOST,
|
||||||
icon: BxIcon.AUDIO,
|
icon: BxIcon.AUDIO,
|
||||||
onClick: onClick,
|
onClick: this.onClick.bind(this),
|
||||||
});
|
});
|
||||||
|
|
||||||
const $btnMuted = createButton({
|
const $btnMuted = createButton({
|
||||||
style: ButtonStyle.GHOST,
|
style: ButtonStyle.GHOST,
|
||||||
icon: BxIcon.SPEAKER_MUTED,
|
icon: BxIcon.SPEAKER_MUTED,
|
||||||
onClick: onClick,
|
onClick: this.onClick.bind(this),
|
||||||
classes: ['bx-activated'],
|
classes: ['bx-activated'],
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$content = CE('div', {},
|
this.$content = CE('div', {}, $btnEnable, $btnMuted);
|
||||||
$btnEnable,
|
|
||||||
$btnMuted,
|
|
||||||
);
|
|
||||||
|
|
||||||
this.reset();
|
|
||||||
|
|
||||||
window.addEventListener(BxEvent.SPEAKER_STATE_CHANGED, e => {
|
window.addEventListener(BxEvent.SPEAKER_STATE_CHANGED, e => {
|
||||||
const speakerState = (e as any).speakerState;
|
const speakerState = (e as any).speakerState;
|
||||||
const enabled = speakerState === SpeakerState.ENABLED;
|
const enabled = speakerState === SpeakerState.ENABLED;
|
||||||
|
|
||||||
this.$content.dataset.enabled = enabled.toString();
|
this.$content.dataset.activated = (!enabled).toString();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render(): HTMLElement {
|
onClick(e: Event) {
|
||||||
return this.$content;
|
super.onClick(e);
|
||||||
|
SoundShortcut.muteUnmute();
|
||||||
}
|
}
|
||||||
|
|
||||||
reset(): void {
|
reset(): void {
|
||||||
this.$content.dataset.enabled = 'true';
|
this.$content.dataset.activated = 'false';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { BxEvent } from "@utils/bx-event";
|
|
||||||
import { BxIcon } from "@utils/bx-icon";
|
import { BxIcon } from "@utils/bx-icon";
|
||||||
import { createButton, ButtonStyle, CE } from "@utils/html";
|
import { createButton, ButtonStyle, CE } from "@utils/html";
|
||||||
import { TouchController } from "@modules/touch-controller";
|
import { TouchController } from "@modules/touch-controller";
|
||||||
@ -11,44 +10,31 @@ export class TouchControlAction extends BaseGameBarAction {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
const onClick = (e: Event) => {
|
|
||||||
BxEvent.dispatch(window, BxEvent.GAME_BAR_ACTION_ACTIVATED);
|
|
||||||
|
|
||||||
const $parent = (e as any).target.closest('div[data-enabled]');
|
|
||||||
let enabled = $parent.getAttribute('data-enabled', 'true') === 'true';
|
|
||||||
$parent.setAttribute('data-enabled', (!enabled).toString());
|
|
||||||
|
|
||||||
TouchController.toggleVisibility(enabled);
|
|
||||||
};
|
|
||||||
|
|
||||||
const $btnEnable = createButton({
|
const $btnEnable = createButton({
|
||||||
style: ButtonStyle.GHOST,
|
style: ButtonStyle.GHOST,
|
||||||
icon: BxIcon.TOUCH_CONTROL_ENABLE,
|
icon: BxIcon.TOUCH_CONTROL_ENABLE,
|
||||||
title: t('show-touch-controller'),
|
title: t('show-touch-controller'),
|
||||||
onClick: onClick,
|
onClick: this.onClick.bind(this),
|
||||||
});
|
});
|
||||||
|
|
||||||
const $btnDisable = createButton({
|
const $btnDisable = createButton({
|
||||||
style: ButtonStyle.GHOST,
|
style: ButtonStyle.GHOST,
|
||||||
icon: BxIcon.TOUCH_CONTROL_DISABLE,
|
icon: BxIcon.TOUCH_CONTROL_DISABLE,
|
||||||
title: t('hide-touch-controller'),
|
title: t('hide-touch-controller'),
|
||||||
onClick: onClick,
|
onClick: this.onClick.bind(this),
|
||||||
classes: ['bx-activated'],
|
classes: ['bx-activated'],
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$content = CE('div', {},
|
this.$content = CE('div', {}, $btnEnable, $btnDisable);
|
||||||
$btnEnable,
|
|
||||||
$btnDisable,
|
|
||||||
);
|
|
||||||
|
|
||||||
this.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render(): HTMLElement {
|
onClick(e: Event) {
|
||||||
return this.$content;
|
super.onClick(e);
|
||||||
|
const isVisible = TouchController.toggleVisibility();
|
||||||
|
this.$content.dataset.activated = (!isVisible).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
reset(): void {
|
reset(): void {
|
||||||
this.$content.setAttribute('data-enabled', 'true');
|
this.$content.dataset.activated = 'false';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import { BxEvent } from "@/utils/bx-event";
|
|
||||||
import { BxIcon } from "@/utils/bx-icon";
|
import { BxIcon } from "@/utils/bx-icon";
|
||||||
import { createButton, ButtonStyle } from "@/utils/html";
|
import { createButton, ButtonStyle } from "@/utils/html";
|
||||||
import { t } from "@/utils/translation";
|
|
||||||
import { BaseGameBarAction } from "./action-base";
|
import { BaseGameBarAction } from "./action-base";
|
||||||
import { TrueAchievements } from "@/utils/true-achievements";
|
import { TrueAchievements } from "@/utils/true-achievements";
|
||||||
|
|
||||||
@ -11,20 +9,15 @@ export class TrueAchievementsAction extends BaseGameBarAction {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
const onClick = (e: Event) => {
|
|
||||||
BxEvent.dispatch(window, BxEvent.GAME_BAR_ACTION_ACTIVATED);
|
|
||||||
TrueAchievements.open(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.$content = createButton({
|
this.$content = createButton({
|
||||||
style: ButtonStyle.GHOST,
|
style: ButtonStyle.GHOST,
|
||||||
icon: BxIcon.TRUE_ACHIEVEMENTS,
|
icon: BxIcon.TRUE_ACHIEVEMENTS,
|
||||||
title: t('true-achievements'),
|
onClick: this.onClick.bind(this),
|
||||||
onClick: onClick,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render(): HTMLElement {
|
onClick(e: Event) {
|
||||||
return this.$content;
|
super.onClick(e);
|
||||||
|
TrueAchievements.getInstance().open(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { CE, clearFocus, createSvgIcon } from "@utils/html";
|
import { CE, createSvgIcon } from "@utils/html";
|
||||||
import { ScreenshotAction } from "./action-screenshot";
|
import { ScreenshotAction } from "./action-screenshot";
|
||||||
import { TouchControlAction } from "./action-touch-control";
|
import { TouchControlAction } from "./action-touch-control";
|
||||||
import { BxEvent } from "@utils/bx-event";
|
import { BxEvent } from "@utils/bx-event";
|
||||||
@ -7,44 +7,44 @@ import type { BaseGameBarAction } from "./action-base";
|
|||||||
import { STATES } from "@utils/global";
|
import { STATES } from "@utils/global";
|
||||||
import { MicrophoneAction } from "./action-microphone";
|
import { MicrophoneAction } from "./action-microphone";
|
||||||
import { PrefKey } from "@/enums/pref-keys";
|
import { PrefKey } from "@/enums/pref-keys";
|
||||||
import { getPref, StreamTouchController } from "@/utils/settings-storages/global-settings-storage";
|
import { getPref, StreamTouchController, type GameBarPosition } from "@/utils/settings-storages/global-settings-storage";
|
||||||
import { TrueAchievementsAction } from "./action-true-achievements";
|
import { TrueAchievementsAction } from "./action-true-achievements";
|
||||||
import { SpeakerAction } from "./action-speaker";
|
import { SpeakerAction } from "./action-speaker";
|
||||||
|
import { RendererAction } from "./action-renderer";
|
||||||
|
import { BxLogger } from "@/utils/bx-logger";
|
||||||
|
|
||||||
|
|
||||||
export class GameBar {
|
export class GameBar {
|
||||||
private static instance: GameBar;
|
private static instance: GameBar;
|
||||||
public static getInstance(): GameBar {
|
public static getInstance = () => GameBar.instance ?? (GameBar.instance = new GameBar());
|
||||||
if (!GameBar.instance) {
|
private readonly LOG_TAG = 'GameBar';
|
||||||
GameBar.instance = new GameBar();
|
|
||||||
}
|
|
||||||
|
|
||||||
return GameBar.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static readonly VISIBLE_DURATION = 2000;
|
private static readonly VISIBLE_DURATION = 2000;
|
||||||
|
|
||||||
private $gameBar: HTMLElement;
|
private $gameBar: HTMLElement;
|
||||||
private $container: HTMLElement;
|
private $container: HTMLElement;
|
||||||
|
|
||||||
private timeout: number | null = null;
|
private timeoutId: number | null = null;
|
||||||
|
|
||||||
private actions: BaseGameBarAction[] = [];
|
private actions: BaseGameBarAction[] = [];
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
|
|
||||||
let $container;
|
let $container;
|
||||||
|
|
||||||
const position = getPref(PrefKey.GAME_BAR_POSITION);
|
const position = getPref(PrefKey.GAME_BAR_POSITION) as GameBarPosition;
|
||||||
|
|
||||||
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'}),
|
||||||
createSvgIcon(position === 'bottom-left' ? BxIcon.CARET_RIGHT : BxIcon.CARET_LEFT),
|
createSvgIcon(position === 'bottom-left' ? BxIcon.CARET_RIGHT : BxIcon.CARET_LEFT),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.actions = [
|
this.actions = [
|
||||||
new ScreenshotAction(),
|
new ScreenshotAction(),
|
||||||
...(STATES.userAgent.capabilities.touch && (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) !== StreamTouchController.OFF) ? [new TouchControlAction()] : []),
|
...(STATES.userAgent.capabilities.touch && (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) !== StreamTouchController.OFF) ? [new TouchControlAction()] : []),
|
||||||
new SpeakerAction(),
|
new SpeakerAction(),
|
||||||
|
new RendererAction(),
|
||||||
new MicrophoneAction(),
|
new MicrophoneAction(),
|
||||||
new TrueAchievementsAction(),
|
new TrueAchievementsAction(),
|
||||||
];
|
];
|
||||||
@ -76,11 +76,7 @@ export class GameBar {
|
|||||||
|
|
||||||
// Add animation when hiding game bar
|
// Add animation when hiding game bar
|
||||||
$container.addEventListener('transitionend', e => {
|
$container.addEventListener('transitionend', e => {
|
||||||
const classList = $container.classList;
|
$container.classList.replace('bx-hide', 'bx-offscreen');
|
||||||
if (classList.contains('bx-hide')) {
|
|
||||||
classList.remove('bx-hide');
|
|
||||||
classList.add('bx-offscreen');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
document.documentElement.appendChild($gameBar);
|
document.documentElement.appendChild($gameBar);
|
||||||
@ -89,45 +85,38 @@ export class GameBar {
|
|||||||
|
|
||||||
// Enable/disable Game Bar when playing/pausing
|
// Enable/disable Game Bar when playing/pausing
|
||||||
getPref(PrefKey.GAME_BAR_POSITION) !== 'off' && window.addEventListener(BxEvent.XCLOUD_POLLING_MODE_CHANGED, ((e: Event) => {
|
getPref(PrefKey.GAME_BAR_POSITION) !== 'off' && window.addEventListener(BxEvent.XCLOUD_POLLING_MODE_CHANGED, ((e: Event) => {
|
||||||
if (!STATES.isPlaying) {
|
|
||||||
this.disable();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Toggle Game bar
|
// Toggle Game bar
|
||||||
const mode = (e as any).mode;
|
if (STATES.isPlaying) {
|
||||||
mode !== 'none' ? this.disable() : this.enable();
|
const mode = (e as any).mode;
|
||||||
|
mode !== 'none' ? this.disable() : this.enable();
|
||||||
|
}
|
||||||
}).bind(this));
|
}).bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private beginHideTimeout() {
|
private beginHideTimeout() {
|
||||||
this.clearHideTimeout();
|
this.clearHideTimeout();
|
||||||
|
|
||||||
this.timeout = window.setTimeout(() => {
|
this.timeoutId = window.setTimeout(() => {
|
||||||
this.timeout = null;
|
this.timeoutId = null;
|
||||||
this.hideBar();
|
this.hideBar();
|
||||||
}, GameBar.VISIBLE_DURATION);
|
}, GameBar.VISIBLE_DURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
private clearHideTimeout() {
|
private clearHideTimeout() {
|
||||||
this.timeout && clearTimeout(this.timeout);
|
this.timeoutId && clearTimeout(this.timeoutId);
|
||||||
this.timeout = null;
|
this.timeoutId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
enable() {
|
enable() {
|
||||||
this.$gameBar && this.$gameBar.classList.remove('bx-gone');
|
this.$gameBar.classList.remove('bx-gone');
|
||||||
}
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
this.hideBar();
|
this.hideBar();
|
||||||
this.$gameBar && this.$gameBar.classList.add('bx-gone');
|
this.$gameBar.classList.add('bx-gone');
|
||||||
}
|
}
|
||||||
|
|
||||||
showBar() {
|
showBar() {
|
||||||
if (!this.$container) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.$container.classList.remove('bx-offscreen', 'bx-hide' , 'bx-gone');
|
this.$container.classList.remove('bx-offscreen', 'bx-hide' , 'bx-gone');
|
||||||
this.$container.classList.add('bx-show');
|
this.$container.classList.add('bx-show');
|
||||||
|
|
||||||
@ -136,16 +125,7 @@ export class GameBar {
|
|||||||
|
|
||||||
hideBar() {
|
hideBar() {
|
||||||
this.clearHideTimeout();
|
this.clearHideTimeout();
|
||||||
|
this.$container.classList.replace('bx-show', 'bx-hide');
|
||||||
// Stop focusing Game Bar
|
|
||||||
clearFocus();
|
|
||||||
|
|
||||||
if (!this.$container) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.$container.classList.remove('bx-show');
|
|
||||||
this.$container.classList.add('bx-hide');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset all states
|
// Reset all states
|
||||||
|
@ -7,13 +7,13 @@ import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
|||||||
import { compressCss } from "@macros/build" with {type: "macro"};
|
import { compressCss } from "@macros/build" with {type: "macro"};
|
||||||
|
|
||||||
export class LoadingScreen {
|
export class LoadingScreen {
|
||||||
static #$bgStyle: HTMLElement;
|
private static $bgStyle: HTMLElement;
|
||||||
static #$waitTimeBox: HTMLElement;
|
private static $waitTimeBox: HTMLElement;
|
||||||
|
|
||||||
static #waitTimeInterval?: number | null = null;
|
private static waitTimeInterval?: number | null = null;
|
||||||
static #orgWebTitle: string;
|
private static orgWebTitle: string;
|
||||||
|
|
||||||
static #secondsToString(seconds: number) {
|
private static secondsToString(seconds: number) {
|
||||||
const m = Math.floor(seconds / 60);
|
const m = Math.floor(seconds / 60);
|
||||||
const s = Math.floor(seconds % 60);
|
const s = Math.floor(seconds % 60);
|
||||||
|
|
||||||
@ -28,21 +28,21 @@ export class LoadingScreen {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LoadingScreen.#$bgStyle) {
|
if (!LoadingScreen.$bgStyle) {
|
||||||
const $bgStyle = CE('style');
|
const $bgStyle = CE('style');
|
||||||
document.documentElement.appendChild($bgStyle);
|
document.documentElement.appendChild($bgStyle);
|
||||||
LoadingScreen.#$bgStyle = $bgStyle;
|
LoadingScreen.$bgStyle = $bgStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadingScreen.#setBackground(titleInfo.product.heroImageUrl || titleInfo.product.titledHeroImageUrl || titleInfo.product.tileImageUrl);
|
LoadingScreen.setBackground(titleInfo.product.heroImageUrl || titleInfo.product.titledHeroImageUrl || titleInfo.product.tileImageUrl);
|
||||||
|
|
||||||
if (getPref(PrefKey.UI_LOADING_SCREEN_ROCKET) === 'hide') {
|
if (getPref(PrefKey.UI_LOADING_SCREEN_ROCKET) === 'hide') {
|
||||||
LoadingScreen.#hideRocket();
|
LoadingScreen.hideRocket();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static #hideRocket() {
|
private static hideRocket() {
|
||||||
let $bgStyle = LoadingScreen.#$bgStyle;
|
let $bgStyle = LoadingScreen.$bgStyle;
|
||||||
|
|
||||||
$bgStyle.textContent! += compressCss(`
|
$bgStyle.textContent! += compressCss(`
|
||||||
#game-stream div[class*=RocketAnimation-module__container] > svg {
|
#game-stream div[class*=RocketAnimation-module__container] > svg {
|
||||||
@ -55,9 +55,9 @@ export class LoadingScreen {
|
|||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
static #setBackground(imageUrl: string) {
|
private static setBackground(imageUrl: string) {
|
||||||
// Setup style tag
|
// Setup style tag
|
||||||
let $bgStyle = LoadingScreen.#$bgStyle;
|
let $bgStyle = LoadingScreen.$bgStyle;
|
||||||
|
|
||||||
// Limit max width to reduce image size
|
// Limit max width to reduce image size
|
||||||
imageUrl = imageUrl + '?w=1920';
|
imageUrl = imageUrl + '?w=1920';
|
||||||
@ -89,14 +89,14 @@ export class LoadingScreen {
|
|||||||
static setupWaitTime(waitTime: number) {
|
static setupWaitTime(waitTime: number) {
|
||||||
// Hide rocket when queing
|
// Hide rocket when queing
|
||||||
if (getPref(PrefKey.UI_LOADING_SCREEN_ROCKET) === 'hide-queue') {
|
if (getPref(PrefKey.UI_LOADING_SCREEN_ROCKET) === 'hide-queue') {
|
||||||
LoadingScreen.#hideRocket();
|
LoadingScreen.hideRocket();
|
||||||
}
|
}
|
||||||
|
|
||||||
let secondsLeft = waitTime;
|
let secondsLeft = waitTime;
|
||||||
let $countDown;
|
let $countDown;
|
||||||
let $estimated;
|
let $estimated;
|
||||||
|
|
||||||
LoadingScreen.#orgWebTitle = document.title;
|
LoadingScreen.orgWebTitle = document.title;
|
||||||
|
|
||||||
const endDate = new Date();
|
const endDate = new Date();
|
||||||
const timeZoneOffsetSeconds = endDate.getTimezoneOffset() * 60;
|
const timeZoneOffsetSeconds = endDate.getTimezoneOffset() * 60;
|
||||||
@ -104,9 +104,9 @@ export class LoadingScreen {
|
|||||||
|
|
||||||
let endDateStr = endDate.toISOString().slice(0, 19);
|
let endDateStr = endDate.toISOString().slice(0, 19);
|
||||||
endDateStr = endDateStr.substring(0, 10) + ' ' + endDateStr.substring(11, 19);
|
endDateStr = endDateStr.substring(0, 10) + ' ' + endDateStr.substring(11, 19);
|
||||||
endDateStr += ` (${LoadingScreen.#secondsToString(waitTime)})`;
|
endDateStr += ` (${LoadingScreen.secondsToString(waitTime)})`;
|
||||||
|
|
||||||
let $waitTimeBox = LoadingScreen.#$waitTimeBox;
|
let $waitTimeBox = LoadingScreen.$waitTimeBox;
|
||||||
if (!$waitTimeBox) {
|
if (!$waitTimeBox) {
|
||||||
$waitTimeBox = CE('div', {'class': 'bx-wait-time-box'},
|
$waitTimeBox = CE('div', {'class': 'bx-wait-time-box'},
|
||||||
CE('label', {}, t('server')),
|
CE('label', {}, t('server')),
|
||||||
@ -118,7 +118,7 @@ export class LoadingScreen {
|
|||||||
);
|
);
|
||||||
|
|
||||||
document.documentElement.appendChild($waitTimeBox);
|
document.documentElement.appendChild($waitTimeBox);
|
||||||
LoadingScreen.#$waitTimeBox = $waitTimeBox;
|
LoadingScreen.$waitTimeBox = $waitTimeBox;
|
||||||
} else {
|
} else {
|
||||||
$waitTimeBox.classList.remove('bx-gone');
|
$waitTimeBox.classList.remove('bx-gone');
|
||||||
$estimated = $waitTimeBox.querySelector('.bx-wait-time-estimated')!;
|
$estimated = $waitTimeBox.querySelector('.bx-wait-time-estimated')!;
|
||||||
@ -126,36 +126,36 @@ export class LoadingScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$estimated.textContent = endDateStr;
|
$estimated.textContent = endDateStr;
|
||||||
$countDown.textContent = LoadingScreen.#secondsToString(secondsLeft);
|
$countDown.textContent = LoadingScreen.secondsToString(secondsLeft);
|
||||||
document.title = `[${$countDown.textContent}] ${LoadingScreen.#orgWebTitle}`;
|
document.title = `[${$countDown.textContent}] ${LoadingScreen.orgWebTitle}`;
|
||||||
|
|
||||||
LoadingScreen.#waitTimeInterval = window.setInterval(() => {
|
LoadingScreen.waitTimeInterval = window.setInterval(() => {
|
||||||
secondsLeft--;
|
secondsLeft--;
|
||||||
$countDown.textContent = LoadingScreen.#secondsToString(secondsLeft);
|
$countDown.textContent = LoadingScreen.secondsToString(secondsLeft);
|
||||||
document.title = `[${$countDown.textContent}] ${LoadingScreen.#orgWebTitle}`;
|
document.title = `[${$countDown.textContent}] ${LoadingScreen.orgWebTitle}`;
|
||||||
|
|
||||||
if (secondsLeft <= 0) {
|
if (secondsLeft <= 0) {
|
||||||
LoadingScreen.#waitTimeInterval && clearInterval(LoadingScreen.#waitTimeInterval);
|
LoadingScreen.waitTimeInterval && clearInterval(LoadingScreen.waitTimeInterval);
|
||||||
LoadingScreen.#waitTimeInterval = null;
|
LoadingScreen.waitTimeInterval = null;
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
static hide() {
|
static hide() {
|
||||||
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.UI_LOADING_SCREEN_GAME_ART) && LoadingScreen.#$bgStyle) {
|
if (getPref(PrefKey.UI_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(`
|
||||||
#game-stream {
|
#game-stream {
|
||||||
background: #000 !important;
|
background: #000 !important;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
LoadingScreen.#$bgStyle.textContent += compressCss(`
|
LoadingScreen.$bgStyle.textContent += compressCss(`
|
||||||
#game-stream rect[width="800"] {
|
#game-stream rect[width="800"] {
|
||||||
opacity: 1 !important;
|
opacity: 1 !important;
|
||||||
}
|
}
|
||||||
@ -166,10 +166,10 @@ export class LoadingScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static reset() {
|
static reset() {
|
||||||
LoadingScreen.#$bgStyle && (LoadingScreen.#$bgStyle.textContent = '');
|
LoadingScreen.$bgStyle && (LoadingScreen.$bgStyle.textContent = '');
|
||||||
|
|
||||||
LoadingScreen.#$waitTimeBox && LoadingScreen.#$waitTimeBox.classList.add('bx-gone');
|
LoadingScreen.$waitTimeBox && LoadingScreen.$waitTimeBox.classList.add('bx-gone');
|
||||||
LoadingScreen.#waitTimeInterval && clearInterval(LoadingScreen.#waitTimeInterval);
|
LoadingScreen.waitTimeInterval && clearInterval(LoadingScreen.waitTimeInterval);
|
||||||
LoadingScreen.#waitTimeInterval = null;
|
LoadingScreen.waitTimeInterval = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import { createButton, ButtonStyle, CE } from "@utils/html";
|
|||||||
import { BxEvent } from "@utils/bx-event";
|
import { BxEvent } from "@utils/bx-event";
|
||||||
import { Toast } from "@utils/toast";
|
import { Toast } from "@utils/toast";
|
||||||
import { t } from "@utils/translation";
|
import { t } from "@utils/translation";
|
||||||
import { LocalDb } from "@utils/local-db";
|
|
||||||
import { KeyHelper } from "./key-helper";
|
import { KeyHelper } from "./key-helper";
|
||||||
import type { MkbStoredPreset } from "@/types/mkb";
|
import type { MkbStoredPreset } from "@/types/mkb";
|
||||||
import { AppInterface, STATES } from "@utils/global";
|
import { AppInterface, STATES } from "@utils/global";
|
||||||
@ -19,8 +18,7 @@ import { SettingsNavigationDialog } from "../ui/dialog/settings-dialog";
|
|||||||
import { NavigationDialogManager } from "../ui/dialog/navigation-dialog";
|
import { NavigationDialogManager } from "../ui/dialog/navigation-dialog";
|
||||||
import { PrefKey } from "@/enums/pref-keys";
|
import { PrefKey } from "@/enums/pref-keys";
|
||||||
import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
||||||
|
import { MkbPresetsDb } from "@/utils/local-db/mkb-presets-db";
|
||||||
const LOG_TAG = 'MkbHandler';
|
|
||||||
|
|
||||||
const PointerToMouseButton = {
|
const PointerToMouseButton = {
|
||||||
1: 0,
|
1: 0,
|
||||||
@ -124,14 +122,9 @@ This class uses some code from Yuzu emulator to handle mouse's movements
|
|||||||
Source: https://github.com/yuzu-emu/yuzu-mainline/blob/master/src/input_common/drivers/mouse.cpp
|
Source: https://github.com/yuzu-emu/yuzu-mainline/blob/master/src/input_common/drivers/mouse.cpp
|
||||||
*/
|
*/
|
||||||
export class EmulatedMkbHandler extends MkbHandler {
|
export class EmulatedMkbHandler extends MkbHandler {
|
||||||
static #instance: EmulatedMkbHandler;
|
private static instance: EmulatedMkbHandler;
|
||||||
public static getInstance(): EmulatedMkbHandler {
|
public static getInstance = () => EmulatedMkbHandler.instance ?? (EmulatedMkbHandler.instance = new EmulatedMkbHandler());
|
||||||
if (!EmulatedMkbHandler.#instance) {
|
private static readonly LOG_TAG = 'EmulatedMkbHandler';
|
||||||
EmulatedMkbHandler.#instance = new EmulatedMkbHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
return EmulatedMkbHandler.#instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
#CURRENT_PRESET_DATA = MkbPreset.convert(MkbPreset.DEFAULT_PRESET);
|
#CURRENT_PRESET_DATA = MkbPreset.convert(MkbPreset.DEFAULT_PRESET);
|
||||||
|
|
||||||
@ -173,8 +166,9 @@ export class EmulatedMkbHandler extends MkbHandler {
|
|||||||
#RIGHT_STICK_X: GamepadKey[] = [];
|
#RIGHT_STICK_X: GamepadKey[] = [];
|
||||||
#RIGHT_STICK_Y: GamepadKey[] = [];
|
#RIGHT_STICK_Y: GamepadKey[] = [];
|
||||||
|
|
||||||
constructor() {
|
private constructor() {
|
||||||
super();
|
super();
|
||||||
|
BxLogger.info(EmulatedMkbHandler.LOG_TAG, 'constructor()');
|
||||||
|
|
||||||
this.#STICK_MAP = {
|
this.#STICK_MAP = {
|
||||||
[GamepadKey.LS_LEFT]: [this.#LEFT_STICK_X, 0, -1],
|
[GamepadKey.LS_LEFT]: [this.#LEFT_STICK_X, 0, -1],
|
||||||
@ -437,7 +431,7 @@ export class EmulatedMkbHandler extends MkbHandler {
|
|||||||
#getCurrentPreset = (): Promise<MkbStoredPreset> => {
|
#getCurrentPreset = (): Promise<MkbStoredPreset> => {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
const presetId = getPref(PrefKey.MKB_DEFAULT_PRESET_ID);
|
const presetId = getPref(PrefKey.MKB_DEFAULT_PRESET_ID);
|
||||||
LocalDb.INSTANCE.getPreset(presetId).then((preset: MkbStoredPreset) => {
|
MkbPresetsDb.getInstance().getPreset(presetId).then((preset: MkbStoredPreset) => {
|
||||||
resolve(preset);
|
resolve(preset);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -686,7 +680,7 @@ export class EmulatedMkbHandler extends MkbHandler {
|
|||||||
AppInterface && NativeMkbHandler.getInstance().init();
|
AppInterface && NativeMkbHandler.getInstance().init();
|
||||||
}
|
}
|
||||||
} else if (getPref(PrefKey.MKB_ENABLED) && (AppInterface || !UserAgent.isMobile())) {
|
} else if (getPref(PrefKey.MKB_ENABLED) && (AppInterface || !UserAgent.isMobile())) {
|
||||||
BxLogger.info(LOG_TAG, 'Emulate MKB');
|
BxLogger.info(EmulatedMkbHandler.LOG_TAG, 'Emulate MKB');
|
||||||
EmulatedMkbHandler.getInstance().init();
|
EmulatedMkbHandler.getInstance().init();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -130,7 +130,6 @@ export class MkbPreset {
|
|||||||
mouse[MkbPresetKey.MOUSE_MAP_TO] = MkbPreset.MOUSE_SETTINGS[MkbPresetKey.MOUSE_MAP_TO].default;
|
mouse[MkbPresetKey.MOUSE_MAP_TO] = MkbPreset.MOUSE_SETTINGS[MkbPresetKey.MOUSE_MAP_TO].default;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(obj);
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import { CE, createButton, ButtonStyle } from "@utils/html";
|
import { CE, createButton, ButtonStyle, removeChildElements } from "@utils/html";
|
||||||
import { t } from "@utils/translation";
|
import { t } from "@utils/translation";
|
||||||
import { Dialog } from "@modules/dialog";
|
import { Dialog } from "@modules/dialog";
|
||||||
import { KeyHelper } from "./key-helper";
|
import { KeyHelper } from "./key-helper";
|
||||||
import { MkbPreset } from "./mkb-preset";
|
import { MkbPreset } from "./mkb-preset";
|
||||||
import { EmulatedMkbHandler } from "./mkb-handler";
|
import { EmulatedMkbHandler } from "./mkb-handler";
|
||||||
import { LocalDb } from "@utils/local-db";
|
|
||||||
import { BxIcon } from "@utils/bx-icon";
|
import { BxIcon } from "@utils/bx-icon";
|
||||||
import type { MkbPresetData, MkbStoredPresets } from "@/types/mkb";
|
import type { MkbPresetData, MkbStoredPresets } from "@/types/mkb";
|
||||||
import { MkbPresetKey, GamepadKey, GamepadKeyName } from "@enums/mkb";
|
import { MkbPresetKey, GamepadKey, GamepadKeyName } from "@enums/mkb";
|
||||||
@ -12,18 +11,10 @@ import { deepClone } from "@utils/global";
|
|||||||
import { SettingElement } from "@/utils/setting-element";
|
import { SettingElement } from "@/utils/setting-element";
|
||||||
import { PrefKey } from "@/enums/pref-keys";
|
import { PrefKey } from "@/enums/pref-keys";
|
||||||
import { getPref, setPref } from "@/utils/settings-storages/global-settings-storage";
|
import { getPref, setPref } from "@/utils/settings-storages/global-settings-storage";
|
||||||
|
import { MkbPresetsDb } from "@/utils/local-db/mkb-presets-db";
|
||||||
|
import { BxLogger } from "@/utils/bx-logger";
|
||||||
|
|
||||||
|
|
||||||
type MkbRemapperElements = {
|
|
||||||
wrapper: HTMLElement | null;
|
|
||||||
presetsSelect: HTMLSelectElement | null;
|
|
||||||
activateButton: HTMLButtonElement | null;
|
|
||||||
currentBindingKey: HTMLElement | null;
|
|
||||||
|
|
||||||
allKeyElements: HTMLElement[];
|
|
||||||
allMouseElements: {[key in MkbPresetKey]?: HTMLElement};
|
|
||||||
};
|
|
||||||
|
|
||||||
type MkbRemapperStates = {
|
type MkbRemapperStates = {
|
||||||
currentPresetId: number;
|
currentPresetId: number;
|
||||||
presets: MkbStoredPresets;
|
presets: MkbStoredPresets;
|
||||||
@ -33,7 +24,7 @@ type MkbRemapperStates = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class MkbRemapper {
|
export class MkbRemapper {
|
||||||
readonly #BUTTON_ORDERS = [
|
private readonly BUTTON_ORDERS = [
|
||||||
GamepadKey.UP,
|
GamepadKey.UP,
|
||||||
GamepadKey.DOWN,
|
GamepadKey.DOWN,
|
||||||
GamepadKey.LEFT,
|
GamepadKey.LEFT,
|
||||||
@ -66,169 +57,170 @@ export class MkbRemapper {
|
|||||||
GamepadKey.RS_RIGHT,
|
GamepadKey.RS_RIGHT,
|
||||||
];
|
];
|
||||||
|
|
||||||
static #instance: MkbRemapper;
|
private static instance: MkbRemapper;
|
||||||
static get INSTANCE() {
|
public static getInstance = () => MkbRemapper.instance ?? (MkbRemapper.instance = new MkbRemapper());
|
||||||
if (!MkbRemapper.#instance) {
|
private readonly LOG_TAG = 'MkbRemapper';
|
||||||
MkbRemapper.#instance = new MkbRemapper();
|
|
||||||
}
|
|
||||||
|
|
||||||
return MkbRemapper.#instance;
|
private states: MkbRemapperStates = {
|
||||||
};
|
|
||||||
|
|
||||||
#STATE: MkbRemapperStates = {
|
|
||||||
currentPresetId: 0,
|
currentPresetId: 0,
|
||||||
presets: {},
|
presets: {},
|
||||||
|
|
||||||
editingPresetData: null,
|
editingPresetData: null,
|
||||||
|
|
||||||
isEditing: false,
|
isEditing: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
#$: MkbRemapperElements = {
|
private $wrapper!: HTMLElement;
|
||||||
wrapper: null,
|
private $presetsSelect!: HTMLSelectElement;
|
||||||
presetsSelect: null,
|
private $activateButton!: HTMLButtonElement;
|
||||||
activateButton: null,
|
|
||||||
|
|
||||||
currentBindingKey: null,
|
private $currentBindingKey!: HTMLElement;
|
||||||
|
|
||||||
allKeyElements: [],
|
private allKeyElements: HTMLElement[] = [];
|
||||||
allMouseElements: {},
|
private allMouseElements: {[key in MkbPresetKey]?: HTMLElement} = {};
|
||||||
};
|
|
||||||
|
|
||||||
bindingDialog: Dialog;
|
bindingDialog: Dialog;
|
||||||
|
|
||||||
constructor() {
|
private constructor() {
|
||||||
this.#STATE.currentPresetId = getPref(PrefKey.MKB_DEFAULT_PRESET_ID);
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
|
this.states.currentPresetId = getPref(PrefKey.MKB_DEFAULT_PRESET_ID);
|
||||||
|
|
||||||
this.bindingDialog = new Dialog({
|
this.bindingDialog = new Dialog({
|
||||||
className: 'bx-binding-dialog',
|
className: 'bx-binding-dialog',
|
||||||
content: CE('div', {},
|
content: CE('div', {},
|
||||||
CE('p', {}, t('press-to-bind')),
|
CE('p', {}, t('press-to-bind')),
|
||||||
CE('i', {}, t('press-esc-to-cancel')),
|
CE('i', {}, t('press-esc-to-cancel')),
|
||||||
),
|
),
|
||||||
hideCloseButton: true,
|
hideCloseButton: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#clearEventListeners = () => {
|
private clearEventListeners = () => {
|
||||||
window.removeEventListener('keydown', this.#onKeyDown);
|
window.removeEventListener('keydown', this.onKeyDown);
|
||||||
window.removeEventListener('mousedown', this.#onMouseDown);
|
window.removeEventListener('mousedown', this.onMouseDown);
|
||||||
window.removeEventListener('wheel', this.#onWheel);
|
window.removeEventListener('wheel', this.onWheel);
|
||||||
};
|
};
|
||||||
|
|
||||||
#bindKey = ($elm: HTMLElement, key: any) => {
|
private bindKey = ($elm: HTMLElement, key: any) => {
|
||||||
const buttonIndex = parseInt($elm.getAttribute('data-button-index')!);
|
const buttonIndex = parseInt($elm.dataset.buttonIndex!);
|
||||||
const keySlot = parseInt($elm.getAttribute('data-key-slot')!);
|
const keySlot = parseInt($elm.dataset.keySlot!);
|
||||||
|
|
||||||
// Ignore if bind the save key to the same element
|
// Ignore if bind the save key to the same element
|
||||||
if ($elm.getAttribute('data-key-code') === key.code) {
|
if ($elm.dataset.keyCode! === key.code) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unbind duplicated keys
|
// Unbind duplicated keys
|
||||||
for (const $otherElm of this.#$.allKeyElements) {
|
for (const $otherElm of this.allKeyElements) {
|
||||||
if ($otherElm.getAttribute('data-key-code') === key.code) {
|
if ($otherElm.dataset.keyCode === key.code) {
|
||||||
this.#unbindKey($otherElm);
|
this.unbindKey($otherElm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#STATE.editingPresetData!.mapping[buttonIndex][keySlot] = key.code;
|
this.states.editingPresetData!.mapping[buttonIndex][keySlot] = key.code;
|
||||||
$elm.textContent = key.name;
|
$elm.textContent = key.name;
|
||||||
$elm.setAttribute('data-key-code', key.code);
|
$elm.dataset.keyCode = key.code;
|
||||||
}
|
}
|
||||||
|
|
||||||
#unbindKey = ($elm: HTMLElement) => {
|
private unbindKey = ($elm: HTMLElement) => {
|
||||||
const buttonIndex = parseInt($elm.getAttribute('data-button-index')!);
|
const buttonIndex = parseInt($elm.dataset.buttonIndex!);
|
||||||
const keySlot = parseInt($elm.getAttribute('data-key-slot')!);
|
const keySlot = parseInt($elm.dataset.keySlot!);
|
||||||
|
|
||||||
// Remove key from preset
|
// Remove key from preset
|
||||||
this.#STATE.editingPresetData!.mapping[buttonIndex][keySlot] = null;
|
this.states.editingPresetData!.mapping[buttonIndex][keySlot] = null;
|
||||||
$elm.textContent = '';
|
$elm.textContent = '';
|
||||||
$elm.removeAttribute('data-key-code');
|
delete $elm.dataset.keyCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
#onWheel = (e: WheelEvent) => {
|
private onWheel = (e: WheelEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.#clearEventListeners();
|
this.clearEventListeners();
|
||||||
|
|
||||||
this.#bindKey(this.#$.currentBindingKey!, KeyHelper.getKeyFromEvent(e));
|
this.bindKey(this.$currentBindingKey!, KeyHelper.getKeyFromEvent(e));
|
||||||
window.setTimeout(() => this.bindingDialog.hide(), 200);
|
window.setTimeout(() => this.bindingDialog.hide(), 200);
|
||||||
};
|
};
|
||||||
|
|
||||||
#onMouseDown = (e: MouseEvent) => {
|
private onMouseDown = (e: MouseEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.#clearEventListeners();
|
this.clearEventListeners();
|
||||||
|
|
||||||
this.#bindKey(this.#$.currentBindingKey!, KeyHelper.getKeyFromEvent(e));
|
this.bindKey(this.$currentBindingKey!, KeyHelper.getKeyFromEvent(e));
|
||||||
window.setTimeout(() => this.bindingDialog.hide(), 200);
|
window.setTimeout(() => this.bindingDialog.hide(), 200);
|
||||||
};
|
};
|
||||||
|
|
||||||
#onKeyDown = (e: KeyboardEvent) => {
|
private onKeyDown = (e: KeyboardEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.#clearEventListeners();
|
this.clearEventListeners();
|
||||||
|
|
||||||
if (e.code !== 'Escape') {
|
if (e.code !== 'Escape') {
|
||||||
this.#bindKey(this.#$.currentBindingKey!, KeyHelper.getKeyFromEvent(e));
|
this.bindKey(this.$currentBindingKey!, KeyHelper.getKeyFromEvent(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
window.setTimeout(() => this.bindingDialog.hide(), 200);
|
window.setTimeout(() => this.bindingDialog.hide(), 200);
|
||||||
};
|
};
|
||||||
|
|
||||||
#onBindingKey = (e: MouseEvent) => {
|
private onBindingKey = (e: MouseEvent) => {
|
||||||
if (!this.#STATE.isEditing || e.button !== 0) {
|
if (!this.states.isEditing || e.button !== 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
|
||||||
this.#$.currentBindingKey = e.target as HTMLElement;
|
this.$currentBindingKey = e.target as HTMLElement;
|
||||||
|
|
||||||
window.addEventListener('keydown', this.#onKeyDown);
|
window.addEventListener('keydown', this.onKeyDown);
|
||||||
window.addEventListener('mousedown', this.#onMouseDown);
|
window.addEventListener('mousedown', this.onMouseDown);
|
||||||
window.addEventListener('wheel', this.#onWheel);
|
window.addEventListener('wheel', this.onWheel);
|
||||||
|
|
||||||
this.bindingDialog.show({title: this.#$.currentBindingKey.getAttribute('data-prompt')!});
|
this.bindingDialog.show({title: this.$currentBindingKey.dataset.prompt!});
|
||||||
};
|
};
|
||||||
|
|
||||||
#onContextMenu = (e: Event) => {
|
private onContextMenu = (e: Event) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!this.#STATE.isEditing) {
|
if (!this.states.isEditing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#unbindKey(e.target as HTMLElement);
|
this.unbindKey(e.target as HTMLElement);
|
||||||
};
|
};
|
||||||
|
|
||||||
#getPreset = (presetId: number) => {
|
private getPreset = (presetId: number) => {
|
||||||
return this.#STATE.presets[presetId];
|
return this.states.presets[presetId];
|
||||||
}
|
}
|
||||||
|
|
||||||
#getCurrentPreset = () => {
|
private getCurrentPreset = () => {
|
||||||
return this.#getPreset(this.#STATE.currentPresetId);
|
let preset = this.getPreset(this.states.currentPresetId);
|
||||||
|
if (!preset) {
|
||||||
|
// Get the first preset in the list
|
||||||
|
const firstPresetId = parseInt(Object.keys(this.states.presets)[0]);
|
||||||
|
preset = this.states.presets[firstPresetId];
|
||||||
|
this.states.currentPresetId = firstPresetId;
|
||||||
|
setPref(PrefKey.MKB_DEFAULT_PRESET_ID, firstPresetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return preset;
|
||||||
}
|
}
|
||||||
|
|
||||||
#switchPreset = (presetId: number) => {
|
private switchPreset = (presetId: number) => {
|
||||||
this.#STATE.currentPresetId = presetId;
|
this.states.currentPresetId = presetId;
|
||||||
const presetData = this.#getCurrentPreset().data;
|
const presetData = this.getCurrentPreset().data;
|
||||||
|
|
||||||
for (const $elm of this.#$.allKeyElements) {
|
for (const $elm of this.allKeyElements) {
|
||||||
const buttonIndex = parseInt($elm.getAttribute('data-button-index')!);
|
const buttonIndex = parseInt($elm.dataset.buttonIndex!);
|
||||||
const keySlot = parseInt($elm.getAttribute('data-key-slot')!);
|
const keySlot = parseInt($elm.dataset.keySlot!);
|
||||||
|
|
||||||
const buttonKeys = presetData.mapping[buttonIndex];
|
const buttonKeys = presetData.mapping[buttonIndex];
|
||||||
if (buttonKeys && buttonKeys[keySlot]) {
|
if (buttonKeys && buttonKeys[keySlot]) {
|
||||||
$elm.textContent = KeyHelper.codeToKeyName(buttonKeys[keySlot]!);
|
$elm.textContent = KeyHelper.codeToKeyName(buttonKeys[keySlot]!);
|
||||||
$elm.setAttribute('data-key-code', buttonKeys[keySlot]!);
|
$elm.dataset.keyCode = buttonKeys[keySlot]!;
|
||||||
} else {
|
} else {
|
||||||
$elm.textContent = '';
|
$elm.textContent = '';
|
||||||
$elm.removeAttribute('data-key-code');
|
delete $elm.dataset.keyCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let key: MkbPresetKey;
|
let key: MkbPresetKey;
|
||||||
for (key in this.#$.allMouseElements) {
|
for (key in this.allMouseElements) {
|
||||||
const $elm = this.#$.allMouseElements[key]!;
|
const $elm = this.allMouseElements[key]!;
|
||||||
let value = presetData.mouse[key];
|
let value = presetData.mouse[key];
|
||||||
if (typeof value === 'undefined') {
|
if (typeof value === 'undefined') {
|
||||||
value = MkbPreset.MOUSE_SETTINGS[key].default;
|
value = MkbPreset.MOUSE_SETTINGS[key].default;
|
||||||
@ -238,74 +230,72 @@ export class MkbRemapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update state of Activate button
|
// Update state of Activate button
|
||||||
const activated = getPref(PrefKey.MKB_DEFAULT_PRESET_ID) === this.#STATE.currentPresetId;
|
const activated = getPref(PrefKey.MKB_DEFAULT_PRESET_ID) === this.states.currentPresetId;
|
||||||
this.#$.activateButton!.disabled = activated;
|
this.$activateButton.disabled = activated;
|
||||||
this.#$.activateButton!.querySelector('span')!.textContent = activated ? t('activated') : t('activate');
|
this.$activateButton.querySelector('span')!.textContent = activated ? t('activated') : t('activate');
|
||||||
}
|
}
|
||||||
|
|
||||||
#refresh() {
|
private async refresh() {
|
||||||
// Clear presets select
|
// Clear presets select
|
||||||
while (this.#$.presetsSelect!.firstChild) {
|
removeChildElements(this.$presetsSelect);
|
||||||
this.#$.presetsSelect!.removeChild(this.#$.presetsSelect!.firstChild);
|
|
||||||
|
const presets = await MkbPresetsDb.getInstance().getPresets();
|
||||||
|
|
||||||
|
this.states.presets = presets;
|
||||||
|
const fragment = document.createDocumentFragment();
|
||||||
|
|
||||||
|
let defaultPresetId;
|
||||||
|
if (this.states.currentPresetId === 0) {
|
||||||
|
this.states.currentPresetId = parseInt(Object.keys(presets)[0]);
|
||||||
|
|
||||||
|
defaultPresetId = this.states.currentPresetId;
|
||||||
|
setPref(PrefKey.MKB_DEFAULT_PRESET_ID, defaultPresetId);
|
||||||
|
EmulatedMkbHandler.getInstance().refreshPresetData();
|
||||||
|
} else {
|
||||||
|
defaultPresetId = getPref(PrefKey.MKB_DEFAULT_PRESET_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalDb.INSTANCE.getPresets().then(presets => {
|
for (let id in presets) {
|
||||||
this.#STATE.presets = presets;
|
const preset = presets[id];
|
||||||
const $fragment = document.createDocumentFragment();
|
let name = preset.name;
|
||||||
|
if (id === defaultPresetId) {
|
||||||
let defaultPresetId;
|
name = `🎮 ` + name;
|
||||||
if (this.#STATE.currentPresetId === 0) {
|
|
||||||
this.#STATE.currentPresetId = parseInt(Object.keys(presets)[0]);
|
|
||||||
|
|
||||||
defaultPresetId = this.#STATE.currentPresetId;
|
|
||||||
setPref(PrefKey.MKB_DEFAULT_PRESET_ID, defaultPresetId);
|
|
||||||
EmulatedMkbHandler.getInstance().refreshPresetData();
|
|
||||||
} else {
|
|
||||||
defaultPresetId = getPref(PrefKey.MKB_DEFAULT_PRESET_ID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let id in presets) {
|
const $options = CE<HTMLOptionElement>('option', {value: id}, name);
|
||||||
const preset = presets[id];
|
$options.selected = parseInt(id) === this.states.currentPresetId;
|
||||||
let name = preset.name;
|
|
||||||
if (id === defaultPresetId) {
|
|
||||||
name = `🎮 ` + name;
|
|
||||||
}
|
|
||||||
|
|
||||||
const $options = CE<HTMLOptionElement>('option', {value: id}, name);
|
fragment.appendChild($options);
|
||||||
$options.selected = parseInt(id) === this.#STATE.currentPresetId;
|
};
|
||||||
|
|
||||||
$fragment.appendChild($options);
|
this.$presetsSelect.appendChild(fragment);
|
||||||
};
|
|
||||||
|
|
||||||
this.#$.presetsSelect!.appendChild($fragment);
|
// Update state of Activate button
|
||||||
|
const activated = defaultPresetId === this.states.currentPresetId;
|
||||||
|
this.$activateButton.disabled = activated;
|
||||||
|
this.$activateButton.querySelector('span')!.textContent = activated ? t('activated') : t('activate');
|
||||||
|
|
||||||
// Update state of Activate button
|
!this.states.isEditing && this.switchPreset(this.states.currentPresetId);
|
||||||
const activated = defaultPresetId === this.#STATE.currentPresetId;
|
|
||||||
this.#$.activateButton!.disabled = activated;
|
|
||||||
this.#$.activateButton!.querySelector('span')!.textContent = activated ? t('activated') : t('activate');
|
|
||||||
|
|
||||||
!this.#STATE.isEditing && this.#switchPreset(this.#STATE.currentPresetId);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#toggleEditing = (force?: boolean) => {
|
private toggleEditing = (force?: boolean) => {
|
||||||
this.#STATE.isEditing = typeof force !== 'undefined' ? force : !this.#STATE.isEditing;
|
this.states.isEditing = typeof force !== 'undefined' ? force : !this.states.isEditing;
|
||||||
this.#$.wrapper!.classList.toggle('bx-editing', this.#STATE.isEditing);
|
this.$wrapper.classList.toggle('bx-editing', this.states.isEditing);
|
||||||
|
|
||||||
if (this.#STATE.isEditing) {
|
if (this.states.isEditing) {
|
||||||
this.#STATE.editingPresetData = deepClone(this.#getCurrentPreset().data);
|
this.states.editingPresetData = deepClone(this.getCurrentPreset().data);
|
||||||
} else {
|
} else {
|
||||||
this.#STATE.editingPresetData = null;
|
this.states.editingPresetData = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const childElements = this.#$.wrapper!.querySelectorAll('select, button, input');
|
const childElements = this.$wrapper.querySelectorAll('select, button, input');
|
||||||
for (const $elm of Array.from(childElements)) {
|
for (const $elm of Array.from(childElements)) {
|
||||||
if ($elm.parentElement!.parentElement!.classList.contains('bx-mkb-action-buttons')) {
|
if ($elm.parentElement!.parentElement!.classList.contains('bx-mkb-action-buttons')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let disable = !this.#STATE.isEditing;
|
let disable = !this.states.isEditing;
|
||||||
|
|
||||||
if ($elm.parentElement!.classList.contains('bx-mkb-preset-tools')) {
|
if ($elm.parentElement!.classList.contains('bx-mkb-preset-tools')) {
|
||||||
disable = !disable;
|
disable = !disable;
|
||||||
@ -316,14 +306,14 @@ export class MkbRemapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
this.#$.wrapper = CE('div', {'class': 'bx-mkb-settings'});
|
this.$wrapper = CE('div', {class: 'bx-mkb-settings'});
|
||||||
|
|
||||||
this.#$.presetsSelect = CE<HTMLSelectElement>('select', {tabindex: -1});
|
this.$presetsSelect = CE<HTMLSelectElement>('select', {tabindex: -1});
|
||||||
this.#$.presetsSelect!.addEventListener('change', e => {
|
this.$presetsSelect.addEventListener('change', e => {
|
||||||
this.#switchPreset(parseInt((e.target as HTMLSelectElement).value));
|
this.switchPreset(parseInt((e.target as HTMLSelectElement).value));
|
||||||
});
|
});
|
||||||
|
|
||||||
const promptNewName = (value?: string) => {
|
const promptNewName = (value: string) => {
|
||||||
let newName: string | null = '';
|
let newName: string | null = '';
|
||||||
while (!newName) {
|
while (!newName) {
|
||||||
newName = prompt(t('prompt-preset-name'), value);
|
newName = prompt(t('prompt-preset-name'), value);
|
||||||
@ -336,15 +326,15 @@ export class MkbRemapper {
|
|||||||
return newName ? newName : false;
|
return newName ? newName : false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const $header = CE('div', {'class': 'bx-mkb-preset-tools'},
|
const $header = CE('div', {class: 'bx-mkb-preset-tools'},
|
||||||
this.#$.presetsSelect,
|
this.$presetsSelect,
|
||||||
// Rename button
|
// Rename button
|
||||||
createButton({
|
createButton({
|
||||||
title: t('rename'),
|
title: t('rename'),
|
||||||
icon: BxIcon.CURSOR_TEXT,
|
icon: BxIcon.CURSOR_TEXT,
|
||||||
tabIndex: -1,
|
tabIndex: -1,
|
||||||
onClick: e => {
|
onClick: async () => {
|
||||||
const preset = this.#getCurrentPreset();
|
const preset = this.getCurrentPreset();
|
||||||
|
|
||||||
let newName = promptNewName(preset.name);
|
let newName = promptNewName(preset.name);
|
||||||
if (!newName || newName === preset.name) {
|
if (!newName || newName === preset.name) {
|
||||||
@ -353,28 +343,30 @@ export class MkbRemapper {
|
|||||||
|
|
||||||
// Update preset with new name
|
// Update preset with new name
|
||||||
preset.name = newName;
|
preset.name = newName;
|
||||||
LocalDb.INSTANCE.updatePreset(preset).then(id => this.#refresh());
|
|
||||||
|
await MkbPresetsDb.getInstance().updatePreset(preset);
|
||||||
|
await this.refresh();
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// New button
|
// New button
|
||||||
createButton({
|
createButton({
|
||||||
icon: BxIcon.NEW,
|
icon: BxIcon.NEW,
|
||||||
title: t('new'),
|
title: t('new'),
|
||||||
tabIndex: -1,
|
tabIndex: -1,
|
||||||
onClick: e => {
|
onClick: e => {
|
||||||
let newName = promptNewName('');
|
let newName = promptNewName('');
|
||||||
if (!newName) {
|
if (!newName) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new preset selected name
|
// Create new preset selected name
|
||||||
LocalDb.INSTANCE.newPreset(newName, MkbPreset.DEFAULT_PRESET).then(id => {
|
MkbPresetsDb.getInstance().newPreset(newName, MkbPreset.DEFAULT_PRESET).then(id => {
|
||||||
this.#STATE.currentPresetId = id;
|
this.states.currentPresetId = id;
|
||||||
this.#refresh();
|
this.refresh();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Copy button
|
// Copy button
|
||||||
createButton({
|
createButton({
|
||||||
@ -382,7 +374,7 @@ export class MkbRemapper {
|
|||||||
title: t('copy'),
|
title: t('copy'),
|
||||||
tabIndex: -1,
|
tabIndex: -1,
|
||||||
onClick: e => {
|
onClick: e => {
|
||||||
const preset = this.#getCurrentPreset();
|
const preset = this.getCurrentPreset();
|
||||||
|
|
||||||
let newName = promptNewName(`${preset.name} (2)`);
|
let newName = promptNewName(`${preset.name} (2)`);
|
||||||
if (!newName) {
|
if (!newName) {
|
||||||
@ -390,9 +382,9 @@ export class MkbRemapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create new preset selected name
|
// Create new preset selected name
|
||||||
LocalDb.INSTANCE.newPreset(newName, preset.data).then(id => {
|
MkbPresetsDb.getInstance().newPreset(newName, preset.data).then(id => {
|
||||||
this.#STATE.currentPresetId = id;
|
this.states.currentPresetId = id;
|
||||||
this.#refresh();
|
this.refresh();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@ -408,23 +400,23 @@ export class MkbRemapper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalDb.INSTANCE.deletePreset(this.#STATE.currentPresetId).then(id => {
|
MkbPresetsDb.getInstance().deletePreset(this.states.currentPresetId).then(id => {
|
||||||
this.#STATE.currentPresetId = 0;
|
this.states.currentPresetId = 0;
|
||||||
this.#refresh();
|
this.refresh();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.#$.wrapper!.appendChild($header);
|
this.$wrapper.appendChild($header);
|
||||||
|
|
||||||
const $rows = CE('div', {'class': 'bx-mkb-settings-rows'},
|
const $rows = CE('div', {class: 'bx-mkb-settings-rows'},
|
||||||
CE('i', {'class': 'bx-mkb-note'}, t('right-click-to-unbind')),
|
CE('i', {class: 'bx-mkb-note'}, t('right-click-to-unbind')),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Render keys
|
// Render keys
|
||||||
const keysPerButton = 2;
|
const keysPerButton = 2;
|
||||||
for (const buttonIndex of this.#BUTTON_ORDERS) {
|
for (const buttonIndex of this.BUTTON_ORDERS) {
|
||||||
const [buttonName, buttonPrompt] = GamepadKeyName[buttonIndex];
|
const [buttonName, buttonPrompt] = GamepadKeyName[buttonIndex];
|
||||||
|
|
||||||
let $elm;
|
let $elm;
|
||||||
@ -437,22 +429,22 @@ export class MkbRemapper {
|
|||||||
'data-key-slot': i,
|
'data-key-slot': i,
|
||||||
}, ' ');
|
}, ' ');
|
||||||
|
|
||||||
$elm.addEventListener('mouseup', this.#onBindingKey);
|
$elm.addEventListener('mouseup', this.onBindingKey);
|
||||||
$elm.addEventListener('contextmenu', this.#onContextMenu);
|
$elm.addEventListener('contextmenu', this.onContextMenu);
|
||||||
|
|
||||||
$fragment.appendChild($elm);
|
$fragment.appendChild($elm);
|
||||||
this.#$.allKeyElements.push($elm);
|
this.allKeyElements.push($elm);
|
||||||
}
|
}
|
||||||
|
|
||||||
const $keyRow = CE('div', {'class': 'bx-mkb-key-row'},
|
const $keyRow = CE('div', {class: 'bx-mkb-key-row'},
|
||||||
CE('label', {'title': buttonName}, buttonPrompt),
|
CE('label', {title: buttonName}, buttonPrompt),
|
||||||
$fragment,
|
$fragment,
|
||||||
);
|
);
|
||||||
|
|
||||||
$rows.appendChild($keyRow);
|
$rows.appendChild($keyRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
$rows.appendChild(CE('i', {'class': 'bx-mkb-note'}, t('mkb-adjust-ingame-settings')),);
|
$rows.appendChild(CE('i', {class: 'bx-mkb-note'}, t('mkb-adjust-ingame-settings')),);
|
||||||
|
|
||||||
// Render mouse settings
|
// Render mouse settings
|
||||||
const $mouseSettings = document.createDocumentFragment();
|
const $mouseSettings = document.createDocumentFragment();
|
||||||
@ -463,7 +455,7 @@ export class MkbRemapper {
|
|||||||
|
|
||||||
let $elm;
|
let $elm;
|
||||||
const onChange = (e: Event, value: any) => {
|
const onChange = (e: Event, value: any) => {
|
||||||
(this.#STATE.editingPresetData!.mouse as any)[key] = value;
|
(this.states.editingPresetData!.mouse as any)[key] = value;
|
||||||
};
|
};
|
||||||
const $row = CE('label', {
|
const $row = CE('label', {
|
||||||
class: 'bx-settings-row',
|
class: 'bx-settings-row',
|
||||||
@ -474,32 +466,32 @@ export class MkbRemapper {
|
|||||||
);
|
);
|
||||||
|
|
||||||
$mouseSettings.appendChild($row);
|
$mouseSettings.appendChild($row);
|
||||||
this.#$.allMouseElements[key as MkbPresetKey] = $elm;
|
this.allMouseElements[key as MkbPresetKey] = $elm;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rows.appendChild($mouseSettings);
|
$rows.appendChild($mouseSettings);
|
||||||
this.#$.wrapper!.appendChild($rows);
|
this.$wrapper.appendChild($rows);
|
||||||
|
|
||||||
// Render action buttons
|
// Render action buttons
|
||||||
const $actionButtons = CE('div', {'class': 'bx-mkb-action-buttons'},
|
const $actionButtons = CE('div', {class: 'bx-mkb-action-buttons'},
|
||||||
CE('div', {},
|
CE('div', {},
|
||||||
// Edit button
|
// Edit button
|
||||||
createButton({
|
createButton({
|
||||||
label: t('edit'),
|
label: t('edit'),
|
||||||
tabIndex: -1,
|
tabIndex: -1,
|
||||||
onClick: e => this.#toggleEditing(true),
|
onClick: e => this.toggleEditing(true),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Activate button
|
// Activate button
|
||||||
this.#$.activateButton = createButton({
|
this.$activateButton = createButton({
|
||||||
label: t('activate'),
|
label: t('activate'),
|
||||||
style: ButtonStyle.PRIMARY,
|
style: ButtonStyle.PRIMARY,
|
||||||
tabIndex: -1,
|
tabIndex: -1,
|
||||||
onClick: e => {
|
onClick: e => {
|
||||||
setPref(PrefKey.MKB_DEFAULT_PRESET_ID, this.#STATE.currentPresetId);
|
setPref(PrefKey.MKB_DEFAULT_PRESET_ID, this.states.currentPresetId);
|
||||||
EmulatedMkbHandler.getInstance().refreshPresetData();
|
EmulatedMkbHandler.getInstance().refreshPresetData();
|
||||||
|
|
||||||
this.#refresh();
|
this.refresh();
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@ -512,8 +504,8 @@ export class MkbRemapper {
|
|||||||
tabIndex: -1,
|
tabIndex: -1,
|
||||||
onClick: e => {
|
onClick: e => {
|
||||||
// Restore preset
|
// Restore preset
|
||||||
this.#switchPreset(this.#STATE.currentPresetId);
|
this.switchPreset(this.states.currentPresetId);
|
||||||
this.#toggleEditing(false);
|
this.toggleEditing(false);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -523,27 +515,27 @@ export class MkbRemapper {
|
|||||||
style: ButtonStyle.PRIMARY,
|
style: ButtonStyle.PRIMARY,
|
||||||
tabIndex: -1,
|
tabIndex: -1,
|
||||||
onClick: e => {
|
onClick: e => {
|
||||||
const updatedPreset = deepClone(this.#getCurrentPreset());
|
const updatedPreset = deepClone(this.getCurrentPreset());
|
||||||
updatedPreset.data = this.#STATE.editingPresetData as MkbPresetData;
|
updatedPreset.data = this.states.editingPresetData as MkbPresetData;
|
||||||
|
|
||||||
LocalDb.INSTANCE.updatePreset(updatedPreset).then(id => {
|
MkbPresetsDb.getInstance().updatePreset(updatedPreset).then(id => {
|
||||||
// If this is the default preset => refresh preset data
|
// If this is the default preset => refresh preset data
|
||||||
if (id === getPref(PrefKey.MKB_DEFAULT_PRESET_ID)) {
|
if (id === getPref(PrefKey.MKB_DEFAULT_PRESET_ID)) {
|
||||||
EmulatedMkbHandler.getInstance().refreshPresetData();
|
EmulatedMkbHandler.getInstance().refreshPresetData();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#toggleEditing(false);
|
this.toggleEditing(false);
|
||||||
this.#refresh();
|
this.refresh();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.#$.wrapper!.appendChild($actionButtons);
|
this.$wrapper.appendChild($actionButtons);
|
||||||
|
|
||||||
this.#toggleEditing(false);
|
this.toggleEditing(false);
|
||||||
this.#refresh();
|
this.refresh();
|
||||||
return this.#$.wrapper;
|
return this.$wrapper;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import { BxEvent } from "@/utils/bx-event";
|
|||||||
import { ButtonStyle, CE, createButton } from "@/utils/html";
|
import { ButtonStyle, CE, createButton } from "@/utils/html";
|
||||||
import { PrefKey } from "@/enums/pref-keys";
|
import { PrefKey } from "@/enums/pref-keys";
|
||||||
import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
||||||
|
import { BxLogger } from "@/utils/bx-logger";
|
||||||
|
|
||||||
type NativeMouseData = {
|
type NativeMouseData = {
|
||||||
X: number,
|
X: number,
|
||||||
@ -23,6 +24,9 @@ type XcloudInputSink = {
|
|||||||
|
|
||||||
export class NativeMkbHandler extends MkbHandler {
|
export class NativeMkbHandler extends MkbHandler {
|
||||||
private static instance: NativeMkbHandler;
|
private static instance: NativeMkbHandler;
|
||||||
|
public static getInstance = () => NativeMkbHandler.instance ?? (NativeMkbHandler.instance = new NativeMkbHandler());
|
||||||
|
private readonly LOG_TAG = 'NativeMkbHandler';
|
||||||
|
|
||||||
#pointerClient: PointerClient | undefined;
|
#pointerClient: PointerClient | undefined;
|
||||||
#enabled: boolean = false;
|
#enabled: boolean = false;
|
||||||
|
|
||||||
@ -37,12 +41,9 @@ export class NativeMkbHandler extends MkbHandler {
|
|||||||
|
|
||||||
#$message?: HTMLElement;
|
#$message?: HTMLElement;
|
||||||
|
|
||||||
public static getInstance(): NativeMkbHandler {
|
private constructor() {
|
||||||
if (!NativeMkbHandler.instance) {
|
super();
|
||||||
NativeMkbHandler.instance = new NativeMkbHandler();
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
}
|
|
||||||
|
|
||||||
return NativeMkbHandler.instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#onKeyboardEvent(e: KeyboardEvent) {
|
#onKeyboardEvent(e: KeyboardEvent) {
|
||||||
|
@ -2,8 +2,6 @@ import { BxLogger } from "@/utils/bx-logger";
|
|||||||
import { Toast } from "@/utils/toast";
|
import { Toast } from "@/utils/toast";
|
||||||
import type { MkbHandler } from "./base-mkb-handler";
|
import type { MkbHandler } from "./base-mkb-handler";
|
||||||
|
|
||||||
const LOG_TAG = 'PointerClient';
|
|
||||||
|
|
||||||
enum PointerAction {
|
enum PointerAction {
|
||||||
MOVE = 1,
|
MOVE = 1,
|
||||||
BUTTON_PRESS = 2,
|
BUTTON_PRESS = 2,
|
||||||
@ -15,45 +13,44 @@ enum PointerAction {
|
|||||||
|
|
||||||
export class PointerClient {
|
export class PointerClient {
|
||||||
private static instance: PointerClient;
|
private static instance: PointerClient;
|
||||||
public static getInstance(): PointerClient {
|
public static getInstance = () => PointerClient.instance ?? (PointerClient.instance = new PointerClient());
|
||||||
if (!PointerClient.instance) {
|
private readonly LOG_TAG = 'PointerClient';
|
||||||
PointerClient.instance = new PointerClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
return PointerClient.instance;
|
private socket: WebSocket | undefined | null;
|
||||||
|
private mkbHandler: MkbHandler | undefined;
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
}
|
}
|
||||||
|
|
||||||
#socket: WebSocket | undefined | null;
|
|
||||||
#mkbHandler: MkbHandler | undefined;
|
|
||||||
|
|
||||||
start(port: number, mkbHandler: MkbHandler) {
|
start(port: number, mkbHandler: MkbHandler) {
|
||||||
if (!port) {
|
if (!port) {
|
||||||
throw new Error('PointerServer port is 0');
|
throw new Error('PointerServer port is 0');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#mkbHandler = mkbHandler;
|
this.mkbHandler = mkbHandler;
|
||||||
|
|
||||||
// Create WebSocket connection.
|
// Create WebSocket connection.
|
||||||
this.#socket = new WebSocket(`ws://localhost:${port}`);
|
this.socket = new WebSocket(`ws://localhost:${port}`);
|
||||||
this.#socket.binaryType = 'arraybuffer';
|
this.socket.binaryType = 'arraybuffer';
|
||||||
|
|
||||||
// Connection opened
|
// Connection opened
|
||||||
this.#socket.addEventListener('open', (event) => {
|
this.socket.addEventListener('open', (event) => {
|
||||||
BxLogger.info(LOG_TAG, 'connected')
|
BxLogger.info(this.LOG_TAG, 'connected')
|
||||||
});
|
});
|
||||||
|
|
||||||
// Error
|
// Error
|
||||||
this.#socket.addEventListener('error', (event) => {
|
this.socket.addEventListener('error', (event) => {
|
||||||
BxLogger.error(LOG_TAG, event);
|
BxLogger.error(this.LOG_TAG, event);
|
||||||
Toast.show('Cannot setup mouse: ' + event);
|
Toast.show('Cannot setup mouse: ' + event);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.#socket.addEventListener('close', (event) => {
|
this.socket.addEventListener('close', (event) => {
|
||||||
this.#socket = null;
|
this.socket = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Listen for messages
|
// Listen for messages
|
||||||
this.#socket.addEventListener('message', (event) => {
|
this.socket.addEventListener('message', (event) => {
|
||||||
const dataView = new DataView(event.data);
|
const dataView = new DataView(event.data);
|
||||||
|
|
||||||
let messageType = dataView.getInt8(0);
|
let messageType = dataView.getInt8(0);
|
||||||
@ -84,7 +81,7 @@ export class PointerClient {
|
|||||||
offset += Int16Array.BYTES_PER_ELEMENT;
|
offset += Int16Array.BYTES_PER_ELEMENT;
|
||||||
const y = dataView.getInt16(offset);
|
const y = dataView.getInt16(offset);
|
||||||
|
|
||||||
this.#mkbHandler?.handleMouseMove({
|
this.mkbHandler?.handleMouseMove({
|
||||||
movementX: x,
|
movementX: x,
|
||||||
movementY: y,
|
movementY: y,
|
||||||
});
|
});
|
||||||
@ -94,7 +91,7 @@ export class PointerClient {
|
|||||||
onPress(messageType: PointerAction, dataView: DataView, offset: number) {
|
onPress(messageType: PointerAction, dataView: DataView, offset: number) {
|
||||||
const button = dataView.getUint8(offset);
|
const button = dataView.getUint8(offset);
|
||||||
|
|
||||||
this.#mkbHandler?.handleMouseClick({
|
this.mkbHandler?.handleMouseClick({
|
||||||
pointerButton: button,
|
pointerButton: button,
|
||||||
pressed: messageType === PointerAction.BUTTON_PRESS,
|
pressed: messageType === PointerAction.BUTTON_PRESS,
|
||||||
});
|
});
|
||||||
@ -108,7 +105,7 @@ export class PointerClient {
|
|||||||
offset += Int16Array.BYTES_PER_ELEMENT;
|
offset += Int16Array.BYTES_PER_ELEMENT;
|
||||||
const hScroll = dataView.getInt16(offset);
|
const hScroll = dataView.getInt16(offset);
|
||||||
|
|
||||||
this.#mkbHandler?.handleMouseWheel({
|
this.mkbHandler?.handleMouseWheel({
|
||||||
vertical: vScroll,
|
vertical: vScroll,
|
||||||
horizontal: hScroll,
|
horizontal: hScroll,
|
||||||
});
|
});
|
||||||
@ -118,13 +115,13 @@ export class PointerClient {
|
|||||||
|
|
||||||
onPointerCaptureChanged(dataView: DataView, offset: number) {
|
onPointerCaptureChanged(dataView: DataView, offset: number) {
|
||||||
const hasCapture = dataView.getInt8(offset) === 1;
|
const hasCapture = dataView.getInt8(offset) === 1;
|
||||||
!hasCapture && this.#mkbHandler?.stop();
|
!hasCapture && this.mkbHandler?.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
try {
|
try {
|
||||||
this.#socket?.close();
|
this.socket?.close();
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
this.#socket = null;
|
this.socket = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import { UiSection } from "@/enums/ui-sections.js";
|
|||||||
import { PrefKey } from "@/enums/pref-keys.js";
|
import { PrefKey } from "@/enums/pref-keys.js";
|
||||||
import { getPref, StreamTouchController } from "@/utils/settings-storages/global-settings-storage";
|
import { getPref, StreamTouchController } from "@/utils/settings-storages/global-settings-storage";
|
||||||
import { GamePassCloudGallery } from "@/enums/game-pass-gallery.js";
|
import { GamePassCloudGallery } from "@/enums/game-pass-gallery.js";
|
||||||
|
import { t } from "@/utils/translation.js";
|
||||||
|
|
||||||
type PatchArray = (keyof typeof PATCHES)[];
|
type PatchArray = (keyof typeof PATCHES)[];
|
||||||
|
|
||||||
@ -174,17 +175,16 @@ const PATCHES = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Remote Play: change web page's title
|
// Remote Play: change web page's title
|
||||||
/*
|
|
||||||
remotePlayWebTitle(str: string) {
|
remotePlayWebTitle(str: string) {
|
||||||
let text = '"undefined"!==typeof e&&document.title!==e';
|
let text = 'titleTemplate:void 0,title:';
|
||||||
if (!str.includes(text)) {
|
const index = str.indexOf(text);
|
||||||
|
if (index < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newCode = `if (window.BX_REMOTE_PLAY_CONFIG) { e = "${t('remote-play')} - ${t('better-xcloud')}"; }`;
|
str = PatcherUtils.insertAt(str, index + text.length, `!!window.BX_REMOTE_PLAY_CONFIG ? "${t('remote-play')} - Better xCloud" :`);
|
||||||
return str.replace(text, newCode + text);
|
return str;
|
||||||
},
|
},
|
||||||
*/
|
|
||||||
|
|
||||||
// Block WebRTC stats collector
|
// Block WebRTC stats collector
|
||||||
blockWebRtcStatsCollector(str: string) {
|
blockWebRtcStatsCollector(str: string) {
|
||||||
@ -202,16 +202,22 @@ const PATCHES = {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextIndex = str.indexOf('setTimeout(this.pollGamepads', index);
|
const setTimeoutIndex = str.indexOf('setTimeout(this.pollGamepads', index);
|
||||||
if (nextIndex === -1) {
|
if (setTimeoutIndex < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let codeBlock = str.substring(index, nextIndex);
|
let codeBlock = str.substring(index, setTimeoutIndex);
|
||||||
|
|
||||||
|
// Patch polling rate
|
||||||
|
const tmp = str.substring(setTimeoutIndex, setTimeoutIndex + 150);
|
||||||
|
const tmpPatched = tmp.replaceAll('Math.max(0,4-', 'Math.max(0,window.BX_CONTROLLER_POLLING_RATE-');
|
||||||
|
str = PatcherUtils.replaceWith(str, setTimeoutIndex, tmp, tmpPatched);
|
||||||
|
|
||||||
// Block gamepad stats collecting
|
// Block gamepad stats collecting
|
||||||
if (getPref(PrefKey.BLOCK_TRACKING)) {
|
if (getPref(PrefKey.BLOCK_TRACKING)) {
|
||||||
codeBlock = codeBlock.replaceAll('this.inputPollingIntervalStats.addValue', '');
|
codeBlock = codeBlock.replace('this.inputPollingIntervalStats.addValue', '');
|
||||||
|
codeBlock = codeBlock.replace('this.inputPollingDurationStats.addValue', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map the Share button on Xbox Series controller with the capturing screenshot feature
|
// Map the Share button on Xbox Series controller with the capturing screenshot feature
|
||||||
@ -219,13 +225,14 @@ const PATCHES = {
|
|||||||
if (match) {
|
if (match) {
|
||||||
const gamepadVar = match[1];
|
const gamepadVar = match[1];
|
||||||
const newCode = renderString(codeControllerShortcuts, {
|
const newCode = renderString(codeControllerShortcuts, {
|
||||||
gamepadVar,
|
gamepadVar,
|
||||||
});
|
});
|
||||||
|
|
||||||
codeBlock = codeBlock.replace('this.gamepadTimestamps.set', newCode + 'this.gamepadTimestamps.set');
|
codeBlock = codeBlock.replace('this.gamepadTimestamps.set', newCode + 'this.gamepadTimestamps.set');
|
||||||
}
|
}
|
||||||
|
|
||||||
return str.substring(0, index) + codeBlock + str.substring(nextIndex);
|
str = str.substring(0, index) + codeBlock + str.substring(setTimeoutIndex);
|
||||||
|
return str;
|
||||||
},
|
},
|
||||||
|
|
||||||
enableXcloudLogger(str: string) {
|
enableXcloudLogger(str: string) {
|
||||||
@ -631,12 +638,12 @@ true` + text;
|
|||||||
},
|
},
|
||||||
|
|
||||||
skipFeedbackDialog(str: string) {
|
skipFeedbackDialog(str: string) {
|
||||||
let text = '&&this.shouldTransitionToFeedback(';
|
let text = 'shouldTransitionToFeedback(e){';
|
||||||
if (!str.includes(text)) {
|
if (!str.includes(text)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = str.replace(text, '&& false ' + text);
|
str = str.replace(text, text + 'return !1;');
|
||||||
return str;
|
return str;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -828,10 +835,10 @@ true` + text;
|
|||||||
[UiSection.MOST_POPULAR]: GamePassCloudGallery.MOST_POPULAR,
|
[UiSection.MOST_POPULAR]: GamePassCloudGallery.MOST_POPULAR,
|
||||||
};
|
};
|
||||||
|
|
||||||
PREF_HIDE_SECTIONS.forEach(section => {
|
for (const section of PREF_HIDE_SECTIONS) {
|
||||||
const galleryId = sections[section];
|
const galleryId = sections[section];
|
||||||
galleryId && siglIds.push(galleryId);
|
galleryId && siglIds.push(galleryId);
|
||||||
});
|
};
|
||||||
|
|
||||||
const checkSyntax = siglIds.map(item => `siglId === "${item}"`).join(' || ');
|
const checkSyntax = siglIds.map(item => `siglId === "${item}"`).join(' || ');
|
||||||
|
|
||||||
@ -935,22 +942,59 @@ if (this.baseStorageKey in window.BX_EXPOSED.overrideSettings) {
|
|||||||
// Set Achievements list's filter default to "Locked"
|
// Set Achievements list's filter default to "Locked"
|
||||||
guideAchievementsDefaultLocked(str: string) {
|
guideAchievementsDefaultLocked(str: string) {
|
||||||
let index = str.indexOf('FilterButton-module__container');
|
let index = str.indexOf('FilterButton-module__container');
|
||||||
index >= 0 && (index = PatcherUtils.lastIndexOf(str, '.All', index, 150));
|
index >= 0 && (index = PatcherUtils.lastIndexOf(str, '"All"', index, 150));
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = PatcherUtils.replaceWith(str, index, '.All', '.Locked');
|
str = PatcherUtils.replaceWith(str, index, '"All"', '"Locked"');
|
||||||
|
|
||||||
index = str.indexOf('"Guide_Achievements_Unlocked_Empty","Guide_Achievements_Locked_Empty"');
|
index = str.indexOf('"Guide_Achievements_Unlocked_Empty","Guide_Achievements_Locked_Empty"');
|
||||||
index >= 0 && (index = PatcherUtils.indexOf(str, '.All', index, 250));
|
index >= 0 && (index = PatcherUtils.indexOf(str, '"All"', index, 250));
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = PatcherUtils.replaceWith(str, index, '.All', '.Locked');
|
str = PatcherUtils.replaceWith(str, index, '"All"', '"Locked"');
|
||||||
return str;
|
return str;
|
||||||
}
|
},
|
||||||
|
|
||||||
|
// Disable long touch activating context menu
|
||||||
|
disableTouchContextMenu(str: string) {
|
||||||
|
let index = str.indexOf('"ContextualCardActions-module__container');
|
||||||
|
index >= 0 && (index = str.indexOf('addEventListener("touchstart"', index));
|
||||||
|
index >= 0 && (index = PatcherUtils.lastIndexOf(str, 'return ', index, 50));
|
||||||
|
if (index < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
str = PatcherUtils.replaceWith(str, index, 'return', 'return () => {};');
|
||||||
|
return str;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Optimize Game slug generator by using cached RegEx
|
||||||
|
optimizeGameSlugGenerator(str: string) {
|
||||||
|
let text = '/[;,/?:@&=+_`~$%#^*()!^\\u2122\\xae\\xa9]/g';
|
||||||
|
if (!str.includes(text)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
str = str.replace(text, 'window.BX_EXPOSED.GameSlugRegexes[0]');
|
||||||
|
str = str.replace('/ {2,}/g', 'window.BX_EXPOSED.GameSlugRegexes[1]');
|
||||||
|
str = str.replace('/ /g', 'window.BX_EXPOSED.GameSlugRegexes[2]');
|
||||||
|
|
||||||
|
return str;
|
||||||
|
},
|
||||||
|
|
||||||
|
modifyPreloadedState(str: string) {
|
||||||
|
let text = '=window.__PRELOADED_STATE__;';
|
||||||
|
if (!str.includes(text)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
str = str.replace(text, '=window.BX_EXPOSED.modifyPreloadedState(window.__PRELOADED_STATE__);');
|
||||||
|
return str;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let PATCH_ORDERS: PatchArray = [
|
let PATCH_ORDERS: PatchArray = [
|
||||||
@ -961,6 +1005,10 @@ let PATCH_ORDERS: PatchArray = [
|
|||||||
'exposeInputSink',
|
'exposeInputSink',
|
||||||
] : []),
|
] : []),
|
||||||
|
|
||||||
|
'modifyPreloadedState',
|
||||||
|
|
||||||
|
'optimizeGameSlugGenerator',
|
||||||
|
|
||||||
'detectBrowserRouterReady',
|
'detectBrowserRouterReady',
|
||||||
'patchRequestInfoCrash',
|
'patchRequestInfoCrash',
|
||||||
|
|
||||||
@ -989,6 +1037,10 @@ let PATCH_ORDERS: PatchArray = [
|
|||||||
getPref(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.TOUCH) && 'ignorePlayWithTouchSection',
|
getPref(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.TOUCH) && 'ignorePlayWithTouchSection',
|
||||||
(getPref(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.NATIVE_MKB) || getPref(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.MOST_POPULAR)) && 'ignoreSiglSections',
|
(getPref(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.NATIVE_MKB) || getPref(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.MOST_POPULAR)) && 'ignoreSiglSections',
|
||||||
|
|
||||||
|
...(STATES.userAgent.capabilities.touch ? [
|
||||||
|
'disableTouchContextMenu',
|
||||||
|
] : []),
|
||||||
|
|
||||||
...(getPref(PrefKey.BLOCK_TRACKING) ? [
|
...(getPref(PrefKey.BLOCK_TRACKING) ? [
|
||||||
'disableAiTrack',
|
'disableAiTrack',
|
||||||
'disableTelemetry',
|
'disableTelemetry',
|
||||||
@ -1004,6 +1056,7 @@ let PATCH_ORDERS: PatchArray = [
|
|||||||
'remotePlayDirectConnectUrl',
|
'remotePlayDirectConnectUrl',
|
||||||
'remotePlayDisableAchievementToast',
|
'remotePlayDisableAchievementToast',
|
||||||
'remotePlayRecentlyUsedTitleIds',
|
'remotePlayRecentlyUsedTitleIds',
|
||||||
|
'remotePlayWebTitle',
|
||||||
STATES.userAgent.capabilities.touch && 'patchUpdateInputConfigurationAsync',
|
STATES.userAgent.capabilities.touch && 'patchUpdateInputConfigurationAsync',
|
||||||
] : []),
|
] : []),
|
||||||
|
|
||||||
@ -1076,7 +1129,7 @@ export class Patcher {
|
|||||||
return nativeBind.apply(this, arguments);
|
return nativeBind.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
PatcherCache.init();
|
PatcherCache.getInstance().init();
|
||||||
|
|
||||||
if (typeof arguments[1] === 'function') {
|
if (typeof arguments[1] === 'function') {
|
||||||
BxLogger.info(LOG_TAG, 'Restored Function.prototype.bind()');
|
BxLogger.info(LOG_TAG, 'Restored Function.prototype.bind()');
|
||||||
@ -1101,11 +1154,12 @@ export class Patcher {
|
|||||||
let appliedPatches: PatchArray;
|
let appliedPatches: PatchArray;
|
||||||
|
|
||||||
const patchesMap: Record<string, PatchArray> = {};
|
const patchesMap: Record<string, PatchArray> = {};
|
||||||
|
const patcherCache = PatcherCache.getInstance();
|
||||||
|
|
||||||
for (let id in item[1]) {
|
for (let id in item[1]) {
|
||||||
appliedPatches = [];
|
appliedPatches = [];
|
||||||
|
|
||||||
const cachedPatches = PatcherCache.getPatches(id);
|
const cachedPatches = patcherCache.getPatches(id);
|
||||||
if (cachedPatches) {
|
if (cachedPatches) {
|
||||||
patchesToCheck = cachedPatches.slice(0);
|
patchesToCheck = cachedPatches.slice(0);
|
||||||
patchesToCheck.push(...PATCH_ORDERS);
|
patchesToCheck.push(...PATCH_ORDERS);
|
||||||
@ -1172,7 +1226,7 @@ export class Patcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(patchesMap).length) {
|
if (Object.keys(patchesMap).length) {
|
||||||
PatcherCache.saveToCache(patchesMap);
|
patcherCache.saveToCache(patchesMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1182,51 +1236,65 @@ export class Patcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class PatcherCache {
|
export class PatcherCache {
|
||||||
static #KEY_CACHE = 'better_xcloud_patches_cache';
|
private static instance: PatcherCache;
|
||||||
static #KEY_SIGNATURE = 'better_xcloud_patches_cache_signature';
|
public static getInstance = () => PatcherCache.instance ?? (PatcherCache.instance = new PatcherCache());
|
||||||
|
|
||||||
static #CACHE: any;
|
private readonly KEY_CACHE = 'better_xcloud_patches_cache';
|
||||||
|
private readonly KEY_SIGNATURE = 'better_xcloud_patches_cache_signature';
|
||||||
|
|
||||||
static #isInitialized = false;
|
private CACHE: any;
|
||||||
|
|
||||||
|
private isInitialized = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get patch's signature
|
* Get patch's signature
|
||||||
*/
|
*/
|
||||||
static #getSignature(): number {
|
private getSignature(): number {
|
||||||
const scriptVersion = SCRIPT_VERSION;
|
const scriptVersion = SCRIPT_VERSION;
|
||||||
const webVersion = (document.querySelector('meta[name=gamepass-app-version]') as HTMLMetaElement)?.content;
|
|
||||||
const patches = JSON.stringify(ALL_PATCHES);
|
const patches = JSON.stringify(ALL_PATCHES);
|
||||||
|
|
||||||
|
// Get client.js's hash
|
||||||
|
let webVersion = '';
|
||||||
|
const $link = document.querySelector<HTMLLinkElement>('link[data-chunk="client"][href*="/client."]');
|
||||||
|
if ($link) {
|
||||||
|
const match = /\/client\.([^\.]+)\.js/.exec($link.href);
|
||||||
|
match && (webVersion = match[1]);
|
||||||
|
} else {
|
||||||
|
// Get version from <meta>
|
||||||
|
// Sometimes this value is missing
|
||||||
|
webVersion = (document.querySelector<HTMLMetaElement>('meta[name=gamepass-app-version]'))?.content ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate signature
|
// Calculate signature
|
||||||
const sig = hashCode(scriptVersion + webVersion + patches)
|
const sig = hashCode(scriptVersion + webVersion + patches)
|
||||||
return sig;
|
return sig;
|
||||||
}
|
}
|
||||||
|
|
||||||
static clear() {
|
clear() {
|
||||||
// Clear cache
|
// Clear cache
|
||||||
window.localStorage.removeItem(PatcherCache.#KEY_CACHE);
|
window.localStorage.removeItem(this.KEY_CACHE);
|
||||||
PatcherCache.#CACHE = {};
|
this.CACHE = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static checkSignature() {
|
private checkSignature() {
|
||||||
const storedSig = window.localStorage.getItem(PatcherCache.#KEY_SIGNATURE) || 0;
|
const storedSig = window.localStorage.getItem(this.KEY_SIGNATURE) || 0;
|
||||||
const currentSig = PatcherCache.#getSignature();
|
const currentSig = this.getSignature();
|
||||||
|
|
||||||
if (currentSig !== parseInt(storedSig as string)) {
|
if (currentSig !== parseInt(storedSig as string)) {
|
||||||
// Save new signature
|
// Save new signature
|
||||||
BxLogger.warning(LOG_TAG, 'Signature changed');
|
BxLogger.warning(LOG_TAG, 'Signature changed');
|
||||||
window.localStorage.setItem(PatcherCache.#KEY_SIGNATURE, currentSig.toString());
|
window.localStorage.setItem(this.KEY_SIGNATURE, currentSig.toString());
|
||||||
|
|
||||||
PatcherCache.clear();
|
this.clear();
|
||||||
} else {
|
} else {
|
||||||
BxLogger.info(LOG_TAG, 'Signature unchanged');
|
BxLogger.info(LOG_TAG, 'Signature unchanged');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static #cleanupPatches(patches: PatchArray): PatchArray {
|
private cleanupPatches(patches: PatchArray): PatchArray {
|
||||||
return patches.filter(item => {
|
return patches.filter(item => {
|
||||||
for (const id in PatcherCache.#CACHE) {
|
for (const id in this.CACHE) {
|
||||||
const cached = PatcherCache.#CACHE[id];
|
const cached = this.CACHE[id];
|
||||||
|
|
||||||
if (cached.includes(item)) {
|
if (cached.includes(item)) {
|
||||||
return false;
|
return false;
|
||||||
@ -1237,17 +1305,17 @@ export class PatcherCache {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static getPatches(id: string): PatchArray {
|
getPatches(id: string): PatchArray {
|
||||||
return PatcherCache.#CACHE[id];
|
return this.CACHE[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
static saveToCache(subCache: Record<string, PatchArray>) {
|
saveToCache(subCache: Record<string, PatchArray>) {
|
||||||
for (const id in subCache) {
|
for (const id in subCache) {
|
||||||
const patchNames = subCache[id];
|
const patchNames = subCache[id];
|
||||||
|
|
||||||
let data = PatcherCache.#CACHE[id];
|
let data = this.CACHE[id];
|
||||||
if (!data) {
|
if (!data) {
|
||||||
PatcherCache.#CACHE[id] = patchNames;
|
this.CACHE[id] = patchNames;
|
||||||
} else {
|
} else {
|
||||||
for (const patchName of patchNames) {
|
for (const patchName of patchNames) {
|
||||||
if (!data.includes(patchName)) {
|
if (!data.includes(patchName)) {
|
||||||
@ -1258,20 +1326,20 @@ export class PatcherCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save to storage
|
// Save to storage
|
||||||
window.localStorage.setItem(PatcherCache.#KEY_CACHE, JSON.stringify(PatcherCache.#CACHE));
|
window.localStorage.setItem(this.KEY_CACHE, JSON.stringify(this.CACHE));
|
||||||
}
|
}
|
||||||
|
|
||||||
static init() {
|
init() {
|
||||||
if (PatcherCache.#isInitialized) {
|
if (this.isInitialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PatcherCache.#isInitialized = true;
|
this.isInitialized = true;
|
||||||
|
|
||||||
PatcherCache.checkSignature();
|
this.checkSignature();
|
||||||
|
|
||||||
// Read cache from storage
|
// Read cache from storage
|
||||||
PatcherCache.#CACHE = JSON.parse(window.localStorage.getItem(PatcherCache.#KEY_CACHE) || '{}');
|
this.CACHE = JSON.parse(window.localStorage.getItem(this.KEY_CACHE) || '{}');
|
||||||
BxLogger.info(LOG_TAG, PatcherCache.#CACHE);
|
BxLogger.info(LOG_TAG, this.CACHE);
|
||||||
|
|
||||||
if (window.location.pathname.includes('/play/')) {
|
if (window.location.pathname.includes('/play/')) {
|
||||||
PATCH_ORDERS.push(...PLAYING_PATCH_ORDERS);
|
PATCH_ORDERS.push(...PLAYING_PATCH_ORDERS);
|
||||||
@ -1280,8 +1348,8 @@ export class PatcherCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove cached patches from PATCH_ORDERS & PLAYING_PATCH_ORDERS
|
// Remove cached patches from PATCH_ORDERS & PLAYING_PATCH_ORDERS
|
||||||
PATCH_ORDERS = PatcherCache.#cleanupPatches(PATCH_ORDERS);
|
PATCH_ORDERS = this.cleanupPatches(PATCH_ORDERS);
|
||||||
PLAYING_PATCH_ORDERS = PatcherCache.#cleanupPatches(PLAYING_PATCH_ORDERS);
|
PLAYING_PATCH_ORDERS = this.cleanupPatches(PLAYING_PATCH_ORDERS);
|
||||||
|
|
||||||
BxLogger.info(LOG_TAG, PATCH_ORDERS.slice(0));
|
BxLogger.info(LOG_TAG, PATCH_ORDERS.slice(0));
|
||||||
BxLogger.info(LOG_TAG, PLAYING_PATCH_ORDERS.slice(0));
|
BxLogger.info(LOG_TAG, PLAYING_PATCH_ORDERS.slice(0));
|
||||||
|
@ -85,7 +85,7 @@ if (btnHome) {
|
|||||||
|
|
||||||
this.inputSink.onGamepadInput(performance.now() - intervalMs, fakeGamepadMappings);
|
this.inputSink.onGamepadInput(performance.now() - intervalMs, fakeGamepadMappings);
|
||||||
} else {
|
} else {
|
||||||
intervalMs = 4;
|
intervalMs = window.BX_CONTROLLER_POLLING_RATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,121 +1,100 @@
|
|||||||
const int FILTER_UNSHARP_MASKING = 1;
|
#version 300 es
|
||||||
const int FILTER_CAS = 2;
|
|
||||||
|
|
||||||
precision highp float;
|
precision mediump float;
|
||||||
uniform sampler2D data;
|
uniform sampler2D data;
|
||||||
uniform vec2 iResolution;
|
uniform vec2 iResolution;
|
||||||
|
|
||||||
|
const int FILTER_UNSHARP_MASKING = 1;
|
||||||
|
// const int FILTER_CAS = 2;
|
||||||
|
|
||||||
|
// constrast = 0.8
|
||||||
|
const float CAS_CONTRAST_PEAK = 0.8 * -3.0 + 8.0;
|
||||||
|
|
||||||
|
// Luminosity factor
|
||||||
|
const vec3 LUMINOSITY_FACTOR = vec3(0.2126, 0.7152, 0.0722);
|
||||||
|
|
||||||
uniform int filterId;
|
uniform int filterId;
|
||||||
uniform float sharpenFactor;
|
uniform float sharpenFactor;
|
||||||
uniform float brightness;
|
uniform float brightness;
|
||||||
uniform float contrast;
|
uniform float contrast;
|
||||||
uniform float saturation;
|
uniform float saturation;
|
||||||
|
|
||||||
vec3 textureAt(sampler2D tex, vec2 coord) {
|
out vec4 fragColor;
|
||||||
return texture2D(tex, coord / iResolution.xy).rgb;
|
|
||||||
}
|
vec3 clarityBoost(sampler2D tex, vec2 coord, vec3 e) {
|
||||||
|
vec2 texelSize = 1.0 / iResolution.xy;
|
||||||
|
|
||||||
vec3 clarityBoost(sampler2D tex, vec2 coord)
|
|
||||||
{
|
|
||||||
// Load a collection of samples in a 3x3 neighorhood, where e is the current pixel.
|
// Load a collection of samples in a 3x3 neighorhood, where e is the current pixel.
|
||||||
// a b c
|
// a b c
|
||||||
// d e f
|
// d e f
|
||||||
// g h i
|
// g h i
|
||||||
vec3 a = textureAt(tex, coord + vec2(-1, 1));
|
vec3 a = texture(tex, coord + texelSize * vec2(-1, 1)).rgb;
|
||||||
vec3 b = textureAt(tex, coord + vec2(0, 1));
|
vec3 b = texture(tex, coord + texelSize * vec2(0, 1)).rgb;
|
||||||
vec3 c = textureAt(tex, coord + vec2(1, 1));
|
vec3 c = texture(tex, coord + texelSize * vec2(1, 1)).rgb;
|
||||||
|
|
||||||
vec3 d = textureAt(tex, coord + vec2(-1, 0));
|
vec3 d = texture(tex, coord + texelSize * vec2(-1, 0)).rgb;
|
||||||
vec3 e = textureAt(tex, coord);
|
vec3 f = texture(tex, coord + texelSize * vec2(1, 0)).rgb;
|
||||||
vec3 f = textureAt(tex, coord + vec2(1, 0));
|
|
||||||
|
|
||||||
vec3 g = textureAt(tex, coord + vec2(-1, -1));
|
vec3 g = texture(tex, coord + texelSize * vec2(-1, -1)).rgb;
|
||||||
vec3 h = textureAt(tex, coord + vec2(0, -1));
|
vec3 h = texture(tex, coord + texelSize * vec2(0, -1)).rgb;
|
||||||
vec3 i = textureAt(tex, coord + vec2(1, -1));
|
vec3 i = texture(tex, coord + texelSize * vec2(1, -1)).rgb;
|
||||||
|
|
||||||
if (filterId == FILTER_CAS) {
|
// USM
|
||||||
// Soft min and max.
|
if (filterId == FILTER_UNSHARP_MASKING) {
|
||||||
// a b c b
|
vec3 gaussianBlur = (a + c + g + i) * 1.0 + (b + d + f + h) * 2.0 + e * 4.0;
|
||||||
// d e f * 0.5 + d e f * 0.5
|
gaussianBlur /= 16.0;
|
||||||
// g h i h
|
|
||||||
// These are 2.0x bigger (factored out the extra multiply).
|
|
||||||
vec3 minRgb = min(min(min(d, e), min(f, b)), h);
|
|
||||||
vec3 minRgb2 = min(min(a, c), min(g, i));
|
|
||||||
minRgb += min(minRgb, minRgb2);
|
|
||||||
|
|
||||||
vec3 maxRgb = max(max(max(d, e), max(f, b)), h);
|
|
||||||
vec3 maxRgb2 = max(max(a, c), max(g, i));
|
|
||||||
maxRgb += max(maxRgb, maxRgb2);
|
|
||||||
|
|
||||||
// Smooth minimum distance to signal limit divided by smooth max.
|
|
||||||
vec3 reciprocalMaxRgb = 1.0 / maxRgb;
|
|
||||||
vec3 amplifyRgb = clamp(min(minRgb, 2.0 - maxRgb) * reciprocalMaxRgb, 0.0, 1.0);
|
|
||||||
|
|
||||||
// Shaping amount of sharpening.
|
|
||||||
amplifyRgb = inversesqrt(amplifyRgb);
|
|
||||||
|
|
||||||
float contrast = 0.8;
|
|
||||||
float peak = -3.0 * contrast + 8.0;
|
|
||||||
vec3 weightRgb = -(1.0 / (amplifyRgb * peak));
|
|
||||||
|
|
||||||
vec3 reciprocalWeightRgb = 1.0 / (4.0 * weightRgb + 1.0);
|
|
||||||
|
|
||||||
// 0 w 0
|
|
||||||
// Filter shape: w 1 w
|
|
||||||
// 0 w 0
|
|
||||||
vec3 window = (b + d) + (f + h);
|
|
||||||
vec3 outColor = clamp((window * weightRgb + e) * reciprocalWeightRgb, 0.0, 1.0);
|
|
||||||
|
|
||||||
outColor = mix(e, outColor, sharpenFactor / 2.0);
|
|
||||||
|
|
||||||
return outColor;
|
|
||||||
} else if (filterId == FILTER_UNSHARP_MASKING) {
|
|
||||||
vec3 gaussianBlur = (a * 1.0 + b * 2.0 + c * 1.0 +
|
|
||||||
d * 2.0 + e * 4.0 + f * 2.0 +
|
|
||||||
g * 1.0 + h * 2.0 + i * 1.0) / 16.0;
|
|
||||||
|
|
||||||
// Return edge detection
|
// Return edge detection
|
||||||
return e + (e - gaussianBlur) * sharpenFactor / 3.0;
|
return e + (e - gaussianBlur) * sharpenFactor / 3.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return e;
|
// CAS
|
||||||
}
|
// Soft min and max.
|
||||||
|
// a b c b
|
||||||
|
// d e f * 0.5 + d e f * 0.5
|
||||||
|
// g h i h
|
||||||
|
// These are 2.0x bigger (factored out the extra multiply).
|
||||||
|
vec3 minRgb = min(min(min(d, e), min(f, b)), h);
|
||||||
|
minRgb += min(min(a, c), min(g, i));
|
||||||
|
|
||||||
vec3 adjustBrightness(vec3 color) {
|
vec3 maxRgb = max(max(max(d, e), max(f, b)), h);
|
||||||
return (1.0 + brightness) * color;
|
maxRgb += max(max(a, c), max(g, i));
|
||||||
}
|
|
||||||
|
|
||||||
vec3 adjustContrast(vec3 color) {
|
// Smooth minimum distance to signal limit divided by smooth max.
|
||||||
return 0.5 + (1.0 + contrast) * (color - 0.5);
|
vec3 reciprocalMaxRgb = 1.0 / maxRgb;
|
||||||
}
|
vec3 amplifyRgb = clamp(min(minRgb, 2.0 - maxRgb) * reciprocalMaxRgb, 0.0, 1.0);
|
||||||
|
|
||||||
vec3 adjustSaturation(vec3 color) {
|
// Shaping amount of sharpening.
|
||||||
const vec3 luminosityFactor = vec3(0.2126, 0.7152, 0.0722);
|
amplifyRgb = inversesqrt(amplifyRgb);
|
||||||
vec3 grayscale = vec3(dot(color, luminosityFactor));
|
|
||||||
|
|
||||||
return mix(grayscale, color, 1.0 + saturation);
|
vec3 weightRgb = -(1.0 / (amplifyRgb * CAS_CONTRAST_PEAK));
|
||||||
|
vec3 reciprocalWeightRgb = 1.0 / (4.0 * weightRgb + 1.0);
|
||||||
|
|
||||||
|
// 0 w 0
|
||||||
|
// Filter shape: w 1 w
|
||||||
|
// 0 w 0
|
||||||
|
vec3 window = b + d + f + h;
|
||||||
|
vec3 outColor = clamp((window * weightRgb + e) * reciprocalWeightRgb, 0.0, 1.0);
|
||||||
|
|
||||||
|
return mix(e, outColor, sharpenFactor / 2.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 color;
|
vec2 uv = gl_FragCoord.xy / iResolution.xy;
|
||||||
|
// Get current pixel
|
||||||
|
vec3 color = texture(data, uv).rgb;
|
||||||
|
|
||||||
if (sharpenFactor > 0.0) {
|
// Clarity boost
|
||||||
color = clarityBoost(data, gl_FragCoord.xy);
|
color = sharpenFactor > 0.0 ? clarityBoost(data, uv, color) : color;
|
||||||
} else {
|
|
||||||
color = textureAt(data, gl_FragCoord.xy);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (saturation != 0.0) {
|
// Saturation
|
||||||
color = adjustSaturation(color);
|
color = saturation != 1.0 ? mix(vec3(dot(color, LUMINOSITY_FACTOR)), color, saturation) : color;
|
||||||
}
|
|
||||||
|
|
||||||
if (contrast != 0.0) {
|
// Contrast
|
||||||
color = adjustContrast(color);
|
color = contrast * (color - 0.5) + 0.5;
|
||||||
}
|
|
||||||
|
|
||||||
if (brightness != 0.0) {
|
// Brightness
|
||||||
color = adjustBrightness(color);
|
color = brightness * color;
|
||||||
}
|
|
||||||
|
|
||||||
gl_FragColor = vec4(color, 1.0);
|
fragColor = vec4(color, 1.0);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
attribute vec2 position;
|
#version 300 es
|
||||||
|
|
||||||
|
in vec4 position;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = vec4(position, 0, 1);
|
gl_Position = position;
|
||||||
}
|
}
|
||||||
|
@ -5,19 +5,19 @@ import { PrefKey } from "@/enums/pref-keys";
|
|||||||
import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
||||||
|
|
||||||
|
|
||||||
const LOG_TAG = 'WebGL2Player';
|
|
||||||
|
|
||||||
export class WebGL2Player {
|
export class WebGL2Player {
|
||||||
#$video: HTMLVideoElement;
|
private readonly LOG_TAG = 'WebGL2Player';
|
||||||
#$canvas: HTMLCanvasElement;
|
|
||||||
|
|
||||||
#gl: WebGL2RenderingContext | null = null;
|
private $video: HTMLVideoElement;
|
||||||
#resources: Array<any> = [];
|
private $canvas: HTMLCanvasElement;
|
||||||
#program: WebGLProgram | null = null;
|
|
||||||
|
|
||||||
#stopped: boolean = false;
|
private gl: WebGL2RenderingContext | null = null;
|
||||||
|
private resources: Array<any> = [];
|
||||||
|
private program: WebGLProgram | null = null;
|
||||||
|
|
||||||
#options = {
|
private stopped: boolean = false;
|
||||||
|
|
||||||
|
private options = {
|
||||||
filterId: 1,
|
filterId: 1,
|
||||||
sharpenFactor: 0,
|
sharpenFactor: 0,
|
||||||
brightness: 0.0,
|
brightness: 0.0,
|
||||||
@ -25,112 +25,133 @@ export class WebGL2Player {
|
|||||||
saturation: 0.0,
|
saturation: 0.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
#animFrameId: number | null = null;
|
private targetFps = 60;
|
||||||
|
private frameInterval = 0;
|
||||||
|
private lastFrameTime = 0;
|
||||||
|
|
||||||
|
private animFrameId: number | null = null;
|
||||||
|
|
||||||
constructor($video: HTMLVideoElement) {
|
constructor($video: HTMLVideoElement) {
|
||||||
BxLogger.info(LOG_TAG, 'Initialize');
|
BxLogger.info(this.LOG_TAG, 'Initialize');
|
||||||
this.#$video = $video;
|
this.$video = $video;
|
||||||
|
|
||||||
const $canvas = document.createElement('canvas');
|
const $canvas = document.createElement('canvas');
|
||||||
$canvas.width = $video.videoWidth;
|
$canvas.width = $video.videoWidth;
|
||||||
$canvas.height = $video.videoHeight;
|
$canvas.height = $video.videoHeight;
|
||||||
this.#$canvas = $canvas;
|
this.$canvas = $canvas;
|
||||||
|
|
||||||
this.#setupShaders();
|
this.setupShaders();
|
||||||
this.#setupRendering();
|
this.setupRendering();
|
||||||
|
|
||||||
$video.insertAdjacentElement('afterend', $canvas);
|
$video.insertAdjacentElement('afterend', $canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
setFilter(filterId: number, update = true) {
|
setFilter(filterId: number, update = true) {
|
||||||
this.#options.filterId = filterId;
|
this.options.filterId = filterId;
|
||||||
update && this.updateCanvas();
|
update && this.updateCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
setSharpness(sharpness: number, update = true) {
|
setSharpness(sharpness: number, update = true) {
|
||||||
this.#options.sharpenFactor = sharpness;
|
this.options.sharpenFactor = sharpness;
|
||||||
update && this.updateCanvas();
|
update && this.updateCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
setBrightness(brightness: number, update = true) {
|
setBrightness(brightness: number, update = true) {
|
||||||
this.#options.brightness = (brightness - 100) / 100;
|
this.options.brightness = 1 + (brightness - 100) / 100;
|
||||||
update && this.updateCanvas();
|
update && this.updateCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
setContrast(contrast: number, update = true) {
|
setContrast(contrast: number, update = true) {
|
||||||
this.#options.contrast = (contrast - 100) / 100;
|
this.options.contrast = 1 + (contrast - 100) / 100;
|
||||||
update && this.updateCanvas();
|
update && this.updateCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
setSaturation(saturation: number, update = true) {
|
setSaturation(saturation: number, update = true) {
|
||||||
this.#options.saturation = (saturation - 100) / 100;
|
this.options.saturation = 1 + (saturation - 100) / 100;
|
||||||
update && this.updateCanvas();
|
update && this.updateCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTargetFps(target: number) {
|
||||||
|
this.targetFps = target;
|
||||||
|
this.lastFrameTime = 0;
|
||||||
|
this.frameInterval = target ? Math.floor(1000 / target) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
getCanvas() {
|
getCanvas() {
|
||||||
return this.#$canvas;
|
return this.$canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCanvas() {
|
updateCanvas() {
|
||||||
const gl = this.#gl!;
|
const gl = this.gl!;
|
||||||
const program = this.#program!;
|
const program = this.program!;
|
||||||
|
|
||||||
gl.uniform2f(gl.getUniformLocation(program, 'iResolution'), this.#$canvas.width, this.#$canvas.height);
|
gl.uniform2f(gl.getUniformLocation(program, 'iResolution'), this.$canvas.width, this.$canvas.height);
|
||||||
|
|
||||||
gl.uniform1i(gl.getUniformLocation(program, 'filterId'), this.#options.filterId);
|
gl.uniform1i(gl.getUniformLocation(program, 'filterId'), this.options.filterId);
|
||||||
gl.uniform1f(gl.getUniformLocation(program, 'sharpenFactor'), this.#options.sharpenFactor);
|
gl.uniform1f(gl.getUniformLocation(program, 'sharpenFactor'), this.options.sharpenFactor);
|
||||||
gl.uniform1f(gl.getUniformLocation(program, 'brightness'), this.#options.brightness);
|
gl.uniform1f(gl.getUniformLocation(program, 'brightness'), this.options.brightness);
|
||||||
gl.uniform1f(gl.getUniformLocation(program, 'contrast'), this.#options.contrast);
|
gl.uniform1f(gl.getUniformLocation(program, 'contrast'), this.options.contrast);
|
||||||
gl.uniform1f(gl.getUniformLocation(program, 'saturation'), this.#options.saturation);
|
gl.uniform1f(gl.getUniformLocation(program, 'saturation'), this.options.saturation);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawFrame() {
|
forceDrawFrame() {
|
||||||
const gl = this.#gl!;
|
const gl = this.gl!;
|
||||||
const $video = this.#$video;
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, this.$video);
|
||||||
|
|
||||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, $video);
|
|
||||||
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
#setupRendering() {
|
private setupRendering() {
|
||||||
let animate: any;
|
let frameCallback: any;
|
||||||
|
|
||||||
if ('requestVideoFrameCallback' in HTMLVideoElement.prototype) {
|
if ('requestVideoFrameCallback' in HTMLVideoElement.prototype) {
|
||||||
const $video = this.#$video;
|
const $video = this.$video;
|
||||||
animate = () => {
|
frameCallback = $video.requestVideoFrameCallback.bind($video);
|
||||||
if (this.#stopped) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.drawFrame();
|
|
||||||
this.#animFrameId = $video.requestVideoFrameCallback(animate);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.#animFrameId = $video.requestVideoFrameCallback(animate);
|
|
||||||
} else {
|
} else {
|
||||||
animate = () => {
|
frameCallback = requestAnimationFrame;
|
||||||
if (this.#stopped) {
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.drawFrame();
|
let animate = () => {
|
||||||
this.#animFrameId = requestAnimationFrame(animate);
|
if (this.stopped) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#animFrameId = requestAnimationFrame(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.animFrameId = frameCallback(animate);
|
||||||
}
|
}
|
||||||
|
|
||||||
#setupShaders() {
|
private setupShaders() {
|
||||||
BxLogger.info(LOG_TAG, 'Setting up', getPref(PrefKey.VIDEO_POWER_PREFERENCE));
|
BxLogger.info(this.LOG_TAG, 'Setting up', getPref(PrefKey.VIDEO_POWER_PREFERENCE));
|
||||||
|
|
||||||
const gl = this.#$canvas.getContext('webgl', {
|
const gl = this.$canvas.getContext('webgl2', {
|
||||||
isBx: true,
|
isBx: true,
|
||||||
antialias: true,
|
antialias: true,
|
||||||
alpha: false,
|
alpha: false,
|
||||||
powerPreference: getPref(PrefKey.VIDEO_POWER_PREFERENCE),
|
powerPreference: getPref(PrefKey.VIDEO_POWER_PREFERENCE),
|
||||||
}) as WebGL2RenderingContext;
|
}) as WebGL2RenderingContext;
|
||||||
this.#gl = gl;
|
this.gl = gl;
|
||||||
|
|
||||||
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferWidth);
|
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferWidth);
|
||||||
|
|
||||||
@ -145,7 +166,7 @@ export class WebGL2Player {
|
|||||||
|
|
||||||
// Create and link program
|
// Create and link program
|
||||||
const program = gl.createProgram()!;
|
const program = gl.createProgram()!;
|
||||||
this.#program = program;
|
this.program = program;
|
||||||
|
|
||||||
gl.attachShader(program, vShader);
|
gl.attachShader(program, vShader);
|
||||||
gl.attachShader(program, fShader);
|
gl.attachShader(program, fShader);
|
||||||
@ -162,24 +183,17 @@ export class WebGL2Player {
|
|||||||
|
|
||||||
// Vertices: A screen-filling quad made from two triangles
|
// Vertices: A screen-filling quad made from two triangles
|
||||||
const buffer = gl.createBuffer();
|
const buffer = gl.createBuffer();
|
||||||
this.#resources.push(buffer);
|
this.resources.push(buffer);
|
||||||
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1]), gl.STATIC_DRAW);
|
||||||
-1, -1,
|
|
||||||
1, -1,
|
|
||||||
-1, 1,
|
|
||||||
-1, 1,
|
|
||||||
1, -1,
|
|
||||||
1, 1,
|
|
||||||
]), gl.STATIC_DRAW);
|
|
||||||
|
|
||||||
gl.enableVertexAttribArray(0);
|
gl.enableVertexAttribArray(0);
|
||||||
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
|
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
// Texture to contain the video data
|
// Texture to contain the video data
|
||||||
const texture = gl.createTexture();
|
const texture = gl.createTexture();
|
||||||
this.#resources.push(texture);
|
this.resources.push(texture);
|
||||||
|
|
||||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
||||||
@ -197,40 +211,40 @@ export class WebGL2Player {
|
|||||||
|
|
||||||
resume() {
|
resume() {
|
||||||
this.stop();
|
this.stop();
|
||||||
this.#stopped = false;
|
this.stopped = false;
|
||||||
BxLogger.info(LOG_TAG, 'Resume');
|
BxLogger.info(this.LOG_TAG, 'Resume');
|
||||||
|
|
||||||
this.#$canvas.classList.remove('bx-gone');
|
this.$canvas.classList.remove('bx-gone');
|
||||||
this.#setupRendering();
|
this.setupRendering();
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
BxLogger.info(LOG_TAG, 'Stop');
|
BxLogger.info(this.LOG_TAG, 'Stop');
|
||||||
this.#$canvas.classList.add('bx-gone');
|
this.$canvas.classList.add('bx-gone');
|
||||||
|
|
||||||
this.#stopped = true;
|
this.stopped = true;
|
||||||
if (this.#animFrameId) {
|
if (this.animFrameId) {
|
||||||
if ('requestVideoFrameCallback' in HTMLVideoElement.prototype) {
|
if ('requestVideoFrameCallback' in HTMLVideoElement.prototype) {
|
||||||
this.#$video.cancelVideoFrameCallback(this.#animFrameId);
|
this.$video.cancelVideoFrameCallback(this.animFrameId);
|
||||||
} else {
|
} else {
|
||||||
cancelAnimationFrame(this.#animFrameId);
|
cancelAnimationFrame(this.animFrameId);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#animFrameId = null;
|
this.animFrameId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
BxLogger.info(LOG_TAG, 'Destroy');
|
BxLogger.info(this.LOG_TAG, 'Destroy');
|
||||||
this.stop();
|
this.stop();
|
||||||
|
|
||||||
const gl = this.#gl;
|
const gl = this.gl;
|
||||||
if (gl) {
|
if (gl) {
|
||||||
gl.getExtension('WEBGL_lose_context')?.loseContext();
|
gl.getExtension('WEBGL_lose_context')?.loseContext();
|
||||||
|
gl.useProgram(null);
|
||||||
|
|
||||||
for (const resource of this.#resources) {
|
for (const resource of this.resources) {
|
||||||
if (resource instanceof WebGLProgram) {
|
if (resource instanceof WebGLProgram) {
|
||||||
gl.useProgram(null);
|
|
||||||
gl.deleteProgram(resource);
|
gl.deleteProgram(resource);
|
||||||
} else if (resource instanceof WebGLShader) {
|
} else if (resource instanceof WebGLShader) {
|
||||||
gl.deleteShader(resource);
|
gl.deleteShader(resource);
|
||||||
@ -241,14 +255,14 @@ export class WebGL2Player {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#gl = null;
|
this.gl = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.#$canvas.isConnected) {
|
if (this.$canvas.isConnected) {
|
||||||
this.#$canvas.parentElement?.removeChild(this.#$canvas);
|
this.$canvas.parentElement?.removeChild(this.$canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#$canvas.width = 1;
|
this.$canvas.width = 1;
|
||||||
this.#$canvas.height = 1;
|
this.$canvas.height = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,6 @@ import { PrefKey } from "@/enums/pref-keys";
|
|||||||
import { getPref, setPref } from "@/utils/settings-storages/global-settings-storage";
|
import { getPref, setPref } from "@/utils/settings-storages/global-settings-storage";
|
||||||
import { RemotePlayNavigationDialog } from "./ui/dialog/remote-play-dialog";
|
import { RemotePlayNavigationDialog } from "./ui/dialog/remote-play-dialog";
|
||||||
|
|
||||||
const LOG_TAG = 'RemotePlay';
|
|
||||||
|
|
||||||
export const enum RemotePlayConsoleState {
|
export const enum RemotePlayConsoleState {
|
||||||
ON = 'On',
|
ON = 'On',
|
||||||
OFF = 'Off',
|
OFF = 'Off',
|
||||||
@ -37,13 +35,8 @@ type RemotePlayConsole = {
|
|||||||
|
|
||||||
export class RemotePlayManager {
|
export class RemotePlayManager {
|
||||||
private static instance: RemotePlayManager;
|
private static instance: RemotePlayManager;
|
||||||
public static getInstance(): RemotePlayManager {
|
public static getInstance = () => RemotePlayManager.instance ?? (RemotePlayManager.instance = new RemotePlayManager());
|
||||||
if (!this.instance) {
|
private readonly LOG_TAG = 'RemotePlayManager';
|
||||||
this.instance = new RemotePlayManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private isInitialized = false;
|
private isInitialized = false;
|
||||||
|
|
||||||
@ -53,6 +46,10 @@ export class RemotePlayManager {
|
|||||||
private consoles!: Array<RemotePlayConsole>;
|
private consoles!: Array<RemotePlayConsole>;
|
||||||
private regions: Array<RemotePlayRegion> = [];
|
private regions: Array<RemotePlayRegion> = [];
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
|
}
|
||||||
|
|
||||||
initialize() {
|
initialize() {
|
||||||
if (this.isInitialized) {
|
if (this.isInitialized) {
|
||||||
return;
|
return;
|
||||||
@ -62,9 +59,9 @@ export class RemotePlayManager {
|
|||||||
|
|
||||||
this.getXhomeToken(() => {
|
this.getXhomeToken(() => {
|
||||||
this.getConsolesList(() => {
|
this.getConsolesList(() => {
|
||||||
BxLogger.info(LOG_TAG, 'Consoles', this.consoles);
|
BxLogger.info(this.LOG_TAG, 'Consoles', this.consoles);
|
||||||
|
|
||||||
STATES.supportedRegion && HeaderSection.showRemotePlayButton();
|
STATES.supportedRegion && HeaderSection.getInstance().showRemotePlayButton();
|
||||||
BxEvent.dispatch(window, BxEvent.REMOTE_PLAY_READY);
|
BxEvent.dispatch(window, BxEvent.REMOTE_PLAY_READY);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
18
src/modules/shortcuts/shortcut-renderer.ts
Normal file
18
src/modules/shortcuts/shortcut-renderer.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { PrefKey } from "@/enums/pref-keys";
|
||||||
|
import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
||||||
|
import { limitVideoPlayerFps } from "../stream/stream-settings-utils";
|
||||||
|
|
||||||
|
export class RendererShortcut {
|
||||||
|
static toggleVisibility(): boolean {
|
||||||
|
const $mediaContainer = document.querySelector('#game-stream div[data-testid="media-container"]');
|
||||||
|
if (!$mediaContainer) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mediaContainer.classList.toggle('bx-gone');
|
||||||
|
const isShowing = !$mediaContainer.classList.contains('bx-gone');
|
||||||
|
// Switch FPS
|
||||||
|
limitVideoPlayerFps(isShowing ? getPref(PrefKey.VIDEO_MAX_FPS) : 0);
|
||||||
|
return isShowing;
|
||||||
|
}
|
||||||
|
}
|
@ -77,13 +77,7 @@ export class SoundShortcut {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let $media: HTMLMediaElement;
|
const $media = document.querySelector<HTMLAudioElement>('div[data-testid=media-container] audio') ?? document.querySelector<HTMLAudioElement>('div[data-testid=media-container] video');
|
||||||
|
|
||||||
$media = document.querySelector('div[data-testid=media-container] audio') as HTMLAudioElement;
|
|
||||||
if (!$media) {
|
|
||||||
$media = document.querySelector('div[data-testid=media-container] video') as HTMLAudioElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($media) {
|
if ($media) {
|
||||||
$media.muted = !$media.muted;
|
$media.muted = !$media.muted;
|
||||||
|
|
||||||
|
@ -2,11 +2,12 @@ import { isFullVersion } from "@macros/build" with {type: "macro"};
|
|||||||
|
|
||||||
import { CE } from "@/utils/html";
|
import { CE } from "@/utils/html";
|
||||||
import { WebGL2Player } from "./player/webgl2-player";
|
import { WebGL2Player } from "./player/webgl2-player";
|
||||||
import { Screenshot } from "@/utils/screenshot";
|
import { ScreenshotManager } from "@/utils/screenshot-manager";
|
||||||
import { StreamPlayerType, StreamVideoProcessing } from "@enums/stream-player";
|
import { StreamPlayerType, StreamVideoProcessing } from "@enums/stream-player";
|
||||||
import { STATES } from "@/utils/global";
|
import { STATES } from "@/utils/global";
|
||||||
import { PrefKey } from "@/enums/pref-keys";
|
import { PrefKey } from "@/enums/pref-keys";
|
||||||
import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
||||||
|
import { BX_FLAGS } from "@/utils/bx-flags";
|
||||||
|
|
||||||
export type StreamPlayerOptions = Partial<{
|
export type StreamPlayerOptions = Partial<{
|
||||||
processing: string,
|
processing: string,
|
||||||
@ -17,35 +18,35 @@ export type StreamPlayerOptions = Partial<{
|
|||||||
}>;
|
}>;
|
||||||
|
|
||||||
export class StreamPlayer {
|
export class StreamPlayer {
|
||||||
#$video: HTMLVideoElement;
|
private $video: HTMLVideoElement;
|
||||||
#playerType: StreamPlayerType = StreamPlayerType.VIDEO;
|
private playerType: StreamPlayerType = StreamPlayerType.VIDEO;
|
||||||
|
|
||||||
#options: StreamPlayerOptions = {};
|
private options: StreamPlayerOptions = {};
|
||||||
|
|
||||||
#webGL2Player: WebGL2Player | null = null;
|
private webGL2Player: WebGL2Player | null = null;
|
||||||
|
|
||||||
#$videoCss: HTMLStyleElement | null = null;
|
private $videoCss: HTMLStyleElement | null = null;
|
||||||
#$usmMatrix: SVGFEConvolveMatrixElement | null = null;
|
private $usmMatrix: SVGFEConvolveMatrixElement | null = null;
|
||||||
|
|
||||||
constructor($video: HTMLVideoElement, type: StreamPlayerType, options: StreamPlayerOptions) {
|
constructor($video: HTMLVideoElement, type: StreamPlayerType, options: StreamPlayerOptions) {
|
||||||
this.#setupVideoElements();
|
this.setupVideoElements();
|
||||||
|
|
||||||
this.#$video = $video;
|
this.$video = $video;
|
||||||
this.#options = options || {};
|
this.options = options || {};
|
||||||
this.setPlayerType(type);
|
this.setPlayerType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
#setupVideoElements() {
|
private setupVideoElements() {
|
||||||
this.#$videoCss = document.getElementById('bx-video-css') as HTMLStyleElement;
|
this.$videoCss = document.getElementById('bx-video-css') as HTMLStyleElement;
|
||||||
if (this.#$videoCss) {
|
if (this.$videoCss) {
|
||||||
this.#$usmMatrix = this.#$videoCss.querySelector('#bx-filter-usm-matrix') as any;
|
this.$usmMatrix = this.$videoCss.querySelector('#bx-filter-usm-matrix') as any;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const $fragment = document.createDocumentFragment();
|
const $fragment = document.createDocumentFragment();
|
||||||
|
|
||||||
this.#$videoCss = CE<HTMLStyleElement>('style', {id: 'bx-video-css'});
|
this.$videoCss = CE<HTMLStyleElement>('style', {id: 'bx-video-css'});
|
||||||
$fragment.appendChild(this.#$videoCss);
|
$fragment.appendChild(this.$videoCss);
|
||||||
|
|
||||||
// Setup SVG filters
|
// Setup SVG filters
|
||||||
const $svg = CE('svg', {
|
const $svg = CE('svg', {
|
||||||
@ -56,7 +57,7 @@ export class StreamPlayer {
|
|||||||
CE('filter', {
|
CE('filter', {
|
||||||
id: 'bx-filter-usm',
|
id: 'bx-filter-usm',
|
||||||
xmlns: 'http://www.w3.org/2000/svg',
|
xmlns: 'http://www.w3.org/2000/svg',
|
||||||
}, this.#$usmMatrix = CE('feConvolveMatrix', {
|
}, this.$usmMatrix = CE('feConvolveMatrix', {
|
||||||
id: 'bx-filter-usm-matrix',
|
id: 'bx-filter-usm-matrix',
|
||||||
order: '3',
|
order: '3',
|
||||||
xmlns: 'http://www.w3.org/2000/svg',
|
xmlns: 'http://www.w3.org/2000/svg',
|
||||||
@ -67,29 +68,29 @@ export class StreamPlayer {
|
|||||||
document.documentElement.appendChild($fragment);
|
document.documentElement.appendChild($fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
#getVideoPlayerFilterStyle() {
|
private getVideoPlayerFilterStyle() {
|
||||||
const filters = [];
|
const filters = [];
|
||||||
|
|
||||||
const sharpness = this.#options.sharpness || 0;
|
const sharpness = this.options.sharpness || 0;
|
||||||
if (this.#options.processing === StreamVideoProcessing.USM && 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 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`;
|
const matrix = `0 -1 0 -1 ${level} -1 0 -1 0`;
|
||||||
this.#$usmMatrix?.setAttributeNS(null, 'kernelMatrix', matrix);
|
this.$usmMatrix?.setAttributeNS(null, 'kernelMatrix', matrix);
|
||||||
|
|
||||||
filters.push(`url(#bx-filter-usm)`);
|
filters.push(`url(#bx-filter-usm)`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const saturation = this.#options.saturation || 100;
|
const saturation = this.options.saturation || 100;
|
||||||
if (saturation != 100) {
|
if (saturation != 100) {
|
||||||
filters.push(`saturate(${saturation}%)`);
|
filters.push(`saturate(${saturation}%)`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const contrast = this.#options.contrast || 100;
|
const contrast = this.options.contrast || 100;
|
||||||
if (contrast != 100) {
|
if (contrast != 100) {
|
||||||
filters.push(`contrast(${contrast}%)`);
|
filters.push(`contrast(${contrast}%)`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const brightness = this.#options.brightness || 100;
|
const brightness = this.options.brightness || 100;
|
||||||
if (brightness != 100) {
|
if (brightness != 100) {
|
||||||
filters.push(`brightness(${brightness}%)`);
|
filters.push(`brightness(${brightness}%)`);
|
||||||
}
|
}
|
||||||
@ -97,14 +98,14 @@ export class StreamPlayer {
|
|||||||
return filters.join(' ');
|
return filters.join(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
#resizePlayer() {
|
private resizePlayer() {
|
||||||
const PREF_RATIO = getPref(PrefKey.VIDEO_RATIO);
|
const PREF_RATIO = getPref(PrefKey.VIDEO_RATIO);
|
||||||
const $video = this.#$video;
|
const $video = this.$video;
|
||||||
const isNativeTouchGame = STATES.currentStream.titleInfo?.details.hasNativeTouchSupport;
|
const isNativeTouchGame = STATES.currentStream.titleInfo?.details.hasNativeTouchSupport;
|
||||||
|
|
||||||
let $webGL2Canvas;
|
let $webGL2Canvas;
|
||||||
if (this.#playerType == StreamPlayerType.WEBGL2) {
|
if (this.playerType == StreamPlayerType.WEBGL2) {
|
||||||
$webGL2Canvas = this.#webGL2Player?.getCanvas()!;
|
$webGL2Canvas = this.webGL2Player?.getCanvas()!;
|
||||||
}
|
}
|
||||||
|
|
||||||
let targetWidth;
|
let targetWidth;
|
||||||
@ -166,67 +167,69 @@ export class StreamPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update video dimensions
|
// Update video dimensions
|
||||||
if (isNativeTouchGame && this.#playerType == StreamPlayerType.WEBGL2) {
|
if (isNativeTouchGame && this.playerType == StreamPlayerType.WEBGL2) {
|
||||||
window.BX_EXPOSED.streamSession.updateDimensions();
|
window.BX_EXPOSED.streamSession.updateDimensions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setPlayerType(type: StreamPlayerType, refreshPlayer: boolean = false) {
|
setPlayerType(type: StreamPlayerType, refreshPlayer: boolean = false) {
|
||||||
if (this.#playerType !== type) {
|
if (this.playerType !== type) {
|
||||||
|
const videoClass = BX_FLAGS.DeviceInfo.deviceType === 'android-tv' ? 'bx-pixel' : 'bx-gone';
|
||||||
|
|
||||||
// Switch from Video -> WebGL2
|
// Switch from Video -> WebGL2
|
||||||
if (type === StreamPlayerType.WEBGL2) {
|
if (type === StreamPlayerType.WEBGL2) {
|
||||||
// Initialize WebGL2 player
|
// Initialize WebGL2 player
|
||||||
if (!this.#webGL2Player) {
|
if (!this.webGL2Player) {
|
||||||
this.#webGL2Player = new WebGL2Player(this.#$video);
|
this.webGL2Player = new WebGL2Player(this.$video);
|
||||||
} else {
|
} else {
|
||||||
this.#webGL2Player.resume();
|
this.webGL2Player.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#$videoCss!.textContent = '';
|
this.$videoCss!.textContent = '';
|
||||||
|
|
||||||
this.#$video.classList.add('bx-pixel');
|
this.$video.classList.add(videoClass);
|
||||||
} else {
|
} else {
|
||||||
// Cleanup WebGL2 Player
|
// Cleanup WebGL2 Player
|
||||||
this.#webGL2Player?.stop();
|
this.webGL2Player?.stop();
|
||||||
|
|
||||||
this.#$video.classList.remove('bx-pixel');
|
this.$video.classList.remove(videoClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#playerType = type;
|
this.playerType = type;
|
||||||
refreshPlayer && this.refreshPlayer();
|
refreshPlayer && this.refreshPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
setOptions(options: StreamPlayerOptions, refreshPlayer: boolean = false) {
|
setOptions(options: StreamPlayerOptions, refreshPlayer: boolean = false) {
|
||||||
this.#options = options;
|
this.options = options;
|
||||||
refreshPlayer && this.refreshPlayer();
|
refreshPlayer && this.refreshPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateOptions(options: StreamPlayerOptions, refreshPlayer: boolean = false) {
|
updateOptions(options: StreamPlayerOptions, refreshPlayer: boolean = false) {
|
||||||
this.#options = Object.assign(this.#options, options);
|
this.options = Object.assign(this.options, options);
|
||||||
refreshPlayer && this.refreshPlayer();
|
refreshPlayer && this.refreshPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlayerElement(playerType?: StreamPlayerType) {
|
getPlayerElement(playerType?: StreamPlayerType) {
|
||||||
if (typeof playerType === 'undefined') {
|
if (typeof playerType === 'undefined') {
|
||||||
playerType = this.#playerType;
|
playerType = this.playerType;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerType === StreamPlayerType.WEBGL2) {
|
if (playerType === StreamPlayerType.WEBGL2) {
|
||||||
return this.#webGL2Player?.getCanvas();
|
return this.webGL2Player?.getCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.#$video;
|
return this.$video;
|
||||||
}
|
}
|
||||||
|
|
||||||
getWebGL2Player() {
|
getWebGL2Player() {
|
||||||
return this.#webGL2Player;
|
return this.webGL2Player;
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshPlayer() {
|
refreshPlayer() {
|
||||||
if (this.#playerType === StreamPlayerType.WEBGL2) {
|
if (this.playerType === StreamPlayerType.WEBGL2) {
|
||||||
const options = this.#options;
|
const options = this.options;
|
||||||
const webGL2Player = this.#webGL2Player!;
|
const webGL2Player = this.webGL2Player!;
|
||||||
|
|
||||||
if (options.processing === StreamVideoProcessing.USM) {
|
if (options.processing === StreamVideoProcessing.USM) {
|
||||||
webGL2Player.setFilter(1);
|
webGL2Player.setFilter(1);
|
||||||
@ -234,14 +237,14 @@ export class StreamPlayer {
|
|||||||
webGL2Player.setFilter(2);
|
webGL2Player.setFilter(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
isFullVersion() && Screenshot.updateCanvasFilters('none');
|
isFullVersion() && ScreenshotManager.getInstance().updateCanvasFilters('none');
|
||||||
|
|
||||||
webGL2Player.setSharpness(options.sharpness || 0);
|
webGL2Player.setSharpness(options.sharpness || 0);
|
||||||
webGL2Player.setSaturation(options.saturation || 100);
|
webGL2Player.setSaturation(options.saturation || 100);
|
||||||
webGL2Player.setContrast(options.contrast || 100);
|
webGL2Player.setContrast(options.contrast || 100);
|
||||||
webGL2Player.setBrightness(options.brightness || 100);
|
webGL2Player.setBrightness(options.brightness || 100);
|
||||||
} else {
|
} else {
|
||||||
let filters = this.#getVideoPlayerFilterStyle();
|
let filters = this.getVideoPlayerFilterStyle();
|
||||||
let videoCss = '';
|
let videoCss = '';
|
||||||
if (filters) {
|
if (filters) {
|
||||||
videoCss += `filter: ${filters} !important;`;
|
videoCss += `filter: ${filters} !important;`;
|
||||||
@ -249,7 +252,7 @@ export class StreamPlayer {
|
|||||||
|
|
||||||
// Apply video filters to screenshots
|
// Apply video filters to screenshots
|
||||||
if (isFullVersion() && getPref(PrefKey.SCREENSHOT_APPLY_FILTERS)) {
|
if (isFullVersion() && getPref(PrefKey.SCREENSHOT_APPLY_FILTERS)) {
|
||||||
Screenshot.updateCanvasFilters(filters);
|
ScreenshotManager.getInstance().updateCanvasFilters(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
let css = '';
|
let css = '';
|
||||||
@ -257,26 +260,26 @@ export class StreamPlayer {
|
|||||||
css = `#game-stream video { ${videoCss} }`;
|
css = `#game-stream video { ${videoCss} }`;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#$videoCss!.textContent = css;
|
this.$videoCss!.textContent = css;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#resizePlayer();
|
this.resizePlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
reloadPlayer() {
|
reloadPlayer() {
|
||||||
this.#cleanUpWebGL2Player();
|
this.cleanUpWebGL2Player();
|
||||||
|
|
||||||
this.#playerType = StreamPlayerType.VIDEO;
|
this.playerType = StreamPlayerType.VIDEO;
|
||||||
this.setPlayerType(StreamPlayerType.WEBGL2, false);
|
this.setPlayerType(StreamPlayerType.WEBGL2, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#cleanUpWebGL2Player() {
|
private cleanUpWebGL2Player() {
|
||||||
// Clean up WebGL2 Player
|
// Clean up WebGL2 Player
|
||||||
this.#webGL2Player?.destroy();
|
this.webGL2Player?.destroy();
|
||||||
this.#webGL2Player = null;
|
this.webGL2Player = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.#cleanUpWebGL2Player();
|
this.cleanUpWebGL2Player();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ type StreamBadgeInfo = {
|
|||||||
|
|
||||||
type StreamServerInfo = {
|
type StreamServerInfo = {
|
||||||
server?: {
|
server?: {
|
||||||
ipv6: boolean,
|
|
||||||
region?: string,
|
region?: string,
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -50,13 +49,8 @@ enum StreamBadge {
|
|||||||
|
|
||||||
export class StreamBadges {
|
export class StreamBadges {
|
||||||
private static instance: StreamBadges;
|
private static instance: StreamBadges;
|
||||||
public static getInstance(): StreamBadges {
|
public static getInstance = () => StreamBadges.instance ?? (StreamBadges.instance = new StreamBadges());
|
||||||
if (!StreamBadges.instance) {
|
private readonly LOG_TAG = 'StreamBadges';
|
||||||
StreamBadges.instance = new StreamBadges();
|
|
||||||
}
|
|
||||||
|
|
||||||
return StreamBadges.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private serverInfo: StreamServerInfo = {};
|
private serverInfo: StreamServerInfo = {};
|
||||||
|
|
||||||
@ -103,10 +97,13 @@ export class StreamBadges {
|
|||||||
private intervalId?: number | null;
|
private intervalId?: number | null;
|
||||||
private readonly REFRESH_INTERVAL = 3 * 1000;
|
private readonly REFRESH_INTERVAL = 3 * 1000;
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
|
}
|
||||||
|
|
||||||
setRegion(region: string) {
|
setRegion(region: string) {
|
||||||
this.serverInfo.server = {
|
this.serverInfo.server = {
|
||||||
region: region,
|
region: region,
|
||||||
ipv6: false,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,6 +189,11 @@ export class StreamBadges {
|
|||||||
this.intervalId = null;
|
this.intervalId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
this.serverInfo = {};
|
||||||
|
delete this.$container;
|
||||||
|
}
|
||||||
|
|
||||||
async render() {
|
async render() {
|
||||||
if (this.$container) {
|
if (this.$container) {
|
||||||
this.start();
|
this.start();
|
||||||
@ -211,15 +213,16 @@ export class StreamBadges {
|
|||||||
[StreamBadge.BATTERY, batteryLevel],
|
[StreamBadge.BATTERY, batteryLevel],
|
||||||
[StreamBadge.DOWNLOAD, humanFileSize(0)],
|
[StreamBadge.DOWNLOAD, humanFileSize(0)],
|
||||||
[StreamBadge.UPLOAD, humanFileSize(0)],
|
[StreamBadge.UPLOAD, humanFileSize(0)],
|
||||||
this.serverInfo.server ? this.badges.server.$element : [StreamBadge.SERVER, '?'],
|
this.badges.server.$element ?? [StreamBadge.SERVER, '?'],
|
||||||
this.serverInfo.video ? this.badges.video.$element : [StreamBadge.VIDEO, '?'],
|
this.serverInfo.video ? this.badges.video.$element : [StreamBadge.VIDEO, '?'],
|
||||||
this.serverInfo.audio ? this.badges.audio.$element : [StreamBadge.AUDIO, '?'],
|
this.serverInfo.audio ? this.badges.audio.$element : [StreamBadge.AUDIO, '?'],
|
||||||
];
|
];
|
||||||
|
|
||||||
const $container = CE('div', {class: 'bx-badges'});
|
const $container = CE('div', {class: 'bx-badges'});
|
||||||
BADGES.forEach(item => {
|
|
||||||
|
for (const item of BADGES) {
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let $badge: HTMLElement;
|
let $badge: HTMLElement;
|
||||||
@ -230,7 +233,7 @@ export class StreamBadges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$container.appendChild($badge);
|
$container.appendChild($badge);
|
||||||
});
|
};
|
||||||
|
|
||||||
this.$container = $container;
|
this.$container = $container;
|
||||||
await this.start();
|
await this.start();
|
||||||
@ -336,18 +339,16 @@ export class StreamBadges {
|
|||||||
BxLogger.info('candidate', candidateId, allCandidates);
|
BxLogger.info('candidate', candidateId, allCandidates);
|
||||||
|
|
||||||
// Server + Region
|
// Server + Region
|
||||||
|
let text = '';
|
||||||
|
const isIpv6 = allCandidates[candidateId].includes(':');
|
||||||
|
|
||||||
const server = this.serverInfo.server;
|
const server = this.serverInfo.server;
|
||||||
if (server) {
|
if (server && server.region) {
|
||||||
server.ipv6 = allCandidates[candidateId].includes(':');
|
text += server.region;
|
||||||
|
|
||||||
let text = '';
|
|
||||||
if (server.region) {
|
|
||||||
text += server.region;
|
|
||||||
}
|
|
||||||
|
|
||||||
text += '@' + (server ? 'IPv6' : 'IPv4');
|
|
||||||
this.badges.server.$element = this.renderBadge(StreamBadge.SERVER, text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
text += '@' + (isIpv6 ? 'IPv6' : 'IPv4');
|
||||||
|
this.badges.server.$element = this.renderBadge(StreamBadge.SERVER, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,10 @@ import { getPref, setPref } from "@/utils/settings-storages/global-settings-stor
|
|||||||
|
|
||||||
export function onChangeVideoPlayerType() {
|
export function onChangeVideoPlayerType() {
|
||||||
const playerType = getPref(PrefKey.VIDEO_PLAYER_TYPE);
|
const playerType = getPref(PrefKey.VIDEO_PLAYER_TYPE);
|
||||||
const $videoProcessing = document.getElementById('bx_setting_video_processing') as HTMLSelectElement;
|
const $videoProcessing = document.getElementById(`bx_setting_${PrefKey.VIDEO_PROCESSING}`) as HTMLSelectElement;
|
||||||
const $videoSharpness = document.getElementById('bx_setting_video_sharpness') as HTMLElement;
|
const $videoSharpness = document.getElementById(`bx_setting_${PrefKey.VIDEO_SHARPNESS}`) as HTMLElement;
|
||||||
const $videoPowerPreference = document.getElementById('bx_setting_video_power_preference') as HTMLElement;
|
const $videoPowerPreference = document.getElementById(`bx_setting_${PrefKey.VIDEO_POWER_PREFERENCE}`) as HTMLElement;
|
||||||
|
const $videoMaxFps = document.getElementById(`bx_setting_${PrefKey.VIDEO_MAX_FPS}`) as HTMLElement;
|
||||||
|
|
||||||
if (!$videoProcessing) {
|
if (!$videoProcessing) {
|
||||||
return;
|
return;
|
||||||
@ -17,7 +18,7 @@ export function onChangeVideoPlayerType() {
|
|||||||
|
|
||||||
let isDisabled = false;
|
let isDisabled = false;
|
||||||
|
|
||||||
const $optCas = $videoProcessing.querySelector(`option[value=${StreamVideoProcessing.CAS}]`) as HTMLOptionElement;
|
const $optCas = $videoProcessing.querySelector<HTMLOptionElement>(`option[value=${StreamVideoProcessing.CAS}]`);
|
||||||
|
|
||||||
if (playerType === StreamPlayerType.WEBGL2) {
|
if (playerType === StreamPlayerType.WEBGL2) {
|
||||||
$optCas && ($optCas.disabled = false);
|
$optCas && ($optCas.disabled = false);
|
||||||
@ -38,17 +39,26 @@ export function onChangeVideoPlayerType() {
|
|||||||
|
|
||||||
// Hide Power Preference setting if renderer isn't WebGL2
|
// Hide Power Preference setting if renderer isn't WebGL2
|
||||||
$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);
|
||||||
|
|
||||||
updateVideoPlayer();
|
updateVideoPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function limitVideoPlayerFps(targetFps: number) {
|
||||||
|
const streamPlayer = STATES.currentStream.streamPlayer;
|
||||||
|
streamPlayer?.getWebGL2Player()?.setTargetFps(targetFps);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function updateVideoPlayer() {
|
export function updateVideoPlayer() {
|
||||||
const streamPlayer = STATES.currentStream.streamPlayer;
|
const streamPlayer = STATES.currentStream.streamPlayer;
|
||||||
if (!streamPlayer) {
|
if (!streamPlayer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
limitVideoPlayerFps(getPref(PrefKey.VIDEO_MAX_FPS));
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
processing: getPref(PrefKey.VIDEO_PROCESSING),
|
processing: getPref(PrefKey.VIDEO_PROCESSING),
|
||||||
sharpness: getPref(PrefKey.VIDEO_SHARPNESS),
|
sharpness: getPref(PrefKey.VIDEO_SHARPNESS),
|
||||||
@ -60,6 +70,7 @@ export function updateVideoPlayer() {
|
|||||||
streamPlayer.setPlayerType(getPref(PrefKey.VIDEO_PLAYER_TYPE));
|
streamPlayer.setPlayerType(getPref(PrefKey.VIDEO_PLAYER_TYPE));
|
||||||
streamPlayer.updateOptions(options);
|
streamPlayer.updateOptions(options);
|
||||||
streamPlayer.refreshPlayer();
|
streamPlayer.refreshPlayer();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('resize', updateVideoPlayer);
|
window.addEventListener('resize', updateVideoPlayer);
|
||||||
|
@ -5,17 +5,13 @@ import { STATES } from "@utils/global"
|
|||||||
import { PrefKey } from "@/enums/pref-keys"
|
import { PrefKey } from "@/enums/pref-keys"
|
||||||
import { getPref } from "@/utils/settings-storages/global-settings-storage"
|
import { getPref } from "@/utils/settings-storages/global-settings-storage"
|
||||||
import { StreamStat, StreamStatsCollector, type StreamStatGrade } from "@/utils/stream-stats-collector"
|
import { StreamStat, StreamStatsCollector, type StreamStatGrade } from "@/utils/stream-stats-collector"
|
||||||
|
import { BxLogger } from "@/utils/bx-logger"
|
||||||
|
|
||||||
|
|
||||||
export class StreamStats {
|
export class StreamStats {
|
||||||
private static instance: StreamStats;
|
private static instance: StreamStats;
|
||||||
public static getInstance(): StreamStats {
|
public static getInstance = () => StreamStats.instance ?? (StreamStats.instance = new StreamStats());
|
||||||
if (!StreamStats.instance) {
|
private readonly LOG_TAG = 'StreamStats';
|
||||||
StreamStats.instance = new StreamStats();
|
|
||||||
}
|
|
||||||
|
|
||||||
return StreamStats.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private intervalId?: number | null;
|
private intervalId?: number | null;
|
||||||
private readonly REFRESH_INTERVAL = 1 * 1000;
|
private readonly REFRESH_INTERVAL = 1 * 1000;
|
||||||
@ -37,6 +33,10 @@ export class StreamStats {
|
|||||||
name: t('stat-ping'),
|
name: t('stat-ping'),
|
||||||
$element: CE('span'),
|
$element: CE('span'),
|
||||||
},
|
},
|
||||||
|
[StreamStat.JITTER]: {
|
||||||
|
name: t('jitter'),
|
||||||
|
$element: CE('span'),
|
||||||
|
},
|
||||||
[StreamStat.FPS]: {
|
[StreamStat.FPS]: {
|
||||||
name: t('stat-fps'),
|
name: t('stat-fps'),
|
||||||
$element: CE('span'),
|
$element: CE('span'),
|
||||||
@ -58,11 +58,11 @@ export class StreamStats {
|
|||||||
$element: CE('span'),
|
$element: CE('span'),
|
||||||
},
|
},
|
||||||
[StreamStat.DOWNLOAD]: {
|
[StreamStat.DOWNLOAD]: {
|
||||||
name: t('download'),
|
name: t('downloaded'),
|
||||||
$element: CE('span'),
|
$element: CE('span'),
|
||||||
},
|
},
|
||||||
[StreamStat.UPLOAD]: {
|
[StreamStat.UPLOAD]: {
|
||||||
name: t('upload'),
|
name: t('uploaded'),
|
||||||
$element: CE('span'),
|
$element: CE('span'),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -71,7 +71,8 @@ export class StreamStats {
|
|||||||
|
|
||||||
quickGlanceObserver?: MutationObserver | null;
|
quickGlanceObserver?: MutationObserver | null;
|
||||||
|
|
||||||
constructor() {
|
private constructor() {
|
||||||
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
this.render();
|
this.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +110,7 @@ export class StreamStats {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onStoppedPlaying() {
|
destroy() {
|
||||||
this.stop();
|
this.stop();
|
||||||
this.quickGlanceStop();
|
this.quickGlanceStop();
|
||||||
this.hideSettingsUi();
|
this.hideSettingsUi();
|
||||||
@ -158,7 +159,7 @@ export class StreamStats {
|
|||||||
|
|
||||||
private async update(forceUpdate=false) {
|
private async update(forceUpdate=false) {
|
||||||
if ((!forceUpdate && this.isHidden()) || !STATES.currentStream.peerConnection) {
|
if ((!forceUpdate && this.isHidden()) || !STATES.currentStream.peerConnection) {
|
||||||
this.onStoppedPlaying();
|
this.destroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,10 +180,8 @@ export class StreamStats {
|
|||||||
$element.textContent = value.toString();
|
$element.textContent = value.toString();
|
||||||
|
|
||||||
// Get stat's grade
|
// Get stat's grade
|
||||||
if (PREF_STATS_CONDITIONAL_FORMATTING) {
|
if (PREF_STATS_CONDITIONAL_FORMATTING && 'grades' in value) {
|
||||||
if (statKey === StreamStat.PING || statKey === StreamStat.DECODE_TIME) {
|
grade = statsCollector.calculateGrade(value.current, value.grades);
|
||||||
grade = (value as any).calculateGrade();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($element.dataset.grade !== grade) {
|
if ($element.dataset.grade !== grade) {
|
||||||
|
@ -39,7 +39,7 @@ export class StreamUiHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const $streamHud = (e.target as HTMLElement).closest('#StreamHud') as HTMLElement;
|
const $streamHud = (e.target as HTMLElement).closest<HTMLElement>('#StreamHud');
|
||||||
if (!$streamHud) {
|
if (!$streamHud) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -58,13 +58,13 @@ export class StreamUiHandler {
|
|||||||
$container.addEventListener('transitionend', onTransitionEnd);
|
$container.addEventListener('transitionend', onTransitionEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
const $button = $container.querySelector('button') as HTMLElement;
|
const $button = $container.querySelector<HTMLButtonElement>('button');
|
||||||
if (!$button) {
|
if (!$button) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$button.setAttribute('title', label);
|
$button.setAttribute('title', label);
|
||||||
|
|
||||||
const $orgSvg = $button.querySelector('svg') as SVGElement;
|
const $orgSvg = $button.querySelector<SVGElement>('svg');
|
||||||
if (!$orgSvg) {
|
if (!$orgSvg) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ export class StreamUiHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static async handleStreamMenu() {
|
private static async handleStreamMenu() {
|
||||||
const $btnCloseHud = document.querySelector('button[class*=StreamMenu-module__backButton]') as HTMLElement;
|
const $btnCloseHud = document.querySelector<HTMLElement>('button[class*=StreamMenu-module__backButton]');
|
||||||
if (!$btnCloseHud) {
|
if (!$btnCloseHud) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -136,14 +136,14 @@ export class StreamUiHandler {
|
|||||||
|
|
||||||
private static handleSystemMenu($streamHud: HTMLElement) {
|
private static handleSystemMenu($streamHud: HTMLElement) {
|
||||||
// Get the last button
|
// Get the last button
|
||||||
const $orgButton = $streamHud.querySelector('div[class^=HUDButton]') as HTMLElement;
|
const $orgButton = $streamHud.querySelector<HTMLElement>('div[class^=HUDButton]');
|
||||||
if (!$orgButton) {
|
if (!$orgButton) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const hideGripHandle = () => {
|
const hideGripHandle = () => {
|
||||||
// Grip handle
|
// Grip handle
|
||||||
const $gripHandle = document.querySelector('#StreamHud button[class^=GripHandle]') as HTMLElement;
|
const $gripHandle = document.querySelector<HTMLElement>('#StreamHud button[class^=GripHandle]');
|
||||||
if ($gripHandle && $gripHandle.ariaExpanded === 'true') {
|
if ($gripHandle && $gripHandle.ariaExpanded === 'true') {
|
||||||
$gripHandle.dispatchEvent(new PointerEvent('pointerdown'));
|
$gripHandle.dispatchEvent(new PointerEvent('pointerdown'));
|
||||||
$gripHandle.click();
|
$gripHandle.click();
|
||||||
@ -221,9 +221,10 @@ export class StreamUiHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const observer = new MutationObserver(mutationList => {
|
const observer = new MutationObserver(mutationList => {
|
||||||
mutationList.forEach(item => {
|
let item: MutationRecord;
|
||||||
|
for (item of mutationList) {
|
||||||
if (item.type !== 'childList') {
|
if (item.type !== 'childList') {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
item.addedNodes.forEach(async $node => {
|
item.addedNodes.forEach(async $node => {
|
||||||
@ -263,7 +264,7 @@ export class StreamUiHandler {
|
|||||||
// Handle System Menu bar
|
// Handle System Menu bar
|
||||||
StreamUiHandler.handleSystemMenu($elm);
|
StreamUiHandler.handleSystemMenu($elm);
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
observer.observe($screen, {subtree: true, childList: true});
|
observer.observe($screen, {subtree: true, childList: true});
|
||||||
|
@ -85,16 +85,24 @@ export class TouchController {
|
|||||||
document.querySelector('#BabylonCanvasContainer-main')?.parentElement?.classList.remove('bx-offscreen');
|
document.querySelector('#BabylonCanvasContainer-main')?.parentElement?.classList.remove('bx-offscreen');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
static #hide() {
|
static #hide() {
|
||||||
document.querySelector('#BabylonCanvasContainer-main')?.parentElement?.classList.add('bx-offscreen');
|
document.querySelector('#BabylonCanvasContainer-main')?.parentElement?.classList.add('bx-offscreen');
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
static toggleVisibility(status: boolean) {
|
static toggleVisibility(): boolean {
|
||||||
if (!TouchController.#dataChannel) {
|
if (!TouchController.#dataChannel) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
status ? TouchController.#hide() : TouchController.#show();
|
const $container = document.querySelector('#BabylonCanvasContainer-main')?.parentElement;
|
||||||
|
if (!$container) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$container.classList.toggle('bx-offscreen');
|
||||||
|
return !$container.classList.contains('bx-offscreen');
|
||||||
}
|
}
|
||||||
|
|
||||||
static reset() {
|
static reset() {
|
||||||
|
@ -2,6 +2,7 @@ import { GamepadKey } from "@/enums/mkb";
|
|||||||
import { PrefKey } from "@/enums/pref-keys";
|
import { PrefKey } from "@/enums/pref-keys";
|
||||||
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";
|
||||||
|
import { BxLogger } from "@/utils/bx-logger";
|
||||||
import { STATES } from "@/utils/global";
|
import { STATES } from "@/utils/global";
|
||||||
import { CE, isElementVisible } from "@/utils/html";
|
import { CE, isElementVisible } from "@/utils/html";
|
||||||
import { setNearby } from "@/utils/navigation-utils";
|
import { setNearby } from "@/utils/navigation-utils";
|
||||||
@ -88,12 +89,8 @@ export abstract class NavigationDialog {
|
|||||||
|
|
||||||
export class NavigationDialogManager {
|
export class NavigationDialogManager {
|
||||||
private static instance: NavigationDialogManager;
|
private static instance: NavigationDialogManager;
|
||||||
public static getInstance(): NavigationDialogManager {
|
public static getInstance = () => NavigationDialogManager.instance ?? (NavigationDialogManager.instance = new NavigationDialogManager());
|
||||||
if (!NavigationDialogManager.instance) {
|
private readonly LOG_TAG = 'NavigationDialogManager';
|
||||||
NavigationDialogManager.instance = new NavigationDialogManager();
|
|
||||||
}
|
|
||||||
return NavigationDialogManager.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static readonly GAMEPAD_POLLING_INTERVAL = 50;
|
private static readonly GAMEPAD_POLLING_INTERVAL = 50;
|
||||||
private static readonly GAMEPAD_KEYS = [
|
private static readonly GAMEPAD_KEYS = [
|
||||||
@ -141,7 +138,9 @@ export class NavigationDialogManager {
|
|||||||
private $container: HTMLElement;
|
private $container: HTMLElement;
|
||||||
private dialog: NavigationDialog | null = null;
|
private dialog: NavigationDialog | null = null;
|
||||||
|
|
||||||
constructor() {
|
private constructor() {
|
||||||
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
|
|
||||||
this.$overlay = CE('div', {class: 'bx-navigation-dialog-overlay bx-gone'});
|
this.$overlay = CE('div', {class: 'bx-navigation-dialog-overlay bx-gone'});
|
||||||
this.$overlay.addEventListener('click', e => {
|
this.$overlay.addEventListener('click', e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -178,8 +177,9 @@ export class NavigationDialogManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
calculateSelectBoxes($root: HTMLElement) {
|
calculateSelectBoxes($root: HTMLElement) {
|
||||||
const $selects = $root.querySelectorAll('.bx-select:not([data-calculated]) select');
|
const selects = Array.from($root.querySelectorAll('.bx-select:not([data-calculated]) select'));
|
||||||
$selects.forEach($select => {
|
|
||||||
|
for (const $select of selects) {
|
||||||
const $parent = $select.parentElement! as HTMLElement;
|
const $parent = $select.parentElement! as HTMLElement;
|
||||||
|
|
||||||
// Don't apply to select.bx-full-width elements
|
// Don't apply to select.bx-full-width elements
|
||||||
@ -190,23 +190,28 @@ export class NavigationDialogManager {
|
|||||||
|
|
||||||
const rect = $select.getBoundingClientRect();
|
const rect = $select.getBoundingClientRect();
|
||||||
|
|
||||||
let $label;
|
let $label: HTMLElement;
|
||||||
let width = Math.ceil(rect.width);
|
let width = Math.ceil(rect.width);
|
||||||
if (!width) {
|
if (!width) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($select as HTMLSelectElement).multiple) {
|
if (($select as HTMLSelectElement).multiple) {
|
||||||
$label = $parent.querySelector('.bx-select-value') as HTMLElement;
|
$label = $parent.querySelector<HTMLElement>('.bx-select-value')!;
|
||||||
width += 20; // Add checkbox's width
|
width += 20; // Add checkbox's width
|
||||||
} else {
|
} else {
|
||||||
$label = $parent.querySelector('div') as HTMLElement;
|
$label = $parent.querySelector<HTMLElement>('div')!;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reduce width if it has <optgroup>
|
||||||
|
if ($select.querySelector('optgroup')) {
|
||||||
|
width -= 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set min-width
|
// Set min-width
|
||||||
$label.style.minWidth = width + 'px';
|
$label.style.minWidth = width + 'px';
|
||||||
$parent.dataset.calculated = 'true';
|
$parent.dataset.calculated = 'true';
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
handleEvent(event: Event) {
|
handleEvent(event: Event) {
|
||||||
@ -234,7 +239,7 @@ export class NavigationDialogManager {
|
|||||||
} else if (keyCode === 'Enter' || keyCode === 'NumpadEnter' || keyCode === 'Space') {
|
} else if (keyCode === 'Enter' || keyCode === 'NumpadEnter' || keyCode === 'Space') {
|
||||||
if (!($target instanceof HTMLInputElement && $target.type === 'text')) {
|
if (!($target instanceof HTMLInputElement && $target.type === 'text')) {
|
||||||
handled = true;
|
handled = true;
|
||||||
$target.dispatchEvent(new MouseEvent('click'));
|
$target.dispatchEvent(new MouseEvent('click', {bubbles: true}));
|
||||||
}
|
}
|
||||||
} else if (keyCode === 'Escape') {
|
} else if (keyCode === 'Escape') {
|
||||||
handled = true;
|
handled = true;
|
||||||
@ -361,7 +366,7 @@ export class NavigationDialogManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (releasedButton === GamepadKey.A) {
|
if (releasedButton === GamepadKey.A) {
|
||||||
document.activeElement && document.activeElement.dispatchEvent(new MouseEvent('click'));
|
document.activeElement && document.activeElement.dispatchEvent(new MouseEvent('click', {bubbles: true}));
|
||||||
return;
|
return;
|
||||||
} else if (releasedButton === GamepadKey.B) {
|
} else if (releasedButton === GamepadKey.B) {
|
||||||
this.hide();
|
this.hide();
|
||||||
|
@ -7,16 +7,13 @@ 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";
|
||||||
|
|
||||||
|
|
||||||
export class RemotePlayNavigationDialog extends NavigationDialog {
|
export class RemotePlayNavigationDialog extends NavigationDialog {
|
||||||
private static instance: RemotePlayNavigationDialog;
|
private static instance: RemotePlayNavigationDialog;
|
||||||
public static getInstance(): RemotePlayNavigationDialog {
|
public static getInstance = () => RemotePlayNavigationDialog.instance ?? (RemotePlayNavigationDialog.instance = new RemotePlayNavigationDialog());
|
||||||
if (!RemotePlayNavigationDialog.instance) {
|
private readonly LOG_TAG = 'RemotePlayNavigationDialog';
|
||||||
RemotePlayNavigationDialog.instance = new RemotePlayNavigationDialog();
|
|
||||||
}
|
|
||||||
return RemotePlayNavigationDialog.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly STATE_LABELS: Record<RemotePlayConsoleState, string> = {
|
private readonly STATE_LABELS: Record<RemotePlayConsoleState, string> = {
|
||||||
[RemotePlayConsoleState.ON]: t('powered-on'),
|
[RemotePlayConsoleState.ON]: t('powered-on'),
|
||||||
@ -27,8 +24,9 @@ export class RemotePlayNavigationDialog extends NavigationDialog {
|
|||||||
|
|
||||||
$container!: HTMLElement;
|
$container!: HTMLElement;
|
||||||
|
|
||||||
constructor() {
|
private constructor() {
|
||||||
super();
|
super();
|
||||||
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
this.setupDialog();
|
this.setupDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +127,7 @@ export class RemotePlayNavigationDialog extends NavigationDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
focusIfNeeded(): void {
|
focusIfNeeded(): void {
|
||||||
const $btnConnect = this.$container.querySelector('.bx-remote-play-device-wrapper button') as HTMLElement;
|
const $btnConnect = this.$container.querySelector<HTMLElement>('.bx-remote-play-device-wrapper button');
|
||||||
$btnConnect && $btnConnect.focus();
|
$btnConnect && $btnConnect.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { isFullVersion } from "@macros/build" with {type: "macro"};
|
import { isFullVersion } from "@macros/build" with {type: "macro"};
|
||||||
|
|
||||||
import { onChangeVideoPlayerType, updateVideoPlayer } from "@/modules/stream/stream-settings-utils";
|
import { limitVideoPlayerFps, onChangeVideoPlayerType, updateVideoPlayer } from "@/modules/stream/stream-settings-utils";
|
||||||
import { ButtonStyle, CE, createButton, createSvgIcon, removeChildElements, type BxButton } from "@/utils/html";
|
import { ButtonStyle, CE, createButton, createSvgIcon, removeChildElements, type BxButton } from "@/utils/html";
|
||||||
import { NavigationDialog, NavigationDirection } from "./navigation-dialog";
|
import { NavigationDialog, NavigationDirection } from "./navigation-dialog";
|
||||||
import { ControllerShortcut } from "@/modules/controller-shortcut";
|
import { ControllerShortcut } from "@/modules/controller-shortcut";
|
||||||
@ -19,7 +19,7 @@ import { setNearby } from "@/utils/navigation-utils";
|
|||||||
import { PatcherCache } from "@/modules/patcher";
|
import { PatcherCache } from "@/modules/patcher";
|
||||||
import { UserAgentProfile } from "@/enums/user-agent";
|
import { UserAgentProfile } from "@/enums/user-agent";
|
||||||
import { UserAgent } from "@/utils/user-agent";
|
import { UserAgent } from "@/utils/user-agent";
|
||||||
import { BX_FLAGS, NATIVE_FETCH } from "@/utils/bx-flags";
|
import { BX_FLAGS, NATIVE_FETCH, type BxFlags } from "@/utils/bx-flags";
|
||||||
import { copyToClipboard } from "@/utils/utils";
|
import { copyToClipboard } from "@/utils/utils";
|
||||||
import { GamepadKey } from "@/enums/mkb";
|
import { GamepadKey } from "@/enums/mkb";
|
||||||
import { PrefKey, StorageKey } from "@/enums/pref-keys";
|
import { PrefKey, StorageKey } from "@/enums/pref-keys";
|
||||||
@ -27,16 +27,19 @@ import { ControllerDeviceVibration, getPref, getPrefDefinition, setPref, StreamT
|
|||||||
import { SettingElement, type BxHtmlSettingElement } from "@/utils/setting-element";
|
import { SettingElement, type BxHtmlSettingElement } from "@/utils/setting-element";
|
||||||
import type { RecommendedSettings, SettingDefinition, SuggestedSettingCategory as SuggestedSettingProfile } from "@/types/setting-definition";
|
import type { RecommendedSettings, SettingDefinition, SuggestedSettingCategory as SuggestedSettingProfile } from "@/types/setting-definition";
|
||||||
import { FullscreenText } from "../fullscreen-text";
|
import { FullscreenText } from "../fullscreen-text";
|
||||||
|
import { BxLogger } from "@/utils/bx-logger";
|
||||||
|
import { updatePollingRate } from "@/utils/gamepad";
|
||||||
|
|
||||||
|
|
||||||
type SettingTabContentItem = Partial<{
|
type SettingTabContentItem = Partial<{
|
||||||
pref: PrefKey;
|
pref: PrefKey;
|
||||||
label: string;
|
label: string;
|
||||||
note: string;
|
note: string | (() => HTMLElement);
|
||||||
experimental: string;
|
experimental: string;
|
||||||
content: HTMLElement | (() => HTMLElement);
|
content: HTMLElement | (() => HTMLElement);
|
||||||
options: {[key: string]: string};
|
options: {[key: string]: string};
|
||||||
unsupported: boolean;
|
unsupported: boolean;
|
||||||
|
unsupportedNote: string;
|
||||||
onChange: (e: any, value: number) => void;
|
onChange: (e: any, value: number) => void;
|
||||||
onCreated: (setting: SettingTabContentItem, $control: any) => void;
|
onCreated: (setting: SettingTabContentItem, $control: any) => void;
|
||||||
params: any;
|
params: any;
|
||||||
@ -46,33 +49,33 @@ type SettingTabContentItem = Partial<{
|
|||||||
type SettingTabContent = {
|
type SettingTabContent = {
|
||||||
group: 'general' | 'server' | 'stream' | 'game-bar' | 'co-op' | 'mkb' | 'touch-control' | 'loading-screen' | 'ui' | 'other' | 'advanced' | 'footer' | 'audio' | 'video' | 'controller' | 'native-mkb' | 'stats' | 'controller-shortcuts';
|
group: 'general' | 'server' | 'stream' | 'game-bar' | 'co-op' | 'mkb' | 'touch-control' | 'loading-screen' | 'ui' | 'other' | 'advanced' | 'footer' | 'audio' | 'video' | 'controller' | 'native-mkb' | 'stats' | 'controller-shortcuts';
|
||||||
label?: string;
|
label?: string;
|
||||||
note?: string | Text | null;
|
|
||||||
unsupported?: boolean;
|
unsupported?: boolean;
|
||||||
|
unsupportedNote?: string | Text | null;
|
||||||
helpUrl?: string;
|
helpUrl?: string;
|
||||||
content?: any;
|
content?: any;
|
||||||
|
lazyContent?: boolean | (() => HTMLElement);
|
||||||
items?: Array<SettingTabContentItem | PrefKey | (($parent: HTMLElement) => void) | false>;
|
items?: Array<SettingTabContentItem | PrefKey | (($parent: HTMLElement) => void) | false>;
|
||||||
requiredVariants?: BuildVariant | Array<BuildVariant>;
|
requiredVariants?: BuildVariant | Array<BuildVariant>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type SettingTab = {
|
type SettingTab = {
|
||||||
icon: SVGElement;
|
icon: SVGElement;
|
||||||
group: 'global';
|
group: SettingTabGroup,
|
||||||
items: Array<SettingTabContent | false>;
|
items: Array<SettingTabContent | false> | (() => Array<SettingTabContent | false>);
|
||||||
requiredVariants?: BuildVariant | Array<BuildVariant>;
|
requiredVariants?: BuildVariant | Array<BuildVariant>;
|
||||||
|
lazyContent?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type SettingTabGroup = 'global' | 'stream' | 'controller' | 'mkb' | 'native-mkb' | 'shortcuts' | 'stats';
|
||||||
|
|
||||||
export class SettingsNavigationDialog extends NavigationDialog {
|
export class SettingsNavigationDialog extends NavigationDialog {
|
||||||
private static instance: SettingsNavigationDialog;
|
private static instance: SettingsNavigationDialog;
|
||||||
public static getInstance(): SettingsNavigationDialog {
|
public static getInstance = () => SettingsNavigationDialog.instance ?? (SettingsNavigationDialog.instance = new SettingsNavigationDialog());
|
||||||
if (!SettingsNavigationDialog.instance) {
|
private readonly LOG_TAG = 'SettingsNavigationDialog';
|
||||||
SettingsNavigationDialog.instance = new SettingsNavigationDialog();
|
|
||||||
}
|
|
||||||
return SettingsNavigationDialog.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
$container!: HTMLElement;
|
$container!: HTMLElement;
|
||||||
private $tabs!: HTMLElement;
|
private $tabs!: HTMLElement;
|
||||||
private $settings!: HTMLElement;
|
private $tabContents!: HTMLElement;
|
||||||
|
|
||||||
private $btnReload!: HTMLElement;
|
private $btnReload!: HTMLElement;
|
||||||
private $btnGlobalReload!: HTMLButtonElement;
|
private $btnGlobalReload!: HTMLButtonElement;
|
||||||
@ -220,8 +223,14 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
requiredVariants: 'full',
|
requiredVariants: 'full',
|
||||||
group: 'mkb',
|
group: 'mkb',
|
||||||
label: t('mouse-and-keyboard'),
|
label: t('mouse-and-keyboard'),
|
||||||
|
unsupportedNote: !STATES.userAgent.capabilities.mkb ? CE('a', {
|
||||||
|
href: 'https://github.com/redphx/better-xcloud/issues/206#issuecomment-1920475657',
|
||||||
|
target: '_blank',
|
||||||
|
}, '⚠️ ' + t('browser-unsupported-feature')) : null,
|
||||||
|
unsupported: !STATES.userAgent.capabilities.mkb,
|
||||||
items: [
|
items: [
|
||||||
PrefKey.NATIVE_MKB_ENABLED,
|
PrefKey.NATIVE_MKB_ENABLED,
|
||||||
|
PrefKey.GAME_MSFS2020_FORCE_NATIVE_MKB,
|
||||||
PrefKey.MKB_ENABLED,
|
PrefKey.MKB_ENABLED,
|
||||||
PrefKey.MKB_HIDE_IDLE_CURSOR,
|
PrefKey.MKB_HIDE_IDLE_CURSOR,
|
||||||
],
|
],
|
||||||
@ -229,8 +238,8 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
requiredVariants: 'full',
|
requiredVariants: 'full',
|
||||||
group: 'touch-control',
|
group: 'touch-control',
|
||||||
label: t('touch-controller'),
|
label: t('touch-controller'),
|
||||||
note: !STATES.userAgent.capabilities.touch ? '⚠️ ' + t('device-unsupported-touch') : null,
|
|
||||||
unsupported: !STATES.userAgent.capabilities.touch,
|
unsupported: !STATES.userAgent.capabilities.touch,
|
||||||
|
unsupportedNote: !STATES.userAgent.capabilities.touch ? '⚠️ ' + t('device-unsupported-touch') : null,
|
||||||
items: [
|
items: [
|
||||||
PrefKey.STREAM_TOUCH_CONTROLLER,
|
PrefKey.STREAM_TOUCH_CONTROLLER,
|
||||||
PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF,
|
PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF,
|
||||||
@ -244,7 +253,6 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
items: [
|
items: [
|
||||||
PrefKey.UI_LAYOUT,
|
PrefKey.UI_LAYOUT,
|
||||||
PrefKey.UI_GAME_CARD_SHOW_WAIT_TIME,
|
PrefKey.UI_GAME_CARD_SHOW_WAIT_TIME,
|
||||||
PrefKey.UI_HOME_CONTEXT_MENU_DISABLED,
|
|
||||||
PrefKey.CONTROLLER_SHOW_CONNECTION_STATUS,
|
PrefKey.CONTROLLER_SHOW_CONNECTION_STATUS,
|
||||||
PrefKey.STREAM_SIMPLIFY_MENU,
|
PrefKey.STREAM_SIMPLIFY_MENU,
|
||||||
PrefKey.SKIP_SPLASH_VIDEO,
|
PrefKey.SKIP_SPLASH_VIDEO,
|
||||||
@ -325,8 +333,8 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
// xCloud version
|
// xCloud version
|
||||||
($parent) => {
|
($parent) => {
|
||||||
try {
|
try {
|
||||||
const appVersion = (document.querySelector('meta[name=gamepass-app-version]') as HTMLMetaElement).content;
|
const appVersion = document.querySelector<HTMLMetaElement>('meta[name=gamepass-app-version]')!.content;
|
||||||
const appDate = new Date((document.querySelector('meta[name=gamepass-app-date]') as HTMLMetaElement).content).toISOString().substring(0, 10);
|
const appDate = new Date(document.querySelector<HTMLMetaElement>('meta[name=gamepass-app-date]')!.content).toISOString().substring(0, 10);
|
||||||
$parent.appendChild(CE('div', {
|
$parent.appendChild(CE('div', {
|
||||||
class: 'bx-settings-app-version',
|
class: 'bx-settings-app-version',
|
||||||
}, `xCloud website version ${appVersion} (${appDate})`));
|
}, `xCloud website version ${appVersion} (${appDate})`));
|
||||||
@ -379,7 +387,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
disabled: !getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL),
|
disabled: !getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL),
|
||||||
},
|
},
|
||||||
onCreated: (setting: SettingTabContentItem, $elm: HTMLElement) => {
|
onCreated: (setting: SettingTabContentItem, $elm: HTMLElement) => {
|
||||||
const $range = $elm.querySelector('input[type=range') as HTMLInputElement;
|
const $range = $elm.querySelector<HTMLInputElement>('input[type=range')!;
|
||||||
window.addEventListener(BxEvent.SETTINGS_CHANGED, e => {
|
window.addEventListener(BxEvent.SETTINGS_CHANGED, e => {
|
||||||
const { storageKey, settingKey, settingValue } = e as any;
|
const { storageKey, settingKey, settingValue } = e as any;
|
||||||
if (storageKey !== StorageKey.GLOBAL || settingKey !== PrefKey.AUDIO_VOLUME) {
|
if (storageKey !== StorageKey.GLOBAL || settingKey !== PrefKey.AUDIO_VOLUME) {
|
||||||
@ -400,6 +408,11 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
items: [{
|
items: [{
|
||||||
pref: PrefKey.VIDEO_PLAYER_TYPE,
|
pref: PrefKey.VIDEO_PLAYER_TYPE,
|
||||||
onChange: onChangeVideoPlayerType,
|
onChange: onChangeVideoPlayerType,
|
||||||
|
}, {
|
||||||
|
pref: PrefKey.VIDEO_MAX_FPS,
|
||||||
|
onChange: e => {
|
||||||
|
limitVideoPlayerFps(parseInt(e.target.value));
|
||||||
|
},
|
||||||
}, {
|
}, {
|
||||||
pref: PrefKey.VIDEO_POWER_PREFERENCE,
|
pref: PrefKey.VIDEO_POWER_PREFERENCE,
|
||||||
onChange: () => {
|
onChange: () => {
|
||||||
@ -448,6 +461,9 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
pref: PrefKey.CONTROLLER_VIBRATION_INTENSITY,
|
pref: PrefKey.CONTROLLER_VIBRATION_INTENSITY,
|
||||||
unsupported: !VibrationManager.supportDeviceVibration(),
|
unsupported: !VibrationManager.supportDeviceVibration(),
|
||||||
onChange: () => VibrationManager.updateGlobalVars(),
|
onChange: () => VibrationManager.updateGlobalVars(),
|
||||||
|
}, isFullVersion() && {
|
||||||
|
pref: PrefKey.CONTROLLER_POLLING_RATE,
|
||||||
|
onChange: () => updatePollingRate(),
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -505,31 +521,31 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}],
|
}],
|
||||||
}];
|
}];
|
||||||
|
|
||||||
private readonly TAB_VIRTUAL_CONTROLLER_ITEMS: Array<SettingTabContent | false> = [{
|
private readonly TAB_VIRTUAL_CONTROLLER_ITEMS: (() => Array<SettingTabContent | false>) = () => [{
|
||||||
group: 'mkb',
|
group: 'mkb',
|
||||||
label: t('virtual-controller'),
|
label: t('virtual-controller'),
|
||||||
helpUrl: 'https://better-xcloud.github.io/mouse-and-keyboard/',
|
helpUrl: 'https://better-xcloud.github.io/mouse-and-keyboard/',
|
||||||
content: isFullVersion() && MkbRemapper.INSTANCE.render(),
|
content: MkbRemapper.getInstance().render(),
|
||||||
}];
|
}];
|
||||||
|
|
||||||
private readonly TAB_NATIVE_MKB_ITEMS: Array<SettingTabContent | false> = [{
|
private readonly TAB_NATIVE_MKB_ITEMS: Array<SettingTabContent | false> = [{
|
||||||
requiredVariants: 'full',
|
requiredVariants: 'full',
|
||||||
group: 'native-mkb',
|
group: 'native-mkb',
|
||||||
label: t('native-mkb'),
|
label: t('native-mkb'),
|
||||||
items: [isFullVersion() && {
|
items: isFullVersion() ? [{
|
||||||
pref: PrefKey.NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY,
|
pref: PrefKey.NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY,
|
||||||
onChange: (e: any, value: number) => {
|
onChange: (e: any, value: number) => {
|
||||||
NativeMkbHandler.getInstance().setVerticalScrollMultiplier(value / 100);
|
NativeMkbHandler.getInstance().setVerticalScrollMultiplier(value / 100);
|
||||||
},
|
},
|
||||||
}, isFullVersion() && {
|
}, {
|
||||||
pref: PrefKey.NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY,
|
pref: PrefKey.NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY,
|
||||||
onChange: (e: any, value: number) => {
|
onChange: (e: any, value: number) => {
|
||||||
NativeMkbHandler.getInstance().setHorizontalScrollMultiplier(value / 100);
|
NativeMkbHandler.getInstance().setHorizontalScrollMultiplier(value / 100);
|
||||||
},
|
},
|
||||||
}],
|
}] : [],
|
||||||
}];
|
}];
|
||||||
|
|
||||||
private readonly TAB_SHORTCUTS_ITEMS: Array<SettingTabContent | false> = [{
|
private readonly TAB_SHORTCUTS_ITEMS: (() => Array<SettingTabContent | false>) = () => [{
|
||||||
requiredVariants: 'full',
|
requiredVariants: 'full',
|
||||||
group: 'controller-shortcuts',
|
group: 'controller-shortcuts',
|
||||||
label: t('controller-shortcuts'),
|
label: t('controller-shortcuts'),
|
||||||
@ -570,56 +586,59 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
],
|
],
|
||||||
}];
|
}];
|
||||||
|
|
||||||
private readonly SETTINGS_UI: Array<SettingTab> = [
|
private readonly SETTINGS_UI: Record<SettingTabGroup, SettingTab> = {
|
||||||
{
|
global: {
|
||||||
icon: BxIcon.HOME,
|
|
||||||
group: 'global',
|
group: 'global',
|
||||||
|
icon: BxIcon.HOME,
|
||||||
items: this.TAB_GLOBAL_ITEMS,
|
items: this.TAB_GLOBAL_ITEMS,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
stream: {
|
||||||
icon: BxIcon.DISPLAY,
|
|
||||||
group: 'stream',
|
group: 'stream',
|
||||||
|
icon: BxIcon.DISPLAY,
|
||||||
items: this.TAB_DISPLAY_ITEMS,
|
items: this.TAB_DISPLAY_ITEMS,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
controller: {
|
||||||
icon: BxIcon.CONTROLLER,
|
|
||||||
group: 'controller',
|
group: 'controller',
|
||||||
|
icon: BxIcon.CONTROLLER,
|
||||||
items: this.TAB_CONTROLLER_ITEMS,
|
items: this.TAB_CONTROLLER_ITEMS,
|
||||||
requiredVariants: 'full',
|
requiredVariants: 'full',
|
||||||
},
|
},
|
||||||
|
|
||||||
isFullVersion() && getPref(PrefKey.MKB_ENABLED) && {
|
mkb: isFullVersion() && getPref(PrefKey.MKB_ENABLED) && {
|
||||||
icon: BxIcon.VIRTUAL_CONTROLLER,
|
|
||||||
group: 'mkb',
|
group: 'mkb',
|
||||||
|
icon: BxIcon.VIRTUAL_CONTROLLER,
|
||||||
items: this.TAB_VIRTUAL_CONTROLLER_ITEMS,
|
items: this.TAB_VIRTUAL_CONTROLLER_ITEMS,
|
||||||
|
lazyContent: true,
|
||||||
requiredVariants: 'full',
|
requiredVariants: 'full',
|
||||||
},
|
},
|
||||||
|
|
||||||
isFullVersion() && AppInterface && getPref(PrefKey.NATIVE_MKB_ENABLED) === 'on' && {
|
'native-mkb': isFullVersion() && AppInterface && getPref(PrefKey.NATIVE_MKB_ENABLED) === 'on' && {
|
||||||
icon: BxIcon.NATIVE_MKB,
|
|
||||||
group: 'native-mkb',
|
group: 'native-mkb',
|
||||||
|
icon: BxIcon.NATIVE_MKB,
|
||||||
items: this.TAB_NATIVE_MKB_ITEMS,
|
items: this.TAB_NATIVE_MKB_ITEMS,
|
||||||
requiredVariants: 'full',
|
requiredVariants: 'full',
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
shortcuts: {
|
||||||
icon: BxIcon.COMMAND,
|
|
||||||
group: 'shortcuts',
|
group: 'shortcuts',
|
||||||
|
icon: BxIcon.COMMAND,
|
||||||
items: this.TAB_SHORTCUTS_ITEMS,
|
items: this.TAB_SHORTCUTS_ITEMS,
|
||||||
|
lazyContent: true,
|
||||||
requiredVariants: 'full',
|
requiredVariants: 'full',
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
stats: {
|
||||||
icon: BxIcon.STREAM_STATS,
|
|
||||||
group: 'stats',
|
group: 'stats',
|
||||||
|
icon: BxIcon.STREAM_STATS,
|
||||||
items: this.TAB_STATS_ITEMS,
|
items: this.TAB_STATS_ITEMS,
|
||||||
},
|
},
|
||||||
];
|
};
|
||||||
|
|
||||||
constructor() {
|
private constructor() {
|
||||||
super();
|
super();
|
||||||
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
|
|
||||||
this.renderFullSettings = STATES.supportedRegion && STATES.isSignedIn;
|
this.renderFullSettings = STATES.supportedRegion && STATES.isSignedIn;
|
||||||
this.setupDialog();
|
this.setupDialog();
|
||||||
@ -647,7 +666,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Trigger event
|
// Trigger event
|
||||||
const $selectUserAgent = document.querySelector(`#bx_setting_${PrefKey.USER_AGENT_PROFILE}`) as HTMLSelectElement;
|
const $selectUserAgent = document.querySelector<HTMLSelectElement>(`#bx_setting_${PrefKey.USER_AGENT_PROFILE}`);
|
||||||
if ($selectUserAgent) {
|
if ($selectUserAgent) {
|
||||||
$selectUserAgent.disabled = true;
|
$selectUserAgent.disabled = true;
|
||||||
BxEvent.dispatch($selectUserAgent, 'input', {});
|
BxEvent.dispatch($selectUserAgent, 'input', {});
|
||||||
@ -664,10 +683,23 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getRecommendedSettings(deviceCode: string): Promise<string | null> {
|
private async getRecommendedSettings(androidInfo: BxFlags['DeviceInfo']['androidInfo']): Promise<string | null> {
|
||||||
|
function normalize(str: string) {
|
||||||
|
return str.toLowerCase()
|
||||||
|
.trim()
|
||||||
|
.replaceAll(/\s+/g, '-')
|
||||||
|
.replaceAll(/-+/g, '-');
|
||||||
|
}
|
||||||
|
|
||||||
// Get recommended settings from GitHub
|
// Get recommended settings from GitHub
|
||||||
try {
|
try {
|
||||||
const response = await NATIVE_FETCH(`https://raw.githubusercontent.com/redphx/better-xcloud/gh-pages/devices/${deviceCode.toLowerCase()}.json`);
|
let {brand, board, model} = androidInfo!;
|
||||||
|
brand = normalize(brand);
|
||||||
|
board = normalize(board);
|
||||||
|
model = normalize(model);
|
||||||
|
|
||||||
|
const url = `https://raw.githubusercontent.com/redphx/better-xcloud/gh-pages/devices/${brand}/${board}-${model}.json`;
|
||||||
|
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<PrefKey, any> = {};
|
||||||
|
|
||||||
@ -751,8 +783,11 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get labels
|
// Get labels
|
||||||
for (const settingTab of this.SETTINGS_UI) {
|
let settingTabGroup: keyof typeof this.SETTINGS_UI;
|
||||||
if (!settingTab || !settingTab.items) {
|
for (settingTabGroup in this.SETTINGS_UI) {
|
||||||
|
const settingTab = this.SETTINGS_UI[settingTabGroup];
|
||||||
|
|
||||||
|
if (!settingTab || !settingTab.items || typeof settingTab.items === 'function') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -782,11 +817,17 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
|
|
||||||
if (BX_FLAGS.DeviceInfo.deviceType.includes('android')) {
|
if (BX_FLAGS.DeviceInfo.deviceType.includes('android')) {
|
||||||
if (BX_FLAGS.DeviceInfo.androidInfo) {
|
if (BX_FLAGS.DeviceInfo.androidInfo) {
|
||||||
const deviceCode = BX_FLAGS.DeviceInfo.androidInfo.board;
|
recommendedDevice = await this.getRecommendedSettings(BX_FLAGS.DeviceInfo.androidInfo);
|
||||||
recommendedDevice = await this.getRecommendedSettings(deviceCode);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// recommendedDevice = await this.getRecommendedSettings('foster_e');
|
|
||||||
|
/*
|
||||||
|
recommendedDevice = await this.getRecommendedSettings({
|
||||||
|
manufacturer: 'Lenovo',
|
||||||
|
board: 'kona',
|
||||||
|
model: 'Lenovo TB-9707F',
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
const hasRecommendedSettings = Object.keys(this.suggestedSettings.recommended).length > 0;
|
const hasRecommendedSettings = Object.keys(this.suggestedSettings.recommended).length > 0;
|
||||||
|
|
||||||
@ -895,7 +936,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
let prefKey: PrefKey;
|
let prefKey: PrefKey;
|
||||||
for (prefKey in settings) {
|
for (prefKey in settings) {
|
||||||
const suggestedValue = settings[prefKey];
|
const suggestedValue = settings[prefKey];
|
||||||
const $checkBox = $content.querySelector(`#bx_suggest_${prefKey}`) as HTMLInputElement;
|
const $checkBox = $content.querySelector<HTMLInputElement>(`#bx_suggest_${prefKey}`)!;
|
||||||
if (!$checkBox.checked || $checkBox.disabled) {
|
if (!$checkBox.checked || $checkBox.disabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -955,43 +996,64 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}, t('suggest-settings-link')),
|
}, t('suggest-settings-link')),
|
||||||
);
|
);
|
||||||
|
|
||||||
$btnSuggest?.insertAdjacentElement('afterend', $content);
|
$btnSuggest.insertAdjacentElement('afterend', $content);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onTabClicked(e: Event) {
|
||||||
|
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];
|
||||||
|
|
||||||
|
const items = (settingTab.items as Function)();
|
||||||
|
const $tabContent = this.renderTabContent.call(this, settingTab, items);
|
||||||
|
this.$tabContents.appendChild($tabContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Switch tab
|
||||||
|
let $child: HTMLElement;
|
||||||
|
const children = Array.from(this.$tabContents.children) as HTMLElement[];
|
||||||
|
for ($child of children) {
|
||||||
|
if ($child.dataset.tabGroup === $svg.dataset.group) {
|
||||||
|
// Show tab content
|
||||||
|
$child.classList.remove('bx-gone');
|
||||||
|
|
||||||
|
// Calculate size of controller-friendly select boxes
|
||||||
|
if (getPref(PrefKey.UI_CONTROLLER_FRIENDLY)) {
|
||||||
|
this.dialogManager.calculateSelectBoxes($child as HTMLElement);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Hide tab content
|
||||||
|
$child.classList.add('bx-gone');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Highlight current tab button
|
||||||
|
for (const $child of Array.from(this.$tabs.children)) {
|
||||||
|
$child.classList.remove('bx-active');
|
||||||
|
}
|
||||||
|
|
||||||
|
$svg.classList.add('bx-active');
|
||||||
}
|
}
|
||||||
|
|
||||||
private renderTab(settingTab: SettingTab) {
|
private renderTab(settingTab: SettingTab) {
|
||||||
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', e => {
|
$svg.addEventListener('click', this.onTabClicked.bind(this));
|
||||||
// Switch tab
|
|
||||||
for (const $child of Array.from(this.$settings.children)) {
|
|
||||||
if ($child.getAttribute('data-tab-group') === settingTab.group) {
|
|
||||||
$child.classList.remove('bx-gone');
|
|
||||||
|
|
||||||
// Calculate size of controller-friendly select boxes
|
|
||||||
if (getPref(PrefKey.UI_CONTROLLER_FRIENDLY)) {
|
|
||||||
this.dialogManager.calculateSelectBoxes($child as HTMLElement);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$child.classList.add('bx-gone');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Highlight current tab button
|
|
||||||
for (const $child of Array.from(this.$tabs.children)) {
|
|
||||||
$child.classList.remove('bx-active');
|
|
||||||
}
|
|
||||||
|
|
||||||
$svg.classList.add('bx-active');
|
|
||||||
});
|
|
||||||
|
|
||||||
return $svg;
|
return $svg;
|
||||||
}
|
}
|
||||||
|
|
||||||
private onGlobalSettingChanged(e: Event) {
|
private onGlobalSettingChanged(e: Event) {
|
||||||
// Clear PatcherCache;
|
// Clear PatcherCache;
|
||||||
isFullVersion() && PatcherCache.clear();
|
isFullVersion() && PatcherCache.getInstance().clear();
|
||||||
|
|
||||||
this.$btnReload.classList.add('bx-danger');
|
this.$btnReload.classList.add('bx-danger');
|
||||||
|
|
||||||
@ -1001,13 +1063,37 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private renderServerSetting(setting: SettingTabContentItem): HTMLElement {
|
private renderServerSetting(setting: SettingTabContentItem): HTMLElement {
|
||||||
let selectedValue;
|
let selectedValue =getPref(PrefKey.SERVER_REGION);
|
||||||
|
|
||||||
|
const continents: Record<ServerContinent, {
|
||||||
|
label: string,
|
||||||
|
children?: HTMLOptionElement[],
|
||||||
|
}> = {
|
||||||
|
'america-north': {
|
||||||
|
label: t('continent-north-america'),
|
||||||
|
},
|
||||||
|
'america-south': {
|
||||||
|
label: t('continent-south-america'),
|
||||||
|
},
|
||||||
|
'asia': {
|
||||||
|
label: t('continent-asia'),
|
||||||
|
},
|
||||||
|
'australia': {
|
||||||
|
label: t('continent-australia'),
|
||||||
|
},
|
||||||
|
'europe': {
|
||||||
|
label: t('continent-europe'),
|
||||||
|
},
|
||||||
|
'other': {
|
||||||
|
label: t('other'),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const $control = CE<HTMLSelectElement>('select', {
|
const $control = CE<HTMLSelectElement>('select', {
|
||||||
id: `bx_setting_${setting.pref}`,
|
id: `bx_setting_${setting.pref}`,
|
||||||
title: setting.label,
|
title: setting.label,
|
||||||
tabindex: 0,
|
tabindex: 0,
|
||||||
});
|
});
|
||||||
$control.name = $control.id;
|
$control.name = $control.id;
|
||||||
|
|
||||||
$control.addEventListener('input', (e: Event) => {
|
$control.addEventListener('input', (e: Event) => {
|
||||||
@ -1015,8 +1101,6 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
this.onGlobalSettingChanged(e);
|
this.onGlobalSettingChanged(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
selectedValue = getPref(PrefKey.SERVER_REGION);
|
|
||||||
|
|
||||||
setting.options = {};
|
setting.options = {};
|
||||||
for (const regionName in STATES.serverRegions) {
|
for (const regionName in STATES.serverRegions) {
|
||||||
const region = STATES.serverRegions[regionName];
|
const region = STATES.serverRegions[regionName];
|
||||||
@ -1033,15 +1117,29 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setting.options[value] = label;
|
setting.options[value] = label;
|
||||||
|
|
||||||
|
const $option = CE<HTMLOptionElement>('option', {value: value}, label);
|
||||||
|
const continent = continents[region.contintent];
|
||||||
|
if (!continent.children) {
|
||||||
|
continent.children = [];
|
||||||
|
}
|
||||||
|
continent.children.push($option);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const value in setting.options) {
|
const fragment = document.createDocumentFragment();
|
||||||
const label = setting.options[value];
|
let key: keyof typeof continents;
|
||||||
|
for (key in continents) {
|
||||||
|
const continent = continents[key];
|
||||||
|
if (!continent.children) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const $option = CE('option', {value: value}, label);
|
fragment.appendChild(CE('optgroup', {
|
||||||
$control.appendChild($option);
|
label: continent.label,
|
||||||
|
}, ...continent.children));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$control.appendChild(fragment);
|
||||||
$control.disabled = Object.keys(STATES.serverRegions).length === 0;
|
$control.disabled = Object.keys(STATES.serverRegions).length === 0;
|
||||||
|
|
||||||
// Select preferred region
|
// Select preferred region
|
||||||
@ -1131,9 +1229,19 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let label = prefDefinition?.label || setting.label;
|
let label = prefDefinition?.label || setting.label;
|
||||||
let note = prefDefinition?.note || setting.note;
|
let note: string | undefined | (() => HTMLElement) | HTMLElement = prefDefinition?.note || setting.note;
|
||||||
|
let unsupportedNote: string | undefined | (() => HTMLElement) | HTMLElement = prefDefinition?.unsupportedNote || setting.unsupportedNote;
|
||||||
const experimental = prefDefinition?.experimental || setting.experimental;
|
const experimental = prefDefinition?.experimental || setting.experimental;
|
||||||
|
|
||||||
|
// Render note lazily
|
||||||
|
if (typeof note === 'function') {
|
||||||
|
note = note();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof unsupportedNote === 'function') {
|
||||||
|
unsupportedNote = unsupportedNote();
|
||||||
|
}
|
||||||
|
|
||||||
if (settingTabContent.label && setting.pref) {
|
if (settingTabContent.label && setting.pref) {
|
||||||
if (prefDefinition?.suggest) {
|
if (prefDefinition?.suggest) {
|
||||||
typeof prefDefinition.suggest.lowest !== 'undefined' && (this.suggestedSettings.lowest[setting.pref] = prefDefinition.suggest.lowest);
|
typeof prefDefinition.suggest.lowest !== 'undefined' && (this.suggestedSettings.lowest[setting.pref] = prefDefinition.suggest.lowest);
|
||||||
@ -1151,6 +1259,13 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let $note;
|
||||||
|
if (unsupportedNote) {
|
||||||
|
$note = CE('div', {class: 'bx-settings-dialog-note'}, unsupportedNote);
|
||||||
|
} else if (note) {
|
||||||
|
$note = CE('div', {class: 'bx-settings-dialog-note'}, note);
|
||||||
|
}
|
||||||
|
|
||||||
let $label;
|
let $label;
|
||||||
|
|
||||||
const $row = CE('label', {
|
const $row = CE('label', {
|
||||||
@ -1163,7 +1278,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
},
|
},
|
||||||
$label = CE('span', {class: 'bx-settings-label'},
|
$label = CE('span', {class: 'bx-settings-label'},
|
||||||
label,
|
label,
|
||||||
note ? CE('div', {class: 'bx-settings-dialog-note'}, note) : prefDefinition?.unsupported && CE('div', {class: 'bx-settings-dialog-note'}, t('browser-unsupported-feature')),
|
$note,
|
||||||
),
|
),
|
||||||
!prefDefinition?.unsupported && $control,
|
!prefDefinition?.unsupported && $control,
|
||||||
);
|
);
|
||||||
@ -1181,9 +1296,101 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
!prefDefinition?.unsupported && setting.onCreated && setting.onCreated(setting, $control);
|
!prefDefinition?.unsupported && setting.onCreated && setting.onCreated(setting, $control);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private renderTabContent(settingTab: SettingTab, items: Array<SettingTabContent | false>): HTMLElement {
|
||||||
|
const $tabContent = CE('div', {
|
||||||
|
class: 'bx-gone',
|
||||||
|
'data-tab-group': settingTab.group,
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const settingTabContent of items) {
|
||||||
|
if (!settingTabContent) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.isSupportedVariant(settingTabContent.requiredVariants)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't render other settings in unsupported regions
|
||||||
|
if (!this.renderFullSettings && settingTab.group === 'global' && settingTabContent.group !== 'general' && settingTabContent.group !== 'footer') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let label = settingTabContent.label;
|
||||||
|
|
||||||
|
// If label is "Better xCloud" => create a link to Releases page
|
||||||
|
if (label === t('better-xcloud')) {
|
||||||
|
label += ' ' + SCRIPT_VERSION;
|
||||||
|
|
||||||
|
if (SCRIPT_VARIANT === 'lite') {
|
||||||
|
label += ' (Lite)';
|
||||||
|
}
|
||||||
|
|
||||||
|
label = createButton({
|
||||||
|
label: label,
|
||||||
|
url: 'https://github.com/redphx/better-xcloud/releases',
|
||||||
|
style: ButtonStyle.NORMAL_CASE | ButtonStyle.FROSTED | ButtonStyle.FOCUSABLE,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (label) {
|
||||||
|
const $title = CE('h2', {
|
||||||
|
_nearby: {
|
||||||
|
orientation: 'horizontal',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CE('span', {}, label),
|
||||||
|
settingTabContent.helpUrl && createButton({
|
||||||
|
icon: BxIcon.QUESTION,
|
||||||
|
style: ButtonStyle.GHOST | ButtonStyle.FOCUSABLE,
|
||||||
|
url: settingTabContent.helpUrl,
|
||||||
|
title: t('help'),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
$tabContent.appendChild($title);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add note
|
||||||
|
if (settingTabContent.unsupportedNote) {
|
||||||
|
const $note = CE('b', {class: 'bx-note-unsupported'}, settingTabContent.unsupportedNote);
|
||||||
|
|
||||||
|
$tabContent.appendChild($note);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't render settings if this is an unsupported feature
|
||||||
|
if (settingTabContent.unsupported) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add content DOM
|
||||||
|
if (settingTabContent.content) {
|
||||||
|
$tabContent.appendChild(settingTabContent.content);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render list of settings
|
||||||
|
settingTabContent.items = settingTabContent.items || [];
|
||||||
|
for (const setting of settingTabContent.items) {
|
||||||
|
if (setting === false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof setting === 'function') {
|
||||||
|
setting.apply(this, [$tabContent]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.renderSettingRow(settingTab, $tabContent, settingTabContent, setting);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tabContent;
|
||||||
|
}
|
||||||
|
|
||||||
private setupDialog() {
|
private setupDialog() {
|
||||||
let $tabs: HTMLElement;
|
let $tabs: HTMLElement;
|
||||||
let $settings: HTMLElement;
|
let $tabContents: HTMLElement;
|
||||||
|
|
||||||
const $container = CE('div', {
|
const $container = CE('div', {
|
||||||
class: 'bx-settings-dialog',
|
class: 'bx-settings-dialog',
|
||||||
@ -1231,7 +1438,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
$settings = CE('div', {
|
$tabContents = CE('div', {
|
||||||
class: 'bx-settings-tab-contents',
|
class: 'bx-settings-tab-contents',
|
||||||
_nearby: {
|
_nearby: {
|
||||||
orientation: 'vertical',
|
orientation: 'vertical',
|
||||||
@ -1250,7 +1457,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
|
|
||||||
this.$container = $container;
|
this.$container = $container;
|
||||||
this.$tabs = $tabs;
|
this.$tabs = $tabs;
|
||||||
this.$settings = $settings;
|
this.$tabContents = $tabContents;
|
||||||
|
|
||||||
// Close dialog when not clicking on any child elements in the dialog
|
// Close dialog when not clicking on any child elements in the dialog
|
||||||
$container.addEventListener('click', e => {
|
$container.addEventListener('click', e => {
|
||||||
@ -1261,7 +1468,10 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const settingTab of this.SETTINGS_UI) {
|
let settingTabGroup: keyof typeof this.SETTINGS_UI
|
||||||
|
for (settingTabGroup in this.SETTINGS_UI) {
|
||||||
|
const settingTab = this.SETTINGS_UI[settingTabGroup];
|
||||||
|
|
||||||
if (!settingTab) {
|
if (!settingTab) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1279,100 +1489,13 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
const $svg = this.renderTab(settingTab);
|
const $svg = this.renderTab(settingTab);
|
||||||
$tabs.appendChild($svg);
|
$tabs.appendChild($svg);
|
||||||
|
|
||||||
const $tabContent = CE('div', {
|
// Don't render lazy tab content
|
||||||
class: 'bx-gone',
|
if (typeof settingTab.items === 'function') {
|
||||||
'data-tab-group': settingTab.group,
|
continue;
|
||||||
});
|
|
||||||
|
|
||||||
for (const settingTabContent of settingTab.items) {
|
|
||||||
if (settingTabContent === false) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.isSupportedVariant(settingTabContent.requiredVariants)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't render other settings in unsupported regions
|
|
||||||
if (!this.renderFullSettings && settingTab.group === 'global' && settingTabContent.group !== 'general' && settingTabContent.group !== 'footer') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let label = settingTabContent.label;
|
|
||||||
|
|
||||||
// If label is "Better xCloud" => create a link to Releases page
|
|
||||||
if (label === t('better-xcloud')) {
|
|
||||||
label += ' ' + SCRIPT_VERSION;
|
|
||||||
|
|
||||||
if (SCRIPT_VARIANT === 'lite') {
|
|
||||||
label += ' (Lite)';
|
|
||||||
}
|
|
||||||
|
|
||||||
label = createButton({
|
|
||||||
label: label,
|
|
||||||
url: 'https://github.com/redphx/better-xcloud/releases',
|
|
||||||
style: ButtonStyle.NORMAL_CASE | ButtonStyle.FROSTED | ButtonStyle.FOCUSABLE,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (label) {
|
|
||||||
const $title = CE('h2', {
|
|
||||||
_nearby: {
|
|
||||||
orientation: 'horizontal',
|
|
||||||
}
|
|
||||||
},
|
|
||||||
CE('span', {}, label),
|
|
||||||
settingTabContent.helpUrl && createButton({
|
|
||||||
icon: BxIcon.QUESTION,
|
|
||||||
style: ButtonStyle.GHOST | ButtonStyle.FOCUSABLE,
|
|
||||||
url: settingTabContent.helpUrl,
|
|
||||||
title: t('help'),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
$tabContent.appendChild($title);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add note
|
|
||||||
if (settingTabContent.note) {
|
|
||||||
let $note;
|
|
||||||
if (typeof settingTabContent.note === 'string') {
|
|
||||||
$note = CE('b', {class: 'bx-note-unsupported'}, settingTabContent.note);
|
|
||||||
} else {
|
|
||||||
$note = settingTabContent.note;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tabContent.appendChild($note);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't render settings if this is an unsupported feature
|
|
||||||
if (settingTabContent.unsupported) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add content DOM
|
|
||||||
if (settingTabContent.content) {
|
|
||||||
$tabContent.appendChild(settingTabContent.content);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render list of settings
|
|
||||||
settingTabContent.items = settingTabContent.items || [];
|
|
||||||
for (const setting of settingTabContent.items) {
|
|
||||||
if (setting === false) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof setting === 'function') {
|
|
||||||
setting.apply(this, [$tabContent]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.renderSettingRow(settingTab, $tabContent, settingTabContent, setting);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$settings.appendChild($tabContent);
|
const $tabContent = this.renderTabContent.call(this, settingTab, settingTab.items);
|
||||||
|
$tabContents.appendChild($tabContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select first tab
|
// Select first tab
|
||||||
@ -1389,13 +1512,13 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private focusActiveTab() {
|
private focusActiveTab() {
|
||||||
const $currentTab = this.$tabs!.querySelector('.bx-active') as HTMLElement;
|
const $currentTab = this.$tabs!.querySelector<HTMLElement>('.bx-active');
|
||||||
$currentTab && $currentTab.focus();
|
$currentTab && $currentTab.focus();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private focusVisibleSetting(type: 'first' | 'last' = 'first'): boolean {
|
private focusVisibleSetting(type: 'first' | 'last' = 'first'): boolean {
|
||||||
const controls = Array.from(this.$settings.querySelectorAll('div[data-tab-group]:not(.bx-gone) > *'));
|
const controls = Array.from(this.$tabContents.querySelectorAll('div[data-tab-group]:not(.bx-gone) > *'));
|
||||||
if (!controls.length) {
|
if (!controls.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1441,7 +1564,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private jumpToSettingGroup(direction: 'next' | 'previous'): boolean {
|
private jumpToSettingGroup(direction: 'next' | 'previous'): boolean {
|
||||||
const $tabContent = this.$settings.querySelector('div[data-tab-group]:not(.bx-gone)');
|
const $tabContent = this.$tabContents.querySelector('div[data-tab-group]:not(.bx-gone)');
|
||||||
if (!$tabContent) {
|
if (!$tabContent) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1452,7 +1575,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
$header = $tabContent.querySelector('h2');
|
$header = $tabContent.querySelector('h2');
|
||||||
} else {
|
} else {
|
||||||
// Find the parent element
|
// Find the parent element
|
||||||
const $parent = $focusing.closest('[data-tab-group] > *') as HTMLElement;
|
const $parent = $focusing.closest<HTMLElement>('[data-tab-group] > *');
|
||||||
const siblingProperty = direction === 'next' ? 'nextSibling' : 'previousSibling';
|
const siblingProperty = direction === 'next' ? 'nextSibling' : 'previousSibling';
|
||||||
|
|
||||||
let $tmp = $parent;
|
let $tmp = $parent;
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
|
import { BxLogger } from "@/utils/bx-logger";
|
||||||
import { CE } from "@/utils/html";
|
import { CE } from "@/utils/html";
|
||||||
|
|
||||||
export class FullscreenText {
|
export class FullscreenText {
|
||||||
private static instance: FullscreenText;
|
private static instance: FullscreenText;
|
||||||
public static getInstance(): FullscreenText {
|
public static getInstance = () => FullscreenText.instance ?? (FullscreenText.instance = new FullscreenText());
|
||||||
if (!FullscreenText.instance) {
|
private readonly LOG_TAG = 'FullscreenText';
|
||||||
FullscreenText.instance = new FullscreenText();
|
|
||||||
}
|
|
||||||
return FullscreenText.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
$text: HTMLElement;
|
$text: HTMLElement;
|
||||||
|
|
||||||
constructor() {
|
private constructor() {
|
||||||
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
this.$text = CE('div', {
|
this.$text = CE('div', {
|
||||||
class: 'bx-fullscreen-text bx-gone',
|
class: 'bx-fullscreen-text bx-gone',
|
||||||
});
|
});
|
||||||
|
@ -13,101 +13,104 @@ export enum GuideMenuTab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class GuideMenu {
|
export class GuideMenu {
|
||||||
static #BUTTONS = {
|
private static instance: GuideMenu;
|
||||||
scriptSettings: createButton({
|
public static getInstance = () => GuideMenu.instance ?? (GuideMenu.instance = new GuideMenu());
|
||||||
label: t('better-xcloud'),
|
|
||||||
style: ButtonStyle.FULL_WIDTH | ButtonStyle.FOCUSABLE | ButtonStyle.PRIMARY,
|
|
||||||
onClick: e => {
|
|
||||||
// Wait until the Guide dialog is closed
|
|
||||||
window.addEventListener(BxEvent.XCLOUD_DIALOG_DISMISSED, e => {
|
|
||||||
setTimeout(() => SettingsNavigationDialog.getInstance().show(), 50);
|
|
||||||
}, {once: true});
|
|
||||||
|
|
||||||
// Close all xCloud's dialogs
|
private $renderedButtons?: HTMLElement;
|
||||||
GuideMenu.#closeGuideMenu();
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
|
|
||||||
closeApp: AppInterface && createButton({
|
closeGuideMenu() {
|
||||||
icon: BxIcon.POWER,
|
|
||||||
label: t('close-app'),
|
|
||||||
title: t('close-app'),
|
|
||||||
style: ButtonStyle.FULL_WIDTH | ButtonStyle.FOCUSABLE | ButtonStyle.DANGER,
|
|
||||||
onClick: e => {
|
|
||||||
AppInterface.closeApp();
|
|
||||||
},
|
|
||||||
|
|
||||||
attributes: {
|
|
||||||
'data-state': 'normal',
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
|
|
||||||
reloadPage: createButton({
|
|
||||||
icon: BxIcon.REFRESH,
|
|
||||||
label: t('reload-page'),
|
|
||||||
title: t('reload-page'),
|
|
||||||
style: ButtonStyle.FULL_WIDTH | ButtonStyle.FOCUSABLE,
|
|
||||||
onClick: e => {
|
|
||||||
if (STATES.isPlaying) {
|
|
||||||
confirm(t('confirm-reload-stream')) && window.location.reload();
|
|
||||||
} else {
|
|
||||||
window.location.reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close all xCloud's dialogs
|
|
||||||
GuideMenu.#closeGuideMenu();
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
|
|
||||||
backToHome: createButton({
|
|
||||||
icon: BxIcon.HOME,
|
|
||||||
label: t('back-to-home'),
|
|
||||||
title: t('back-to-home'),
|
|
||||||
style: ButtonStyle.FULL_WIDTH | ButtonStyle.FOCUSABLE,
|
|
||||||
onClick: e => {
|
|
||||||
confirm(t('back-to-home-confirm')) && (window.location.href = window.location.href.substring(0, 31));
|
|
||||||
|
|
||||||
// Close all xCloud's dialogs
|
|
||||||
GuideMenu.#closeGuideMenu();
|
|
||||||
},
|
|
||||||
attributes: {
|
|
||||||
'data-state': 'playing',
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
|
|
||||||
static #$renderedButtons: HTMLElement;
|
|
||||||
|
|
||||||
static #closeGuideMenu() {
|
|
||||||
if (window.BX_EXPOSED.dialogRoutes) {
|
if (window.BX_EXPOSED.dialogRoutes) {
|
||||||
window.BX_EXPOSED.dialogRoutes.closeAll();
|
window.BX_EXPOSED.dialogRoutes.closeAll();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use alternative method for Lite version
|
// Use alternative method for Lite version
|
||||||
const $btnClose = document.querySelector('#gamepass-dialog-root button[class^=Header-module__closeButton]') as HTMLElement;
|
const $btnClose = document.querySelector<HTMLElement>('#gamepass-dialog-root button[class^=Header-module__closeButton]');
|
||||||
$btnClose && $btnClose.click();
|
$btnClose && $btnClose.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
static #renderButtons() {
|
private renderButtons() {
|
||||||
if (GuideMenu.#$renderedButtons) {
|
if (this.$renderedButtons) {
|
||||||
return GuideMenu.#$renderedButtons;
|
return this.$renderedButtons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const buttons = {
|
||||||
|
scriptSettings: createButton({
|
||||||
|
label: t('better-xcloud'),
|
||||||
|
style: ButtonStyle.FULL_WIDTH | ButtonStyle.FOCUSABLE | ButtonStyle.PRIMARY,
|
||||||
|
onClick: (() => {
|
||||||
|
// Wait until the Guide dialog is closed
|
||||||
|
window.addEventListener(BxEvent.XCLOUD_DIALOG_DISMISSED, e => {
|
||||||
|
setTimeout(() => SettingsNavigationDialog.getInstance().show(), 50);
|
||||||
|
}, {once: true});
|
||||||
|
|
||||||
|
// Close all xCloud's dialogs
|
||||||
|
this.closeGuideMenu();
|
||||||
|
}).bind(this),
|
||||||
|
}),
|
||||||
|
|
||||||
|
closeApp: AppInterface && createButton({
|
||||||
|
icon: BxIcon.POWER,
|
||||||
|
label: t('close-app'),
|
||||||
|
title: t('close-app'),
|
||||||
|
style: ButtonStyle.FULL_WIDTH | ButtonStyle.FOCUSABLE | ButtonStyle.DANGER,
|
||||||
|
onClick: e => {
|
||||||
|
AppInterface.closeApp();
|
||||||
|
},
|
||||||
|
|
||||||
|
attributes: {
|
||||||
|
'data-state': 'normal',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
|
||||||
|
reloadPage: createButton({
|
||||||
|
icon: BxIcon.REFRESH,
|
||||||
|
label: t('reload-page'),
|
||||||
|
title: t('reload-page'),
|
||||||
|
style: ButtonStyle.FULL_WIDTH | ButtonStyle.FOCUSABLE,
|
||||||
|
onClick: (() => {
|
||||||
|
// Close all xCloud's dialogs
|
||||||
|
this.closeGuideMenu();
|
||||||
|
|
||||||
|
if (STATES.isPlaying) {
|
||||||
|
confirm(t('confirm-reload-stream')) && window.location.reload();
|
||||||
|
} else {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
}).bind(this),
|
||||||
|
}),
|
||||||
|
|
||||||
|
backToHome: createButton({
|
||||||
|
icon: BxIcon.HOME,
|
||||||
|
label: t('back-to-home'),
|
||||||
|
title: t('back-to-home'),
|
||||||
|
style: ButtonStyle.FULL_WIDTH | ButtonStyle.FOCUSABLE,
|
||||||
|
onClick: (() => {
|
||||||
|
// Close all xCloud's dialogs
|
||||||
|
this.closeGuideMenu();
|
||||||
|
|
||||||
|
confirm(t('back-to-home-confirm')) && (window.location.href = window.location.href.substring(0, 31));
|
||||||
|
}).bind(this),
|
||||||
|
attributes: {
|
||||||
|
'data-state': 'playing',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
const buttonsLayout = [
|
||||||
|
buttons.scriptSettings,
|
||||||
|
[
|
||||||
|
buttons.backToHome,
|
||||||
|
buttons.reloadPage,
|
||||||
|
buttons.closeApp,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
const $div = CE('div', {
|
const $div = CE('div', {
|
||||||
class: 'bx-guide-home-buttons',
|
class: 'bx-guide-home-buttons',
|
||||||
});
|
});
|
||||||
|
|
||||||
const buttons = [
|
for (const $button of buttonsLayout) {
|
||||||
GuideMenu.#BUTTONS.scriptSettings,
|
|
||||||
[
|
|
||||||
GuideMenu.#BUTTONS.backToHome,
|
|
||||||
GuideMenu.#BUTTONS.reloadPage,
|
|
||||||
GuideMenu.#BUTTONS.closeApp,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const $button of buttons) {
|
|
||||||
if (!$button) {
|
if (!$button) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -123,15 +126,15 @@ export class GuideMenu {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GuideMenu.#$renderedButtons = $div;
|
this.$renderedButtons = $div;
|
||||||
return $div;
|
return $div;
|
||||||
}
|
}
|
||||||
|
|
||||||
static #injectHome($root: HTMLElement, isPlaying = false) {
|
injectHome($root: HTMLElement, isPlaying = false) {
|
||||||
if (isFullVersion()) {
|
if (isFullVersion()) {
|
||||||
const $achievementsProgress = $root.querySelector('button[class*=AchievementsButton-module__progressBarContainer]');
|
const $achievementsProgress = $root.querySelector('button[class*=AchievementsButton-module__progressBarContainer]');
|
||||||
if ($achievementsProgress) {
|
if ($achievementsProgress) {
|
||||||
TrueAchievements.injectAchievementsProgress($achievementsProgress as HTMLElement);
|
TrueAchievements.getInstance().injectAchievementsProgress($achievementsProgress as HTMLElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +145,7 @@ export class GuideMenu {
|
|||||||
$target = $root.querySelector('a[class*=QuitGameButton]');
|
$target = $root.querySelector('a[class*=QuitGameButton]');
|
||||||
|
|
||||||
// Hide xCloud's Home button
|
// Hide xCloud's Home button
|
||||||
const $btnXcloudHome = $root.querySelector('div[class^=HomeButtonWithDivider]') as HTMLElement;
|
const $btnXcloudHome = $root.querySelector<HTMLElement>('div[class^=HomeButtonWithDivider]');
|
||||||
$btnXcloudHome && ($btnXcloudHome.style.display = 'none');
|
$btnXcloudHome && ($btnXcloudHome.style.display = 'none');
|
||||||
} else {
|
} else {
|
||||||
// Last divider
|
// Last divider
|
||||||
@ -156,29 +159,39 @@ export class GuideMenu {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const $buttons = GuideMenu.#renderButtons();
|
const $buttons = this.renderButtons();
|
||||||
$buttons.dataset.isPlaying = isPlaying.toString();
|
$buttons.dataset.isPlaying = isPlaying.toString();
|
||||||
$target.insertAdjacentElement('afterend', $buttons);
|
$target.insertAdjacentElement('afterend', $buttons);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #onShown(e: Event) {
|
async onShown(e: Event) {
|
||||||
const where = (e as any).where as GuideMenuTab;
|
const where = (e as any).where as GuideMenuTab;
|
||||||
|
|
||||||
if (where === GuideMenuTab.HOME) {
|
if (where === GuideMenuTab.HOME) {
|
||||||
const $root = document.querySelector('#gamepass-dialog-root div[role=dialog] div[role=tabpanel] div[class*=HomeLandingPage]') as HTMLElement;
|
const $root = document.querySelector<HTMLElement>('#gamepass-dialog-root div[role=dialog] div[role=tabpanel] div[class*=HomeLandingPage]');
|
||||||
$root && GuideMenu.#injectHome($root, STATES.isPlaying);
|
$root && this.injectHome($root, STATES.isPlaying);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static addEventListeners() {
|
addEventListeners() {
|
||||||
window.addEventListener(BxEvent.XCLOUD_GUIDE_MENU_SHOWN, GuideMenu.#onShown);
|
window.addEventListener(BxEvent.XCLOUD_GUIDE_MENU_SHOWN, this.onShown.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
static observe($addedElm: HTMLElement) {
|
observe($addedElm: HTMLElement) {
|
||||||
const className = $addedElm.className;
|
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')) {
|
if (isFullVersion() && className.includes('AchievementsButton-module__progressBarContainer')) {
|
||||||
TrueAchievements.injectAchievementsProgress($addedElm);
|
TrueAchievements.getInstance().injectAchievementsProgress($addedElm);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +205,7 @@ export class GuideMenu {
|
|||||||
if (isFullVersion()) {
|
if (isFullVersion()) {
|
||||||
const $achievDetailPage = $addedElm.querySelector('div[class*=AchievementDetailPage]');
|
const $achievDetailPage = $addedElm.querySelector('div[class*=AchievementDetailPage]');
|
||||||
if ($achievDetailPage) {
|
if ($achievDetailPage) {
|
||||||
TrueAchievements.injectAchievementDetailPage($achievDetailPage as HTMLElement);
|
TrueAchievements.getInstance().injectAchievementDetailPage($achievDetailPage as HTMLElement);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,36 +7,45 @@ import { t } from "@utils/translation";
|
|||||||
import { SettingsNavigationDialog } from "./dialog/settings-dialog";
|
import { SettingsNavigationDialog } from "./dialog/settings-dialog";
|
||||||
import { PrefKey } from "@/enums/pref-keys";
|
import { PrefKey } from "@/enums/pref-keys";
|
||||||
import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
||||||
|
import { BxLogger } from "@/utils/bx-logger";
|
||||||
|
|
||||||
export class HeaderSection {
|
export class HeaderSection {
|
||||||
static #$remotePlayBtn = createButton({
|
private static instance: HeaderSection;
|
||||||
classes: ['bx-header-remote-play-button', 'bx-gone'],
|
public static getInstance = () => HeaderSection.instance ?? (HeaderSection.instance = new HeaderSection());
|
||||||
icon: BxIcon.REMOTE_PLAY,
|
private readonly LOG_TAG = 'HeaderSection';
|
||||||
title: t('remote-play'),
|
|
||||||
style: ButtonStyle.GHOST | ButtonStyle.FOCUSABLE | ButtonStyle.CIRCULAR,
|
|
||||||
onClick: e => {
|
|
||||||
RemotePlayManager.getInstance().togglePopup();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
static #$settingsBtn = createButton({
|
private $btnRemotePlay: HTMLElement;
|
||||||
classes: ['bx-header-settings-button'],
|
private $btnSettings: HTMLElement;
|
||||||
label: '???',
|
private $buttonsWrapper: HTMLElement;
|
||||||
style: ButtonStyle.FROSTED | ButtonStyle.DROP_SHADOW | ButtonStyle.FOCUSABLE | ButtonStyle.FULL_HEIGHT,
|
|
||||||
onClick: e => {
|
|
||||||
SettingsNavigationDialog.getInstance().show();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
static #$buttonsWrapper = CE('div', {},
|
private observer?: MutationObserver;
|
||||||
getPref(PrefKey.REMOTE_PLAY_ENABLED) ? HeaderSection.#$remotePlayBtn : null,
|
private timeoutId?: number | null;
|
||||||
HeaderSection.#$settingsBtn,
|
|
||||||
);
|
|
||||||
|
|
||||||
static #observer: MutationObserver;
|
constructor() {
|
||||||
static #timeout: number | null;
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
|
|
||||||
static #injectSettingsButton($parent?: HTMLElement) {
|
this.$btnRemotePlay = createButton({
|
||||||
|
classes: ['bx-header-remote-play-button', 'bx-gone'],
|
||||||
|
icon: BxIcon.REMOTE_PLAY,
|
||||||
|
title: t('remote-play'),
|
||||||
|
style: ButtonStyle.GHOST | ButtonStyle.FOCUSABLE | ButtonStyle.CIRCULAR,
|
||||||
|
onClick: e => RemotePlayManager.getInstance().togglePopup(),
|
||||||
|
});
|
||||||
|
|
||||||
|
this.$btnSettings = createButton({
|
||||||
|
classes: ['bx-header-settings-button'],
|
||||||
|
label: '???',
|
||||||
|
style: ButtonStyle.FROSTED | ButtonStyle.DROP_SHADOW | ButtonStyle.FOCUSABLE | ButtonStyle.FULL_HEIGHT,
|
||||||
|
onClick: e => SettingsNavigationDialog.getInstance().show(),
|
||||||
|
});
|
||||||
|
|
||||||
|
this.$buttonsWrapper = CE('div', {},
|
||||||
|
getPref(PrefKey.REMOTE_PLAY_ENABLED) ? this.$btnRemotePlay : null,
|
||||||
|
this.$btnSettings,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private injectSettingsButton($parent?: HTMLElement) {
|
||||||
if (!$parent) {
|
if (!$parent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -44,8 +53,8 @@ export class HeaderSection {
|
|||||||
const PREF_LATEST_VERSION = getPref(PrefKey.LATEST_VERSION);
|
const PREF_LATEST_VERSION = getPref(PrefKey.LATEST_VERSION);
|
||||||
|
|
||||||
// Setup Settings button
|
// Setup Settings button
|
||||||
const $btnSettings = HeaderSection.#$settingsBtn;
|
const $btnSettings = this.$btnSettings;
|
||||||
if (isElementVisible(HeaderSection.#$buttonsWrapper)) {
|
if (isElementVisible(this.$buttonsWrapper)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,38 +66,42 @@ export class HeaderSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the Settings button to the web page
|
// Add the Settings button to the web page
|
||||||
$parent.appendChild(HeaderSection.#$buttonsWrapper);
|
$parent.appendChild(this.$buttonsWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
static checkHeader() {
|
private checkHeader() {
|
||||||
let $target = document.querySelector('#PageContent div[class*=EdgewaterHeader-module__rightSectionSpacing]');
|
let $target = document.querySelector('#PageContent div[class*=EdgewaterHeader-module__rightSectionSpacing]');
|
||||||
if (!$target) {
|
if (!$target) {
|
||||||
$target = document.querySelector('div[class^=UnsupportedMarketPage-module__buttons]');
|
$target = document.querySelector('div[class^=UnsupportedMarketPage-module__buttons]');
|
||||||
}
|
}
|
||||||
|
|
||||||
$target && HeaderSection.#injectSettingsButton($target as HTMLElement);
|
$target && this.injectSettingsButton($target as HTMLElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
static showRemotePlayButton() {
|
private watchHeader() {
|
||||||
HeaderSection.#$remotePlayBtn.classList.remove('bx-gone');
|
|
||||||
}
|
|
||||||
|
|
||||||
static watchHeader() {
|
|
||||||
const $root = document.querySelector('#PageContent header') || document.querySelector('#root');
|
const $root = document.querySelector('#PageContent header') || document.querySelector('#root');
|
||||||
if (!$root) {
|
if (!$root) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HeaderSection.#timeout && clearTimeout(HeaderSection.#timeout);
|
this.timeoutId && clearTimeout(this.timeoutId);
|
||||||
HeaderSection.#timeout = null;
|
this.timeoutId = null;
|
||||||
|
|
||||||
HeaderSection.#observer && HeaderSection.#observer.disconnect();
|
this.observer && this.observer.disconnect();
|
||||||
HeaderSection.#observer = new MutationObserver(mutationList => {
|
this.observer = new MutationObserver(mutationList => {
|
||||||
HeaderSection.#timeout && clearTimeout(HeaderSection.#timeout);
|
this.timeoutId && clearTimeout(this.timeoutId);
|
||||||
HeaderSection.#timeout = window.setTimeout(HeaderSection.checkHeader, 2000);
|
this.timeoutId = window.setTimeout(this.checkHeader.bind(this), 2000);
|
||||||
});
|
});
|
||||||
HeaderSection.#observer.observe($root, {subtree: true, childList: true});
|
this.observer.observe($root, {subtree: true, childList: true});
|
||||||
|
|
||||||
HeaderSection.checkHeader();
|
this.checkHeader();
|
||||||
|
}
|
||||||
|
|
||||||
|
showRemotePlayButton() {
|
||||||
|
this.$btnRemotePlay.classList.remove('bx-gone');
|
||||||
|
}
|
||||||
|
|
||||||
|
static watchHeader() {
|
||||||
|
HeaderSection.getInstance().watchHeader();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ 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 } from "@/utils/html";
|
||||||
import { t } from "@/utils/translation";
|
import { t } from "@/utils/translation";
|
||||||
|
import { parseDetailsPath } from "@/utils/utils";
|
||||||
|
|
||||||
export class ProductDetailsPage {
|
export class ProductDetailsPage {
|
||||||
private static $btnShortcut = AppInterface && createButton({
|
private static $btnShortcut = AppInterface && createButton({
|
||||||
@ -20,17 +21,9 @@ export class ProductDetailsPage {
|
|||||||
label: t('wallpaper'),
|
label: t('wallpaper'),
|
||||||
style: ButtonStyle.FOCUSABLE,
|
style: ButtonStyle.FOCUSABLE,
|
||||||
tabIndex: 0,
|
tabIndex: 0,
|
||||||
onClick: async e => {
|
onClick: e => {
|
||||||
try {
|
const details = parseDetailsPath(window.location.pathname);
|
||||||
const matches = /\/games\/(?<titleSlug>[^\/]+)\/(?<productId>\w+)/.exec(window.location.pathname);
|
details && AppInterface.downloadWallpapers(details.titleSlug, details.productId);
|
||||||
if (!matches?.groups) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const titleSlug = matches.groups.titleSlug.replaceAll('\%' + '7C', '-');
|
|
||||||
const productId = matches.groups.productId;
|
|
||||||
AppInterface.downloadWallpapers(titleSlug, productId);
|
|
||||||
} catch (e) {}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
19
src/types/index.d.ts
vendored
19
src/types/index.d.ts
vendored
@ -12,6 +12,7 @@ interface Window {
|
|||||||
BX_EXPOSED: any;
|
BX_EXPOSED: any;
|
||||||
|
|
||||||
BX_VIBRATION_INTENSITY: number;
|
BX_VIBRATION_INTENSITY: number;
|
||||||
|
BX_CONTROLLER_POLLING_RATE: number;
|
||||||
BX_ENABLE_CONTROLLER_VIBRATION: boolean;
|
BX_ENABLE_CONTROLLER_VIBRATION: boolean;
|
||||||
BX_ENABLE_DEVICE_VIBRATION: boolean;
|
BX_ENABLE_DEVICE_VIBRATION: boolean;
|
||||||
|
|
||||||
@ -20,20 +21,29 @@ interface Window {
|
|||||||
|
|
||||||
interface NavigatorBattery extends Navigator {
|
interface NavigatorBattery extends Navigator {
|
||||||
getBattery: () => Promise<{
|
getBattery: () => Promise<{
|
||||||
charging: boolean,
|
charging: boolean;
|
||||||
level: float,
|
level: float;
|
||||||
}>,
|
}>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ServerContinent = 'america-north' | 'america-south' | 'asia' | 'australia' | 'europe' | 'other';
|
||||||
|
type ServerRegion = {
|
||||||
|
baseUri: string;
|
||||||
|
isDefault: boolean;
|
||||||
|
name: string;
|
||||||
|
shortName: string;
|
||||||
|
|
||||||
|
contintent: ServerContinent;
|
||||||
|
};
|
||||||
|
|
||||||
type BxStates = {
|
type BxStates = {
|
||||||
supportedRegion: boolean;
|
supportedRegion: boolean;
|
||||||
serverRegions: any;
|
serverRegions: Record<string, ServerRegion>;
|
||||||
selectedRegion: any;
|
selectedRegion: any;
|
||||||
gsToken: string;
|
gsToken: string;
|
||||||
isSignedIn: boolean;
|
isSignedIn: boolean;
|
||||||
|
|
||||||
isPlaying: boolean;
|
isPlaying: boolean;
|
||||||
appContext: any | null;
|
|
||||||
|
|
||||||
browser: {
|
browser: {
|
||||||
capabilities: {
|
capabilities: {
|
||||||
@ -46,6 +56,7 @@ type BxStates = {
|
|||||||
isTv: boolean;
|
isTv: boolean;
|
||||||
capabilities: {
|
capabilities: {
|
||||||
touch: boolean;
|
touch: boolean;
|
||||||
|
mkb: boolean;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
5
src/types/preferences.d.ts
vendored
5
src/types/preferences.d.ts
vendored
@ -3,8 +3,9 @@ export type PreferenceSetting = {
|
|||||||
optionsGroup?: string;
|
optionsGroup?: string;
|
||||||
options?: {[index: string]: string};
|
options?: {[index: string]: string};
|
||||||
multipleOptions?: {[index: string]: string};
|
multipleOptions?: {[index: string]: string};
|
||||||
unsupported?: string | boolean;
|
unsupported?: boolean;
|
||||||
note?: string | HTMLElement;
|
unsupportedNote?: string | (() => HTMLElement);
|
||||||
|
note?: string | (() => HTMLElement);
|
||||||
type?: SettingElementType;
|
type?: SettingElementType;
|
||||||
ready?: (setting: PreferenceSetting) => void;
|
ready?: (setting: PreferenceSetting) => void;
|
||||||
migrate?: (this: Preferences, savedPrefs: any, value: any) => void;
|
migrate?: (this: Preferences, savedPrefs: any, value: any) => void;
|
||||||
|
6
src/types/setting-definition.d.ts
vendored
6
src/types/setting-definition.d.ts
vendored
@ -18,9 +18,10 @@ export type SettingDefinition = {
|
|||||||
default: any;
|
default: any;
|
||||||
} & Partial<{
|
} & Partial<{
|
||||||
label: string;
|
label: string;
|
||||||
note: string | HTMLElement;
|
note: string | (() => HTMLElement);
|
||||||
experimental: boolean;
|
experimental: boolean;
|
||||||
unsupported: string | boolean;
|
unsupported: boolean;
|
||||||
|
unsupportedNote: string | (() => HTMLElement);
|
||||||
suggest: PartialRecord<SuggestedSettingCategory, any>,
|
suggest: PartialRecord<SuggestedSettingCategory, any>,
|
||||||
ready: (setting: SettingDefinition) => void;
|
ready: (setting: SettingDefinition) => void;
|
||||||
type: SettingElementType,
|
type: SettingElementType,
|
||||||
@ -58,4 +59,5 @@ export type NumberStepperParams = Partial<{
|
|||||||
exactTicks: number;
|
exactTicks: number;
|
||||||
|
|
||||||
customTextValue: (value: any) => string | null;
|
customTextValue: (value: any) => string | null;
|
||||||
|
reverse: boolean;
|
||||||
}>
|
}>
|
||||||
|
@ -8,6 +8,8 @@ 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 { PrefKey } from "@/enums/pref-keys";
|
||||||
import { getPref, StreamTouchController } from "./settings-storages/global-settings-storage";
|
import { getPref, StreamTouchController } from "./settings-storages/global-settings-storage";
|
||||||
|
import { GamePassCloudGallery } from "@/enums/game-pass-gallery";
|
||||||
|
import { TouchController } from "@/modules/touch-controller";
|
||||||
|
|
||||||
export enum SupportedInputType {
|
export enum SupportedInputType {
|
||||||
CONTROLLER = 'Controller',
|
CONTROLLER = 'Controller',
|
||||||
@ -22,6 +24,60 @@ export type SupportedInputTypeValue = (typeof SupportedInputType)[keyof typeof S
|
|||||||
export const BxExposed = {
|
export const BxExposed = {
|
||||||
getTitleInfo: () => STATES.currentStream.titleInfo,
|
getTitleInfo: () => STATES.currentStream.titleInfo,
|
||||||
|
|
||||||
|
modifyPreloadedState: isFullVersion() && ((state: any) => {
|
||||||
|
let LOG_TAG = 'PreloadState';
|
||||||
|
|
||||||
|
// Override User-Agent
|
||||||
|
try {
|
||||||
|
state.appContext.requestInfo.userAgent = window.navigator.userAgent;
|
||||||
|
} catch (e) {
|
||||||
|
BxLogger.error(LOG_TAG, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add list of games with custom layouts to the official list
|
||||||
|
try {
|
||||||
|
const sigls = state.xcloud.sigls;
|
||||||
|
if (STATES.userAgent.capabilities.touch) {
|
||||||
|
// The list of custom touch controls
|
||||||
|
let customList = TouchController.getCustomList();
|
||||||
|
|
||||||
|
// Remove non-cloud games from the official list
|
||||||
|
const allGames = sigls[GamePassCloudGallery.ALL].data.products;
|
||||||
|
customList = customList.filter(id => allGames.includes(id));
|
||||||
|
|
||||||
|
// Add to the official touchlist
|
||||||
|
sigls[GamePassCloudGallery.TOUCH]?.data.products.push(...customList);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
BxLogger.error(LOG_TAG, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add forced Native MKB titles to the official list
|
||||||
|
try {
|
||||||
|
const sigls = state.xcloud.sigls;
|
||||||
|
if (BX_FLAGS.ForceNativeMkbTitles) {
|
||||||
|
// Add to the official list
|
||||||
|
sigls[GamePassCloudGallery.NATIVE_MKB]?.data.products.push(...BX_FLAGS.ForceNativeMkbTitles);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
BxLogger.error(LOG_TAG, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redirect to /en-US/play if visiting from an unsupported region
|
||||||
|
try {
|
||||||
|
const xCloud = state.xcloud.authentication.authStatusByStrategy.XCloud;
|
||||||
|
if (xCloud.type === 3 && xCloud.error.type === 'UnsupportedMarketError') {
|
||||||
|
// Redirect to /en-US/play
|
||||||
|
window.stop();
|
||||||
|
window.location.href = 'https://www.xbox.com/en-US/play';
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
BxLogger.error(LOG_TAG, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}),
|
||||||
|
|
||||||
modifyTitleInfo: isFullVersion() && function(titleInfo: XcloudTitleInfo): XcloudTitleInfo {
|
modifyTitleInfo: isFullVersion() && function(titleInfo: XcloudTitleInfo): XcloudTitleInfo {
|
||||||
// Clone the object since the original is read-only
|
// Clone the object since the original is read-only
|
||||||
titleInfo = deepClone(titleInfo);
|
titleInfo = deepClone(titleInfo);
|
||||||
@ -144,4 +200,10 @@ export const BxExposed = {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
GameSlugRegexes: [
|
||||||
|
/[;,/?:@&=+_`~$%#^*()!^\u2122\xae\xa9]/g,
|
||||||
|
/ {2,}/g,
|
||||||
|
/ /g,
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { BxLogger } from "./bx-logger";
|
import { BxLogger } from "./bx-logger";
|
||||||
|
|
||||||
type BxFlags = {
|
export type BxFlags = {
|
||||||
Debug: boolean;
|
Debug: boolean;
|
||||||
|
|
||||||
CheckForUpdate: boolean;
|
CheckForUpdate: boolean;
|
||||||
@ -15,7 +15,10 @@ type BxFlags = {
|
|||||||
userAgent?: string,
|
userAgent?: string,
|
||||||
|
|
||||||
androidInfo?: {
|
androidInfo?: {
|
||||||
|
manufacturer: string,
|
||||||
|
brand: string,
|
||||||
board: string,
|
board: string,
|
||||||
|
model: string,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// Credit: https://phosphoricons.com
|
||||||
import iconBetterXcloud from "@assets/svg/better-xcloud.svg" with { type: "text" };
|
import iconBetterXcloud from "@assets/svg/better-xcloud.svg" with { type: "text" };
|
||||||
import iconTrueAchievements from "@assets/svg/true-achievements.svg" with { type: "text" };
|
import iconTrueAchievements from "@assets/svg/true-achievements.svg" with { type: "text" };
|
||||||
import iconClose from "@assets/svg/close.svg" with { type: "text" };
|
import iconClose from "@assets/svg/close.svg" with { type: "text" };
|
||||||
@ -7,6 +8,8 @@ import iconCopy from "@assets/svg/copy.svg" with { type: "text" };
|
|||||||
import iconCreateShortcut from "@assets/svg/create-shortcut.svg" with { type: "text" };
|
import iconCreateShortcut from "@assets/svg/create-shortcut.svg" with { type: "text" };
|
||||||
import iconCursorText from "@assets/svg/cursor-text.svg" with { type: "text" };
|
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 iconEyeSlash from "@assets/svg/eye-slash.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 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" };
|
||||||
@ -48,6 +51,8 @@ export const BxIcon = {
|
|||||||
CONTROLLER: iconController,
|
CONTROLLER: iconController,
|
||||||
CREATE_SHORTCUT: iconCreateShortcut,
|
CREATE_SHORTCUT: iconCreateShortcut,
|
||||||
DISPLAY: iconDisplay,
|
DISPLAY: iconDisplay,
|
||||||
|
EYE: iconEye,
|
||||||
|
EYE_SLASH: iconEyeSlash,
|
||||||
HOME: iconHome,
|
HOME: iconHome,
|
||||||
NATIVE_MKB: iconNativeMkb,
|
NATIVE_MKB: iconNativeMkb,
|
||||||
NEW: iconNew,
|
NEW: iconNew,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { BX_FLAGS } from "./bx-flags";
|
||||||
|
|
||||||
const enum TextColor {
|
const enum TextColor {
|
||||||
INFO = '#008746',
|
INFO = '#008746',
|
||||||
WARNING = '#c1a404',
|
WARNING = '#c1a404',
|
||||||
@ -5,22 +7,12 @@ const enum TextColor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class BxLogger {
|
export class BxLogger {
|
||||||
static #PREFIX = '[BxC]';
|
static info = (tag: string, ...args: any[]) => BxLogger.log(TextColor.INFO, tag, ...args);
|
||||||
|
static warning = (tag: string, ...args: any[]) => BxLogger.log(TextColor.WARNING, tag, ...args);
|
||||||
|
static error = (tag: string, ...args: any[]) => BxLogger.log(TextColor.ERROR, tag, ...args);
|
||||||
|
|
||||||
static info(tag: string, ...args: any[]) {
|
private static log(color: string, tag: string, ...args: any) {
|
||||||
BxLogger.#log(TextColor.INFO, tag, ...args);
|
BX_FLAGS.Debug && console.log(`%c[BxC]`, `color:${color};font-weight:bold;`, tag, '//', ...args);
|
||||||
}
|
|
||||||
|
|
||||||
static warning(tag: string, ...args: any[]) {
|
|
||||||
BxLogger.#log(TextColor.WARNING, tag, ...args);
|
|
||||||
}
|
|
||||||
|
|
||||||
static error(tag: string, ...args: any[]) {
|
|
||||||
BxLogger.#log(TextColor.ERROR, tag, ...args);
|
|
||||||
}
|
|
||||||
|
|
||||||
static #log(color: string, tag: string, ...args: any) {
|
|
||||||
console.log(`%c${BxLogger.#PREFIX}`, `color:${color};font-weight:bold;`, tag, '//', ...args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,11 +9,6 @@ export let FeatureGates: {[key: string]: boolean} = {
|
|||||||
'ShowForcedUpdateScreen': false,
|
'ShowForcedUpdateScreen': false,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Disable context menu in Home page
|
|
||||||
if (getPref(PrefKey.UI_HOME_CONTEXT_MENU_DISABLED)) {
|
|
||||||
FeatureGates['EnableHomeContextMenu'] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable chat feature
|
// Disable chat feature
|
||||||
if (getPref(PrefKey.BLOCK_SOCIAL_FEATURES)) {
|
if (getPref(PrefKey.BLOCK_SOCIAL_FEATURES)) {
|
||||||
FeatureGates['EnableGuideChatTab'] = false;
|
FeatureGates['EnableGuideChatTab'] = false;
|
||||||
|
@ -33,3 +33,7 @@ export function showGamepadToast(gamepad: Gamepad) {
|
|||||||
|
|
||||||
Toast.show(text, status, {instant: false});
|
Toast.show(text, status, {instant: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updatePollingRate() {
|
||||||
|
window.BX_CONTROLLER_POLLING_RATE = getPref(PrefKey.CONTROLLER_POLLING_RATE);
|
||||||
|
}
|
||||||
|
@ -13,6 +13,7 @@ const isTv = userAgent.includes('smart-tv') || userAgent.includes('smarttv') ||
|
|||||||
const isVr = window.navigator.userAgent.includes('VR') && window.navigator.userAgent.includes('OculusBrowser');
|
const isVr = window.navigator.userAgent.includes('VR') && window.navigator.userAgent.includes('OculusBrowser');
|
||||||
const browserHasTouchSupport = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
const browserHasTouchSupport = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
||||||
const userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport;
|
const userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport;
|
||||||
|
const supportMkb = AppInterface || !userAgent.match(/(android|iphone|ipad)/);
|
||||||
|
|
||||||
export const STATES: BxStates = {
|
export const STATES: BxStates = {
|
||||||
supportedRegion: true,
|
supportedRegion: true,
|
||||||
@ -22,7 +23,6 @@ export const STATES: BxStates = {
|
|||||||
isSignedIn: false,
|
isSignedIn: false,
|
||||||
|
|
||||||
isPlaying: false,
|
isPlaying: false,
|
||||||
appContext: {},
|
|
||||||
|
|
||||||
browser: {
|
browser: {
|
||||||
capabilities: {
|
capabilities: {
|
||||||
@ -35,6 +35,7 @@ export const STATES: BxStates = {
|
|||||||
isTv: isTv,
|
isTv: isTv,
|
||||||
capabilities: {
|
capabilities: {
|
||||||
touch: userAgentHasTouchSupport,
|
touch: userAgentHasTouchSupport,
|
||||||
|
mkb: supportMkb,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -56,6 +56,8 @@ function createElement<T=HTMLElement>(elmName: string, props: CreateElementOptio
|
|||||||
let $elm;
|
let $elm;
|
||||||
const hasNs = 'xmlns' in props;
|
const hasNs = 'xmlns' in props;
|
||||||
|
|
||||||
|
// console.trace('createElement', elmName, props);
|
||||||
|
|
||||||
if (hasNs) {
|
if (hasNs) {
|
||||||
$elm = document.createElementNS(props.xmlns, elmName);
|
$elm = document.createElementNS(props.xmlns, elmName);
|
||||||
delete props.xmlns;
|
delete props.xmlns;
|
||||||
@ -101,29 +103,30 @@ function createElement<T=HTMLElement>(elmName: string, props: CreateElementOptio
|
|||||||
|
|
||||||
export const CE = createElement;
|
export const CE = createElement;
|
||||||
|
|
||||||
// Credit: https://phosphoricons.com
|
const domParser = new DOMParser();
|
||||||
const svgParser = (svg: string) => new DOMParser().parseFromString(svg, 'image/svg+xml').documentElement;
|
export function createSvgIcon(icon: typeof BxIcon) {
|
||||||
|
return domParser.parseFromString(icon.toString(), 'image/svg+xml').documentElement;
|
||||||
export const createSvgIcon = (icon: typeof BxIcon) => {
|
|
||||||
return svgParser(icon.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ButtonStyleIndices = Object.keys(ButtonStyleClass).map(i => parseInt(i));
|
const ButtonStyleIndices = Object.keys(ButtonStyleClass).map(i => parseInt(i));
|
||||||
|
|
||||||
export const createButton = <T=HTMLButtonElement>(options: BxButton): T => {
|
export function createButton<T=HTMLButtonElement>(options: BxButton): T {
|
||||||
let $btn;
|
let $btn;
|
||||||
if (options.url) {
|
if (options.url) {
|
||||||
$btn = CE('a', {'class': 'bx-button'}) as HTMLAnchorElement;
|
$btn = CE<HTMLAnchorElement>('a', {'class': 'bx-button'});
|
||||||
$btn.href = options.url;
|
$btn.href = options.url;
|
||||||
$btn.target = '_blank';
|
$btn.target = '_blank';
|
||||||
} else {
|
} else {
|
||||||
$btn = CE('button', {'class': 'bx-button', type: 'button'}) as HTMLButtonElement;
|
$btn = CE<HTMLButtonElement>('button', {'class': 'bx-button', type: 'button'});
|
||||||
}
|
}
|
||||||
|
|
||||||
const style = (options.style || 0) as number;
|
const style = (options.style || 0) as number;
|
||||||
style && ButtonStyleIndices.forEach((index: keyof typeof ButtonStyleClass) => {
|
if (style) {
|
||||||
|
let index: keyof typeof ButtonStyleClass;
|
||||||
|
for (index of ButtonStyleIndices) {
|
||||||
(style & index) && $btn.classList.add(ButtonStyleClass[index] as string);
|
(style & index) && $btn.classList.add(ButtonStyleClass[index] as string);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
|
||||||
options.classes && $btn.classList.add(...options.classes);
|
options.classes && $btn.classList.add(...options.classes);
|
||||||
|
|
||||||
|
@ -1,165 +0,0 @@
|
|||||||
import { MkbPreset } from "@modules/mkb/mkb-preset";
|
|
||||||
import { t } from "@utils/translation";
|
|
||||||
import type { MkbStoredPreset, MkbStoredPresets } from "@/types/mkb";
|
|
||||||
import { PrefKey } from "@/enums/pref-keys";
|
|
||||||
import { setPref } from "./settings-storages/global-settings-storage";
|
|
||||||
|
|
||||||
export class LocalDb {
|
|
||||||
static #instance: LocalDb;
|
|
||||||
static get INSTANCE() {
|
|
||||||
if (!LocalDb.#instance) {
|
|
||||||
LocalDb.#instance = new LocalDb();
|
|
||||||
}
|
|
||||||
|
|
||||||
return LocalDb.#instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
static readonly DB_NAME = 'BetterXcloud';
|
|
||||||
static readonly DB_VERSION = 1;
|
|
||||||
static readonly TABLE_PRESETS = 'mkb_presets';
|
|
||||||
|
|
||||||
#DB: any;
|
|
||||||
|
|
||||||
#open() {
|
|
||||||
return new Promise<void>((resolve, reject) => {
|
|
||||||
if (this.#DB) {
|
|
||||||
resolve();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const request = window.indexedDB.open(LocalDb.DB_NAME, LocalDb.DB_VERSION);
|
|
||||||
request.onupgradeneeded = (e: IDBVersionChangeEvent) => {
|
|
||||||
const db = (e.target! as any).result;
|
|
||||||
|
|
||||||
switch (e.oldVersion) {
|
|
||||||
case 0: {
|
|
||||||
const presets = db.createObjectStore(LocalDb.TABLE_PRESETS, {keyPath: 'id', autoIncrement: true});
|
|
||||||
presets.createIndex('name_idx', 'name');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
request.onerror = e => {
|
|
||||||
console.log(e);
|
|
||||||
alert((e.target as any).error.message);
|
|
||||||
reject && reject();
|
|
||||||
};
|
|
||||||
|
|
||||||
request.onsuccess = e => {
|
|
||||||
this.#DB = (e.target as any).result;
|
|
||||||
resolve();
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#table(name: string, type: string): Promise<IDBObjectStore> {
|
|
||||||
const transaction = this.#DB.transaction(name, type || 'readonly');
|
|
||||||
const table = transaction.objectStore(name);
|
|
||||||
|
|
||||||
return new Promise(resolve => resolve(table));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert IndexDB method to Promise
|
|
||||||
#call(method: any) {
|
|
||||||
const table = arguments[1];
|
|
||||||
return new Promise(resolve => {
|
|
||||||
const request = method.call(table, ...Array.from(arguments).slice(2));
|
|
||||||
request.onsuccess = (e: Event) => {
|
|
||||||
resolve([table, (e.target as any).result]);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#count(table: IDBObjectStore): Promise<[IDBObjectStore, number]> {
|
|
||||||
// @ts-ignore
|
|
||||||
return this.#call(table.count, ...arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
#add(table: IDBObjectStore, data: any): Promise<[IDBObjectStore, number]> {
|
|
||||||
// @ts-ignore
|
|
||||||
return this.#call(table.add, ...arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
#put(table: IDBObjectStore, data: any): Promise<[IDBObjectStore, number]> {
|
|
||||||
// @ts-ignore
|
|
||||||
return this.#call(table.put, ...arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
#delete(table: IDBObjectStore, data: any): Promise<[IDBObjectStore, number]> {
|
|
||||||
// @ts-ignore
|
|
||||||
return this.#call(table.delete, ...arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
#get(table: IDBObjectStore, id: number): Promise<any> {
|
|
||||||
// @ts-ignore
|
|
||||||
return this.#call(table.get, ...arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
#getAll(table: IDBObjectStore): Promise<[IDBObjectStore, any]> {
|
|
||||||
// @ts-ignore
|
|
||||||
return this.#call(table.getAll, ...arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
newPreset(name: string, data: any) {
|
|
||||||
return this.#open()
|
|
||||||
.then(() => this.#table(LocalDb.TABLE_PRESETS, 'readwrite'))
|
|
||||||
.then(table => this.#add(table, {name, data}))
|
|
||||||
.then(([table, id]) => new Promise<number>(resolve => resolve(id)));
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePreset(preset: MkbStoredPreset) {
|
|
||||||
return this.#open()
|
|
||||||
.then(() => this.#table(LocalDb.TABLE_PRESETS, 'readwrite'))
|
|
||||||
.then(table => this.#put(table, preset))
|
|
||||||
.then(([table, id]) => new Promise(resolve => resolve(id)));
|
|
||||||
}
|
|
||||||
|
|
||||||
deletePreset(id: number) {
|
|
||||||
return this.#open()
|
|
||||||
.then(() => this.#table(LocalDb.TABLE_PRESETS, 'readwrite'))
|
|
||||||
.then(table => this.#delete(table, id))
|
|
||||||
.then(([table, id]) => new Promise(resolve => resolve(id)));
|
|
||||||
}
|
|
||||||
|
|
||||||
getPreset(id: number): Promise<MkbStoredPreset> {
|
|
||||||
return this.#open()
|
|
||||||
.then(() => this.#table(LocalDb.TABLE_PRESETS, 'readwrite'))
|
|
||||||
.then(table => this.#get(table, id))
|
|
||||||
.then(([table, preset]) => new Promise(resolve => resolve(preset)));
|
|
||||||
}
|
|
||||||
|
|
||||||
getPresets(): Promise<MkbStoredPresets> {
|
|
||||||
return this.#open()
|
|
||||||
.then(() => this.#table(LocalDb.TABLE_PRESETS, 'readwrite'))
|
|
||||||
.then(table => this.#count(table))
|
|
||||||
.then(([table, count]) => {
|
|
||||||
if (count > 0) {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
this.#getAll(table)
|
|
||||||
.then(([table, items]) => {
|
|
||||||
const presets: MkbStoredPresets = {};
|
|
||||||
items.forEach((item: MkbStoredPreset) => (presets[item.id!] = item));
|
|
||||||
resolve(presets);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create "Default" preset when the table is empty
|
|
||||||
const preset: MkbStoredPreset = {
|
|
||||||
name: t('default'),
|
|
||||||
data: MkbPreset.DEFAULT_PRESET,
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise<MkbStoredPresets>(resolve => {
|
|
||||||
this.#add(table, preset)
|
|
||||||
.then(([table, id]) => {
|
|
||||||
preset.id = id;
|
|
||||||
setPref(PrefKey.MKB_DEFAULT_PRESET_ID, id);
|
|
||||||
|
|
||||||
resolve({[id]: preset});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
79
src/utils/local-db/local-db.ts
Normal file
79
src/utils/local-db/local-db.ts
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
export abstract class LocalDb {
|
||||||
|
static readonly DB_NAME = 'BetterXcloud';
|
||||||
|
static readonly DB_VERSION = 2;
|
||||||
|
|
||||||
|
protected db!: IDBDatabase;
|
||||||
|
|
||||||
|
protected open() {
|
||||||
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
if (this.db) {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const request = window.indexedDB.open(LocalDb.DB_NAME, LocalDb.DB_VERSION);
|
||||||
|
request.onupgradeneeded = this.onUpgradeNeeded.bind(this);
|
||||||
|
|
||||||
|
request.onerror = e => {
|
||||||
|
console.log(e);
|
||||||
|
alert((e.target as any).error.message);
|
||||||
|
reject && reject();
|
||||||
|
};
|
||||||
|
|
||||||
|
request.onsuccess = e => {
|
||||||
|
this.db = (e.target as any).result;
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract onUpgradeNeeded(e: IDBVersionChangeEvent): void;
|
||||||
|
|
||||||
|
protected table(name: string, type: IDBTransactionMode): Promise<IDBObjectStore> {
|
||||||
|
const transaction = this.db.transaction(name, type || 'readonly');
|
||||||
|
const table = transaction.objectStore(name);
|
||||||
|
|
||||||
|
return new Promise(resolve => resolve(table));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert IndexDB method to Promise
|
||||||
|
protected call(method: any) {
|
||||||
|
const table = arguments[1];
|
||||||
|
return new Promise(resolve => {
|
||||||
|
const request = method.call(table, ...Array.from(arguments).slice(2));
|
||||||
|
request.onsuccess = (e: Event) => {
|
||||||
|
resolve([table, (e.target as any).result]);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected count(table: IDBObjectStore): Promise<[IDBObjectStore, number]> {
|
||||||
|
// @ts-ignore
|
||||||
|
return this.call(table.count, ...arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected add(table: IDBObjectStore, data: any): Promise<[IDBObjectStore, number]> {
|
||||||
|
// @ts-ignore
|
||||||
|
return this.call(table.add, ...arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected put(table: IDBObjectStore, data: any): Promise<[IDBObjectStore, number]> {
|
||||||
|
// @ts-ignore
|
||||||
|
return this.call(table.put, ...arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected delete(table: IDBObjectStore, data: any): Promise<[IDBObjectStore, number]> {
|
||||||
|
// @ts-ignore
|
||||||
|
return this.call(table.delete, ...arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected get(table: IDBObjectStore, id: number): Promise<any> {
|
||||||
|
// @ts-ignore
|
||||||
|
return this.call(table.get, ...arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getAll(table: IDBObjectStore): Promise<[IDBObjectStore, any]> {
|
||||||
|
// @ts-ignore
|
||||||
|
return this.call(table.getAll, ...arguments);
|
||||||
|
}
|
||||||
|
}
|
102
src/utils/local-db/mkb-presets-db.ts
Normal file
102
src/utils/local-db/mkb-presets-db.ts
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
import { PrefKey } from "@/enums/pref-keys";
|
||||||
|
import { MkbPreset } from "@/modules/mkb/mkb-preset";
|
||||||
|
import type { MkbStoredPreset, MkbStoredPresets } from "@/types/mkb";
|
||||||
|
import { setPref } from "../settings-storages/global-settings-storage";
|
||||||
|
import { t } from "../translation";
|
||||||
|
import { LocalDb } from "./local-db";
|
||||||
|
import { BxLogger } from "../bx-logger";
|
||||||
|
|
||||||
|
export class MkbPresetsDb extends LocalDb {
|
||||||
|
private static instance: MkbPresetsDb;
|
||||||
|
public static getInstance = () => MkbPresetsDb.instance ?? (MkbPresetsDb.instance = new MkbPresetsDb());
|
||||||
|
private readonly LOG_TAG = 'MkbPresetsDb';
|
||||||
|
|
||||||
|
private readonly TABLE_PRESETS = 'mkb_presets';
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
super();
|
||||||
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
|
}
|
||||||
|
|
||||||
|
private createTable(db: IDBDatabase) {
|
||||||
|
const presets = db.createObjectStore(this.TABLE_PRESETS, {
|
||||||
|
keyPath: 'id',
|
||||||
|
autoIncrement: true,
|
||||||
|
});
|
||||||
|
presets.createIndex('name_idx', 'name');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onUpgradeNeeded(e: IDBVersionChangeEvent): void {
|
||||||
|
const db = (e.target! as any).result as IDBDatabase;
|
||||||
|
|
||||||
|
if (db.objectStoreNames.contains('undefined')) {
|
||||||
|
db.deleteObjectStore('undefined');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!db.objectStoreNames.contains(this.TABLE_PRESETS)) {
|
||||||
|
this.createTable(db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async presetsTable() {
|
||||||
|
await this.open();
|
||||||
|
return await this.table(this.TABLE_PRESETS, 'readwrite');
|
||||||
|
}
|
||||||
|
|
||||||
|
async newPreset(name: string, data: any) {
|
||||||
|
const table = await this.presetsTable();
|
||||||
|
const [, id] = await this.add(table, { name, data });
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
async updatePreset(preset: MkbStoredPreset) {
|
||||||
|
const table = await this.presetsTable();
|
||||||
|
const [, id] = await this.put(table, preset);
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
async deletePreset(id: number) {
|
||||||
|
const table = await this.presetsTable();
|
||||||
|
await this.delete(table, id);
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getPreset(id: number): Promise<MkbStoredPreset> {
|
||||||
|
const table = await this.presetsTable();
|
||||||
|
const [, preset] = await this.get(table, id);
|
||||||
|
|
||||||
|
return preset;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getPresets(): Promise<MkbStoredPresets> {
|
||||||
|
const table = await this.presetsTable();
|
||||||
|
const [, count] = await this.count(table);
|
||||||
|
|
||||||
|
// Return stored presets
|
||||||
|
if (count > 0) {
|
||||||
|
const [, items] = await this.getAll(table);
|
||||||
|
const presets: MkbStoredPresets = {};
|
||||||
|
items.forEach((item: MkbStoredPreset) => (presets[item.id!] = item));
|
||||||
|
|
||||||
|
return presets;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create "Default" preset when the table is empty
|
||||||
|
const preset: MkbStoredPreset = {
|
||||||
|
name: t('default'),
|
||||||
|
data: MkbPreset.DEFAULT_PRESET,
|
||||||
|
};
|
||||||
|
|
||||||
|
const [, id] = await this.add(table, preset);
|
||||||
|
|
||||||
|
preset.id = id;
|
||||||
|
setPref(PrefKey.MKB_DEFAULT_PRESET_ID, id);
|
||||||
|
|
||||||
|
return {
|
||||||
|
[id]: preset,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
import { isFullVersion } from "@macros/build" with {type: "macro"};
|
import { isFullVersion } from "@macros/build" with {type: "macro"};
|
||||||
|
|
||||||
import { BxEvent } from "@utils/bx-event";
|
|
||||||
import { BX_FLAGS, NATIVE_FETCH } from "@utils/bx-flags";
|
import { BX_FLAGS, NATIVE_FETCH } from "@utils/bx-flags";
|
||||||
import { TouchController } from "@modules/touch-controller";
|
import { TouchController } from "@modules/touch-controller";
|
||||||
import { STATES } from "@utils/global";
|
import { STATES } from "@utils/global";
|
||||||
@ -29,9 +28,7 @@ function clearDbLogs(dbName: string, table: string) {
|
|||||||
const objectStore = db.transaction(table, 'readwrite').objectStore(table);
|
const objectStore = db.transaction(table, 'readwrite').objectStore(table);
|
||||||
const objectStoreRequest = objectStore.clear();
|
const objectStoreRequest = objectStore.clear();
|
||||||
|
|
||||||
objectStoreRequest.onsuccess = function() {
|
objectStoreRequest.onsuccess = () => BxLogger.info('clearDbLogs', `Cleared ${dbName}.${table}`);
|
||||||
console.log(`[Better xCloud] Cleared ${dbName}.${table}`);
|
|
||||||
};
|
|
||||||
} catch (ex) {}
|
} catch (ex) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,6 +131,7 @@ export function interceptHttpRequests() {
|
|||||||
'https://browser.events.data.microsoft.com',
|
'https://browser.events.data.microsoft.com',
|
||||||
'https://dc.services.visualstudio.com',
|
'https://dc.services.visualstudio.com',
|
||||||
'https://2c06dea3f26c40c69b8456d319791fd0@o427368.ingest.sentry.io',
|
'https://2c06dea3f26c40c69b8456d319791fd0@o427368.ingest.sentry.io',
|
||||||
|
'https://mscom.demdex.net',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,29 +170,42 @@ export function interceptHttpRequests() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let gamepassAllGames: string[] = [];
|
let gamepassAllGames: string[] = [];
|
||||||
|
const IGNORED_DOMAINS = [
|
||||||
|
'accounts.xboxlive.com',
|
||||||
|
'chat.xboxlive.com',
|
||||||
|
'notificationinbox.xboxlive.com',
|
||||||
|
'peoplehub.xboxlive.com',
|
||||||
|
'rta.xboxlive.com',
|
||||||
|
'userpresence.xboxlive.com',
|
||||||
|
'xblmessaging.xboxlive.com',
|
||||||
|
'consent.config.office.com',
|
||||||
|
|
||||||
|
'arc.msn.com',
|
||||||
|
'browser.events.data.microsoft.com',
|
||||||
|
'dc.services.visualstudio.com',
|
||||||
|
'2c06dea3f26c40c69b8456d319791fd0@o427368.ingest.sentry.io',
|
||||||
|
];
|
||||||
|
|
||||||
(window as any).BX_FETCH = window.fetch = async (request: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
|
(window as any).BX_FETCH = window.fetch = async (request: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
|
||||||
let url = (typeof request === 'string') ? request : (request as Request).url;
|
let url = (typeof request === 'string') ? request : (request as Request).url;
|
||||||
|
|
||||||
// Check blocked URLs
|
// Check blocked URLs
|
||||||
for (let blocked of BLOCKED_URLS) {
|
for (let blocked of BLOCKED_URLS) {
|
||||||
if (!url.startsWith(blocked)) {
|
if (url.startsWith(blocked)) {
|
||||||
continue;
|
return new Response('{"acc":1,"webResult":{}}', {
|
||||||
|
status: 200,
|
||||||
|
statusText: '200 OK',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response('{"acc":1,"webResult":{}}', {
|
|
||||||
status: 200,
|
|
||||||
statusText: '200 OK',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.endsWith('/play')) {
|
// Ignore URLs
|
||||||
BxEvent.dispatch(window, BxEvent.STREAM_LOADING);
|
const domain = (new URL(url)).hostname;
|
||||||
|
if (IGNORED_DOMAINS.includes(domain)) {
|
||||||
|
return NATIVE_FETCH(request, init);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.endsWith('/configuration')) {
|
// BxLogger.info('fetch', url);
|
||||||
BxEvent.dispatch(window, BxEvent.STREAM_STARTING);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Override experimentals
|
// Override experimentals
|
||||||
if (url.startsWith('https://emerald.xboxservices.com/xboxcomfd/experimentation')) {
|
if (url.startsWith('https://emerald.xboxservices.com/xboxcomfd/experimentation')) {
|
||||||
@ -212,6 +223,7 @@ export function interceptHttpRequests() {
|
|||||||
return response;
|
return response;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
return NATIVE_FETCH(request, init);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,66 +0,0 @@
|
|||||||
import { deepClone, STATES } from "@utils/global";
|
|
||||||
import { BxLogger } from "./bx-logger";
|
|
||||||
import { TouchController } from "@modules/touch-controller";
|
|
||||||
import { GamePassCloudGallery } from "../enums/game-pass-gallery";
|
|
||||||
import { BX_FLAGS } from "./bx-flags";
|
|
||||||
import { PrefKey } from "@/enums/pref-keys";
|
|
||||||
import { getPref } from "./settings-storages/global-settings-storage";
|
|
||||||
|
|
||||||
const LOG_TAG = 'PreloadState';
|
|
||||||
|
|
||||||
export function overridePreloadState() {
|
|
||||||
let _state: any;
|
|
||||||
|
|
||||||
Object.defineProperty(window, '__PRELOADED_STATE__', {
|
|
||||||
configurable: true,
|
|
||||||
get: () => {
|
|
||||||
return _state;
|
|
||||||
},
|
|
||||||
set: state => {
|
|
||||||
// Override User-Agent
|
|
||||||
try {
|
|
||||||
state.appContext.requestInfo.userAgent = window.navigator.userAgent;
|
|
||||||
} catch (e) {
|
|
||||||
BxLogger.error(LOG_TAG, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add list of games with custom layouts to the official list
|
|
||||||
if (STATES.userAgent.capabilities.touch) {
|
|
||||||
try {
|
|
||||||
const sigls = state.xcloud.sigls;
|
|
||||||
if (GamePassCloudGallery.TOUCH in sigls) {
|
|
||||||
let customList = TouchController.getCustomList();
|
|
||||||
|
|
||||||
const allGames = sigls[GamePassCloudGallery.ALL].data.products;
|
|
||||||
|
|
||||||
// Remove non-cloud games from the list
|
|
||||||
customList = customList.filter(id => allGames.includes(id));
|
|
||||||
|
|
||||||
// Add to the official list
|
|
||||||
sigls[GamePassCloudGallery.TOUCH]?.data.products.push(...customList);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BX_FLAGS.ForceNativeMkbTitles && GamePassCloudGallery.NATIVE_MKB in sigls) {
|
|
||||||
// Add to the official list
|
|
||||||
sigls[GamePassCloudGallery.NATIVE_MKB]?.data.products.push(...BX_FLAGS.ForceNativeMkbTitles);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
BxLogger.error(LOG_TAG, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getPref(PrefKey.UI_HOME_CONTEXT_MENU_DISABLED)) {
|
|
||||||
try {
|
|
||||||
state.experiments.experimentationInfo.data.treatments.EnableHomeContextMenu = false;
|
|
||||||
} catch (e) {
|
|
||||||
BxLogger.error(LOG_TAG, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
_state = state;
|
|
||||||
STATES.appContext = deepClone(state.appContext);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
114
src/utils/root-dialog-observer.ts
Normal file
114
src/utils/root-dialog-observer.ts
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
import { GuideMenu } from "@/modules/ui/guide-menu";
|
||||||
|
import { BxEvent } from "./bx-event";
|
||||||
|
import { BX_FLAGS } from "./bx-flags";
|
||||||
|
import { BxLogger } from "./bx-logger";
|
||||||
|
import { BxIcon } from "./bx-icon";
|
||||||
|
import { AppInterface } from "./global";
|
||||||
|
import { createButton, ButtonStyle } from "./html";
|
||||||
|
import { t } from "./translation";
|
||||||
|
import { parseDetailsPath } from "./utils";
|
||||||
|
|
||||||
|
|
||||||
|
export class RootDialogObserver {
|
||||||
|
private static $btnShortcut = AppInterface && createButton({
|
||||||
|
icon: BxIcon.CREATE_SHORTCUT,
|
||||||
|
label: t('create-shortcut'),
|
||||||
|
style: ButtonStyle.FOCUSABLE | ButtonStyle.GHOST | ButtonStyle.FULL_WIDTH | ButtonStyle.NORMAL_CASE | ButtonStyle.NORMAL_LINK,
|
||||||
|
tabIndex: 0,
|
||||||
|
onClick: e => {
|
||||||
|
window.BX_EXPOSED.dialogRoutes?.closeAll();
|
||||||
|
|
||||||
|
const $btn = (e.target as HTMLElement).closest('button');
|
||||||
|
AppInterface.createShortcut($btn?.dataset.path);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
private static $btnWallpaper = AppInterface && createButton({
|
||||||
|
icon: BxIcon.DOWNLOAD,
|
||||||
|
label: t('wallpaper'),
|
||||||
|
style: ButtonStyle.FOCUSABLE | ButtonStyle.GHOST | ButtonStyle.FULL_WIDTH | ButtonStyle.NORMAL_CASE | ButtonStyle.NORMAL_LINK,
|
||||||
|
tabIndex: 0,
|
||||||
|
onClick: e => {
|
||||||
|
window.BX_EXPOSED.dialogRoutes?.closeAll();
|
||||||
|
|
||||||
|
const $btn = (e.target as HTMLElement).closest('button');
|
||||||
|
const details = parseDetailsPath($btn!.dataset.path!);
|
||||||
|
details && AppInterface.downloadWallpapers(details.titleSlug, details.productId);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
private static handleGameCardMenu($root: HTMLElement) {
|
||||||
|
const $detail = $root.querySelector('a[href^="/play/"]') as HTMLAnchorElement;
|
||||||
|
if (!$detail) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const path = $detail.getAttribute('href')!;
|
||||||
|
RootDialogObserver.$btnShortcut.dataset.path = path;
|
||||||
|
RootDialogObserver.$btnWallpaper.dataset.path = path;
|
||||||
|
|
||||||
|
$root.append(RootDialogObserver.$btnShortcut, RootDialogObserver.$btnWallpaper);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static handleAddedElement($root: HTMLElement, $addedElm: HTMLElement): boolean {
|
||||||
|
if (AppInterface && $addedElm.className.startsWith('SlideSheet-module__container')) {
|
||||||
|
// Game card's context menu
|
||||||
|
const $gameCardMenu = $addedElm.querySelector<HTMLElement>('div[class^=MruContextMenu],div[class^=GameCardContextMenu]');
|
||||||
|
if ($gameCardMenu) {
|
||||||
|
RootDialogObserver.handleGameCardMenu($gameCardMenu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if ($root.querySelector('div[class*=GuideDialog]')) {
|
||||||
|
// Guide menu
|
||||||
|
GuideMenu.getInstance().observe($addedElm);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static observe($root: HTMLElement) {
|
||||||
|
let beingShown = false;
|
||||||
|
|
||||||
|
const observer = new MutationObserver(mutationList => {
|
||||||
|
for (const mutation of mutationList) {
|
||||||
|
if (mutation.type !== 'childList') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
BX_FLAGS.Debug && BxLogger.warning('RootDialog', 'added', mutation.addedNodes);
|
||||||
|
if (mutation.addedNodes.length === 1) {
|
||||||
|
const $addedElm = mutation.addedNodes[0];
|
||||||
|
if ($addedElm instanceof HTMLElement) {
|
||||||
|
RootDialogObserver.handleAddedElement($root, $addedElm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const shown = !!($root.firstElementChild && $root.firstElementChild.childElementCount > 0);
|
||||||
|
if (shown !== beingShown) {
|
||||||
|
beingShown = shown;
|
||||||
|
BxEvent.dispatch(window, shown ? BxEvent.XCLOUD_DIALOG_SHOWN : BxEvent.XCLOUD_DIALOG_DISMISSED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
observer.observe($root, {subtree: true, childList: true});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static waitForRootDialog() {
|
||||||
|
const observer = new MutationObserver(mutationList => {
|
||||||
|
for (const mutation of mutationList) {
|
||||||
|
if (mutation.type !== 'childList') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const $target = mutation.target as HTMLElement;
|
||||||
|
if ($target.id && $target.id === 'gamepass-dialog-root') {
|
||||||
|
observer.disconnect();
|
||||||
|
RootDialogObserver.observe($target);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
observer.observe(document.documentElement, {subtree: true, childList: true});
|
||||||
|
}
|
||||||
|
}
|
105
src/utils/screenshot-manager.ts
Normal file
105
src/utils/screenshot-manager.ts
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
import { StreamPlayerType } from "@enums/stream-player";
|
||||||
|
import { AppInterface, STATES } from "./global";
|
||||||
|
import { CE } from "./html";
|
||||||
|
import { PrefKey } from "@/enums/pref-keys";
|
||||||
|
import { getPref } from "./settings-storages/global-settings-storage";
|
||||||
|
import { BxLogger } from "./bx-logger";
|
||||||
|
|
||||||
|
|
||||||
|
export class ScreenshotManager {
|
||||||
|
private static instance: ScreenshotManager;
|
||||||
|
public static getInstance = () => ScreenshotManager.instance ?? (ScreenshotManager.instance = new ScreenshotManager());
|
||||||
|
private readonly LOG_TAG = 'ScreenshotManager';
|
||||||
|
|
||||||
|
private $download: HTMLAnchorElement;
|
||||||
|
private $canvas: HTMLCanvasElement;
|
||||||
|
private canvasContext: CanvasRenderingContext2D;
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
|
|
||||||
|
this.$download = CE<HTMLAnchorElement>('a');
|
||||||
|
|
||||||
|
this.$canvas = CE<HTMLCanvasElement>('canvas', {'class': 'bx-gone'});
|
||||||
|
this.canvasContext = this.$canvas.getContext('2d', {
|
||||||
|
alpha: false,
|
||||||
|
willReadFrequently: false,
|
||||||
|
})!;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateCanvasSize(width: number, height: number) {
|
||||||
|
this.$canvas.width = width;
|
||||||
|
this.$canvas.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateCanvasFilters(filters: string) {
|
||||||
|
this.canvasContext.filter = filters;
|
||||||
|
}
|
||||||
|
|
||||||
|
private onAnimationEnd(e: Event) {
|
||||||
|
(e.target as HTMLElement).classList.remove('bx-taking-screenshot');
|
||||||
|
}
|
||||||
|
|
||||||
|
takeScreenshot(callback?: any) {
|
||||||
|
const currentStream = STATES.currentStream;
|
||||||
|
const streamPlayer = currentStream.streamPlayer;
|
||||||
|
const $canvas = this.$canvas;
|
||||||
|
if (!streamPlayer || !$canvas) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let $player;
|
||||||
|
if (getPref(PrefKey.SCREENSHOT_APPLY_FILTERS)) {
|
||||||
|
$player = streamPlayer.getPlayerElement();
|
||||||
|
} else {
|
||||||
|
$player = streamPlayer.getPlayerElement(StreamPlayerType.VIDEO);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$player || !$player.isConnected) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$player.parentElement!.addEventListener('animationend', this.onAnimationEnd, { once: true });
|
||||||
|
$player.parentElement!.classList.add('bx-taking-screenshot');
|
||||||
|
|
||||||
|
const canvasContext = this.canvasContext;
|
||||||
|
|
||||||
|
if ($player instanceof HTMLCanvasElement) {
|
||||||
|
streamPlayer.getWebGL2Player().forceDrawFrame();
|
||||||
|
}
|
||||||
|
canvasContext.drawImage($player, 0, 0, $canvas.width, $canvas.height);
|
||||||
|
|
||||||
|
// Get data URL and pass to parent app
|
||||||
|
if (AppInterface) {
|
||||||
|
const data = $canvas.toDataURL('image/png').split(';base64,')[1];
|
||||||
|
AppInterface.saveScreenshot(currentStream.titleSlug, data);
|
||||||
|
|
||||||
|
// Free screenshot from memory
|
||||||
|
canvasContext.clearRect(0, 0, $canvas.width, $canvas.height);
|
||||||
|
|
||||||
|
callback && callback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$canvas.toBlob(blob => {
|
||||||
|
if (!blob) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download screenshot
|
||||||
|
const now = +new Date;
|
||||||
|
const $download = this.$download;
|
||||||
|
$download.download = `${currentStream.titleSlug}-${now}.png`;
|
||||||
|
$download.href = URL.createObjectURL(blob);
|
||||||
|
$download.click();
|
||||||
|
|
||||||
|
// Free screenshot from memory
|
||||||
|
URL.revokeObjectURL($download.href);
|
||||||
|
$download.href = '';
|
||||||
|
$download.download = '';
|
||||||
|
canvasContext.clearRect(0, 0, $canvas.width, $canvas.height);
|
||||||
|
|
||||||
|
callback && callback();
|
||||||
|
}, 'image/png');
|
||||||
|
}
|
||||||
|
}
|
@ -1,99 +0,0 @@
|
|||||||
import { StreamPlayerType } from "@enums/stream-player";
|
|
||||||
import { AppInterface, STATES } from "./global";
|
|
||||||
import { CE } from "./html";
|
|
||||||
import { PrefKey } from "@/enums/pref-keys";
|
|
||||||
import { getPref } from "./settings-storages/global-settings-storage";
|
|
||||||
|
|
||||||
|
|
||||||
export class Screenshot {
|
|
||||||
static #$canvas: HTMLCanvasElement;
|
|
||||||
static #canvasContext: CanvasRenderingContext2D;
|
|
||||||
|
|
||||||
static setup() {
|
|
||||||
if (Screenshot.#$canvas) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Screenshot.#$canvas = CE<HTMLCanvasElement>('canvas', {'class': 'bx-gone'});
|
|
||||||
|
|
||||||
Screenshot.#canvasContext = Screenshot.#$canvas.getContext('2d', {
|
|
||||||
alpha: false,
|
|
||||||
willReadFrequently: false,
|
|
||||||
})!;
|
|
||||||
}
|
|
||||||
|
|
||||||
static updateCanvasSize(width: number, height: number) {
|
|
||||||
const $canvas = Screenshot.#$canvas;
|
|
||||||
if ($canvas) {
|
|
||||||
$canvas.width = width;
|
|
||||||
$canvas.height = height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static updateCanvasFilters(filters: string) {
|
|
||||||
Screenshot.#canvasContext && (Screenshot.#canvasContext.filter = filters);
|
|
||||||
}
|
|
||||||
|
|
||||||
static #onAnimationEnd(e: Event) {
|
|
||||||
const $target = e.target as HTMLElement;
|
|
||||||
$target.classList.remove('bx-taking-screenshot');
|
|
||||||
}
|
|
||||||
|
|
||||||
static takeScreenshot(callback?: any) {
|
|
||||||
const currentStream = STATES.currentStream;
|
|
||||||
const streamPlayer = currentStream.streamPlayer;
|
|
||||||
const $canvas = Screenshot.#$canvas;
|
|
||||||
if (!streamPlayer || !$canvas) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let $player;
|
|
||||||
if (getPref(PrefKey.SCREENSHOT_APPLY_FILTERS)) {
|
|
||||||
$player = streamPlayer.getPlayerElement();
|
|
||||||
} else {
|
|
||||||
$player = streamPlayer.getPlayerElement(StreamPlayerType.VIDEO);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$player || !$player.isConnected) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$player.parentElement!.addEventListener('animationend', this.#onAnimationEnd, { once: true });
|
|
||||||
$player.parentElement!.classList.add('bx-taking-screenshot');
|
|
||||||
|
|
||||||
const canvasContext = Screenshot.#canvasContext;
|
|
||||||
|
|
||||||
if ($player instanceof HTMLCanvasElement) {
|
|
||||||
streamPlayer.getWebGL2Player().drawFrame();
|
|
||||||
}
|
|
||||||
canvasContext.drawImage($player, 0, 0, $canvas.width, $canvas.height);
|
|
||||||
|
|
||||||
// Get data URL and pass to parent app
|
|
||||||
if (AppInterface) {
|
|
||||||
const data = $canvas.toDataURL('image/png').split(';base64,')[1];
|
|
||||||
AppInterface.saveScreenshot(currentStream.titleSlug, data);
|
|
||||||
|
|
||||||
// Free screenshot from memory
|
|
||||||
canvasContext.clearRect(0, 0, $canvas.width, $canvas.height);
|
|
||||||
|
|
||||||
callback && callback();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$canvas && $canvas.toBlob(blob => {
|
|
||||||
// Download screenshot
|
|
||||||
const now = +new Date;
|
|
||||||
const $anchor = CE<HTMLAnchorElement>('a', {
|
|
||||||
'download': `${currentStream.titleSlug}-${now}.png`,
|
|
||||||
'href': URL.createObjectURL(blob!),
|
|
||||||
});
|
|
||||||
$anchor.click();
|
|
||||||
|
|
||||||
// Free screenshot from memory
|
|
||||||
URL.revokeObjectURL($anchor.href);
|
|
||||||
canvasContext.clearRect(0, 0, $canvas.width, $canvas.height);
|
|
||||||
|
|
||||||
callback && callback();
|
|
||||||
}, 'image/png');
|
|
||||||
}
|
|
||||||
}
|
|
@ -25,9 +25,9 @@ export interface BxSelectSettingElement extends HTMLSelectElement, BxBaseSetting
|
|||||||
export class SettingElement {
|
export class SettingElement {
|
||||||
static #renderOptions(key: string, setting: PreferenceSetting, currentValue: any, onChange: any): BxSelectSettingElement {
|
static #renderOptions(key: string, setting: PreferenceSetting, currentValue: any, onChange: any): BxSelectSettingElement {
|
||||||
const $control = CE<BxSelectSettingElement>('select', {
|
const $control = CE<BxSelectSettingElement>('select', {
|
||||||
// title: setting.label,
|
// title: setting.label,
|
||||||
tabindex: 0,
|
tabindex: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
let $parent: HTMLElement;
|
let $parent: HTMLElement;
|
||||||
if (setting.optionsGroup) {
|
if (setting.optionsGroup) {
|
||||||
@ -64,10 +64,10 @@ export class SettingElement {
|
|||||||
|
|
||||||
static #renderMultipleOptions(key: string, setting: PreferenceSetting, currentValue: any, onChange: any, params: MultipleOptionsParams={}): BxSelectSettingElement {
|
static #renderMultipleOptions(key: string, setting: PreferenceSetting, currentValue: any, onChange: any, params: MultipleOptionsParams={}): BxSelectSettingElement {
|
||||||
const $control = CE<BxSelectSettingElement>('select', {
|
const $control = CE<BxSelectSettingElement>('select', {
|
||||||
// title: setting.label,
|
// title: setting.label,
|
||||||
multiple: true,
|
multiple: true,
|
||||||
tabindex: 0,
|
tabindex: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (params && params.size) {
|
if (params && params.size) {
|
||||||
$control.setAttribute('size', params.size.toString());
|
$control.setAttribute('size', params.size.toString());
|
||||||
@ -160,10 +160,18 @@ export class SettingElement {
|
|||||||
|
|
||||||
let controlValue = value;
|
let controlValue = value;
|
||||||
|
|
||||||
const MIN = setting.min!;
|
const MIN = options.reverse ? -setting.max! : setting.min!;
|
||||||
const MAX = setting.max!;
|
const MAX = options.reverse ? -setting.min! : setting.max!;
|
||||||
const STEPS = Math.max(setting.steps || 1, 1);
|
const STEPS = Math.max(setting.steps || 1, 1);
|
||||||
|
|
||||||
|
let intervalId: number | null;
|
||||||
|
let isHolding = false;
|
||||||
|
|
||||||
|
const clearIntervalId = () => {
|
||||||
|
intervalId && clearInterval(intervalId);
|
||||||
|
intervalId = null;
|
||||||
|
}
|
||||||
|
|
||||||
const renderTextValue = (value: any) => {
|
const renderTextValue = (value: any) => {
|
||||||
value = parseInt(value as string);
|
value = parseInt(value as string);
|
||||||
|
|
||||||
@ -182,6 +190,10 @@ export class SettingElement {
|
|||||||
const updateButtonsVisibility = () => {
|
const updateButtonsVisibility = () => {
|
||||||
$btnDec.classList.toggle('bx-inactive', controlValue === MIN);
|
$btnDec.classList.toggle('bx-inactive', controlValue === MIN);
|
||||||
$btnInc.classList.toggle('bx-inactive', controlValue === MAX);
|
$btnInc.classList.toggle('bx-inactive', controlValue === MAX);
|
||||||
|
|
||||||
|
if (controlValue === MIN || controlValue === MAX) {
|
||||||
|
clearIntervalId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const $wrapper = CE<BxHtmlSettingElement>('div', {'class': 'bx-number-stepper', id: `bx_setting_${key}`},
|
const $wrapper = CE<BxHtmlSettingElement>('div', {'class': 'bx-number-stepper', id: `bx_setting_${key}`},
|
||||||
@ -212,11 +224,11 @@ export class SettingElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$range = CE<HTMLInputElement>('input', {
|
$range = CE<HTMLInputElement>('input', {
|
||||||
id: `bx_setting_${key}`,
|
id: `bx_inp_setting_${key}`,
|
||||||
type: 'range',
|
type: 'range',
|
||||||
min: MIN,
|
min: MIN,
|
||||||
max: MAX,
|
max: MAX,
|
||||||
value: value,
|
value: options.reverse ? -value : value,
|
||||||
step: STEPS,
|
step: STEPS,
|
||||||
tabindex: 0,
|
tabindex: 0,
|
||||||
});
|
});
|
||||||
@ -225,13 +237,16 @@ export class SettingElement {
|
|||||||
|
|
||||||
$range.addEventListener('input', e => {
|
$range.addEventListener('input', e => {
|
||||||
value = parseInt((e.target as HTMLInputElement).value);
|
value = parseInt((e.target as HTMLInputElement).value);
|
||||||
const valueChanged = controlValue !== value;
|
if (options.reverse) {
|
||||||
|
value *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const valueChanged = controlValue !== value;
|
||||||
if (!valueChanged) {
|
if (!valueChanged) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
controlValue = value;
|
controlValue = options.reverse ? -value : value;
|
||||||
updateButtonsVisibility();
|
updateButtonsVisibility();
|
||||||
$text.textContent = renderTextValue(value);
|
$text.textContent = renderTextValue(value);
|
||||||
|
|
||||||
@ -245,22 +260,24 @@ export class SettingElement {
|
|||||||
|
|
||||||
if (options.ticks || options.exactTicks) {
|
if (options.ticks || options.exactTicks) {
|
||||||
const markersId = `markers-${key}`;
|
const markersId = `markers-${key}`;
|
||||||
const $markers = CE('datalist', {'id': markersId});
|
const $markers = CE('datalist', {id: markersId});
|
||||||
$range.setAttribute('list', markersId);
|
$range.setAttribute('list', markersId);
|
||||||
|
|
||||||
if (options.exactTicks) {
|
if (options.exactTicks) {
|
||||||
let start = Math.max(Math.floor(MIN / options.exactTicks), 1) * options.exactTicks;
|
let start = Math.max(Math.floor(setting.min! / options.exactTicks), 1) * options.exactTicks;
|
||||||
|
|
||||||
if (start === MIN) {
|
if (start === setting.min!) {
|
||||||
start += options.exactTicks;
|
start += options.exactTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = start; i < MAX; i += options.exactTicks) {
|
for (let i = start; i < setting.max!; i += options.exactTicks) {
|
||||||
$markers.appendChild(CE<HTMLOptionElement>('option', {'value': i}));
|
$markers.appendChild(CE<HTMLOptionElement>('option', {
|
||||||
|
value: options.reverse ? -i : i,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (let i = MIN + options.ticks!; i < MAX; i += options.ticks!) {
|
for (let i = MIN + options.ticks!; i < MAX; i += options.ticks!) {
|
||||||
$markers.appendChild(CE<HTMLOptionElement>('option', {'value': i}));
|
$markers.appendChild(CE<HTMLOptionElement>('option', {value: i}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$wrapper.appendChild($markers);
|
$wrapper.appendChild($markers);
|
||||||
@ -268,18 +285,7 @@ export class SettingElement {
|
|||||||
|
|
||||||
updateButtonsVisibility();
|
updateButtonsVisibility();
|
||||||
|
|
||||||
let interval: number;
|
const buttonPressed = (e: Event, $btn: HTMLElement) => {
|
||||||
let isHolding = false;
|
|
||||||
|
|
||||||
const onClick = (e: Event) => {
|
|
||||||
if (isHolding) {
|
|
||||||
e.preventDefault();
|
|
||||||
isHolding = false;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const $btn = e.target as HTMLElement;
|
|
||||||
let value = parseInt(controlValue);
|
let value = parseInt(controlValue);
|
||||||
|
|
||||||
const btnType = $btn.dataset.type;
|
const btnType = $btn.dataset.type;
|
||||||
@ -295,27 +301,43 @@ export class SettingElement {
|
|||||||
$text.textContent = renderTextValue(value);
|
$text.textContent = renderTextValue(value);
|
||||||
$range && ($range.value = value.toString());
|
$range && ($range.value = value.toString());
|
||||||
|
|
||||||
isHolding = false;
|
onChange && onChange(e, value);
|
||||||
!(e as any).ignoreOnChange && onChange && onChange(e, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
const onMouseDown = (e: PointerEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
isHolding = true;
|
|
||||||
|
|
||||||
const args = arguments;
|
|
||||||
interval && clearInterval(interval);
|
|
||||||
interval = window.setInterval(() => {
|
|
||||||
e.target && BxEvent.dispatch(e.target as HTMLElement, 'click', {
|
|
||||||
arguments: args,
|
|
||||||
});
|
|
||||||
}, 200);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onMouseUp = (e: PointerEvent) => {
|
const onClick = (e: Event) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (isHolding) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const $btn = (e.target as HTMLElement).closest('button') as HTMLElement;
|
||||||
|
$btn && buttonPressed(e, $btn);
|
||||||
|
|
||||||
|
clearIntervalId();
|
||||||
|
isHolding = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const onPointerDown = (e: PointerEvent) => {
|
||||||
|
clearIntervalId();
|
||||||
|
|
||||||
|
const $btn = (e.target as HTMLElement).closest('button') as HTMLElement;
|
||||||
|
if (!$btn) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isHolding = true;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
interval && clearInterval(interval);
|
intervalId = window.setInterval((e: Event) => {
|
||||||
|
buttonPressed(e, $btn);
|
||||||
|
}, 200);
|
||||||
|
|
||||||
|
window.addEventListener('pointerup', onPointerUp, {once: true});
|
||||||
|
window.addEventListener('pointercancel', onPointerUp, {once: true});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onPointerUp = (e: PointerEvent) => {
|
||||||
|
clearIntervalId();
|
||||||
isHolding = false;
|
isHolding = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -324,21 +346,14 @@ export class SettingElement {
|
|||||||
// Custom method
|
// Custom method
|
||||||
$wrapper.setValue = (value: any) => {
|
$wrapper.setValue = (value: any) => {
|
||||||
$text.textContent = renderTextValue(value);
|
$text.textContent = renderTextValue(value);
|
||||||
$range.value = value;
|
$range.value = options.reverse ? -value : value;
|
||||||
};
|
};
|
||||||
|
|
||||||
$btnDec.addEventListener('click', onClick);
|
$wrapper.addEventListener('click', onClick);
|
||||||
$btnDec.addEventListener('pointerdown', onMouseDown);
|
$wrapper.addEventListener('pointerdown', onPointerDown);
|
||||||
$btnDec.addEventListener('pointerup', onMouseUp);
|
$wrapper.addEventListener('contextmenu', onContextMenu);
|
||||||
$btnDec.addEventListener('contextmenu', onContextMenu);
|
|
||||||
|
|
||||||
$btnInc.addEventListener('click', onClick);
|
|
||||||
$btnInc.addEventListener('pointerdown', onMouseDown);
|
|
||||||
$btnInc.addEventListener('pointerup', onMouseUp);
|
|
||||||
$btnInc.addEventListener('contextmenu', onContextMenu);
|
|
||||||
|
|
||||||
setNearby($wrapper, {
|
setNearby($wrapper, {
|
||||||
focus: $range || $btnInc,
|
focus: options.hideSlider ? $btnInc : $range,
|
||||||
})
|
})
|
||||||
|
|
||||||
return $wrapper;
|
return $wrapper;
|
||||||
|
@ -39,6 +39,10 @@ export const enum ControllerDeviceVibration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export type GameBarPosition = 'bottom-left' | 'bottom-right' | 'off';
|
||||||
|
export type GameBarPositionOptions = Record<GameBarPosition, string>;
|
||||||
|
|
||||||
|
|
||||||
function getSupportedCodecProfiles() {
|
function getSupportedCodecProfiles() {
|
||||||
const options: PartialRecord<CodecProfile, string> = {
|
const options: PartialRecord<CodecProfile, string> = {
|
||||||
default: t('default'),
|
default: t('default'),
|
||||||
@ -113,6 +117,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
[PrefKey.SERVER_REGION]: {
|
[PrefKey.SERVER_REGION]: {
|
||||||
label: t('region'),
|
label: t('region'),
|
||||||
|
note: CE('a', {target: '_blank', href: 'https://umap.openstreetmap.fr/en/map/xbox-cloud-gaming-servers_1135022'}, t('server-locations')),
|
||||||
default: 'default',
|
default: 'default',
|
||||||
},
|
},
|
||||||
[PrefKey.SERVER_BYPASS_RESTRICTION]: {
|
[PrefKey.SERVER_BYPASS_RESTRICTION]: {
|
||||||
@ -131,6 +136,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
options: {
|
options: {
|
||||||
default: t('default'),
|
default: t('default'),
|
||||||
'ar-SA': 'العربية',
|
'ar-SA': 'العربية',
|
||||||
|
'bg-BG': 'Български',
|
||||||
'cs-CZ': 'čeština',
|
'cs-CZ': 'čeština',
|
||||||
'da-DK': 'dansk',
|
'da-DK': 'dansk',
|
||||||
'de-DE': 'Deutsch',
|
'de-DE': 'Deutsch',
|
||||||
@ -151,9 +157,11 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
'pl-PL': 'polski',
|
'pl-PL': 'polski',
|
||||||
'pt-BR': 'português (Brasil)',
|
'pt-BR': 'português (Brasil)',
|
||||||
'pt-PT': 'português (Portugal)',
|
'pt-PT': 'português (Portugal)',
|
||||||
|
'ro-RO': 'Română',
|
||||||
'ru-RU': 'русский',
|
'ru-RU': 'русский',
|
||||||
'sk-SK': 'slovenčina',
|
'sk-SK': 'slovenčina',
|
||||||
'sv-SE': 'svenska',
|
'sv-SE': 'svenska',
|
||||||
|
'th-TH': 'ไทย',
|
||||||
'tr-TR': 'Türkçe',
|
'tr-TR': 'Türkçe',
|
||||||
'zh-CN': '中文(简体)',
|
'zh-CN': '中文(简体)',
|
||||||
'zh-TW': '中文 (繁體)',
|
'zh-TW': '中文 (繁體)',
|
||||||
@ -182,7 +190,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
|
|
||||||
if (keys.length <= 1) { // Unsupported
|
if (keys.length <= 1) { // Unsupported
|
||||||
setting.unsupported = true;
|
setting.unsupported = true;
|
||||||
setting.note = '⚠️ ' + t('browser-unsupported-feature');
|
setting.unsupportedNote = '⚠️ ' + t('browser-unsupported-feature');
|
||||||
}
|
}
|
||||||
|
|
||||||
setting.suggest = {
|
setting.suggest = {
|
||||||
@ -323,22 +331,22 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
[PrefKey.GAME_BAR_POSITION]: {
|
[PrefKey.GAME_BAR_POSITION]: {
|
||||||
requiredVariants: 'full',
|
requiredVariants: 'full',
|
||||||
label: t('position'),
|
label: t('position'),
|
||||||
default: 'bottom-left',
|
default: 'bottom-left' satisfies GameBarPosition,
|
||||||
options: {
|
options: {
|
||||||
'bottom-left': t('bottom-left'),
|
'bottom-left': t('bottom-left'),
|
||||||
'bottom-right': t('bottom-right'),
|
'bottom-right': t('bottom-right'),
|
||||||
'off': t('off'),
|
'off': t('off'),
|
||||||
},
|
} satisfies GameBarPositionOptions,
|
||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.LOCAL_CO_OP_ENABLED]: {
|
[PrefKey.LOCAL_CO_OP_ENABLED]: {
|
||||||
requiredVariants: 'full',
|
requiredVariants: 'full',
|
||||||
label: t('enable-local-co-op-support'),
|
label: t('enable-local-co-op-support'),
|
||||||
default: false,
|
default: false,
|
||||||
note: CE<HTMLAnchorElement>('a', {
|
note: () => CE<HTMLAnchorElement>('a', {
|
||||||
href: 'https://github.com/redphx/better-xcloud/discussions/275',
|
href: 'https://github.com/redphx/better-xcloud/discussions/275',
|
||||||
target: '_blank',
|
target: '_blank',
|
||||||
}, t('enable-local-co-op-support-note')),
|
}, t('enable-local-co-op-support-note')),
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -353,11 +361,6 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.CONTROLLER_ENABLE_SHORTCUTS]: {
|
|
||||||
requiredVariants: 'full',
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
[PrefKey.CONTROLLER_ENABLE_VIBRATION]: {
|
[PrefKey.CONTROLLER_ENABLE_VIBRATION]: {
|
||||||
requiredVariants: 'full',
|
requiredVariants: 'full',
|
||||||
label: t('controller-vibration'),
|
label: t('controller-vibration'),
|
||||||
@ -389,14 +392,35 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
[PrefKey.CONTROLLER_POLLING_RATE]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
|
label: t('polling-rate'),
|
||||||
|
type: SettingElementType.NUMBER_STEPPER,
|
||||||
|
default: 4,
|
||||||
|
min: 4,
|
||||||
|
max: 60,
|
||||||
|
steps: 4,
|
||||||
|
params: {
|
||||||
|
exactTicks: 20,
|
||||||
|
reverse: true,
|
||||||
|
customTextValue(value: any) {
|
||||||
|
value = parseInt(value);
|
||||||
|
|
||||||
|
let text = +(1000 / value).toFixed(2) + ' Hz';
|
||||||
|
if (value === 4) {
|
||||||
|
text = `${text} (${t('default')})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return text;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
[PrefKey.MKB_ENABLED]: {
|
[PrefKey.MKB_ENABLED]: {
|
||||||
requiredVariants: 'full',
|
requiredVariants: 'full',
|
||||||
label: t('enable-mkb'),
|
label: t('enable-mkb'),
|
||||||
default: false,
|
default: false,
|
||||||
unsupported: ((): string | boolean => {
|
unsupported: !STATES.userAgent.capabilities.mkb,
|
||||||
const userAgent = ((window.navigator as any).orgUserAgent || window.navigator.userAgent || '').toLowerCase();
|
|
||||||
return !AppInterface && userAgent.match(/(android|iphone|ipad)/) ? t('browser-unsupported-feature') : false;
|
|
||||||
})(),
|
|
||||||
ready: (setting: SettingDefinition) => {
|
ready: (setting: SettingDefinition) => {
|
||||||
let note;
|
let note;
|
||||||
let url;
|
let url;
|
||||||
@ -408,10 +432,10 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
url = 'https://better-xcloud.github.io/mouse-and-keyboard/#disclaimer';
|
url = 'https://better-xcloud.github.io/mouse-and-keyboard/#disclaimer';
|
||||||
}
|
}
|
||||||
|
|
||||||
setting.note = CE('a', {
|
setting.unsupportedNote = () => CE<HTMLAnchorElement>('a', {
|
||||||
href: url,
|
href: url,
|
||||||
target: '_blank',
|
target: '_blank',
|
||||||
}, '⚠️ ' + note);
|
}, '⚠️ ' + note);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -532,12 +556,6 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.UI_HOME_CONTEXT_MENU_DISABLED]: {
|
|
||||||
requiredVariants: 'full',
|
|
||||||
label: t('disable-home-context-menu'),
|
|
||||||
default: STATES.browser.capabilities.touch,
|
|
||||||
},
|
|
||||||
|
|
||||||
[PrefKey.UI_HIDE_SECTIONS]: {
|
[PrefKey.UI_HIDE_SECTIONS]: {
|
||||||
requiredVariants: 'full',
|
requiredVariants: 'full',
|
||||||
label: t('hide-sections'),
|
label: t('hide-sections'),
|
||||||
@ -619,6 +637,21 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
highest: 'low-power',
|
highest: 'low-power',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
[PrefKey.VIDEO_MAX_FPS]: {
|
||||||
|
label: t('max-fps'),
|
||||||
|
type: SettingElementType.NUMBER_STEPPER,
|
||||||
|
default: 60,
|
||||||
|
min: 10,
|
||||||
|
max: 60,
|
||||||
|
steps: 10,
|
||||||
|
params: {
|
||||||
|
exactTicks: 10,
|
||||||
|
customTextValue: (value: any) => {
|
||||||
|
value = parseInt(value);
|
||||||
|
return value === 60 ? t('unlimited') : value + 'fps';
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
[PrefKey.VIDEO_SHARPNESS]: {
|
[PrefKey.VIDEO_SHARPNESS]: {
|
||||||
label: t('sharpness'),
|
label: t('sharpness'),
|
||||||
type: SettingElementType.NUMBER_STEPPER,
|
type: SettingElementType.NUMBER_STEPPER,
|
||||||
@ -634,7 +667,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
suggest: {
|
suggest: {
|
||||||
lowest: 0,
|
lowest: 0,
|
||||||
highest: 4,
|
highest: 2,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[PrefKey.VIDEO_RATIO]: {
|
[PrefKey.VIDEO_RATIO]: {
|
||||||
@ -717,13 +750,14 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
[StreamStat.PLAYTIME]: `${StreamStat.PLAYTIME.toUpperCase()}: ${t('playtime')}`,
|
[StreamStat.PLAYTIME]: `${StreamStat.PLAYTIME.toUpperCase()}: ${t('playtime')}`,
|
||||||
[StreamStat.BATTERY]: `${StreamStat.BATTERY.toUpperCase()}: ${t('battery')}`,
|
[StreamStat.BATTERY]: `${StreamStat.BATTERY.toUpperCase()}: ${t('battery')}`,
|
||||||
[StreamStat.PING]: `${StreamStat.PING.toUpperCase()}: ${t('stat-ping')}`,
|
[StreamStat.PING]: `${StreamStat.PING.toUpperCase()}: ${t('stat-ping')}`,
|
||||||
|
[StreamStat.JITTER]: `${StreamStat.JITTER.toUpperCase()}: ${t('jitter')}`,
|
||||||
[StreamStat.FPS]: `${StreamStat.FPS.toUpperCase()}: ${t('stat-fps')}`,
|
[StreamStat.FPS]: `${StreamStat.FPS.toUpperCase()}: ${t('stat-fps')}`,
|
||||||
[StreamStat.BITRATE]: `${StreamStat.BITRATE.toUpperCase()}: ${t('stat-bitrate')}`,
|
[StreamStat.BITRATE]: `${StreamStat.BITRATE.toUpperCase()}: ${t('stat-bitrate')}`,
|
||||||
[StreamStat.DECODE_TIME]: `${StreamStat.DECODE_TIME.toUpperCase()}: ${t('stat-decode-time')}`,
|
[StreamStat.DECODE_TIME]: `${StreamStat.DECODE_TIME.toUpperCase()}: ${t('stat-decode-time')}`,
|
||||||
[StreamStat.PACKETS_LOST]: `${StreamStat.PACKETS_LOST.toUpperCase()}: ${t('stat-packets-lost')}`,
|
[StreamStat.PACKETS_LOST]: `${StreamStat.PACKETS_LOST.toUpperCase()}: ${t('stat-packets-lost')}`,
|
||||||
[StreamStat.FRAMES_LOST]: `${StreamStat.FRAMES_LOST.toUpperCase()}: ${t('stat-frames-lost')}`,
|
[StreamStat.FRAMES_LOST]: `${StreamStat.FRAMES_LOST.toUpperCase()}: ${t('stat-frames-lost')}`,
|
||||||
[StreamStat.DOWNLOAD]: `${StreamStat.DOWNLOAD.toUpperCase()}: ${t('download')}`,
|
[StreamStat.DOWNLOAD]: `${StreamStat.DOWNLOAD.toUpperCase()}: ${t('downloaded')}`,
|
||||||
[StreamStat.UPLOAD]: `${StreamStat.UPLOAD.toUpperCase()}: ${t('upload')}`,
|
[StreamStat.UPLOAD]: `${StreamStat.UPLOAD.toUpperCase()}: ${t('uploaded')}`,
|
||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
size: 6,
|
size: 6,
|
||||||
@ -804,6 +838,13 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
default: false,
|
default: false,
|
||||||
note: t('fortnite-allow-stw-mode'),
|
note: t('fortnite-allow-stw-mode'),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
[PrefKey.GAME_MSFS2020_FORCE_NATIVE_MKB]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
|
label: '✈️ ' + t('msfs2020-force-native-mkb'),
|
||||||
|
default: false,
|
||||||
|
note: t('may-not-work-properly'),
|
||||||
|
},
|
||||||
} satisfies SettingDefinitions;
|
} satisfies SettingDefinitions;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
|
import { PrefKey } from "@/enums/pref-keys";
|
||||||
import { BxEvent } from "./bx-event";
|
import { BxEvent } from "./bx-event";
|
||||||
import { STATES } from "./global";
|
import { STATES } from "./global";
|
||||||
import { humanFileSize, secondsToHm } from "./html";
|
import { humanFileSize, secondsToHm } from "./html";
|
||||||
|
import { getPref } from "./settings-storages/global-settings-storage";
|
||||||
|
import { BxLogger } from "./bx-logger";
|
||||||
|
|
||||||
export enum StreamStat {
|
export enum StreamStat {
|
||||||
PING = 'ping',
|
PING = 'ping',
|
||||||
|
JITTER = 'jit',
|
||||||
FPS = 'fps',
|
FPS = 'fps',
|
||||||
BITRATE = 'btr',
|
BITRATE = 'btr',
|
||||||
DECODE_TIME = 'dt',
|
DECODE_TIME = 'dt',
|
||||||
@ -21,7 +25,13 @@ export type StreamStatGrade = '' | 'bad' | 'ok' | 'good';
|
|||||||
type CurrentStats = {
|
type CurrentStats = {
|
||||||
[StreamStat.PING]: {
|
[StreamStat.PING]: {
|
||||||
current: number;
|
current: number;
|
||||||
calculateGrade: () => StreamStatGrade;
|
grades: [number, number, number];
|
||||||
|
toString: () => string;
|
||||||
|
};
|
||||||
|
|
||||||
|
[StreamStat.JITTER]: {
|
||||||
|
current: number;
|
||||||
|
grades: [number, number, number];
|
||||||
toString: () => string;
|
toString: () => string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -50,7 +60,7 @@ type CurrentStats = {
|
|||||||
[StreamStat.DECODE_TIME]: {
|
[StreamStat.DECODE_TIME]: {
|
||||||
current: number;
|
current: number;
|
||||||
total: number;
|
total: number;
|
||||||
calculateGrade: () => StreamStatGrade;
|
grades: [number, number, number];
|
||||||
toString: () => string;
|
toString: () => string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -85,32 +95,38 @@ type CurrentStats = {
|
|||||||
|
|
||||||
export class StreamStatsCollector {
|
export class StreamStatsCollector {
|
||||||
private static instance: StreamStatsCollector;
|
private static instance: StreamStatsCollector;
|
||||||
public static getInstance(): StreamStatsCollector {
|
public static getInstance = () => StreamStatsCollector.instance ?? (StreamStatsCollector.instance = new StreamStatsCollector());
|
||||||
if (!StreamStatsCollector.instance) {
|
private readonly LOG_TAG = 'StreamStatsCollector';
|
||||||
StreamStatsCollector.instance = new StreamStatsCollector();
|
|
||||||
}
|
|
||||||
|
|
||||||
return StreamStatsCollector.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect in background - 60 seconds
|
// Collect in background - 60 seconds
|
||||||
static readonly INTERVAL_BACKGROUND = 60 * 1000;
|
static readonly INTERVAL_BACKGROUND = 60 * 1000;
|
||||||
|
|
||||||
|
public calculateGrade(value: number, grades: [number, number, number]): StreamStatGrade {
|
||||||
|
return (value > grades[2]) ? 'bad' : (value > grades[1]) ? 'ok' : (value > grades[0]) ? 'good' : '';
|
||||||
|
}
|
||||||
|
|
||||||
private currentStats: CurrentStats = {
|
private currentStats: CurrentStats = {
|
||||||
[StreamStat.PING]: {
|
[StreamStat.PING]: {
|
||||||
current: -1,
|
current: -1,
|
||||||
calculateGrade() {
|
grades: [40, 75, 100],
|
||||||
return (this.current >= 100) ? 'bad' : (this.current > 75) ? 'ok' : (this.current > 40) ? 'good' : '';
|
|
||||||
},
|
|
||||||
toString() {
|
toString() {
|
||||||
return this.current === -1 ? '???' : this.current.toString();
|
return this.current === -1 ? '???' : this.current.toString();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
[StreamStat.JITTER]: {
|
||||||
|
current: 0,
|
||||||
|
grades: [30, 40, 60],
|
||||||
|
toString() {
|
||||||
|
return `${this.current.toFixed(2)}ms`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
[StreamStat.FPS]: {
|
[StreamStat.FPS]: {
|
||||||
current: 0,
|
current: 0,
|
||||||
toString() {
|
toString() {
|
||||||
return this.current.toString();
|
const maxFps = getPref(PrefKey.VIDEO_MAX_FPS);
|
||||||
|
return maxFps < 60 ? `${maxFps}/${this.current}` : this.current.toString();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -142,9 +158,7 @@ export class StreamStatsCollector {
|
|||||||
[StreamStat.DECODE_TIME]: {
|
[StreamStat.DECODE_TIME]: {
|
||||||
current: 0,
|
current: 0,
|
||||||
total: 0,
|
total: 0,
|
||||||
calculateGrade() {
|
grades: [6, 9, 12],
|
||||||
return (this.current > 12) ? 'bad' : (this.current > 9) ? 'ok' : (this.current > 6) ? 'good' : '';
|
|
||||||
},
|
|
||||||
toString() {
|
toString() {
|
||||||
return isNaN(this.current) ? '??ms' : `${this.current.toFixed(2)}ms`;
|
return isNaN(this.current) ? '??ms' : `${this.current.toFixed(2)}ms`;
|
||||||
},
|
},
|
||||||
@ -200,12 +214,19 @@ export class StreamStatsCollector {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
private lastVideoStat?: RTCBasicStat | null;
|
private lastVideoStat?: RTCInboundRtpStreamStats | null;
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
|
}
|
||||||
|
|
||||||
async collect() {
|
async collect() {
|
||||||
const stats = await STATES.currentStream.peerConnection?.getStats();
|
const stats = await STATES.currentStream.peerConnection?.getStats();
|
||||||
|
if (!stats) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
stats?.forEach(stat => {
|
stats.forEach(stat => {
|
||||||
if (stat.type === 'inbound-rtp' && stat.kind === 'video') {
|
if (stat.type === 'inbound-rtp' && stat.kind === 'video') {
|
||||||
// FPS
|
// FPS
|
||||||
const fps = this.currentStats[StreamStat.FPS];
|
const fps = this.currentStats[StreamStat.FPS];
|
||||||
@ -229,15 +250,23 @@ export class StreamStatsCollector {
|
|||||||
|
|
||||||
const lastStat = this.lastVideoStat;
|
const lastStat = this.lastVideoStat;
|
||||||
|
|
||||||
|
// Jitter
|
||||||
|
const jit = this.currentStats[StreamStat.JITTER];
|
||||||
|
const bufferDelayDiff = (stat as RTCInboundRtpStreamStats).jitterBufferDelay! - lastStat.jitterBufferDelay!;
|
||||||
|
const emittedCountDiff = (stat as RTCInboundRtpStreamStats).jitterBufferEmittedCount! - lastStat.jitterBufferEmittedCount!;
|
||||||
|
if (emittedCountDiff > 0) {
|
||||||
|
jit.current = bufferDelayDiff / emittedCountDiff * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
// Bitrate
|
// Bitrate
|
||||||
const btr = this.currentStats[StreamStat.BITRATE];
|
const btr = this.currentStats[StreamStat.BITRATE];
|
||||||
const timeDiff = stat.timestamp - lastStat.timestamp;
|
const timeDiff = stat.timestamp - lastStat.timestamp;
|
||||||
btr.current = 8 * (stat.bytesReceived - lastStat.bytesReceived) / timeDiff / 1000;
|
btr.current = 8 * (stat.bytesReceived - lastStat.bytesReceived!) / timeDiff / 1000;
|
||||||
|
|
||||||
// Decode time
|
// Decode time
|
||||||
const dt = this.currentStats[StreamStat.DECODE_TIME];
|
const dt = this.currentStats[StreamStat.DECODE_TIME];
|
||||||
dt.total = stat.totalDecodeTime - lastStat.totalDecodeTime;
|
dt.total = stat.totalDecodeTime - lastStat.totalDecodeTime!;
|
||||||
const framesDecodedDiff = stat.framesDecoded - lastStat.framesDecoded;
|
const framesDecodedDiff = stat.framesDecoded - lastStat.framesDecoded!;
|
||||||
dt.current = dt.total / framesDecodedDiff * 1000;
|
dt.current = dt.total / framesDecodedDiff * 1000;
|
||||||
|
|
||||||
this.lastVideoStat = stat;
|
this.lastVideoStat = stat;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { CE } from "@utils/html";
|
import { CE } from "@utils/html";
|
||||||
|
import { BxLogger } from "./bx-logger";
|
||||||
|
|
||||||
type ToastOptions = {
|
type ToastOptions = {
|
||||||
instant?: boolean;
|
instant?: boolean;
|
||||||
@ -6,84 +7,100 @@ type ToastOptions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Toast {
|
export class Toast {
|
||||||
static #$wrapper: HTMLElement;
|
private static instance: Toast;
|
||||||
static #$msg: HTMLElement;
|
public static getInstance = () => Toast.instance ?? (Toast.instance = new Toast());
|
||||||
static #$status: HTMLElement;
|
private readonly LOG_TAG = 'Toast';
|
||||||
static #stack: Array<[string, string, ToastOptions]> = [];
|
|
||||||
static #isShowing = false;
|
|
||||||
|
|
||||||
static #timeout?: number | null;
|
private $wrapper: HTMLElement;
|
||||||
static #DURATION = 3000;
|
private $msg: HTMLElement;
|
||||||
|
private $status: HTMLElement;
|
||||||
|
|
||||||
static show(msg: string, status?: string, options: Partial<ToastOptions> = {}) {
|
private stack: Array<[string, string, ToastOptions]> = [];
|
||||||
|
private isShowing = false;
|
||||||
|
|
||||||
|
private timeoutId?: number | null;
|
||||||
|
private DURATION = 3000;
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
|
|
||||||
|
this.$wrapper = CE('div', {class: 'bx-toast bx-offscreen'},
|
||||||
|
this.$msg = CE('span', {class: 'bx-toast-msg'}),
|
||||||
|
this.$status = CE('span', {class: 'bx-toast-status'}),
|
||||||
|
);
|
||||||
|
|
||||||
|
this.$wrapper.addEventListener('transitionend', e => {
|
||||||
|
const classList = this.$wrapper.classList;
|
||||||
|
if (classList.contains('bx-hide')) {
|
||||||
|
classList.remove('bx-offscreen', 'bx-hide');
|
||||||
|
classList.add('bx-offscreen');
|
||||||
|
|
||||||
|
this.showNext();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.documentElement.appendChild(this.$wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
private show(msg: string, status?: string, options: Partial<ToastOptions> = {}) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
const args = Array.from(arguments) as [string, string, ToastOptions];
|
const args = Array.from(arguments) as [string, string, ToastOptions];
|
||||||
if (options.instant) {
|
if (options.instant) {
|
||||||
// Clear stack
|
// Clear stack
|
||||||
Toast.#stack = [args];
|
this.stack = [args];
|
||||||
Toast.#showNext();
|
this.showNext();
|
||||||
} else {
|
} else {
|
||||||
Toast.#stack.push(args);
|
this.stack.push(args);
|
||||||
!Toast.#isShowing && Toast.#showNext();
|
!this.isShowing && this.showNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static #showNext() {
|
private showNext() {
|
||||||
if (!Toast.#stack.length) {
|
if (!this.stack.length) {
|
||||||
Toast.#isShowing = false;
|
this.isShowing = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Toast.#isShowing = true;
|
this.isShowing = true;
|
||||||
|
|
||||||
Toast.#timeout && clearTimeout(Toast.#timeout);
|
this.timeoutId && clearTimeout(this.timeoutId);
|
||||||
Toast.#timeout = window.setTimeout(Toast.#hide, Toast.#DURATION);
|
this.timeoutId = window.setTimeout(this.hide.bind(this), this.DURATION);
|
||||||
|
|
||||||
// Get values from item
|
// Get values from item
|
||||||
const [msg, status, options] = Toast.#stack.shift()!;
|
const [msg, status, options] = this.stack.shift()!;
|
||||||
|
|
||||||
if (options && options.html) {
|
if (options && options.html) {
|
||||||
Toast.#$msg.innerHTML = msg;
|
this.$msg.innerHTML = msg;
|
||||||
} else {
|
} else {
|
||||||
Toast.#$msg.textContent = msg;
|
this.$msg.textContent = msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status) {
|
if (status) {
|
||||||
Toast.#$status.classList.remove('bx-gone');
|
this.$status.classList.remove('bx-gone');
|
||||||
Toast.#$status.textContent = status;
|
this.$status.textContent = status;
|
||||||
} else {
|
} else {
|
||||||
Toast.#$status.classList.add('bx-gone');
|
this.$status.classList.add('bx-gone');
|
||||||
}
|
}
|
||||||
|
|
||||||
const classList = Toast.#$wrapper.classList;
|
const classList = this.$wrapper.classList;
|
||||||
classList.remove('bx-offscreen', 'bx-hide');
|
classList.remove('bx-offscreen', 'bx-hide');
|
||||||
classList.add('bx-show');
|
classList.add('bx-show');
|
||||||
}
|
}
|
||||||
|
|
||||||
static #hide() {
|
private hide() {
|
||||||
Toast.#timeout = null;
|
this.timeoutId = null;
|
||||||
|
|
||||||
const classList = Toast.#$wrapper.classList;
|
const classList = this.$wrapper.classList;
|
||||||
classList.remove('bx-show');
|
classList.remove('bx-show');
|
||||||
classList.add('bx-hide');
|
classList.add('bx-hide');
|
||||||
}
|
}
|
||||||
|
|
||||||
static setup() {
|
static show(msg: string, status?: string, options: Partial<ToastOptions> = {}) {
|
||||||
Toast.#$wrapper = CE('div', {'class': 'bx-toast bx-offscreen'},
|
Toast.getInstance().show(msg, status, options);
|
||||||
Toast.#$msg = CE('span', {'class': 'bx-toast-msg'}),
|
}
|
||||||
Toast.#$status = CE('span', {'class': 'bx-toast-status'}));
|
|
||||||
|
|
||||||
Toast.#$wrapper.addEventListener('transitionend', e => {
|
static showNext() {
|
||||||
const classList = Toast.#$wrapper.classList;
|
Toast.getInstance().showNext();
|
||||||
if (classList.contains('bx-hide')) {
|
|
||||||
classList.remove('bx-offscreen', 'bx-hide');
|
|
||||||
classList.add('bx-offscreen');
|
|
||||||
|
|
||||||
Toast.#showNext();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
document.documentElement.appendChild(Toast.#$wrapper);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,11 @@ const Texts = {
|
|||||||
"confirm-reload-stream": "Do you want to refresh the stream?",
|
"confirm-reload-stream": "Do you want to refresh the stream?",
|
||||||
"connected": "Connected",
|
"connected": "Connected",
|
||||||
"console-connect": "Connect",
|
"console-connect": "Connect",
|
||||||
|
"continent-asia": "Asia",
|
||||||
|
"continent-australia": "Australia",
|
||||||
|
"continent-europe": "Europe",
|
||||||
|
"continent-north-america": "North America",
|
||||||
|
"continent-south-america": "South America",
|
||||||
"contrast": "Contrast",
|
"contrast": "Contrast",
|
||||||
"controller": "Controller",
|
"controller": "Controller",
|
||||||
"controller-friendly-ui": "Controller-friendly UI",
|
"controller-friendly-ui": "Controller-friendly UI",
|
||||||
@ -93,10 +98,11 @@ const Texts = {
|
|||||||
"disabled": "Disabled",
|
"disabled": "Disabled",
|
||||||
"disconnected": "Disconnected",
|
"disconnected": "Disconnected",
|
||||||
"download": "Download",
|
"download": "Download",
|
||||||
|
"downloaded": "Downloaded",
|
||||||
"edit": "Edit",
|
"edit": "Edit",
|
||||||
"enable-controller-shortcuts": "Enable controller shortcuts",
|
"enable-controller-shortcuts": "Enable controller shortcuts",
|
||||||
"enable-local-co-op-support": "Enable local co-op support",
|
"enable-local-co-op-support": "Enable local co-op support",
|
||||||
"enable-local-co-op-support-note": "Only works if the game doesn't require a different profile",
|
"enable-local-co-op-support-note": "Only works with some games",
|
||||||
"enable-mic-on-startup": "Enable microphone on game launch",
|
"enable-mic-on-startup": "Enable microphone on game launch",
|
||||||
"enable-mkb": "Emulate controller with Mouse & Keyboard",
|
"enable-mkb": "Emulate controller with Mouse & Keyboard",
|
||||||
"enable-quick-glance-mode": "Enable \"Quick Glance\" mode",
|
"enable-quick-glance-mode": "Enable \"Quick Glance\" mode",
|
||||||
@ -106,7 +112,7 @@ const Texts = {
|
|||||||
"experimental": "Experimental",
|
"experimental": "Experimental",
|
||||||
"export": "Export",
|
"export": "Export",
|
||||||
"fast": "Fast",
|
"fast": "Fast",
|
||||||
"fortnite-allow-stw-mode": "Allows playing STW mode on mobile",
|
"fortnite-allow-stw-mode": "Allows playing \"Save the World\" mode on mobile",
|
||||||
"fortnite-force-console-version": "Fortnite: force console version",
|
"fortnite-force-console-version": "Fortnite: force console version",
|
||||||
"game-bar": "Game Bar",
|
"game-bar": "Game Bar",
|
||||||
"getting-consoles-list": "Getting the list of consoles...",
|
"getting-consoles-list": "Getting the list of consoles...",
|
||||||
@ -130,6 +136,7 @@ const Texts = {
|
|||||||
"increase": "Increase",
|
"increase": "Increase",
|
||||||
"install-android": "Better xCloud app for Android",
|
"install-android": "Better xCloud app for Android",
|
||||||
"japan": "Japan",
|
"japan": "Japan",
|
||||||
|
"jitter": "Jitter",
|
||||||
"keyboard-shortcuts": "Keyboard shortcuts",
|
"keyboard-shortcuts": "Keyboard shortcuts",
|
||||||
"korea": "Korea",
|
"korea": "Korea",
|
||||||
"language": "Language",
|
"language": "Language",
|
||||||
@ -141,6 +148,7 @@ const Texts = {
|
|||||||
"local-co-op": "Local co-op",
|
"local-co-op": "Local co-op",
|
||||||
"lowest-quality": "Lowest quality",
|
"lowest-quality": "Lowest quality",
|
||||||
"map-mouse-to": "Map mouse to",
|
"map-mouse-to": "Map mouse to",
|
||||||
|
"max-fps": "Max FPS",
|
||||||
"may-not-work-properly": "May not work properly!",
|
"may-not-work-properly": "May not work properly!",
|
||||||
"menu": "Menu",
|
"menu": "Menu",
|
||||||
"microphone": "Microphone",
|
"microphone": "Microphone",
|
||||||
@ -149,6 +157,7 @@ const Texts = {
|
|||||||
"mkb-disclaimer": "Using this feature when playing online could be viewed as cheating",
|
"mkb-disclaimer": "Using this feature when playing online could be viewed as cheating",
|
||||||
"mouse-and-keyboard": "Mouse & Keyboard",
|
"mouse-and-keyboard": "Mouse & Keyboard",
|
||||||
"mouse-wheel": "Mouse wheel",
|
"mouse-wheel": "Mouse wheel",
|
||||||
|
"msfs2020-force-native-mkb": "MSFS2020: force native M&KB support",
|
||||||
"muted": "Muted",
|
"muted": "Muted",
|
||||||
"name": "Name",
|
"name": "Name",
|
||||||
"native-mkb": "Native Mouse & Keyboard",
|
"native-mkb": "Native Mouse & Keyboard",
|
||||||
@ -158,7 +167,7 @@ const Texts = {
|
|||||||
,
|
,
|
||||||
,
|
,
|
||||||
(e: any) => `Version ${e.version} verfügbar`,
|
(e: any) => `Version ${e.version} verfügbar`,
|
||||||
,
|
(e: any) => `Versi ${e.version} tersedia`,
|
||||||
(e: any) => `Versión ${e.version} disponible`,
|
(e: any) => `Versión ${e.version} disponible`,
|
||||||
(e: any) => `Version ${e.version} disponible`,
|
(e: any) => `Version ${e.version} disponible`,
|
||||||
(e: any) => `Disponibile la versione ${e.version}`,
|
(e: any) => `Disponibile la versione ${e.version}`,
|
||||||
@ -166,7 +175,7 @@ const Texts = {
|
|||||||
(e: any) => `${e.version} 버전 사용가능`,
|
(e: any) => `${e.version} 버전 사용가능`,
|
||||||
(e: any) => `Dostępna jest nowa wersja ${e.version}`,
|
(e: any) => `Dostępna jest nowa wersja ${e.version}`,
|
||||||
(e: any) => `Versão ${e.version} disponível`,
|
(e: any) => `Versão ${e.version} disponível`,
|
||||||
,
|
(e: any) => `Версия ${e.version} доступна`,
|
||||||
(e: any) => `เวอร์ชัน ${e.version} พร้อมใช้งานแล้ว`,
|
(e: any) => `เวอร์ชัน ${e.version} พร้อมใช้งานแล้ว`,
|
||||||
(e: any) => `${e.version} sayılı yeni sürüm mevcut`,
|
(e: any) => `${e.version} sayılı yeni sürüm mevcut`,
|
||||||
(e: any) => `Доступна версія ${e.version}`,
|
(e: any) => `Доступна версія ${e.version}`,
|
||||||
@ -184,6 +193,7 @@ const Texts = {
|
|||||||
"playing": "Playing",
|
"playing": "Playing",
|
||||||
"playtime": "Playtime",
|
"playtime": "Playtime",
|
||||||
"poland": "Poland",
|
"poland": "Poland",
|
||||||
|
"polling-rate": "Polling rate",
|
||||||
"position": "Position",
|
"position": "Position",
|
||||||
"powered-off": "Powered off",
|
"powered-off": "Powered off",
|
||||||
"powered-on": "Powered on",
|
"powered-on": "Powered on",
|
||||||
@ -220,7 +230,7 @@ const Texts = {
|
|||||||
(e: any) => `Configuració recomanada per a ${e.device}`,
|
(e: any) => `Configuració recomanada per a ${e.device}`,
|
||||||
,
|
,
|
||||||
(e: any) => `Empfohlene Einstellungen für ${e.device}`,
|
(e: any) => `Empfohlene Einstellungen für ${e.device}`,
|
||||||
,
|
(e: any) => `Rekomendasi pengaturan untuk ${e.device}`,
|
||||||
(e: any) => `Ajustes recomendados para ${e.device}`,
|
(e: any) => `Ajustes recomendados para ${e.device}`,
|
||||||
(e: any) => `Paramètres recommandés pour ${e.device}`,
|
(e: any) => `Paramètres recommandés pour ${e.device}`,
|
||||||
(e: any) => `Configurazioni consigliate per ${e.device}`,
|
(e: any) => `Configurazioni consigliate per ${e.device}`,
|
||||||
@ -262,6 +272,7 @@ const Texts = {
|
|||||||
"separate-touch-controller": "Separate Touch controller & Controller #1",
|
"separate-touch-controller": "Separate Touch controller & Controller #1",
|
||||||
"separate-touch-controller-note": "Touch controller is Player 1, Controller #1 is Player 2",
|
"separate-touch-controller-note": "Touch controller is Player 1, Controller #1 is Player 2",
|
||||||
"server": "Server",
|
"server": "Server",
|
||||||
|
"server-locations": "Server locations",
|
||||||
"settings": "Settings",
|
"settings": "Settings",
|
||||||
"settings-reload": "Reload page to reflect changes",
|
"settings-reload": "Reload page to reflect changes",
|
||||||
"settings-reload-note": "Settings in this tab only go into effect on the next page load",
|
"settings-reload-note": "Settings in this tab only go into effect on the next page load",
|
||||||
@ -348,6 +359,7 @@ const Texts = {
|
|||||||
"unmuted": "Unmuted",
|
"unmuted": "Unmuted",
|
||||||
"unsharp-masking": "Unsharp masking",
|
"unsharp-masking": "Unsharp masking",
|
||||||
"upload": "Upload",
|
"upload": "Upload",
|
||||||
|
"uploaded": "Uploaded",
|
||||||
"use-mouse-absolute-position": "Use mouse's absolute position",
|
"use-mouse-absolute-position": "Use mouse's absolute position",
|
||||||
"use-this-at-your-own-risk": "Use this at your own risk",
|
"use-this-at-your-own-risk": "Use this at your own risk",
|
||||||
"user-agent-profile": "User-Agent profile",
|
"user-agent-profile": "User-Agent profile",
|
||||||
|
@ -1,42 +1,55 @@
|
|||||||
import { BxIcon } from "./bx-icon";
|
import { BxIcon } from "./bx-icon";
|
||||||
|
import { BxLogger } from "./bx-logger";
|
||||||
import { AppInterface, SCRIPT_VARIANT, STATES } from "./global";
|
import { AppInterface, SCRIPT_VARIANT, STATES } from "./global";
|
||||||
import { ButtonStyle, CE, clearDataSet, createButton, getReactProps } from "./html";
|
import { ButtonStyle, CE, clearDataSet, createButton, getReactProps } from "./html";
|
||||||
import { t } from "./translation";
|
import { t } from "./translation";
|
||||||
|
|
||||||
export class TrueAchievements {
|
export class TrueAchievements {
|
||||||
private static $link = createButton({
|
private static instance: TrueAchievements;
|
||||||
label: t('true-achievements'),
|
public static getInstance = () => TrueAchievements.instance ?? (TrueAchievements.instance = new TrueAchievements());
|
||||||
url: '#',
|
private readonly LOG_TAG = 'TrueAchievements';
|
||||||
icon: BxIcon.TRUE_ACHIEVEMENTS,
|
|
||||||
style: ButtonStyle.FOCUSABLE | ButtonStyle.GHOST | ButtonStyle.FULL_WIDTH | ButtonStyle.NORMAL_LINK,
|
|
||||||
onClick: TrueAchievements.onClick,
|
|
||||||
}) as HTMLAnchorElement;
|
|
||||||
|
|
||||||
static $button = createButton({
|
private $link: HTMLElement;
|
||||||
label: t('true-achievements'),
|
private $button: HTMLElement;
|
||||||
title: t('true-achievements'),
|
private $hiddenLink: HTMLAnchorElement;
|
||||||
icon: BxIcon.TRUE_ACHIEVEMENTS,
|
|
||||||
style: ButtonStyle.FOCUSABLE,
|
|
||||||
onClick: TrueAchievements.onClick,
|
|
||||||
}) as HTMLAnchorElement;
|
|
||||||
|
|
||||||
private static onClick(e: Event) {
|
constructor() {
|
||||||
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
|
|
||||||
|
this.$link = createButton<HTMLAnchorElement>({
|
||||||
|
label: t('true-achievements'),
|
||||||
|
url: '#',
|
||||||
|
icon: BxIcon.TRUE_ACHIEVEMENTS,
|
||||||
|
style: ButtonStyle.FOCUSABLE | ButtonStyle.GHOST | ButtonStyle.FULL_WIDTH | ButtonStyle.NORMAL_LINK,
|
||||||
|
onClick: this.onClick.bind(this),
|
||||||
|
});
|
||||||
|
|
||||||
|
this.$button = createButton<HTMLAnchorElement>({
|
||||||
|
label: t('true-achievements'),
|
||||||
|
title: t('true-achievements'),
|
||||||
|
icon: BxIcon.TRUE_ACHIEVEMENTS,
|
||||||
|
style: ButtonStyle.FOCUSABLE,
|
||||||
|
onClick: this.onClick.bind(this),
|
||||||
|
});
|
||||||
|
|
||||||
|
this.$hiddenLink = CE<HTMLAnchorElement>('a', {
|
||||||
|
target: '_blank',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private onClick(e: Event) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const dataset = TrueAchievements.$link.dataset;
|
|
||||||
TrueAchievements.open(true, dataset.xboxTitleId, dataset.id);
|
|
||||||
|
|
||||||
// Close all xCloud's dialogs
|
// Close all xCloud's dialogs
|
||||||
window.BX_EXPOSED.dialogRoutes?.closeAll();
|
window.BX_EXPOSED.dialogRoutes?.closeAll();
|
||||||
|
|
||||||
|
const dataset = this.$link.dataset;
|
||||||
|
this.open(true, dataset.xboxTitleId, dataset.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static $hiddenLink = CE<HTMLAnchorElement>('a', {
|
private updateIds(xboxTitleId?: string, id?: string) {
|
||||||
target: '_blank',
|
const $link = this.$link;
|
||||||
});
|
const $button = this.$button;
|
||||||
|
|
||||||
private static updateIds(xboxTitleId?: string, id?: string) {
|
|
||||||
const $link = TrueAchievements.$link;
|
|
||||||
const $button = TrueAchievements.$button;
|
|
||||||
|
|
||||||
clearDataSet($link);
|
clearDataSet($link);
|
||||||
clearDataSet($button);
|
clearDataSet($button);
|
||||||
@ -52,7 +65,7 @@ export class TrueAchievements {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static injectAchievementsProgress($elm: HTMLElement) {
|
injectAchievementsProgress($elm: HTMLElement) {
|
||||||
// Only do this in Full version
|
// Only do this in Full version
|
||||||
if (SCRIPT_VARIANT !== 'full') {
|
if (SCRIPT_VARIANT !== 'full') {
|
||||||
return;
|
return;
|
||||||
@ -68,7 +81,7 @@ export class TrueAchievements {
|
|||||||
// Get xboxTitleId of the game
|
// Get xboxTitleId of the game
|
||||||
let xboxTitleId: string | number | undefined;
|
let xboxTitleId: string | number | undefined;
|
||||||
try {
|
try {
|
||||||
const $container = $parent.closest('div[class*=AchievementsPreview-module__container]') as HTMLElement;
|
const $container = $parent.closest<HTMLElement>('div[class*=AchievementsPreview-module__container]');
|
||||||
if ($container) {
|
if ($container) {
|
||||||
const props = getReactProps($container);
|
const props = getReactProps($container);
|
||||||
xboxTitleId = props.children.props.data.data.xboxTitleId;
|
xboxTitleId = props.children.props.data.data.xboxTitleId;
|
||||||
@ -76,24 +89,24 @@ export class TrueAchievements {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
if (!xboxTitleId) {
|
if (!xboxTitleId) {
|
||||||
xboxTitleId = TrueAchievements.getStreamXboxTitleId();
|
xboxTitleId = this.getStreamXboxTitleId();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof xboxTitleId !== 'undefined') {
|
if (typeof xboxTitleId !== 'undefined') {
|
||||||
xboxTitleId = xboxTitleId.toString();
|
xboxTitleId = xboxTitleId.toString();
|
||||||
}
|
}
|
||||||
TrueAchievements.updateIds(xboxTitleId);
|
this.updateIds(xboxTitleId);
|
||||||
|
|
||||||
if (document.documentElement.dataset.xdsPlatform === 'tv') {
|
if (document.documentElement.dataset.xdsPlatform === 'tv') {
|
||||||
$div.appendChild(TrueAchievements.$link);
|
$div.appendChild(this.$link);
|
||||||
} else {
|
} else {
|
||||||
$div.appendChild(TrueAchievements.$button);
|
$div.appendChild(this.$button);
|
||||||
}
|
}
|
||||||
|
|
||||||
$parent.appendChild($div);
|
$parent.appendChild($div);
|
||||||
}
|
}
|
||||||
|
|
||||||
static injectAchievementDetailPage($parent: HTMLElement) {
|
injectAchievementDetailPage($parent: HTMLElement) {
|
||||||
// Only do this in Full version
|
// Only do this in Full version
|
||||||
if (SCRIPT_VARIANT !== 'full') {
|
if (SCRIPT_VARIANT !== 'full') {
|
||||||
return;
|
return;
|
||||||
@ -109,7 +122,7 @@ export class TrueAchievements {
|
|||||||
const achievementList: XboxAchievement[] = props.children.props.data.data;
|
const achievementList: XboxAchievement[] = props.children.props.data.data;
|
||||||
|
|
||||||
// Get current achievement name
|
// Get current achievement name
|
||||||
const $header = $parent.querySelector('div[class*=AchievementDetailHeader]') as HTMLElement;
|
const $header = $parent.querySelector<HTMLElement>('div[class*=AchievementDetailHeader]')!;
|
||||||
const achievementName = getReactProps($header).children[0].props.achievementName;
|
const achievementName = getReactProps($header).children[0].props.achievementName;
|
||||||
|
|
||||||
// Find achievement based on name
|
// Find achievement based on name
|
||||||
@ -125,19 +138,19 @@ export class TrueAchievements {
|
|||||||
|
|
||||||
// Found achievement -> add TrueAchievements button
|
// Found achievement -> add TrueAchievements button
|
||||||
if (id) {
|
if (id) {
|
||||||
TrueAchievements.updateIds(xboxTitleId, id);
|
this.updateIds(xboxTitleId, id);
|
||||||
$parent.appendChild(TrueAchievements.$link);
|
$parent.appendChild(this.$link);
|
||||||
}
|
}
|
||||||
} catch (e) {};
|
} catch (e) {};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static getStreamXboxTitleId() : number | undefined {
|
private getStreamXboxTitleId() : number | undefined {
|
||||||
return STATES.currentStream.xboxTitleId || STATES.currentStream.titleInfo?.details.xboxTitleId;
|
return STATES.currentStream.xboxTitleId || STATES.currentStream.titleInfo?.details.xboxTitleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
static open(override: boolean, xboxTitleId?: number | string, id?: number | string) {
|
open(override: boolean, xboxTitleId?: number | string, id?: number | string) {
|
||||||
if (!xboxTitleId || xboxTitleId === 'undefined') {
|
if (!xboxTitleId || xboxTitleId === 'undefined') {
|
||||||
xboxTitleId = TrueAchievements.getStreamXboxTitleId();
|
xboxTitleId = this.getStreamXboxTitleId();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AppInterface && AppInterface.openTrueAchievementsLink) {
|
if (AppInterface && AppInterface.openTrueAchievementsLink) {
|
||||||
@ -154,7 +167,7 @@ export class TrueAchievements {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TrueAchievements.$hiddenLink.href = url;
|
this.$hiddenLink.href = url;
|
||||||
TrueAchievements.$hiddenLink.click();
|
this.$hiddenLink.click();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ export class UserAgent {
|
|||||||
static #USER_AGENTS: PartialRecord<UserAgentProfile, string> = {
|
static #USER_AGENTS: PartialRecord<UserAgentProfile, string> = {
|
||||||
[UserAgentProfile.WINDOWS_EDGE]: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${CHROMIUM_VERSION} Safari/537.36 Edg/${CHROMIUM_VERSION}`,
|
[UserAgentProfile.WINDOWS_EDGE]: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${CHROMIUM_VERSION} Safari/537.36 Edg/${CHROMIUM_VERSION}`,
|
||||||
[UserAgentProfile.MACOS_SAFARI]: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.2 Safari/605.1.1',
|
[UserAgentProfile.MACOS_SAFARI]: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.2 Safari/605.1.1',
|
||||||
[UserAgentProfile.SMART_TV_GENERIC]: `${window.navigator.userAgent} SmartTV`,
|
[UserAgentProfile.SMART_TV_GENERIC]: `${window.navigator.userAgent} Smart-TV`,
|
||||||
[UserAgentProfile.SMART_TV_TIZEN]: `Mozilla/5.0 (SMART-TV; LINUX; Tizen 7.0) AppleWebKit/537.36 (KHTML, like Gecko) ${CHROMIUM_VERSION}/7.0 TV Safari/537.36 ${SMART_TV_UNIQUE_ID}`,
|
[UserAgentProfile.SMART_TV_TIZEN]: `Mozilla/5.0 (SMART-TV; LINUX; Tizen 7.0) AppleWebKit/537.36 (KHTML, like Gecko) ${CHROMIUM_VERSION}/7.0 TV Safari/537.36 ${SMART_TV_UNIQUE_ID}`,
|
||||||
[UserAgentProfile.VR_OCULUS]: window.navigator.userAgent + ' OculusBrowser VR',
|
[UserAgentProfile.VR_OCULUS]: window.navigator.userAgent + ' OculusBrowser VR',
|
||||||
}
|
}
|
||||||
|
@ -120,3 +120,15 @@ export function productTitleToSlug(title: string): string {
|
|||||||
.replace(/ /g, '-')
|
.replace(/ /g, '-')
|
||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function parseDetailsPath(path: string) {
|
||||||
|
const matches = /\/games\/(?<titleSlug>[^\/]+)\/(?<productId>\w+)/.exec(path);
|
||||||
|
if (!matches?.groups) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const titleSlug = matches.groups.titleSlug.replaceAll('\%' + '7C', '-');
|
||||||
|
const productId = matches.groups.productId;
|
||||||
|
|
||||||
|
return {titleSlug, productId};
|
||||||
|
}
|
||||||
|
@ -1,23 +1,22 @@
|
|||||||
import { NATIVE_FETCH } from "./bx-flags";
|
import { NATIVE_FETCH } from "./bx-flags";
|
||||||
|
import { BxLogger } from "./bx-logger";
|
||||||
import { STATES } from "./global";
|
import { STATES } from "./global";
|
||||||
|
|
||||||
export class XcloudApi {
|
export class XcloudApi {
|
||||||
private static instance: XcloudApi;
|
private static instance: XcloudApi;
|
||||||
|
public static getInstance = () => XcloudApi.instance ?? (XcloudApi.instance = new XcloudApi());
|
||||||
|
private readonly LOG_TAG = 'XcloudApi';
|
||||||
|
|
||||||
public static getInstance(): XcloudApi {
|
private CACHE_TITLES: {[key: string]: XcloudTitleInfo} = {};
|
||||||
if (!XcloudApi.instance) {
|
private CACHE_WAIT_TIME: {[key: string]: XcloudWaitTimeInfo} = {};
|
||||||
XcloudApi.instance = new XcloudApi();
|
|
||||||
}
|
|
||||||
|
|
||||||
return XcloudApi.instance;
|
private constructor() {
|
||||||
|
BxLogger.info(this.LOG_TAG, 'constructor()');
|
||||||
}
|
}
|
||||||
|
|
||||||
#CACHE_TITLES: {[key: string]: XcloudTitleInfo} = {};
|
|
||||||
#CACHE_WAIT_TIME: {[key: string]: XcloudWaitTimeInfo} = {};
|
|
||||||
|
|
||||||
async getTitleInfo(id: string): Promise<XcloudTitleInfo | null> {
|
async getTitleInfo(id: string): Promise<XcloudTitleInfo | null> {
|
||||||
if (id in this.#CACHE_TITLES) {
|
if (id in this.CACHE_TITLES) {
|
||||||
return this.#CACHE_TITLES[id];
|
return this.CACHE_TITLES[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseUri = STATES.selectedRegion.baseUri;
|
const baseUri = STATES.selectedRegion.baseUri;
|
||||||
@ -45,13 +44,13 @@ export class XcloudApi {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
json = {}
|
json = {}
|
||||||
}
|
}
|
||||||
this.#CACHE_TITLES[id] = json;
|
this.CACHE_TITLES[id] = json;
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getWaitTime(id: string): Promise<XcloudWaitTimeInfo | null> {
|
async getWaitTime(id: string): Promise<XcloudWaitTimeInfo | null> {
|
||||||
if (id in this.#CACHE_WAIT_TIME) {
|
if (id in this.CACHE_WAIT_TIME) {
|
||||||
return this.#CACHE_WAIT_TIME[id];
|
return this.CACHE_WAIT_TIME[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseUri = STATES.selectedRegion.baseUri;
|
const baseUri = STATES.selectedRegion.baseUri;
|
||||||
@ -73,7 +72,7 @@ export class XcloudApi {
|
|||||||
json = {};
|
json = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#CACHE_WAIT_TIME[id] = json;
|
this.CACHE_WAIT_TIME[id] = json;
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,35 @@ import { BypassServerIps } from "@/enums/bypass-servers";
|
|||||||
import { PrefKey } from "@/enums/pref-keys";
|
import { PrefKey } from "@/enums/pref-keys";
|
||||||
import { getPref, StreamResolution, StreamTouchController } from "./settings-storages/global-settings-storage";
|
import { getPref, StreamResolution, StreamTouchController } from "./settings-storages/global-settings-storage";
|
||||||
|
|
||||||
export
|
export class XcloudInterceptor {
|
||||||
class XcloudInterceptor {
|
private static readonly SERVER_EXTRA_INFO: Record<string, [string, ServerContinent]> = {
|
||||||
static async #handleLogin(request: RequestInfo | URL, init?: RequestInit) {
|
// North America
|
||||||
|
EastUS: ['🇺🇸', 'america-north'],
|
||||||
|
EastUS2: ['🇺🇸', 'america-north'],
|
||||||
|
NorthCentralUs: ['🇺🇸', 'america-north'],
|
||||||
|
SouthCentralUS: ['🇺🇸', 'america-north'],
|
||||||
|
WestUS: ['🇺🇸', 'america-north'],
|
||||||
|
WestUS2: ['🇺🇸', 'america-north'],
|
||||||
|
MexicoCentral: ['🇲🇽', 'america-north'],
|
||||||
|
|
||||||
|
// South America
|
||||||
|
BrazilSouth: ['🇧🇷', 'america-south'],
|
||||||
|
|
||||||
|
// Asia
|
||||||
|
JapanEast: ['🇯🇵', 'asia'],
|
||||||
|
KoreaCentral: ['🇰🇷', 'asia'],
|
||||||
|
|
||||||
|
// Australia
|
||||||
|
AustraliaEast: ['🇦🇺', 'australia'],
|
||||||
|
AustraliaSouthEast: ['🇦🇺', 'australia'],
|
||||||
|
|
||||||
|
// Europe
|
||||||
|
SwedenCentral: ['🇸🇪', 'europe'],
|
||||||
|
UKSouth: ['🇬🇧', 'europe'],
|
||||||
|
WestEurope: ['🇪🇺', 'europe'],
|
||||||
|
};
|
||||||
|
|
||||||
|
private static async handleLogin(request: RequestInfo | URL, init?: RequestInit) {
|
||||||
const bypassServer = getPref(PrefKey.SERVER_BYPASS_RESTRICTION);
|
const bypassServer = getPref(PrefKey.SERVER_BYPASS_RESTRICTION);
|
||||||
if (bypassServer !== 'off') {
|
if (bypassServer !== 'off') {
|
||||||
const ip = BypassServerIps[bypassServer as keyof typeof BypassServerIps];
|
const ip = BypassServerIps[bypassServer as keyof typeof BypassServerIps];
|
||||||
@ -35,27 +61,12 @@ class XcloudInterceptor {
|
|||||||
RemotePlayManager.getInstance().xcloudToken = obj.gsToken;
|
RemotePlayManager.getInstance().xcloudToken = obj.gsToken;
|
||||||
|
|
||||||
// Get server list
|
// Get server list
|
||||||
const serverEmojis = {
|
|
||||||
AustraliaEast: '🇦🇺',
|
|
||||||
AustraliaSouthEast: '🇦🇺',
|
|
||||||
BrazilSouth: '🇧🇷',
|
|
||||||
EastUS: '🇺🇸',
|
|
||||||
EastUS2: '🇺🇸',
|
|
||||||
JapanEast: '🇯🇵',
|
|
||||||
KoreaCentral: '🇰🇷',
|
|
||||||
MexicoCentral: '🇲🇽',
|
|
||||||
NorthCentralUs: '🇺🇸',
|
|
||||||
SouthCentralUS: '🇺🇸',
|
|
||||||
UKSouth: '🇬🇧',
|
|
||||||
WestEurope: '🇪🇺',
|
|
||||||
WestUS: '🇺🇸',
|
|
||||||
WestUS2: '🇺🇸',
|
|
||||||
};
|
|
||||||
|
|
||||||
const serverRegex = /\/\/(\w+)\./;
|
const serverRegex = /\/\/(\w+)\./;
|
||||||
|
const serverExtra = XcloudInterceptor.SERVER_EXTRA_INFO;
|
||||||
|
|
||||||
for (let region of obj.offeringSettings.regions) {
|
let region: ServerRegion;
|
||||||
const regionName = region.name as keyof typeof serverEmojis;
|
for (region of obj.offeringSettings.regions) {
|
||||||
|
const regionName = region.name as keyof typeof serverExtra;
|
||||||
let shortName = region.name;
|
let shortName = region.name;
|
||||||
|
|
||||||
if (region.isDefault) {
|
if (region.isDefault) {
|
||||||
@ -65,8 +76,11 @@ class XcloudInterceptor {
|
|||||||
let match = serverRegex.exec(region.baseUri);
|
let match = serverRegex.exec(region.baseUri);
|
||||||
if (match) {
|
if (match) {
|
||||||
shortName = match[1];
|
shortName = match[1];
|
||||||
if (serverEmojis[regionName]) {
|
if (serverExtra[regionName]) {
|
||||||
shortName = serverEmojis[regionName] + ' ' + shortName;
|
shortName = serverExtra[regionName][0] + ' ' + shortName;
|
||||||
|
region.contintent = serverExtra[regionName][1];
|
||||||
|
} else {
|
||||||
|
region.contintent = 'other';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +105,9 @@ class XcloudInterceptor {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #handlePlay(request: RequestInfo | URL, init?: RequestInit) {
|
private static async handlePlay(request: RequestInfo | URL, init?: RequestInit) {
|
||||||
|
BxEvent.dispatch(window, BxEvent.STREAM_LOADING);
|
||||||
|
|
||||||
const PREF_STREAM_TARGET_RESOLUTION = getPref(PrefKey.STREAM_TARGET_RESOLUTION);
|
const PREF_STREAM_TARGET_RESOLUTION = getPref(PrefKey.STREAM_TARGET_RESOLUTION);
|
||||||
const PREF_STREAM_PREFERRED_LOCALE = getPref(PrefKey.STREAM_PREFERRED_LOCALE);
|
const PREF_STREAM_PREFERRED_LOCALE = getPref(PrefKey.STREAM_PREFERRED_LOCALE);
|
||||||
|
|
||||||
@ -129,7 +145,7 @@ class XcloudInterceptor {
|
|||||||
return NATIVE_FETCH(newRequest);
|
return NATIVE_FETCH(newRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #handleWaitTime(request: RequestInfo | URL, init?: RequestInit) {
|
private static async handleWaitTime(request: RequestInfo | URL, init?: RequestInit) {
|
||||||
const response = await NATIVE_FETCH(request, init);
|
const response = await NATIVE_FETCH(request, init);
|
||||||
|
|
||||||
if (getPref(PrefKey.UI_LOADING_SCREEN_WAIT_TIME)) {
|
if (getPref(PrefKey.UI_LOADING_SCREEN_WAIT_TIME)) {
|
||||||
@ -143,7 +159,7 @@ class XcloudInterceptor {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #handleConfiguration(request: RequestInfo | URL, init?: RequestInit) {
|
private static async handleConfiguration(request: RequestInfo | URL, init?: RequestInit) {
|
||||||
if ((request as Request).method !== 'GET') {
|
if ((request as Request).method !== 'GET') {
|
||||||
return NATIVE_FETCH(request, init);
|
return NATIVE_FETCH(request, init);
|
||||||
}
|
}
|
||||||
@ -165,6 +181,8 @@ class XcloudInterceptor {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BxEvent.dispatch(window, BxEvent.STREAM_STARTING);
|
||||||
|
|
||||||
const obj = JSON.parse(text);
|
const obj = JSON.parse(text);
|
||||||
let overrides = JSON.parse(obj.clientStreamingConfigOverrides || '{}') || {};
|
let overrides = JSON.parse(obj.clientStreamingConfigOverrides || '{}') || {};
|
||||||
|
|
||||||
@ -213,13 +231,13 @@ class XcloudInterceptor {
|
|||||||
|
|
||||||
// Server list
|
// Server list
|
||||||
if (url.endsWith('/v2/login/user')) {
|
if (url.endsWith('/v2/login/user')) {
|
||||||
return XcloudInterceptor.#handleLogin(request, init);
|
return XcloudInterceptor.handleLogin(request, init);
|
||||||
} else if (url.endsWith('/sessions/cloud/play')) { // Get session
|
} else if (url.endsWith('/sessions/cloud/play')) { // Get session
|
||||||
return XcloudInterceptor.#handlePlay(request, init);
|
return XcloudInterceptor.handlePlay(request, init);
|
||||||
} else if (url.includes('xboxlive.com') && url.includes('/waittime/')) {
|
} else if (url.includes('xboxlive.com') && url.includes('/waittime/')) {
|
||||||
return XcloudInterceptor.#handleWaitTime(request, init);
|
return XcloudInterceptor.handleWaitTime(request, init);
|
||||||
} else if (url.endsWith('/configuration')) {
|
} else if (url.endsWith('/configuration')) {
|
||||||
return XcloudInterceptor.#handleConfiguration(request, init);
|
return XcloudInterceptor.handleConfiguration(request, init);
|
||||||
} else if (url && url.endsWith('/ice') && url.includes('/sessions/') && (request as Request).method === 'GET') {
|
} else if (url && url.endsWith('/ice') && url.includes('/sessions/') && (request as Request).method === 'GET') {
|
||||||
return patchIceCandidates(request as Request);
|
return patchIceCandidates(request as Request);
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import type { RemotePlayConsoleAddresses } from "@/types/network";
|
|||||||
import { RemotePlayManager } from "@/modules/remote-play-manager";
|
import { RemotePlayManager } from "@/modules/remote-play-manager";
|
||||||
|
|
||||||
export class XhomeInterceptor {
|
export class XhomeInterceptor {
|
||||||
static #consoleAddrs: RemotePlayConsoleAddresses = {};
|
private static consoleAddrs: RemotePlayConsoleAddresses = {};
|
||||||
|
|
||||||
private static readonly BASE_DEVICE_INFO = {
|
private static readonly BASE_DEVICE_INFO = {
|
||||||
appInfo: {
|
appInfo: {
|
||||||
@ -52,10 +52,9 @@ export class XhomeInterceptor {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static async #handleLogin(request: Request) {
|
private static async handleLogin(request: Request) {
|
||||||
try {
|
try {
|
||||||
const clone = (request as Request).clone();
|
const clone = request.clone();
|
||||||
|
|
||||||
const obj = await clone.json();
|
const obj = await clone.json();
|
||||||
obj.offeringId = 'xhome';
|
obj.offeringId = 'xhome';
|
||||||
|
|
||||||
@ -74,31 +73,31 @@ export class XhomeInterceptor {
|
|||||||
return NATIVE_FETCH(request);
|
return NATIVE_FETCH(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #handleConfiguration(request: Request | URL) {
|
private static async handleConfiguration(request: Request | URL) {
|
||||||
|
BxEvent.dispatch(window, BxEvent.STREAM_STARTING);
|
||||||
|
|
||||||
const response = await NATIVE_FETCH(request);
|
const response = await NATIVE_FETCH(request);
|
||||||
|
const obj = await response.clone().json();
|
||||||
const obj = await response.clone().json()
|
|
||||||
console.log(obj);
|
|
||||||
|
|
||||||
const processPorts = (port: number): number[] => {
|
|
||||||
const ports = new Set<number>();
|
|
||||||
port && ports.add(port);
|
|
||||||
ports.add(9002);
|
|
||||||
|
|
||||||
return Array.from(ports);
|
|
||||||
};
|
|
||||||
|
|
||||||
const serverDetails = obj.serverDetails;
|
const serverDetails = obj.serverDetails;
|
||||||
if (serverDetails.ipAddress) {
|
const pairs = [
|
||||||
XhomeInterceptor.#consoleAddrs[serverDetails.ipAddress] = processPorts(serverDetails.port);
|
['ipAddress', 'port'],
|
||||||
}
|
['ipV4Address', 'ipV4Port'],
|
||||||
|
['ipV6Address', 'ipV6Port'],
|
||||||
|
];
|
||||||
|
|
||||||
if (serverDetails.ipV4Address) {
|
XhomeInterceptor.consoleAddrs = {};
|
||||||
XhomeInterceptor.#consoleAddrs[serverDetails.ipV4Address] = processPorts(serverDetails.ipV4Port);
|
for (const pair of pairs) {
|
||||||
}
|
const [keyAddr, keyPort] = pair;
|
||||||
|
if (serverDetails[keyAddr]) {
|
||||||
if (serverDetails.ipV6Address) {
|
const port = serverDetails[keyPort];
|
||||||
XhomeInterceptor.#consoleAddrs[serverDetails.ipV6Address] = processPorts(serverDetails.ipV6Port);
|
// Add port 9002 to the list of ports
|
||||||
|
const ports = new Set<number>();
|
||||||
|
port && ports.add(port);
|
||||||
|
ports.add(9002);
|
||||||
|
// Save it
|
||||||
|
XhomeInterceptor.consoleAddrs[serverDetails[keyAddr]] = Array.from(ports);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
response.json = () => Promise.resolve(obj);
|
response.json = () => Promise.resolve(obj);
|
||||||
@ -107,7 +106,7 @@ export class XhomeInterceptor {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #handleInputConfigs(request: Request | URL, opts: {[index: string]: any}) {
|
private static async handleInputConfigs(request: Request | URL, opts: {[index: string]: any}) {
|
||||||
const response = await NATIVE_FETCH(request);
|
const response = await NATIVE_FETCH(request);
|
||||||
|
|
||||||
if (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) !== StreamTouchController.ALL) {
|
if (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) !== StreamTouchController.ALL) {
|
||||||
@ -144,7 +143,7 @@ export class XhomeInterceptor {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #handleTitles(request: Request) {
|
private static async handleTitles(request: Request) {
|
||||||
const clone = request.clone();
|
const clone = request.clone();
|
||||||
|
|
||||||
const headers: {[index: string]: any} = {};
|
const headers: {[index: string]: any} = {};
|
||||||
@ -163,7 +162,9 @@ export class XhomeInterceptor {
|
|||||||
return NATIVE_FETCH(request);
|
return NATIVE_FETCH(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #handlePlay(request: RequestInfo | URL) {
|
private static async handlePlay(request: RequestInfo | URL) {
|
||||||
|
BxEvent.dispatch(window, BxEvent.STREAM_LOADING);
|
||||||
|
|
||||||
const clone = (request as Request).clone();
|
const clone = (request as Request).clone();
|
||||||
const body = await clone.json();
|
const body = await clone.json();
|
||||||
|
|
||||||
@ -196,37 +197,39 @@ export class XhomeInterceptor {
|
|||||||
|
|
||||||
headers['x-ms-device-info'] = JSON.stringify(deviceInfo);
|
headers['x-ms-device-info'] = JSON.stringify(deviceInfo);
|
||||||
|
|
||||||
const opts: {[index: string]: any} = {
|
const opts: Record<string, any> = {
|
||||||
method: clone.method,
|
method: clone.method,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Copy body
|
||||||
if (clone.method === 'POST') {
|
if (clone.method === 'POST') {
|
||||||
opts.body = await clone.text();
|
opts.body = await clone.text();
|
||||||
}
|
}
|
||||||
|
|
||||||
let newUrl = request.url;
|
// Replace xCloud domain with xHome domain
|
||||||
if (!newUrl.includes('/servers/home')) {
|
let url = request.url;
|
||||||
const index = request.url.indexOf('.xboxlive.com');
|
if (!url.includes('/servers/home')) {
|
||||||
newUrl = STATES.remotePlay.server + request.url.substring(index + 13);
|
const parsed = new URL(url);
|
||||||
|
url = STATES.remotePlay.server + parsed.pathname;
|
||||||
}
|
}
|
||||||
|
|
||||||
request = new Request(newUrl, opts);
|
// Create new Request instance
|
||||||
let url = (typeof request === 'string') ? request : request.url;
|
request = new Request(url, opts);
|
||||||
|
|
||||||
// Get console IP
|
// Get console IP
|
||||||
if (url.includes('/configuration')) {
|
if (url.includes('/configuration')) {
|
||||||
return XhomeInterceptor.#handleConfiguration(request);
|
return XhomeInterceptor.handleConfiguration(request);
|
||||||
} else if (url.endsWith('/sessions/home/play')) {
|
} else if (url.endsWith('/sessions/home/play')) {
|
||||||
return XhomeInterceptor.#handlePlay(request);
|
return XhomeInterceptor.handlePlay(request);
|
||||||
} else if (url.includes('inputconfigs')) {
|
} else if (url.includes('inputconfigs')) {
|
||||||
return XhomeInterceptor.#handleInputConfigs(request, opts);
|
return XhomeInterceptor.handleInputConfigs(request, opts);
|
||||||
} else if (url.includes('/login/user')) {
|
} else if (url.includes('/login/user')) {
|
||||||
return XhomeInterceptor.#handleLogin(request);
|
return XhomeInterceptor.handleLogin(request);
|
||||||
} else if (url.endsWith('/titles')) {
|
} else if (url.endsWith('/titles')) {
|
||||||
return XhomeInterceptor.#handleTitles(request);
|
return XhomeInterceptor.handleTitles(request);
|
||||||
} else if (url && url.endsWith('/ice') && url.includes('/sessions/') && (request as Request).method === 'GET') {
|
} else if (url && url.endsWith('/ice') && url.includes('/sessions/') && request.method === 'GET') {
|
||||||
return patchIceCandidates(request, XhomeInterceptor.#consoleAddrs);
|
return patchIceCandidates(request, XhomeInterceptor.consoleAddrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await NATIVE_FETCH(request);
|
return await NATIVE_FETCH(request);
|
||||||
|
Reference in New Issue
Block a user