mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-25 08:53: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": {
|
"video.player.type": {
|
||||||
onChange: () => {
|
onChange: updateVideoPlayer,
|
||||||
if (onChangeVideoPlayerType(), STATES.isPlaying) updateVideoPlayer();
|
onChangeUi: onChangeVideoPlayerType
|
||||||
},
|
|
||||||
alwaysTriggerOnChange: !0
|
|
||||||
},
|
},
|
||||||
"video.player.powerPreference": {
|
"video.player.powerPreference": {
|
||||||
onChange: () => {
|
onChange: () => {
|
||||||
@ -4270,9 +4268,11 @@ class SettingsManager {
|
|||||||
this.switchGameSettings(id);
|
this.switchGameSettings(id);
|
||||||
}), this.renderStreamSettingsSelection();
|
}), this.renderStreamSettingsSelection();
|
||||||
}
|
}
|
||||||
updateStreamElement(key, onChanges) {
|
updateStreamElement(key, onChanges, onChangeUis) {
|
||||||
let info = this.SETTINGS[key];
|
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();
|
else info.onChange();
|
||||||
let $elm = info.$element;
|
let $elm = info.$element;
|
||||||
if (!$elm) return;
|
if (!$elm) return;
|
||||||
@ -4283,18 +4283,16 @@ class SettingsManager {
|
|||||||
}
|
}
|
||||||
switchGameSettings(id) {
|
switchGameSettings(id) {
|
||||||
if (setGameIdPref(id), this.targetGameId === id) return;
|
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;
|
this.targetGameId = id;
|
||||||
let key;
|
let key;
|
||||||
for (key in this.SETTINGS) {
|
for (key in this.SETTINGS) {
|
||||||
if (!isStreamPref(key)) continue;
|
if (!isStreamPref(key)) continue;
|
||||||
let oldValue = getGamePref(oldGameId, key, !0), newValue = getGamePref(this.targetGameId, key, !0);
|
let oldValue = getGamePref(oldGameId, key, !0), newValue = getGamePref(this.targetGameId, key, !0);
|
||||||
if (oldValue === newValue) continue;
|
if (oldValue === newValue) continue;
|
||||||
this.updateStreamElement(key, onChanges);
|
this.updateStreamElement(key, onChanges, onChangeUis);
|
||||||
}
|
}
|
||||||
onChanges.forEach((onChange) => {
|
onChangeUis.forEach((fn) => fn && fn()), onChanges.forEach((fn) => fn && fn()), this.$tips.classList.toggle("bx-gone", id < 0);
|
||||||
onChange && onChange();
|
|
||||||
}), this.$tips.classList.toggle("bx-gone", id < 0);
|
|
||||||
}
|
}
|
||||||
setElement(pref, $elm) {
|
setElement(pref, $elm) {
|
||||||
if (!this.SETTINGS[pref]) this.SETTINGS[pref] = {};
|
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<{
|
type SettingType = Partial<{
|
||||||
hidden: true;
|
hidden: true;
|
||||||
onChange: () => void;
|
onChange: () => void;
|
||||||
alwaysTriggerOnChange: boolean; // Always trigger onChange(), not just when playing
|
onChangeUi: () => void;
|
||||||
$element: HTMLElement;
|
$element: HTMLElement;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
@ -67,14 +67,8 @@ export class SettingsManager {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
[StreamPref.VIDEO_PLAYER_TYPE]: {
|
[StreamPref.VIDEO_PLAYER_TYPE]: {
|
||||||
onChange: () => {
|
onChange: updateVideoPlayer,
|
||||||
onChangeVideoPlayerType();
|
onChangeUi: onChangeVideoPlayerType,
|
||||||
|
|
||||||
if (STATES.isPlaying) {
|
|
||||||
updateVideoPlayer();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
alwaysTriggerOnChange: true,
|
|
||||||
},
|
},
|
||||||
[StreamPref.VIDEO_POWER_PREFERENCE]: {
|
[StreamPref.VIDEO_POWER_PREFERENCE]: {
|
||||||
onChange: () => {
|
onChange: () => {
|
||||||
@ -177,11 +171,21 @@ export class SettingsManager {
|
|||||||
this.renderStreamSettingsSelection();
|
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];
|
const info = this.SETTINGS[key];
|
||||||
|
|
||||||
// Add event
|
// Add events
|
||||||
if (info.onChange && (STATES.isPlaying || info.alwaysTriggerOnChange)) {
|
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) {
|
if (onChanges) {
|
||||||
// Save to a Set()
|
// Save to a Set()
|
||||||
onChanges.add(info.onChange);
|
onChanges.add(info.onChange);
|
||||||
@ -217,6 +221,7 @@ export class SettingsManager {
|
|||||||
|
|
||||||
// Re-apply all stream settings
|
// Re-apply all stream settings
|
||||||
const onChanges: Set<SettingType['onChange']> = new Set();
|
const onChanges: Set<SettingType['onChange']> = new Set();
|
||||||
|
const onChangeUis: Set<SettingType['onChangeUi']> = new Set();
|
||||||
const oldGameId = this.targetGameId;
|
const oldGameId = this.targetGameId;
|
||||||
this.targetGameId = id;
|
this.targetGameId = id;
|
||||||
|
|
||||||
@ -234,13 +239,12 @@ export class SettingsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only apply Stream settings
|
// Only apply Stream settings
|
||||||
this.updateStreamElement(key, onChanges);
|
this.updateStreamElement(key, onChanges, onChangeUis);
|
||||||
}
|
}
|
||||||
|
|
||||||
// BxLogger.warning('Settings Manager', onChanges);
|
// Trigger onChange callbacks
|
||||||
onChanges.forEach(onChange => {
|
onChangeUis.forEach(fn => fn && fn());
|
||||||
onChange && onChange();
|
onChanges.forEach(fn => fn && fn());
|
||||||
});
|
|
||||||
|
|
||||||
// Toggle tips if not playing anything
|
// Toggle tips if not playing anything
|
||||||
this.$tips.classList.toggle('bx-gone', id < 0);
|
this.$tips.classList.toggle('bx-gone', id < 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user