mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 07:37:19 +02:00
Only switch to game settings if it's not empty (#652)
This commit is contained in:
parent
bf23943da8
commit
706665713f
17
dist/better-xcloud.pretty.user.js
vendored
17
dist/better-xcloud.pretty.user.js
vendored
@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name Better xCloud
|
||||
// @namespace https://github.com/redphx
|
||||
// @version 6.3.0
|
||||
// @version 6.3.1-beta
|
||||
// @description Improve Xbox Cloud Gaming (xCloud) experience
|
||||
// @author redphx
|
||||
// @license MIT
|
||||
@ -190,7 +190,7 @@ class UserAgent {
|
||||
});
|
||||
}
|
||||
}
|
||||
var SCRIPT_VERSION = "6.3.0", SCRIPT_VARIANT = "full", AppInterface = window.AppInterface;
|
||||
var SCRIPT_VERSION = "6.3.1-beta", SCRIPT_VARIANT = "full", AppInterface = window.AppInterface;
|
||||
UserAgent.init();
|
||||
var userAgent = window.navigator.userAgent.toLowerCase(), isTv = userAgent.includes("smart-tv") || userAgent.includes("smarttv") || /\baft.*\b/.test(userAgent), isVr = window.navigator.userAgent.includes("VR") && window.navigator.userAgent.includes("OculusBrowser"), browserHasTouchSupport = "ontouchstart" in window || navigator.maxTouchPoints > 0, userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport, STATES = {
|
||||
supportedRegion: !0,
|
||||
@ -1944,6 +1944,9 @@ class GameSettingsStorage extends BaseSettingsStorage {
|
||||
constructor(id) {
|
||||
super(`${"BetterXcloud.Stream"}.${id}`, StreamSettingsStorage.DEFINITIONS);
|
||||
}
|
||||
isEmpty() {
|
||||
return Object.keys(this.settings).length === 0;
|
||||
}
|
||||
deleteSetting(pref) {
|
||||
if (this.hasSetting(pref)) return delete this.settings[pref], this.saveSettings(), !0;
|
||||
return !1;
|
||||
@ -4304,7 +4307,9 @@ class SettingsManager {
|
||||
class: "bx-stream-settings-selection bx-gone",
|
||||
_nearby: { orientation: "vertical" }
|
||||
}, CE("div", !1, $select), this.$tips), BxEventBus.Stream.on("xboxTitleId.changed", async ({ id }) => {
|
||||
this.playingGameId = id, setGameIdPref(id);
|
||||
this.playingGameId = id;
|
||||
let gameSettings = STORAGE.Stream.getGameSettings(id), selectedId = gameSettings && !gameSettings.isEmpty() ? id : -1;
|
||||
setGameIdPref(selectedId);
|
||||
let $optGroup = $select.querySelector("optgroup");
|
||||
while ($optGroup.childElementCount > 1)
|
||||
$optGroup.lastElementChild?.remove();
|
||||
@ -4312,9 +4317,9 @@ class SettingsManager {
|
||||
let title = id === 0 ? "Xbox" : await XboxApi.getProductTitle(id);
|
||||
$optGroup.appendChild(CE("option", {
|
||||
value: id
|
||||
}, title)), $select.value = id.toString();
|
||||
} else $select.value = "-1";
|
||||
BxEventBus.Stream.emit("gameSettings.switched", { id });
|
||||
}, title));
|
||||
}
|
||||
$select.value = selectedId.toString(), BxEventBus.Stream.emit("gameSettings.switched", { id: selectedId });
|
||||
});
|
||||
}
|
||||
getStreamSettingsSelection() {
|
||||
|
8
dist/better-xcloud.user.js
vendored
8
dist/better-xcloud.user.js
vendored
File diff suppressed because one or more lines are too long
@ -270,7 +270,6 @@ BxEventBus.Stream.on('state.playing', payload => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
updateVideoPlayer();
|
||||
});
|
||||
|
||||
|
@ -3,7 +3,7 @@ import { limitVideoPlayerFps, onChangeVideoPlayerType, updateVideoPlayer } from
|
||||
import { StreamStats } from "./stream/stream-stats";
|
||||
import { SoundShortcut } from "./shortcuts/sound-shortcut";
|
||||
import { STATES } from "@/utils/global";
|
||||
import { getGamePref, getStreamPref, hasGamePref, isStreamPref, setGameIdPref } from "@/utils/pref-utils";
|
||||
import { getGamePref, getStreamPref, hasGamePref, isStreamPref, setGameIdPref, STORAGE } from "@/utils/pref-utils";
|
||||
import { BxExposed } from "@/utils/bx-exposed";
|
||||
import { StreamSettings } from "@/utils/stream-settings";
|
||||
import { NativeMkbHandler } from "./mkb/native-mkb-handler";
|
||||
@ -311,10 +311,16 @@ export class SettingsManager {
|
||||
|
||||
BxEventBus.Stream.on('xboxTitleId.changed', async ({ id }) => {
|
||||
this.playingGameId = id;
|
||||
setGameIdPref(id);
|
||||
const $optGroup = $select.querySelector('optgroup')!;
|
||||
|
||||
// Only switch to game settings if it's not empty
|
||||
const gameSettings = STORAGE.Stream.getGameSettings(id);
|
||||
const customSettings = gameSettings && !gameSettings.isEmpty();
|
||||
const selectedId = customSettings ? id : -1;
|
||||
|
||||
setGameIdPref(selectedId);
|
||||
|
||||
// Remove every options except the first one (All games)
|
||||
const $optGroup = $select.querySelector('optgroup')!;
|
||||
while ($optGroup.childElementCount > 1) {
|
||||
$optGroup.lastElementChild?.remove();
|
||||
}
|
||||
@ -325,13 +331,12 @@ export class SettingsManager {
|
||||
$optGroup.appendChild(CE('option', {
|
||||
value: id,
|
||||
}, title));
|
||||
|
||||
$select.value = id.toString();
|
||||
} else {
|
||||
$select.value = '-1';
|
||||
}
|
||||
|
||||
BxEventBus.Stream.emit('gameSettings.switched', { id });
|
||||
// Activate custom settings
|
||||
|
||||
$select.value = selectedId.toString();
|
||||
BxEventBus.Stream.emit('gameSettings.switched', { id: selectedId });
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,10 @@ export class GameSettingsStorage extends BaseSettingsStorage<StreamPref> {
|
||||
super(`${StorageKey.STREAM}.${id}`, StreamSettingsStorage.DEFINITIONS);
|
||||
}
|
||||
|
||||
isEmpty() {
|
||||
return Object.keys(this.settings).length === 0;
|
||||
}
|
||||
|
||||
deleteSetting(pref: StreamPref) {
|
||||
if (this.hasSetting(pref)) {
|
||||
delete this.settings[pref];
|
||||
|
Loading…
x
Reference in New Issue
Block a user