mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-25 00:43:04 +02:00
Replace alwaysTriggerOnChange with onChangeUi
This commit is contained in:
parent
fe418e6918
commit
17dc7996b1
20
dist/better-xcloud.pretty.user.js
vendored
20
dist/better-xcloud.pretty.user.js
vendored
@ -4182,10 +4182,8 @@ class SettingsManager {
|
||||
}
|
||||
},
|
||||
"video.player.type": {
|
||||
onChange: () => {
|
||||
if (onChangeVideoPlayerType(), STATES.isPlaying) updateVideoPlayer();
|
||||
},
|
||||
alwaysTriggerOnChange: !0
|
||||
onChange: updateVideoPlayer,
|
||||
onChangeUi: onChangeVideoPlayerType
|
||||
},
|
||||
"video.player.powerPreference": {
|
||||
onChange: () => {
|
||||
@ -4270,9 +4268,11 @@ class SettingsManager {
|
||||
this.switchGameSettings(id);
|
||||
}), this.renderStreamSettingsSelection();
|
||||
}
|
||||
updateStreamElement(key, onChanges) {
|
||||
updateStreamElement(key, onChanges, onChangeUis) {
|
||||
let info = this.SETTINGS[key];
|
||||
if (info.onChange && (STATES.isPlaying || info.alwaysTriggerOnChange)) if (onChanges) onChanges.add(info.onChange);
|
||||
if (info.onChangeUi) if (onChangeUis) onChangeUis.add(info.onChangeUi);
|
||||
else info.onChangeUi();
|
||||
if (info.onChange && STATES.isPlaying) if (onChanges) onChanges.add(info.onChange);
|
||||
else info.onChange();
|
||||
let $elm = info.$element;
|
||||
if (!$elm) return;
|
||||
@ -4283,18 +4283,16 @@ class SettingsManager {
|
||||
}
|
||||
switchGameSettings(id) {
|
||||
if (setGameIdPref(id), this.targetGameId === id) return;
|
||||
let onChanges = new Set, oldGameId = this.targetGameId;
|
||||
let onChanges = new Set, onChangeUis = new Set, oldGameId = this.targetGameId;
|
||||
this.targetGameId = id;
|
||||
let key;
|
||||
for (key in this.SETTINGS) {
|
||||
if (!isStreamPref(key)) continue;
|
||||
let oldValue = getGamePref(oldGameId, key, !0), newValue = getGamePref(this.targetGameId, key, !0);
|
||||
if (oldValue === newValue) continue;
|
||||
this.updateStreamElement(key, onChanges);
|
||||
this.updateStreamElement(key, onChanges, onChangeUis);
|
||||
}
|
||||
onChanges.forEach((onChange) => {
|
||||
onChange && onChange();
|
||||
}), this.$tips.classList.toggle("bx-gone", id < 0);
|
||||
onChangeUis.forEach((fn) => fn && fn()), onChanges.forEach((fn) => fn && fn()), this.$tips.classList.toggle("bx-gone", id < 0);
|
||||
}
|
||||
setElement(pref, $elm) {
|
||||
if (!this.SETTINGS[pref]) this.SETTINGS[pref] = {};
|
||||
|
2
dist/better-xcloud.user.js
vendored
2
dist/better-xcloud.user.js
vendored
File diff suppressed because one or more lines are too long
@ -18,7 +18,7 @@ import { EmulatedMkbHandler } from "./mkb/mkb-handler";
|
||||
type SettingType = Partial<{
|
||||
hidden: true;
|
||||
onChange: () => void;
|
||||
alwaysTriggerOnChange: boolean; // Always trigger onChange(), not just when playing
|
||||
onChangeUi: () => void;
|
||||
$element: HTMLElement;
|
||||
}>;
|
||||
|
||||
@ -67,14 +67,8 @@ export class SettingsManager {
|
||||
},
|
||||
},
|
||||
[StreamPref.VIDEO_PLAYER_TYPE]: {
|
||||
onChange: () => {
|
||||
onChangeVideoPlayerType();
|
||||
|
||||
if (STATES.isPlaying) {
|
||||
updateVideoPlayer();
|
||||
}
|
||||
},
|
||||
alwaysTriggerOnChange: true,
|
||||
onChange: updateVideoPlayer,
|
||||
onChangeUi: onChangeVideoPlayerType,
|
||||
},
|
||||
[StreamPref.VIDEO_POWER_PREFERENCE]: {
|
||||
onChange: () => {
|
||||
@ -177,11 +171,21 @@ export class SettingsManager {
|
||||
this.renderStreamSettingsSelection();
|
||||
}
|
||||
|
||||
private updateStreamElement(key: StreamPref, onChanges?: Set<SettingType['onChange']>) {
|
||||
private updateStreamElement(key: StreamPref, onChanges?: Set<SettingType['onChange']>, onChangeUis?: Set<SettingType['onChangeUi']>) {
|
||||
const info = this.SETTINGS[key];
|
||||
|
||||
// Add event
|
||||
if (info.onChange && (STATES.isPlaying || info.alwaysTriggerOnChange)) {
|
||||
// Add events
|
||||
if (info.onChangeUi) {
|
||||
if (onChangeUis) {
|
||||
// Save to a Set()
|
||||
onChangeUis.add(info.onChangeUi);
|
||||
} else {
|
||||
// Trigger onChangeUi()
|
||||
info.onChangeUi();
|
||||
}
|
||||
}
|
||||
|
||||
if (info.onChange && STATES.isPlaying) {
|
||||
if (onChanges) {
|
||||
// Save to a Set()
|
||||
onChanges.add(info.onChange);
|
||||
@ -217,6 +221,7 @@ export class SettingsManager {
|
||||
|
||||
// Re-apply all stream settings
|
||||
const onChanges: Set<SettingType['onChange']> = new Set();
|
||||
const onChangeUis: Set<SettingType['onChangeUi']> = new Set();
|
||||
const oldGameId = this.targetGameId;
|
||||
this.targetGameId = id;
|
||||
|
||||
@ -234,13 +239,12 @@ export class SettingsManager {
|
||||
}
|
||||
|
||||
// Only apply Stream settings
|
||||
this.updateStreamElement(key, onChanges);
|
||||
this.updateStreamElement(key, onChanges, onChangeUis);
|
||||
}
|
||||
|
||||
// BxLogger.warning('Settings Manager', onChanges);
|
||||
onChanges.forEach(onChange => {
|
||||
onChange && onChange();
|
||||
});
|
||||
// Trigger onChange callbacks
|
||||
onChangeUis.forEach(fn => fn && fn());
|
||||
onChanges.forEach(fn => fn && fn());
|
||||
|
||||
// Toggle tips if not playing anything
|
||||
this.$tips.classList.toggle('bx-gone', id < 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user