Compare commits

...

15 Commits

10 changed files with 107 additions and 59 deletions

View File

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

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name Better xCloud
// @namespace https://github.com/redphx
// @version 4.6.0
// @version 4.6.2
// @description Improve Xbox Cloud Gaming (xCloud) experience
// @author redphx
// @license MIT
@ -104,7 +104,7 @@ class UserAgent {
}
// src/utils/global.ts
var SCRIPT_VERSION = "4.6.0";
var SCRIPT_VERSION = "4.6.2";
var SCRIPT_HOME = "https://github.com/redphx/better-xcloud";
var AppInterface = window.AppInterface;
UserAgent.init();
@ -1895,10 +1895,10 @@ class Preferences {
migrate: function(savedPrefs, value) {
try {
value = parseInt(value);
if (value < 100) {
if (value !== 0 && value < 100) {
value *= 1024000;
}
this.set(PrefKey.BITRATE_VIDEO_MAX, value);
this.set(PrefKey.BITRATE_VIDEO_MAX, value, true);
savedPrefs[PrefKey.BITRATE_VIDEO_MAX] = value;
} catch (e) {
}
@ -2206,10 +2206,10 @@ class Preferences {
const savedPrefs = JSON.parse(savedPrefsStr);
for (let settingId in Preferences.SETTINGS) {
const setting = Preferences.SETTINGS[settingId];
setting.ready && setting.ready.call(this, setting);
if (setting.migrate && settingId in savedPrefs) {
setting.migrate.call(this, savedPrefs, savedPrefs[settingId]);
}
setting.ready && setting.ready.call(this, setting);
}
for (let settingId in Preferences.SETTINGS) {
const setting = Preferences.SETTINGS[settingId];
@ -2270,10 +2270,10 @@ class Preferences {
}
return this.#prefs[key];
}
set(key, value) {
set(key, value, skipSave) {
value = this.#validateValue(key, value);
this.#prefs[key] = value;
this.#updateStorage();
!skipSave && this.#updateStorage();
return value;
}
#updateStorage() {
@ -3274,15 +3274,23 @@ class MkbHandler {
}
this.#mouseDataProvider.init();
window.addEventListener("keydown", this.#onKeyboardEvent);
this.#$message = CE("div", { class: "bx-mkb-pointer-lock-msg bx-gone" }, createButton({
this.#$message = CE("div", { class: "bx-mkb-pointer-lock-msg bx-gone" }, CE("div", {}, CE("p", {}, t("mkb-click-to-activate")), CE("p", {}, t("press-key-to-toggle-mkb", { key: "F8" }))), CE("div", {}, createButton({
icon: BxIcon.MOUSE_SETTINGS,
label: t("edit"),
style: ButtonStyle.PRIMARY,
onClick: (e) => {
e.preventDefault();
e.stopPropagation();
showStreamSettings("mkb");
}
}), CE("div", {}, CE("p", {}, t("mkb-click-to-activate")), CE("p", {}, t("press-key-to-toggle-mkb", { key: "F8" }))));
}), createButton({
label: t("disable"),
onClick: (e) => {
e.preventDefault();
e.stopPropagation();
this.toggle();
}
})));
this.#$message.addEventListener("click", this.start.bind(this));
document.documentElement.appendChild(this.#$message);
window.addEventListener(BxEvent.XCLOUD_POLLING_MODE_CHANGED, this.#onPollingModeChanged);
@ -3780,6 +3788,7 @@ var BxExposed = {
}
if (touchControllerAvailability === "off") {
supportedInputTypes = supportedInputTypes.filter((i) => i !== InputType.CUSTOM_TOUCH_OVERLAY && i !== InputType.GENERIC_TOUCH);
titleInfo.details.supportedTabs = [];
}
titleInfo.details.hasTouchSupport = supportedInputTypes.includes(InputType.NATIVE_TOUCH) || supportedInputTypes.includes(InputType.CUSTOM_TOUCH_OVERLAY) || supportedInputTypes.includes(InputType.GENERIC_TOUCH);
if (!titleInfo.details.hasTouchSupport && touchControllerAvailability === "all") {
@ -3877,6 +3886,10 @@ class LoadingScreen {
#game-stream div[class*=RocketAnimation-module__container] > svg {
display: none;
}
#game-stream video[class*=RocketAnimationVideo-module__video] {
display: none;
}
`;
$bgStyle.textContent += css;
}
@ -3965,8 +3978,8 @@ class LoadingScreen {
LoadingScreen.reset();
}
static reset() {
LoadingScreen.#$bgStyle && setTimeout(() => LoadingScreen.#$bgStyle.textContent = "", 2000);
LoadingScreen.#$waitTimeBox && LoadingScreen.#$waitTimeBox.classList.add("bx-gone");
LoadingScreen.#$bgStyle && (LoadingScreen.#$bgStyle.textContent = "");
LoadingScreen.#waitTimeInterval && clearInterval(LoadingScreen.#waitTimeInterval);
LoadingScreen.#waitTimeInterval = null;
}
@ -5107,8 +5120,8 @@ var resizeVideoPlayer = function() {
width = parentRect.width;
height = width / videoRatio;
}
width = Math.floor(width);
height = Math.floor(height);
width = Math.min(parentRect.width, Math.ceil(width));
height = Math.min(parentRect.height, Math.ceil(height));
$video.style.width = `${width}px`;
$video.style.height = `${height}px`;
$video.style.objectFit = "fill";
@ -6051,7 +6064,7 @@ div[class*=NotFocusedDialog] {
height: var(--bx-button-height);
line-height: var(--bx-button-height);
vertical-align: middle;
vertical-align: -webkit-baseline-middle;
/* vertical-align: -webkit-baseline-middle; */
color: #fff;
overflow: hidden;
white-space: nowrap;
@ -7011,7 +7024,6 @@ div[data-testid=media-container].bx-taking-screenshot:before {
color: #fff;
}
.bx-mkb-pointer-lock-msg {
display: flex;
cursor: pointer;
user-select: none;
-webkit-user-select: none;
@ -7035,14 +7047,7 @@ div[data-testid=media-container].bx-taking-screenshot:before {
.bx-mkb-pointer-lock-msg:hover {
background: #151515;
}
.bx-mkb-pointer-lock-msg button {
margin-right: 12px;
height: 60px;
}
.bx-mkb-pointer-lock-msg svg {
width: 32px;
}
.bx-mkb-pointer-lock-msg div {
.bx-mkb-pointer-lock-msg > div:first-of-type {
display: flex;
flex-direction: column;
text-align: left;
@ -7058,6 +7063,21 @@ div[data-testid=media-container].bx-taking-screenshot:before {
font-size: 14px;
font-style: italic;
}
.bx-mkb-pointer-lock-msg > div:last-of-type {
display: flex;
flex-flow: row;
margin-top: 10px;
button
}
.bx-mkb-pointer-lock-msg > div:last-of-type button {
flex: 1;
}
.bx-mkb-pointer-lock-msg > div:last-of-type button:first-of-type {
margin-right: 5px;
}
.bx-mkb-pointer-lock-msg > div:last-of-type button:last-of-type {
margin-left: 5px;
}
.bx-mkb-preset-tools {
display: flex;
margin-bottom: 12px;

View File

@ -74,7 +74,7 @@
height: var(--bx-button-height);
line-height: var(--bx-button-height);
vertical-align: middle;
vertical-align: -webkit-baseline-middle;
/* vertical-align: -webkit-baseline-middle; */
color: #fff;
overflow: hidden;
white-space: nowrap;

View File

@ -16,7 +16,6 @@
}
.bx-mkb-pointer-lock-msg {
display: flex;
cursor: pointer;
user-select: none;
-webkit-user-select: none;
@ -41,16 +40,7 @@
background: #151515;
}
button {
margin-right: 12px;
height: 60px;
}
svg {
width: 32px;
}
div {
> div:first-of-type {
display: flex;
flex-direction: column;
text-align: left;
@ -69,6 +59,26 @@
font-style: italic;
}
}
> div:last-of-type {
display: flex;
flex-flow: row;
margin-top: 10px;
button {
flex: 1;
&:first-of-type {
margin-right: 5px;
}
&:last-of-type {
margin-left: 5px;
}
}
button
}
}
.bx-mkb-preset-tools {

View File

@ -46,6 +46,10 @@ export class LoadingScreen {
#game-stream div[class*=RocketAnimation-module__container] > svg {
display: none;
}
#game-stream video[class*=RocketAnimationVideo-module__video] {
display: none;
}
`;
$bgStyle.textContent += css;
}
@ -163,9 +167,9 @@ export class LoadingScreen {
}
static reset() {
LoadingScreen.#$waitTimeBox && LoadingScreen.#$waitTimeBox.classList.add('bx-gone');
LoadingScreen.#$bgStyle && (LoadingScreen.#$bgStyle.textContent = '');
LoadingScreen.#$bgStyle && setTimeout(() => LoadingScreen.#$bgStyle.textContent = '', 2000);
LoadingScreen.#$waitTimeBox && LoadingScreen.#$waitTimeBox.classList.add('bx-gone');
LoadingScreen.#waitTimeInterval && clearInterval(LoadingScreen.#waitTimeInterval);
LoadingScreen.#waitTimeInterval = null;
}

View File

@ -464,20 +464,34 @@ export class MkbHandler {
window.addEventListener('keydown', this.#onKeyboardEvent);
this.#$message = CE('div', {'class': 'bx-mkb-pointer-lock-msg bx-gone'},
createButton({
icon: BxIcon.MOUSE_SETTINGS,
style: ButtonStyle.PRIMARY,
onClick: e => {
e.preventDefault();
e.stopPropagation();
showStreamSettings('mkb');
},
}),
CE('div', {},
CE('p', {}, t('mkb-click-to-activate')),
CE('p', {}, t('press-key-to-toggle-mkb', {key: 'F8'})),
),
CE('div', {},
createButton({
icon: BxIcon.MOUSE_SETTINGS,
label: t('edit'),
style: ButtonStyle.PRIMARY,
onClick: e => {
e.preventDefault();
e.stopPropagation();
showStreamSettings('mkb');
},
}),
createButton({
label: t('disable'),
onClick: e => {
e.preventDefault();
e.stopPropagation();
this.toggle();
},
}),
),
);
this.#$message.addEventListener('click', this.start.bind(this));

View File

@ -485,8 +485,8 @@ function resizeVideoPlayer() {
}
// Prevent floating points
width = Math.floor(width);
height = Math.floor(height);
width = Math.min(parentRect.width, Math.ceil(width));
height = Math.min(parentRect.height, Math.ceil(height));
// Update size
$video.style.width = `${width}px`;

View File

@ -59,6 +59,7 @@ type XcloudTitleInfo = {
details: {
productId: string;
supportedInputTypes: InputType[];
supportedTabs: any[];
hasTouchSupport: boolean;
hasFakeTouchSupport: boolean;
hasMkbSupport: boolean;

View File

@ -1,5 +1,4 @@
import { ControllerShortcut } from "@/modules/controller-shortcut";
import { GameBar } from "@modules/game-bar/game-bar";
import { BxEvent } from "@utils/bx-event";
import { STATES } from "@utils/global";
import { getPref, PrefKey } from "@utils/preferences";
@ -49,11 +48,11 @@ export const BxExposed = {
gamepadFound && (touchControllerAvailability = 'off');
}
if (touchControllerAvailability === 'off') {
// Disable touch on all games (not native touch)
supportedInputTypes = supportedInputTypes.filter(i => i !== InputType.CUSTOM_TOUCH_OVERLAY && i !== InputType.GENERIC_TOUCH);
// Empty TABs
titleInfo.details.supportedTabs = [];
}
// Pre-check supported input types

View File

@ -344,11 +344,10 @@ export class Preferences {
migrate: function(savedPrefs: any, value: any) {
try {
value = parseInt(value);
if (value < 100) {
if (value !== 0 && value < 100) {
value *= 1024 * 1000;
}
this.set(PrefKey.BITRATE_VIDEO_MAX, value);
this.set(PrefKey.BITRATE_VIDEO_MAX, value, true);
savedPrefs[PrefKey.BITRATE_VIDEO_MAX] = value;
} catch (e) {}
},
@ -701,11 +700,12 @@ export class Preferences {
for (let settingId in Preferences.SETTINGS) {
const setting = Preferences.SETTINGS[settingId];
setting.ready && setting.ready.call(this, setting);
if (setting.migrate && settingId in savedPrefs) {
setting.migrate.call(this, savedPrefs, savedPrefs[settingId]);
}
setting.ready && setting.ready.call(this, setting);
}
for (let settingId in Preferences.SETTINGS) {
@ -716,7 +716,7 @@ export class Preferences {
continue;
}
// Ignore deprecated settings
// Ignore deprecated/migrated settings
if (setting.migrate) {
continue;
}
@ -783,11 +783,11 @@ export class Preferences {
return this.#prefs[key];
}
set(key: PrefKey, value: any): any {
set(key: PrefKey, value: any, skipSave?: boolean): any {
value = this.#validateValue(key, value);
this.#prefs[key] = value;
this.#updateStorage();
!skipSave && this.#updateStorage();
return value;
}