Bug fixes

This commit is contained in:
redphx 2025-02-07 09:00:22 +07:00
parent cf1f656ecf
commit d4c1e8cce3
5 changed files with 23 additions and 37 deletions

View File

@ -3094,7 +3094,7 @@ class StreamStats {
$container; $container;
boundOnStreamHudStateChanged; boundOnStreamHudStateChanged;
constructor() { constructor() {
BxLogger.info(this.LOG_TAG, "constructor()"), this.boundOnStreamHudStateChanged = this.onStreamHudStateChanged.bind(this), this.render(); BxLogger.info(this.LOG_TAG, "constructor()"), this.boundOnStreamHudStateChanged = this.onStreamHudStateChanged.bind(this), BxEventBus.Stream.on("ui.streamHud.expanded", this.boundOnStreamHudStateChanged), this.render();
} }
async start(glancing = !1) { async start(glancing = !1) {
if (!this.isHidden() || glancing && this.isGlancing()) return; if (!this.isHidden() || glancing && this.isGlancing()) return;
@ -3109,21 +3109,15 @@ class StreamStats {
else this.isHidden() ? await this.start() : await this.stop(); else this.isHidden() ? await this.start() : await this.stop();
} }
destroy() { destroy() {
this.stop(), this.quickGlanceStop(), this.hideSettingsUi(); this.stop(), this.hideSettingsUi();
} }
isHidden = () => this.$container.classList.contains("bx-gone"); isHidden = () => this.$container.classList.contains("bx-gone");
isGlancing = () => this.$container.dataset.display === "glancing"; isGlancing = () => this.$container.dataset.display === "glancing";
onStreamHudStateChanged({ state }) { onStreamHudStateChanged({ state }) {
if (!getStreamPref("stats.quickGlance.enabled")) return;
if (state === "expanded") this.isHidden() && this.start(!0); if (state === "expanded") this.isHidden() && this.start(!0);
else this.stop(!0); else this.stop(!0);
} }
quickGlanceSetup() {
if (!STATES.isPlaying) return;
BxEventBus.Stream.on("ui.streamHud.expanded", this.boundOnStreamHudStateChanged);
}
quickGlanceStop() {
BxEventBus.Stream.off("ui.streamHud.expanded", this.boundOnStreamHudStateChanged);
}
update = async (forceUpdate = !1) => { update = async (forceUpdate = !1) => {
if (!forceUpdate && this.isHidden() || !STATES.currentStream.peerConnection) { if (!forceUpdate && this.isHidden() || !STATES.currentStream.peerConnection) {
this.destroy(); this.destroy();
@ -3164,7 +3158,7 @@ class StreamStats {
BxEventBus.Stream.on("state.playing", () => { BxEventBus.Stream.on("state.playing", () => {
let PREF_STATS_QUICK_GLANCE = getStreamPref("stats.quickGlance.enabled"), PREF_STATS_SHOW_WHEN_PLAYING = getStreamPref("stats.showWhenPlaying"), streamStats = StreamStats.getInstance(); let PREF_STATS_QUICK_GLANCE = getStreamPref("stats.quickGlance.enabled"), PREF_STATS_SHOW_WHEN_PLAYING = getStreamPref("stats.showWhenPlaying"), streamStats = StreamStats.getInstance();
if (PREF_STATS_SHOW_WHEN_PLAYING) streamStats.start(); if (PREF_STATS_SHOW_WHEN_PLAYING) streamStats.start();
else if (PREF_STATS_QUICK_GLANCE) streamStats.quickGlanceSetup(), !PREF_STATS_SHOW_WHEN_PLAYING && streamStats.start(!0); else if (PREF_STATS_QUICK_GLANCE) !PREF_STATS_SHOW_WHEN_PLAYING && streamStats.start(!0);
}); });
} }
static refreshStyles() { static refreshStyles() {
@ -4509,8 +4503,7 @@ class SettingsManager {
}, },
"stats.quickGlance.enabled": { "stats.quickGlance.enabled": {
onChange: () => { onChange: () => {
let value = getStreamPref("stats.quickGlance.enabled"), streamStats = StreamStats.getInstance(); if (!getStreamPref("stats.quickGlance.enabled")) StreamStats.getInstance().stop(!0);
value ? streamStats.quickGlanceSetup() : streamStats.quickGlanceStop();
} }
}, },
"stats.position": { "stats.position": {
@ -5389,11 +5382,11 @@ if (titleInfo && !titleInfo.details.hasTouchSupport && !titleInfo.details.hasFak
return str = str.replace(text, "this.useCombinedAudioVideoStream=true"), str; return str = str.replace(text, "this.useCombinedAudioVideoStream=true"), str;
}, },
patchStreamHud(str) { patchStreamHud(str) {
let text = "let{onCollapse"; let index = str.indexOf("let{onCollapse");
if (!str.includes(text)) return !1; if (index < 0) return !1;
let newCode = streamhud_default; let newCode = streamhud_default;
if (getGlobalPref("touchController.mode") === "off") newCode += "options.canShowTakHUD = false;"; if (getGlobalPref("touchController.mode") === "off") newCode += "options.canShowTakHUD = false;";
return str = str.replace(text, newCode + text), str; return str = PatcherUtils.insertAt(str, index, newCode), str;
}, },
broadcastPollingMode(str) { broadcastPollingMode(str) {
let text = ".setPollingMode=e=>{"; let text = ".setPollingMode=e=>{";

File diff suppressed because one or more lines are too long

View File

@ -422,8 +422,8 @@ if (titleInfo && !titleInfo.details.hasTouchSupport && !titleInfo.details.hasFak
}, },
patchStreamHud(str: string) { patchStreamHud(str: string) {
let text = 'let{onCollapse'; let index = str.indexOf('let{onCollapse');
if (!str.includes(text)) { if (index < 0) {
return false; return false;
} }
@ -434,7 +434,7 @@ if (titleInfo && !titleInfo.details.hasTouchSupport && !titleInfo.details.hasFak
newCode += 'options.canShowTakHUD = false;'; newCode += 'options.canShowTakHUD = false;';
} }
str = str.replace(text, newCode + text); str = PatcherUtils.insertAt(str, index, newCode);
return str; return str;
}, },

View File

@ -120,8 +120,9 @@ export class SettingsManager {
[StreamPref.STATS_QUICK_GLANCE_ENABLED]: { [StreamPref.STATS_QUICK_GLANCE_ENABLED]: {
onChange: () => { onChange: () => {
const value = getStreamPref(StreamPref.STATS_QUICK_GLANCE_ENABLED); const value = getStreamPref(StreamPref.STATS_QUICK_GLANCE_ENABLED);
const streamStats = StreamStats.getInstance(); if (!value) {
value ? streamStats.quickGlanceSetup() : streamStats.quickGlanceStop(); StreamStats.getInstance().stop(true);
}
}, },
}, },
[StreamPref.STATS_POSITION]: { [StreamPref.STATS_POSITION]: {

View File

@ -75,6 +75,8 @@ export class StreamStats {
BxLogger.info(this.LOG_TAG, 'constructor()'); BxLogger.info(this.LOG_TAG, 'constructor()');
this.boundOnStreamHudStateChanged = this.onStreamHudStateChanged.bind(this); this.boundOnStreamHudStateChanged = this.onStreamHudStateChanged.bind(this);
BxEventBus.Stream.on('ui.streamHud.expanded', this.boundOnStreamHudStateChanged);
this.render(); this.render();
} }
@ -114,7 +116,6 @@ export class StreamStats {
destroy() { destroy() {
this.stop(); this.stop();
this.quickGlanceStop();
this.hideSettingsUi(); this.hideSettingsUi();
} }
@ -122,6 +123,10 @@ export class StreamStats {
isGlancing = () => this.$container.dataset.display === 'glancing'; isGlancing = () => this.$container.dataset.display === 'glancing';
onStreamHudStateChanged({ state }: { state: string }) { onStreamHudStateChanged({ state }: { state: string }) {
if (!getStreamPref(StreamPref.STATS_QUICK_GLANCE_ENABLED)) {
return;
}
if (state === 'expanded') { if (state === 'expanded') {
this.isHidden() && this.start(true); this.isHidden() && this.start(true);
} else { } else {
@ -129,18 +134,6 @@ export class StreamStats {
} }
} }
quickGlanceSetup() {
if (!STATES.isPlaying) {
return;
}
BxEventBus.Stream.on('ui.streamHud.expanded', this.boundOnStreamHudStateChanged);
}
quickGlanceStop() {
BxEventBus.Stream.off('ui.streamHud.expanded', this.boundOnStreamHudStateChanged);
}
private update = async (forceUpdate=false) => { private update = async (forceUpdate=false) => {
if ((!forceUpdate && this.isHidden()) || !STATES.currentStream.peerConnection) { if ((!forceUpdate && this.isHidden()) || !STATES.currentStream.peerConnection) {
this.destroy(); this.destroy();
@ -232,7 +225,6 @@ export class StreamStats {
if (PREF_STATS_SHOW_WHEN_PLAYING) { if (PREF_STATS_SHOW_WHEN_PLAYING) {
streamStats.start(); streamStats.start();
} else if (PREF_STATS_QUICK_GLANCE) { } else if (PREF_STATS_QUICK_GLANCE) {
streamStats.quickGlanceSetup();
// Show stats bar // Show stats bar
!PREF_STATS_SHOW_WHEN_PLAYING && streamStats.start(true); !PREF_STATS_SHOW_WHEN_PLAYING && streamStats.start(true);
} }