From 36cd73762dce6b074e7e66c2e656ce7a22e694c0 Mon Sep 17 00:00:00 2001 From: Zach Clendenen Date: Wed, 30 Sep 2026 16:06:12 -0500 Subject: [PATCH 01/12] fix(streaming): let the desktop session own the controller The desktop view never set the global playing flag, so useGamepad kept translating pad presses into RomM navigation behind the stream: B popped history (prompting to end the session), the D-pad moved focus and Start opened the user menu while an admin configured the emulator. Hold the flag while the desktop is opening or open, as the game player does. --- frontend/src/v2/views/Player/Desktop.test.ts | 39 ++++++++++++++++++++ frontend/src/v2/views/Player/Desktop.vue | 19 +++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/frontend/src/v2/views/Player/Desktop.test.ts b/frontend/src/v2/views/Player/Desktop.test.ts index b0111f635..abef5256b 100644 --- a/frontend/src/v2/views/Player/Desktop.test.ts +++ b/frontend/src/v2/views/Player/Desktop.test.ts @@ -12,6 +12,7 @@ const mocks = vi.hoisted(() => ({ heartbeatTick: null as (() => Promise) | null, routeLeave: null as (() => Promise | boolean) | null, socketHandlers: {} as Record unknown>, + setPlaying: vi.fn(), })); vi.mock("vue-i18n", () => ({ @@ -49,6 +50,10 @@ vi.mock("@/services/api/streaming", () => ({ }, })); +vi.mock("@/stores/playing", () => ({ + default: () => ({ setPlaying: mocks.setPlaying }), +})); + vi.mock("@/stores/streaming", () => ({ useStreamingStore: () => ({ heartbeatSession: mocks.heartbeatSession }), })); @@ -345,3 +350,37 @@ describe("Desktop container naming", () => { ); }); }); + +describe("Desktop controller ownership", () => { + // The emulator inside the container reads the pad, so RomM's gamepad + // navigation must stay muted or B pops history out of the session. + it("mutes pad navigation while the desktop is claimed", async () => { + await openDesktop(); + + expect(mocks.setPlaying).toHaveBeenLastCalledWith(true); + }); + + it("hands the pad back once a notice ends the claim", async () => { + await openDesktop(); + + endSession({ platform: "ps2", container: KEY }); + await flushPromises(); + + expect(mocks.setPlaying).toHaveBeenLastCalledWith(false); + }); + + it("hands the pad back when the claim is refused", async () => { + await refuseDesktop({ rom_name: null, claimed_at: null, draining: true }); + + expect(mocks.setPlaying).toHaveBeenLastCalledWith(false); + }); + + it("hands the pad back when the view unmounts", async () => { + const wrapper = await openDesktop(); + + wrapper.unmount(); + mounted = null; + + expect(mocks.setPlaying).toHaveBeenLastCalledWith(false); + }); +}); diff --git a/frontend/src/v2/views/Player/Desktop.vue b/frontend/src/v2/views/Player/Desktop.vue index dd98e8834..a8565f7e7 100644 --- a/frontend/src/v2/views/Player/Desktop.vue +++ b/frontend/src/v2/views/Player/Desktop.vue @@ -10,13 +10,14 @@ import { RAlert, RBtn, RSpinner } from "@v2/lib"; import { useEventListener, useIntervalFn } from "@vueuse/core"; import { isAxiosError } from "axios"; -import { computed, onMounted, ref } from "vue"; +import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue"; import { useI18n } from "vue-i18n"; import { onBeforeRouteLeave, useRoute, useRouter } from "vue-router"; import { ROUTES } from "@/plugins/router"; import streamingApi, { type ContainerBusyDetail, } from "@/services/api/streaming"; +import storePlaying from "@/stores/playing"; import { type SessionTermination, useStreamingStore } from "@/stores/streaming"; import SessionEndedReason from "@/v2/components/Player/SessionEndedReason.vue"; import StreamStage from "@/v2/components/Player/StreamStage.vue"; @@ -29,6 +30,7 @@ const route = useRoute(); const router = useRouter(); const confirm = useConfirm(); const streamingStore = useStreamingStore(); +const playingStore = storePlaying(); const containerName = computed(() => String(route.query.container ?? "")); // The claim's key, which the session routes and notices name; the URL may @@ -55,6 +57,17 @@ const claimedAt = ref(""); usePageTitle(() => t("play.desktop-title")); +// While the desktop is open (or opening) the emulator inside it owns the +// controller, as it does in a game session: the global playing flag mutes +// useGamepad's UI translation, which would otherwise turn B into +// history-back and D-pad presses into focus moves behind the stream. +const sessionActive = computed( + () => state.value === "loading" || state.value === "running", +); +watch(sessionActive, (active) => playingStore.setPlaying(active), { + immediate: true, +}); + async function openDesktop(): Promise { if (!containerName.value) { state.value = "error"; @@ -218,6 +231,10 @@ useEventListener(window, "pagehide", onPageHide); onMounted(() => { void openDesktop(); }); + +onBeforeUnmount(() => { + playingStore.setPlaying(false); +});