useEffect() for Error page

This commit is contained in:
redphx
2025-02-07 17:01:03 +07:00
parent d4c1e8cce3
commit 4b06d9fcff
8 changed files with 44 additions and 44 deletions

View File

@@ -261,7 +261,7 @@ BxEventBus.Stream.on('state.playing', payload => {
updateVideoPlayer();
});
BxEventBus.Stream.on('state.error', () => {
BxEventBus.Script.on('error.rendered', () => {
BxEventBus.Stream.emit('state.stopped', {});
});
@@ -324,6 +324,7 @@ function unload() {
return;
}
BxLogger.warning('Unloading');
if (isFullVersion()) {
KeyboardShortcutHandler.getInstance().stop();

View File

@@ -1136,16 +1136,23 @@ ${subsVar} = subs;
injectHeaderUseEffect(str: string) {
let index = str.indexOf('"EdgewaterHeader-module__spaceBetween');
index > -1 && (index = PatcherUtils.lastIndexOf(str, 'return', index, 300));
if (index < 0) {
return false;
}
const newCode = `
window.BX_EXPOSED.reactUseEffect(() => {
window.BxEventBus.Script.emit('header.rendered', {});
});
`;
const newCode = `window.BX_EXPOSED.reactUseEffect(() => window.BxEventBus.Script.emit('header.rendered', {}));`;
str = PatcherUtils.insertAt(str, index, newCode);
return str;
},
injectErrorPageUseEffect(str: string) {
let index = str.indexOf('"PureErrorPage-module__container');
index > -1 && (index = PatcherUtils.lastIndexOf(str, 'return', index, 200));
if (index < 0) {
return false;
}
const newCode = `window.BX_EXPOSED.reactUseEffect(() => window.BxEventBus.Script.emit('error.rendered', {}));`;
str = PatcherUtils.insertAt(str, index, newCode);
return str;
},
@@ -1158,7 +1165,10 @@ let PATCH_ORDERS = PatcherUtils.filterPatches([
] : []),
'exposeReactCreateComponent',
'injectHeaderUseEffect',
'injectErrorPageUseEffect',
'gameCardCustomIcons',
// 'gameCardPassTitle',

View File

@@ -9,5 +9,5 @@ window.BX_EXPOSED.showStreamMenu = options.onShowStreamMenu;
options.guideUI = null;
window.BX_EXPOSED.reactUseEffect(() => {
window.BxEventBus.Stream.emit('ui.streamHud.expanded', { state: options.offset.x < 0 ? 'collapsed' : 'expanded' });
window.BxEventBus.Stream.emit('ui.streamHud.rendered', { expanded: options.offset.x === 0 });
});

View File

@@ -75,7 +75,7 @@ export class StreamStats {
BxLogger.info(this.LOG_TAG, 'constructor()');
this.boundOnStreamHudStateChanged = this.onStreamHudStateChanged.bind(this);
BxEventBus.Stream.on('ui.streamHud.expanded', this.boundOnStreamHudStateChanged);
BxEventBus.Stream.on('ui.streamHud.rendered', this.boundOnStreamHudStateChanged);
this.render();
}
@@ -122,12 +122,12 @@ export class StreamStats {
isHidden = () => this.$container.classList.contains('bx-gone');
isGlancing = () => this.$container.dataset.display === 'glancing';
onStreamHudStateChanged({ state }: { state: string }) {
onStreamHudStateChanged({ expanded }: { expanded: boolean }) {
if (!getStreamPref(StreamPref.STATS_QUICK_GLANCE_ENABLED)) {
return;
}
if (state === 'expanded') {
if (expanded) {
this.isHidden() && this.start(true);
} else {
this.stop(true);

View File

@@ -5,7 +5,6 @@ import { t } from "@utils/translation.ts";
import { StreamBadges } from "./stream-badges.ts";
import { StreamStats } from "./stream-stats.ts";
import { SettingsDialog } from "../ui/dialog/settings-dialog.ts";
import { BxEventBus } from "@/utils/bx-event-bus.ts";
export class StreamUiHandler {
@@ -240,13 +239,6 @@ export class StreamUiHandler {
}
const className = $elm.className || '';
// Error Page: .PureErrorPage.ErrorScreen
if (className.includes('PureErrorPage')) {
BxEventBus.Stream.emit('state.error', {});
return;
}
// Render badges
if (className.startsWith('StreamMenu-module__container')) {
StreamUiHandler.handleStreamMenu();

View File

@@ -37,6 +37,7 @@ type ScriptEvents = {
'webgpu.ready': {},
'header.rendered': {},
'error.rendered': {},
};
type StreamEvents = {
@@ -44,7 +45,6 @@ type StreamEvents = {
'state.starting': {};
'state.playing': { $video?: HTMLVideoElement };
'state.stopped': {};
'state.error': {};
'xboxTitleId.changed': {
id: number;
@@ -68,7 +68,7 @@ type StreamEvents = {
// Inside patch
'microphone.state.changed': { state: MicrophoneState };
'ui.streamHud.expanded': { state: 'expanded' | 'collapsed' },
'ui.streamHud.rendered': { expanded: boolean },
dataChannelCreated: { dataChannel: RTCDataChannel };
};