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

@@ -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();