mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-07 16:17:20 +02:00
Refactor browser & userAgent's capabilities
This commit is contained in:
parent
b6746598a3
commit
2b63edb7eb
@ -283,7 +283,7 @@ function main() {
|
|||||||
getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL) && patchAudioContext();
|
getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL) && patchAudioContext();
|
||||||
getPref(PrefKey.BLOCK_TRACKING) && patchMeControl();
|
getPref(PrefKey.BLOCK_TRACKING) && patchMeControl();
|
||||||
|
|
||||||
STATES.userAgentHasTouchSupport && TouchController.updateCustomList();
|
STATES.userAgent.capabilities.touch && TouchController.updateCustomList();
|
||||||
overridePreloadState();
|
overridePreloadState();
|
||||||
|
|
||||||
VibrationManager.initialSetup();
|
VibrationManager.initialSetup();
|
||||||
|
@ -41,7 +41,7 @@ export class GameBar {
|
|||||||
|
|
||||||
this.actions = [
|
this.actions = [
|
||||||
new ScreenshotAction(),
|
new ScreenshotAction(),
|
||||||
...(STATES.userAgentHasTouchSupport && (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) !== 'off') ? [new TouchControlAction()] : []),
|
...(STATES.userAgent.capabilities.touch && (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) !== 'off') ? [new TouchControlAction()] : []),
|
||||||
new MicrophoneAction(),
|
new MicrophoneAction(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -683,7 +683,7 @@ let PATCH_ORDERS: PatchArray = [
|
|||||||
'remotePlayKeepAlive',
|
'remotePlayKeepAlive',
|
||||||
'remotePlayDirectConnectUrl',
|
'remotePlayDirectConnectUrl',
|
||||||
'remotePlayDisableAchievementToast',
|
'remotePlayDisableAchievementToast',
|
||||||
STATES.userAgentHasTouchSupport && 'patchUpdateInputConfigurationAsync',
|
STATES.userAgent.capabilities.touch && 'patchUpdateInputConfigurationAsync',
|
||||||
] : []),
|
] : []),
|
||||||
|
|
||||||
...(BX_FLAGS.EnableXcloudLogging ? [
|
...(BX_FLAGS.EnableXcloudLogging ? [
|
||||||
@ -709,7 +709,7 @@ let PLAYING_PATCH_ORDERS: PatchArray = [
|
|||||||
// Skip feedback dialog
|
// Skip feedback dialog
|
||||||
getPref(PrefKey.STREAM_DISABLE_FEEDBACK_DIALOG) && 'skipFeedbackDialog',
|
getPref(PrefKey.STREAM_DISABLE_FEEDBACK_DIALOG) && 'skipFeedbackDialog',
|
||||||
|
|
||||||
...(STATES.userAgentHasTouchSupport ? [
|
...(STATES.userAgent.capabilities.touch ? [
|
||||||
getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'all' && 'patchShowSensorControls',
|
getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'all' && 'patchShowSensorControls',
|
||||||
getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'all' && 'exposeTouchLayoutManager',
|
getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'all' && 'exposeTouchLayoutManager',
|
||||||
(getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'off' || getPref(PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF)) && 'disableTakRenderer',
|
(getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'off' || getPref(PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF)) && 'disableTakRenderer',
|
||||||
|
@ -91,7 +91,7 @@ export class StreamBadges {
|
|||||||
let batteryLevel = '100%';
|
let batteryLevel = '100%';
|
||||||
let batteryLevelInt = 100;
|
let batteryLevelInt = 100;
|
||||||
let isCharging = false;
|
let isCharging = false;
|
||||||
if ('getBattery' in navigator) {
|
if (STATES.browser.capabilities.batteryApi) {
|
||||||
try {
|
try {
|
||||||
const bm = await (navigator as NavigatorBattery).getBattery();
|
const bm = await (navigator as NavigatorBattery).getBattery();
|
||||||
isCharging = bm.charging;
|
isCharging = bm.charging;
|
||||||
@ -224,7 +224,7 @@ export class StreamBadges {
|
|||||||
|
|
||||||
// Battery
|
// Battery
|
||||||
let batteryLevel = '';
|
let batteryLevel = '';
|
||||||
if ('getBattery' in navigator) {
|
if (STATES.browser.capabilities.batteryApi) {
|
||||||
batteryLevel = '100%';
|
batteryLevel = '100%';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,7 +338,7 @@ export class StreamBadges {
|
|||||||
|
|
||||||
// Get battery level
|
// Get battery level
|
||||||
try {
|
try {
|
||||||
'getBattery' in navigator && (navigator as NavigatorBattery).getBattery().then(bm => {
|
STATES.browser.capabilities.batteryApi && (navigator as NavigatorBattery).getBattery().then(bm => {
|
||||||
streamBadges.startBatteryLevel = Math.round(bm.level * 100);
|
streamBadges.startBatteryLevel = Math.round(bm.level * 100);
|
||||||
});
|
});
|
||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
|
@ -103,7 +103,7 @@ export class StreamSettings {
|
|||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
|
|
||||||
STATES.userAgentHasTouchSupport && {
|
STATES.userAgent.capabilities.touch && {
|
||||||
group: 'touch-controller',
|
group: 'touch-controller',
|
||||||
label: t('touch-controller'),
|
label: t('touch-controller'),
|
||||||
items: [{
|
items: [{
|
||||||
|
@ -35,7 +35,7 @@ function cloneStreamHudButton($orgButton: HTMLElement, label: string, svgIcon: t
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (STATES.browserHasTouchSupport) {
|
if (STATES.browser.capabilities.touch) {
|
||||||
$container.addEventListener('transitionstart', onTransitionStart);
|
$container.addEventListener('transitionstart', onTransitionStart);
|
||||||
$container.addEventListener('transitionend', onTransitionEnd);
|
$container.addEventListener('transitionend', onTransitionEnd);
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,8 @@ const SETTINGS_UI = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[t('touch-controller')]: {
|
[t('touch-controller')]: {
|
||||||
note: !STATES.userAgentHasTouchSupport ? '⚠️ ' + t('device-unsupported-touch') : null,
|
note: !STATES.userAgent.capabilities.touch ? '⚠️ ' + t('device-unsupported-touch') : null,
|
||||||
unsupported: !STATES.userAgentHasTouchSupport,
|
unsupported: !STATES.userAgent.capabilities.touch,
|
||||||
items: [
|
items: [
|
||||||
PrefKey.STREAM_TOUCH_CONTROLLER,
|
PrefKey.STREAM_TOUCH_CONTROLLER,
|
||||||
PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF,
|
PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF,
|
||||||
|
@ -26,8 +26,10 @@ export function localRedirect(path: string) {
|
|||||||
$anchor.click();
|
$anchor.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function setupStreamUi() {
|
export function setupStreamUi() {
|
||||||
StreamSettings.getInstance();
|
StreamSettings.getInstance();
|
||||||
onChangeVideoPlayerType();
|
onChangeVideoPlayerType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
(window as any).localRedirect = localRedirect;
|
||||||
|
14
src/types/index.d.ts
vendored
14
src/types/index.d.ts
vendored
@ -28,8 +28,18 @@ type BxStates = {
|
|||||||
appContext: any | null;
|
appContext: any | null;
|
||||||
serverRegions: any;
|
serverRegions: any;
|
||||||
|
|
||||||
userAgentHasTouchSupport: boolean;
|
browser: {
|
||||||
browserHasTouchSupport: boolean;
|
capabilities: {
|
||||||
|
touch: boolean;
|
||||||
|
batteryApi: boolean;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
userAgent: {
|
||||||
|
capabilities: {
|
||||||
|
touch: boolean;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
currentStream: Partial<{
|
currentStream: Partial<{
|
||||||
titleId: string;
|
titleId: string;
|
||||||
|
@ -34,7 +34,7 @@ export const BxExposed = {
|
|||||||
|
|
||||||
titleInfo.details.hasMkbSupport = supportedInputTypes.includes(InputType.MKB);
|
titleInfo.details.hasMkbSupport = supportedInputTypes.includes(InputType.MKB);
|
||||||
|
|
||||||
if (STATES.userAgentHasTouchSupport) {
|
if (STATES.userAgent.capabilities.touch) {
|
||||||
let touchControllerAvailability = getPref(PrefKey.STREAM_TOUCH_CONTROLLER);
|
let touchControllerAvailability = getPref(PrefKey.STREAM_TOUCH_CONTROLLER);
|
||||||
|
|
||||||
// Disable touch control when gamepad found
|
// Disable touch control when gamepad found
|
||||||
|
@ -16,8 +16,19 @@ export const STATES: BxStates = {
|
|||||||
isPlaying: false,
|
isPlaying: false,
|
||||||
appContext: {},
|
appContext: {},
|
||||||
serverRegions: {},
|
serverRegions: {},
|
||||||
userAgentHasTouchSupport: userAgentHasTouchSupport,
|
|
||||||
browserHasTouchSupport: browserHasTouchSupport,
|
browser: {
|
||||||
|
capabilities: {
|
||||||
|
touch: browserHasTouchSupport,
|
||||||
|
batteryApi: 'getBattery' in window.navigator,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
userAgent: {
|
||||||
|
capabilities: {
|
||||||
|
touch: userAgentHasTouchSupport,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
currentStream: {},
|
currentStream: {},
|
||||||
remotePlay: {},
|
remotePlay: {},
|
||||||
|
@ -595,7 +595,7 @@ export function interceptHttpRequests() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add list of games with custom layouts to the official list
|
// Add list of games with custom layouts to the official list
|
||||||
if (STATES.userAgentHasTouchSupport && url.includes('catalog.gamepass.com/sigls/')) {
|
if (STATES.userAgent.capabilities.touch && url.includes('catalog.gamepass.com/sigls/')) {
|
||||||
const response = await NATIVE_FETCH(request, init);
|
const response = await NATIVE_FETCH(request, init);
|
||||||
const obj = await response.clone().json();
|
const obj = await response.clone().json();
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ export class Preferences {
|
|||||||
all: t('tc-all-games'),
|
all: t('tc-all-games'),
|
||||||
off: t('off'),
|
off: t('off'),
|
||||||
},
|
},
|
||||||
unsupported: !STATES.userAgentHasTouchSupport,
|
unsupported: !STATES.userAgent.capabilities.touch,
|
||||||
ready: (setting: PreferenceSetting) => {
|
ready: (setting: PreferenceSetting) => {
|
||||||
if (setting.unsupported) {
|
if (setting.unsupported) {
|
||||||
setting.default = 'default';
|
setting.default = 'default';
|
||||||
@ -278,7 +278,7 @@ export class Preferences {
|
|||||||
[PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF]: {
|
[PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF]: {
|
||||||
label: t('tc-auto-off'),
|
label: t('tc-auto-off'),
|
||||||
default: false,
|
default: false,
|
||||||
unsupported: !STATES.userAgentHasTouchSupport,
|
unsupported: !STATES.userAgent.capabilities.touch,
|
||||||
},
|
},
|
||||||
[PrefKey.STREAM_TOUCH_CONTROLLER_DEFAULT_OPACITY]: {
|
[PrefKey.STREAM_TOUCH_CONTROLLER_DEFAULT_OPACITY]: {
|
||||||
type: SettingElementType.NUMBER_STEPPER,
|
type: SettingElementType.NUMBER_STEPPER,
|
||||||
@ -292,7 +292,7 @@ export class Preferences {
|
|||||||
ticks: 10,
|
ticks: 10,
|
||||||
hideSlider: true,
|
hideSlider: true,
|
||||||
},
|
},
|
||||||
unsupported: !STATES.userAgentHasTouchSupport,
|
unsupported: !STATES.userAgent.capabilities.touch,
|
||||||
},
|
},
|
||||||
[PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_STANDARD]: {
|
[PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_STANDARD]: {
|
||||||
label: t('tc-standard-layout-style'),
|
label: t('tc-standard-layout-style'),
|
||||||
@ -302,7 +302,7 @@ export class Preferences {
|
|||||||
white: t('tc-all-white'),
|
white: t('tc-all-white'),
|
||||||
muted: t('tc-muted-colors'),
|
muted: t('tc-muted-colors'),
|
||||||
},
|
},
|
||||||
unsupported: !STATES.userAgentHasTouchSupport,
|
unsupported: !STATES.userAgent.capabilities.touch,
|
||||||
},
|
},
|
||||||
[PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_CUSTOM]: {
|
[PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_CUSTOM]: {
|
||||||
label: t('tc-custom-layout-style'),
|
label: t('tc-custom-layout-style'),
|
||||||
@ -311,7 +311,7 @@ export class Preferences {
|
|||||||
default: t('default'),
|
default: t('default'),
|
||||||
muted: t('tc-muted-colors'),
|
muted: t('tc-muted-colors'),
|
||||||
},
|
},
|
||||||
unsupported: !STATES.userAgentHasTouchSupport,
|
unsupported: !STATES.userAgent.capabilities.touch,
|
||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.STREAM_SIMPLIFY_MENU]: {
|
[PrefKey.STREAM_SIMPLIFY_MENU]: {
|
||||||
@ -554,7 +554,7 @@ export class Preferences {
|
|||||||
|
|
||||||
[PrefKey.UI_HOME_CONTEXT_MENU_DISABLED]: {
|
[PrefKey.UI_HOME_CONTEXT_MENU_DISABLED]: {
|
||||||
label: t('disable-home-context-menu'),
|
label: t('disable-home-context-menu'),
|
||||||
default: STATES.browserHasTouchSupport,
|
default: STATES.browser.capabilities.touch,
|
||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.BLOCK_SOCIAL_FEATURES]: {
|
[PrefKey.BLOCK_SOCIAL_FEATURES]: {
|
||||||
|
@ -24,7 +24,7 @@ export function overridePreloadState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add list of games with custom layouts to the official list
|
// Add list of games with custom layouts to the official list
|
||||||
if (STATES.userAgentHasTouchSupport) {
|
if (STATES.userAgent.capabilities.touch) {
|
||||||
try {
|
try {
|
||||||
const sigls = state.xcloud.sigls;
|
const sigls = state.xcloud.sigls;
|
||||||
if (GamePassCloudGallery.TOUCH in sigls) {
|
if (GamePassCloudGallery.TOUCH in sigls) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user