Rename EventBus to BxEventBus

This commit is contained in:
redphx
2024-12-08 20:09:12 +07:00
parent de7bf3edc7
commit 741bc9a4e5
21 changed files with 130 additions and 125 deletions

View File

@@ -44,7 +44,7 @@ import { StreamSettings } from "./utils/stream-settings";
import { KeyboardShortcutHandler } from "./modules/mkb/keyboard-shortcut-handler";
import { GhPagesUtils } from "./utils/gh-pages";
import { DeviceVibrationManager } from "./modules/device-vibration-manager";
import { EventBus } from "./utils/event-bus";
import { BxEventBus } from "./utils/bx-event-bus";
// Handle login page
if (window.location.pathname.includes('/auth/msa')) {
@@ -191,8 +191,8 @@ window.addEventListener('popstate', onHistoryChanged);
window.history.pushState = patchHistoryMethod('pushState');
window.history.replaceState = patchHistoryMethod('replaceState');
EventBus.Script.on('xcloudServerUnavailable', () => {
EventBus.Script.off('xcloudServerUnavailable', null);
BxEventBus.Script.on('xcloudServerUnavailable', () => {
BxEventBus.Script.off('xcloudServerUnavailable', null);
STATES.supportedRegion = false;
window.setTimeout(HeaderSection.watchHeader, 2000);
@@ -204,12 +204,12 @@ EventBus.Script.on('xcloudServerUnavailable', () => {
}
});
EventBus.Script.on('xcloudServerReady', () => {
BxEventBus.Script.on('xcloudServerReady', () => {
STATES.isSignedIn = true;
window.setTimeout(HeaderSection.watchHeader, 2000);
});
EventBus.Stream.on('stateLoading', () => {
BxEventBus.Stream.on('stateLoading', () => {
// Get title ID for screenshot's name
if (window.location.pathname.includes('/launch/') && STATES.currentStream.titleInfo) {
STATES.currentStream.titleSlug = productTitleToSlug(STATES.currentStream.titleInfo.product.title);
@@ -219,9 +219,9 @@ EventBus.Stream.on('stateLoading', () => {
});
// Setup loading screen
getPref(PrefKey.LOADING_SCREEN_GAME_ART) && EventBus.Script.on('titleInfoReady', LoadingScreen.setup);
getPref(PrefKey.LOADING_SCREEN_GAME_ART) && BxEventBus.Script.on('titleInfoReady', LoadingScreen.setup);
EventBus.Stream.on('stateStarting', () => {
BxEventBus.Stream.on('stateStarting', () => {
// Hide loading screen
LoadingScreen.hide();
@@ -235,7 +235,7 @@ EventBus.Stream.on('stateStarting', () => {
}
});
EventBus.Stream.on('statePlaying', payload => {
BxEventBus.Stream.on('statePlaying', payload => {
window.BX_STREAM_SETTINGS = StreamSettings.settings;
StreamSettings.refreshAllSettings();
@@ -265,8 +265,8 @@ EventBus.Stream.on('statePlaying', payload => {
updateVideoPlayer();
});
EventBus.Stream.on('stateError', () => {
EventBus.Stream.emit('stateStopped', {});
BxEventBus.Stream.on('stateError', () => {
BxEventBus.Stream.emit('stateStopped', {});
});
isFullVersion() && window.addEventListener(BxEvent.XCLOUD_RENDERING_COMPONENT, e => {
@@ -343,9 +343,9 @@ function unload() {
}
}
EventBus.Stream.on('stateStopped', unload);
BxEventBus.Stream.on('stateStopped', unload);
window.addEventListener('pagehide', e => {
EventBus.Stream.emit('stateStopped', {});
BxEventBus.Stream.emit('stateStopped', {});
});
isFullVersion() && window.addEventListener(BxEvent.CAPTURE_SCREENSHOT, e => {

View File

@@ -1,7 +1,7 @@
import { AppInterface, STATES } from "@utils/global";
import { BxEvent } from "@utils/bx-event";
import { StreamSettings } from "@/utils/stream-settings";
import { EventBus } from "@/utils/event-bus";
import { BxEventBus } from "@/utils/bx-event-bus";
const VIBRATION_DATA_MAP = {
gamepadIndex: 8,
@@ -48,7 +48,7 @@ export class DeviceVibrationManager {
}
});
EventBus.Script.on('deviceVibrationUpdated', () => this.setupDataChannel());
BxEventBus.Script.on('deviceVibrationUpdated', () => this.setupDataChannel());
}
private setupDataChannel() {

View File

@@ -18,7 +18,7 @@ import { MkbPopup } from "./mkb-popup";
import type { MkbConvertedPresetData } from "@/types/presets";
import { StreamSettings } from "@/utils/stream-settings";
import { ShortcutAction } from "@/enums/shortcut-actions";
import { EventBus } from "@/utils/event-bus";
import { BxEventBus } from "@/utils/bx-event-bus";
const PointerToMouseButton = {
1: 0,
@@ -640,7 +640,7 @@ export class EmulatedMkbHandler extends MkbHandler {
static setupEvents() {
if (isFullVersion()) {
EventBus.Stream.on('statePlaying', () => {
BxEventBus.Stream.on('statePlaying', () => {
if (STATES.currentStream.titleInfo?.details.hasMkbSupport) {
// Enable native MKB in Android app
NativeMkbHandler.getInstance()?.init();
@@ -650,7 +650,7 @@ export class EmulatedMkbHandler extends MkbHandler {
});
if (EmulatedMkbHandler.isAllowed()) {
EventBus.Script.on('mkbSettingUpdated', () => {
BxEventBus.Script.on('mkbSettingUpdated', () => {
EmulatedMkbHandler.getInstance()?.refreshPresetData();
});
}

View File

@@ -6,7 +6,7 @@ import type { MkbHandler } from "./base-mkb-handler";
import { NativeMkbHandler } from "./native-mkb-handler";
import { StreamSettings } from "@/utils/stream-settings";
import { KeyHelper } from "./key-helper";
import { EventBus } from "@/utils/event-bus";
import { BxEventBus } from "@/utils/bx-event-bus";
type MkbPopupType = 'virtual' | 'native';
@@ -24,7 +24,7 @@ export class MkbPopup {
constructor() {
this.render();
EventBus.Script.on('keyboardShortcutsUpdated', () => {
BxEventBus.Script.on('keyboardShortcutsUpdated', () => {
const $newButton = this.createActivateButton();
this.$btnActivate.replaceWith($newButton);
this.$btnActivate = $newButton;

View File

@@ -6,7 +6,7 @@ import { getPref } from "@/utils/settings-storages/global-settings-storage"
import { StreamStatsCollector, type StreamStatGrade } from "@/utils/stream-stats-collector"
import { BxLogger } from "@/utils/bx-logger"
import { StreamStat } from "@/enums/pref-values"
import { EventBus } from "@/utils/event-bus"
import { BxEventBus } from "@/utils/bx-event-bus"
export class StreamStats {
@@ -230,7 +230,7 @@ export class StreamStats {
}
static setupEvents() {
EventBus.Stream.on('statePlaying', () => {
BxEventBus.Stream.on('statePlaying', () => {
const PREF_STATS_QUICK_GLANCE = getPref(PrefKey.STATS_QUICK_GLANCE_ENABLED);
const PREF_STATS_SHOW_WHEN_PLAYING = getPref(PrefKey.STATS_SHOW_WHEN_PLAYING);

View File

@@ -5,7 +5,7 @@ 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 { EventBus } from "@/utils/event-bus.ts";
import { BxEventBus } from "@/utils/bx-event-bus.ts";
export class StreamUiHandler {
@@ -243,7 +243,7 @@ export class StreamUiHandler {
// Error Page: .PureErrorPage.ErrorScreen
if (className.includes('PureErrorPage')) {
EventBus.Stream.emit('stateError', {});
BxEventBus.Stream.emit('stateError', {});
return;
}

View File

@@ -30,7 +30,7 @@ import { SuggestionsSetting } from "./settings/suggestions";
import { StreamSettings } from "@/utils/stream-settings";
import { MkbExtraSettings } from "./settings/mkb-extra";
import { BxExposed } from "@/utils/bx-exposed";
import { EventBus } from "@/utils/event-bus";
import { BxEventBus } from "@/utils/bx-event-bus";
type SettingTabSectionItem = Partial<{
@@ -436,7 +436,7 @@ export class SettingsDialog extends NavigationDialog {
onCreated: (setting: SettingTabSectionItem, $elm: HTMLElement) => {
const $range = $elm.querySelector<HTMLInputElement>('input[type=range')!;
EventBus.Script.on('settingChanged', payload => {
BxEventBus.Script.on('settingChanged', payload => {
const { storageKey, settingKey, settingValue } = payload;
if (storageKey === StorageKey.GLOBAL && settingKey === PrefKey.AUDIO_VOLUME) {
$range.value = settingValue;

View File

@@ -30,6 +30,7 @@ declare global {
BX_FETCH: typeof window['fetch'];
BxEvent: typeof BxEvent;
BxEventBus: typeof BxEventBus;
BxLogger: typeof BxLogger;
localRedirect: (path: stringn) => void;
testTouchLayout: (layout: any) => void;

View File

@@ -31,11 +31,11 @@ type StreamEvents = {
stateError: {};
};
export class EventBus<TEvents extends Record<string, any>> {
export class BxEventBus<TEvents extends Record<string, any>> {
private listeners: Map<keyof TEvents, Set<EventCallback<any>>> = new Map();
static readonly Script = new EventBus<ScriptEvents>();
static readonly Stream = new EventBus<StreamEvents>();
static readonly Script = new BxEventBus<ScriptEvents>();
static readonly Stream = new BxEventBus<StreamEvents>();
on<K extends keyof TEvents>(event: K, callback: EventCallback<TEvents[K]>): void {
if (!this.listeners.has(event)) {
@@ -79,3 +79,5 @@ export class EventBus<TEvents extends Record<string, any>> {
}
}
}
window.BxEventBus = BxEventBus;

View File

@@ -11,7 +11,7 @@ import { GamePassCloudGallery } from "@/enums/game-pass-gallery";
import { TouchController } from "@/modules/touch-controller";
import { NativeMkbMode, TouchControllerMode } from "@/enums/pref-values";
import { Patcher, type PatchPage } from "@/modules/patcher/patcher";
import { EventBus } from "./event-bus";
import { BxEventBus } from "./bx-event-bus";
export enum SupportedInputType {
CONTROLLER = 'Controller',
@@ -139,7 +139,7 @@ export const BxExposed = {
// Save this info in STATES
STATES.currentStream.titleInfo = titleInfo;
EventBus.Script.emit('titleInfoReady', {});
BxEventBus.Script.emit('titleInfoReady', {});
return titleInfo;
},

View File

@@ -1,7 +1,7 @@
import { StorageKey } from "@/enums/pref-keys";
import { NATIVE_FETCH } from "./bx-flags";
import { BxLogger } from "./bx-logger";
import { EventBus } from "./event-bus";
import { BxEventBus } from "./bx-event-bus";
export type ForceNativeMkbResponse = {
@@ -53,7 +53,7 @@ export class GhPagesUtils {
if (json.$schemaVersion === supportedSchema) {
// Save to storage
window.localStorage.setItem(key, JSON.stringify(json));
EventBus.Script.emit('listForcedNativeMkbUpdated', {});
BxEventBus.Script.emit('listForcedNativeMkbUpdated', {});
}
});

View File

@@ -2,7 +2,7 @@ import { BxEvent } from "@utils/bx-event";
import { LoadingScreen } from "@modules/loading-screen";
import { RemotePlayManager } from "@/modules/remote-play-manager";
import { HeaderSection } from "@/modules/ui/header";
import { EventBus } from "./event-bus";
import { BxEventBus } from "./bx-event-bus";
import { NavigationDialogManager } from "@/modules/ui/dialog/navigation-dialog";
export function patchHistoryMethod(type: 'pushState' | 'replaceState') {
@@ -33,5 +33,5 @@ export function onHistoryChanged(e: PopStateEvent) {
LoadingScreen.reset();
window.setTimeout(HeaderSection.watchHeader, 2000);
EventBus.Stream.emit('stateStopped', {});
BxEventBus.Stream.emit('stateStopped', {});
}

View File

@@ -7,7 +7,7 @@ import { PrefKey } from "@/enums/pref-keys";
import { getPref, getPrefDefinition } from "./settings-storages/global-settings-storage";
import { CodecProfile } from "@/enums/pref-values";
import type { SettingDefinition } from "@/types/setting-definition";
import { EventBus } from "./event-bus";
import { BxEventBus } from "./bx-event-bus";
export function patchVideoApi() {
const PREF_SKIP_SPLASH_VIDEO = getPref(PrefKey.UI_SKIP_SPLASH_VIDEO);
@@ -28,7 +28,7 @@ export function patchVideoApi() {
} satisfies StreamPlayerOptions;
STATES.currentStream.streamPlayer = new StreamPlayer(this, getPref(PrefKey.VIDEO_PLAYER_TYPE), playerOptions);
EventBus.Stream.emit('statePlaying', {
BxEventBus.Stream.emit('statePlaying', {
$video: this,
})
}

View File

@@ -2,7 +2,7 @@ import type { PrefKey, StorageKey } from "@/enums/pref-keys";
import type { NumberStepperParams, SettingAction, SettingDefinitions } from "@/types/setting-definition";
import { t } from "../translation";
import { SCRIPT_VARIANT } from "../global";
import { EventBus } from "../event-bus";
import { BxEventBus } from "../bx-event-bus";
export class BaseSettingsStore {
private storage: Storage;
@@ -93,7 +93,7 @@ export class BaseSettingsStore {
this.settings[key] = this.validateValue('get', key, value);
this.saveSettings();
emitEvent && EventBus.Script.emit('settingChanged', {
emitEvent && BxEventBus.Script.emit('settingChanged', {
storageKey: this.storageKey,
settingKey: key,
settingValue: value,

View File

@@ -12,7 +12,7 @@ import { CodecProfile, StreamResolution, TouchControllerMode, TouchControllerSty
import { MkbMappingDefaultPresetId } from "../local-db/mkb-mapping-presets-table";
import { KeyboardShortcutDefaultId } from "../local-db/keyboard-shortcuts-table";
import { GhPagesUtils } from "../gh-pages";
import { EventBus } from "../event-bus";
import { BxEventBus } from "../bx-event-bus";
function getSupportedCodecProfiles() {
@@ -432,7 +432,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
if (!setting.unsupported) {
(setting as any).multipleOptions = GhPagesUtils.getNativeMkbCustomList(true);
EventBus.Script.on('listForcedNativeMkbUpdated', () => {
BxEventBus.Script.on('listForcedNativeMkbUpdated', () => {
(setting as any).multipleOptions = GhPagesUtils.getNativeMkbCustomList();
});
}

View File

@@ -13,7 +13,7 @@ import { MkbPresetKey, MouseConstant } from "@/enums/mkb";
import { KeyboardShortcutDefaultId, KeyboardShortcutsTable } from "./local-db/keyboard-shortcuts-table";
import { ShortcutAction } from "@/enums/shortcut-actions";
import { KeyHelper } from "@/modules/mkb/key-helper";
import { EventBus } from "./event-bus";
import { BxEventBus } from "./bx-event-bus";
export type StreamSettingsData = {
@@ -110,7 +110,7 @@ export class StreamSettings {
}
StreamSettings.settings.deviceVibrationIntensity = intensity;
EventBus.Script.emit('deviceVibrationUpdated', {});
BxEventBus.Script.emit('deviceVibrationUpdated', {});
}
static async refreshMkbSettings() {
@@ -148,7 +148,7 @@ export class StreamSettings {
settings.mkbPreset = converted;
setPref(PrefKey.MKB_P1_MAPPING_PRESET_ID, orgPreset.id);
EventBus.Script.emit('mkbSettingUpdated', {});
BxEventBus.Script.emit('mkbSettingUpdated', {});
}
static async refreshKeyboardShortcuts() {
@@ -159,7 +159,7 @@ export class StreamSettings {
settings.keyboardShortcuts = null;
setPref(PrefKey.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID, presetId);
EventBus.Script.emit('keyboardShortcutsUpdated', {});
BxEventBus.Script.emit('keyboardShortcutsUpdated', {});
return;
}
@@ -179,7 +179,7 @@ export class StreamSettings {
settings.keyboardShortcuts = converted;
setPref(PrefKey.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID, orgPreset.id);
EventBus.Script.emit('keyboardShortcutsUpdated', {});
BxEventBus.Script.emit('keyboardShortcutsUpdated', {});
}
static async refreshAllSettings() {

View File

@@ -4,7 +4,7 @@ import { humanFileSize, secondsToHm } from "./html";
import { getPref } from "./settings-storages/global-settings-storage";
import { BxLogger } from "./bx-logger";
import { StreamStat } from "@/enums/pref-values";
import { EventBus } from "./event-bus";
import { BxEventBus } from "./bx-event-bus";
export type StreamStatGrade = '' | 'bad' | 'ok' | 'good';
@@ -310,7 +310,7 @@ export class StreamStatsCollector {
}
static setupEvents() {
EventBus.Stream.on('statePlaying', () => {
BxEventBus.Stream.on('statePlaying', () => {
StreamStatsCollector.getInstance().reset();
});
}

View File

@@ -12,7 +12,7 @@ import { BypassServerIps } from "@/enums/bypass-servers";
import { PrefKey } from "@/enums/pref-keys";
import { getPref } from "./settings-storages/global-settings-storage";
import { NativeMkbMode, StreamResolution, TouchControllerMode } from "@/enums/pref-values";
import { EventBus } from "./event-bus";
import { BxEventBus } from "./bx-event-bus";
export class XcloudInterceptor {
private static readonly SERVER_EXTRA_INFO: Record<string, [string, ServerContinent]> = {
@@ -52,7 +52,7 @@ export class XcloudInterceptor {
const response = await NATIVE_FETCH(request, init);
if (response.status !== 200) {
// Unsupported region
EventBus.Script.emit('xcloudServerUnavailable', {});
BxEventBus.Script.emit('xcloudServerUnavailable', {});
return response;
}
@@ -89,7 +89,7 @@ export class XcloudInterceptor {
STATES.serverRegions[region.name] = Object.assign({}, region);
}
EventBus.Script.emit('xcloudServerReady', {});
BxEventBus.Script.emit('xcloudServerReady', {});
const preferredRegion = getPreferredServerRegion();
if (preferredRegion && preferredRegion in STATES.serverRegions) {
@@ -107,7 +107,7 @@ export class XcloudInterceptor {
}
private static async handlePlay(request: RequestInfo | URL, init?: RequestInit) {
EventBus.Stream.emit('stateLoading', {});
BxEventBus.Stream.emit('stateLoading', {});
const PREF_STREAM_TARGET_RESOLUTION = getPref<StreamResolution>(PrefKey.STREAM_RESOLUTION);
const PREF_STREAM_PREFERRED_LOCALE = getPref<StreamPreferredLocale>(PrefKey.STREAM_PREFERRED_LOCALE);
@@ -189,7 +189,7 @@ export class XcloudInterceptor {
return response;
}
EventBus.Stream.emit('stateStarting', {});
BxEventBus.Stream.emit('stateStarting', {});
const obj = JSON.parse(text);
let overrides = JSON.parse(obj.clientStreamingConfigOverrides || '{}') || {};

View File

@@ -9,7 +9,7 @@ import { getPref } from "./settings-storages/global-settings-storage";
import type { RemotePlayConsoleAddresses } from "@/types/network";
import { RemotePlayManager } from "@/modules/remote-play-manager";
import { StreamResolution, TouchControllerMode } from "@/enums/pref-values";
import { EventBus } from "./event-bus";
import { BxEventBus } from "./bx-event-bus";
export class XhomeInterceptor {
private static consoleAddrs: RemotePlayConsoleAddresses = {};
@@ -36,7 +36,7 @@ export class XhomeInterceptor {
}
private static async handleConfiguration(request: Request | URL) {
EventBus.Stream.emit('stateStarting', {});
BxEventBus.Stream.emit('stateStarting', {});
const response = await NATIVE_FETCH(request);
const obj = await response.clone().json();
@@ -125,7 +125,7 @@ export class XhomeInterceptor {
}
private static async handlePlay(request: RequestInfo | URL) {
EventBus.Stream.emit('stateLoading', {});
BxEventBus.Stream.emit('stateLoading', {});
const clone = (request as Request).clone();
const body = await clone.json();