mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-08-08 06:08:27 +02:00
Migrate more events to EventBus
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { BxEvent } from "@/utils/bx-event";
|
||||
import { BxEventBus } from "@/utils/bx-event-bus";
|
||||
|
||||
export abstract class BaseGameBarAction {
|
||||
abstract $content: HTMLElement;
|
||||
@@ -7,7 +7,7 @@ export abstract class BaseGameBarAction {
|
||||
reset() {}
|
||||
|
||||
onClick(e: Event) {
|
||||
BxEvent.dispatch(window, BxEvent.GAME_BAR_ACTION_ACTIVATED);
|
||||
BxEventBus.Stream.emit('gameBar.activated', {});
|
||||
};
|
||||
|
||||
render(): HTMLElement {
|
||||
|
@@ -13,6 +13,7 @@ import { SpeakerAction } from "./speaker-action";
|
||||
import { RendererAction } from "./renderer-action";
|
||||
import { BxLogger } from "@/utils/bx-logger";
|
||||
import { GameBarPosition, TouchControllerMode } from "@/enums/pref-values";
|
||||
import { BxEventBus } from "@/utils/bx-event-bus";
|
||||
|
||||
|
||||
export class GameBar {
|
||||
@@ -81,7 +82,7 @@ export class GameBar {
|
||||
});
|
||||
|
||||
// Hide game bar after clicking on an action
|
||||
window.addEventListener(BxEvent.GAME_BAR_ACTION_ACTIVATED, this.hideBar);
|
||||
BxEventBus.Stream.on('gameBar.activated', this.hideBar);
|
||||
|
||||
$container.addEventListener('pointerover', this.clearHideTimeout);
|
||||
$container.addEventListener('pointerout', this.beginHideTimeout);
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { BxEvent } from "@utils/bx-event";
|
||||
import { BxIcon } from "@utils/bx-icon";
|
||||
import { createButton, ButtonStyle, CE } from "@utils/html";
|
||||
import { BaseGameBarAction } from "./base-action";
|
||||
import { MicrophoneShortcut, MicrophoneState } from "../shortcuts/microphone-shortcut";
|
||||
import { BxEventBus } from "@/utils/bx-event-bus";
|
||||
|
||||
|
||||
export class MicrophoneAction extends BaseGameBarAction {
|
||||
@@ -26,9 +26,8 @@ export class MicrophoneAction extends BaseGameBarAction {
|
||||
|
||||
this.$content = CE('div', {}, $btnMuted, $btnDefault);
|
||||
|
||||
window.addEventListener(BxEvent.MICROPHONE_STATE_CHANGED, e => {
|
||||
const microphoneState = (e as any).microphoneState;
|
||||
const enabled = microphoneState === MicrophoneState.ENABLED;
|
||||
BxEventBus.Stream.on('microphone.state.changed', payload => {
|
||||
const enabled = payload.state === MicrophoneState.ENABLED;
|
||||
this.$content.dataset.activated = enabled.toString();
|
||||
|
||||
// Show the button in Game Bar if the mic is enabled
|
||||
|
@@ -2,7 +2,7 @@ import { BxIcon } from "@utils/bx-icon";
|
||||
import { createButton, ButtonStyle, CE } from "@utils/html";
|
||||
import { BaseGameBarAction } from "./base-action";
|
||||
import { RendererShortcut } from "../shortcuts/renderer-shortcut";
|
||||
import { BxEvent } from "@/utils/bx-event";
|
||||
import { BxEventBus } from "@/utils/bx-event-bus";
|
||||
|
||||
|
||||
export class RendererAction extends BaseGameBarAction {
|
||||
@@ -26,9 +26,8 @@ export class RendererAction extends BaseGameBarAction {
|
||||
|
||||
this.$content = CE('div', {}, $btnDefault, $btnActivated);
|
||||
|
||||
window.addEventListener(BxEvent.VIDEO_VISIBILITY_CHANGED, e => {
|
||||
const isShowing = (e as any).isShowing;
|
||||
this.$content.dataset.activated = (!isShowing).toString();
|
||||
BxEventBus.Stream.on('video.visibility.changed', payload => {
|
||||
this.$content.dataset.activated = (!payload.isVisible).toString();
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { BxEvent } from "@utils/bx-event";
|
||||
import { BxIcon } from "@utils/bx-icon";
|
||||
import { createButton, ButtonStyle, CE } from "@utils/html";
|
||||
import { BaseGameBarAction } from "./base-action";
|
||||
import { SoundShortcut, SpeakerState } from "../shortcuts/sound-shortcut";
|
||||
import { BxEventBus } from "@/utils/bx-event-bus";
|
||||
|
||||
|
||||
export class SpeakerAction extends BaseGameBarAction {
|
||||
@@ -26,10 +26,8 @@ export class SpeakerAction extends BaseGameBarAction {
|
||||
|
||||
this.$content = CE('div', {}, $btnEnable, $btnMuted);
|
||||
|
||||
window.addEventListener(BxEvent.SPEAKER_STATE_CHANGED, e => {
|
||||
const speakerState = (e as any).speakerState;
|
||||
const enabled = speakerState === SpeakerState.ENABLED;
|
||||
|
||||
BxEventBus.Stream.on('speaker.state.changed', payload => {
|
||||
const enabled = payload.state === SpeakerState.ENABLED;
|
||||
this.$content.dataset.activated = (!enabled).toString();
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user