mirror of
https://github.com/rommapp/romm.git
synced 2026-12-06 15:54:45 +01:00
fix(streaming): code-review pass on the exit chord move
Release a desktop claim still held at unmount, mark an unstarted chord hold with null rather than 0, and cover the Stream listener, the held-through-close latch, and escape-stack cleanup in tests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d3792142ab
commit
acfa9d97b3
5 files changed
+78
-9
No files matched your search
@@ -246,12 +246,34 @@ describe("useGamepad", () => {
|
||||
it("holds off while an overlay sits over the game", () => {
|
||||
const dialog = { close: () => {}, persistent: true };
|
||||
pushEscapable(dialog);
|
||||
pads = [padHolding(...CHORD)];
|
||||
stepAt(0);
|
||||
stepAt(EXIT_CHORD_HOLD_MS * 2);
|
||||
popEscapable(dialog);
|
||||
try {
|
||||
pads = [padHolding(...CHORD)];
|
||||
stepAt(0);
|
||||
stepAt(EXIT_CHORD_HOLD_MS * 2);
|
||||
} finally {
|
||||
popEscapable(dialog);
|
||||
}
|
||||
|
||||
expect(chords).toBe(0);
|
||||
});
|
||||
|
||||
it("stays fired after its dialog closes while the chord is still held", () => {
|
||||
const dialog = { close: () => {}, persistent: false };
|
||||
pads = [padHolding(...CHORD)];
|
||||
stepAt(0);
|
||||
stepAt(EXIT_CHORD_HOLD_MS);
|
||||
expect(chords).toBe(1);
|
||||
|
||||
pushEscapable(dialog);
|
||||
try {
|
||||
stepAt(EXIT_CHORD_HOLD_MS + 100);
|
||||
} finally {
|
||||
popEscapable(dialog);
|
||||
}
|
||||
stepAt(EXIT_CHORD_HOLD_MS * 3);
|
||||
stepAt(EXIT_CHORD_HOLD_MS * 5);
|
||||
|
||||
expect(chords).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -256,7 +256,7 @@ export function useGamepad() {
|
||||
const { setModality } = useInputModality();
|
||||
let rafId = 0;
|
||||
let everSawPad = false;
|
||||
let chordHeldSince = 0;
|
||||
let chordHeldSince: number | null = null;
|
||||
// Cleared only on release, so a chord still held after its dialog is
|
||||
// cancelled doesn't reopen it.
|
||||
let chordFired = false;
|
||||
@@ -375,12 +375,12 @@ export function useGamepad() {
|
||||
|
||||
// The game's pad gets no B, so a long Select+Start hold is the way out.
|
||||
if (!chordHeld) {
|
||||
chordHeldSince = 0;
|
||||
chordHeldSince = null;
|
||||
chordFired = false;
|
||||
} else if (!gameOwnsInput) {
|
||||
chordHeldSince = 0;
|
||||
chordHeldSince = null;
|
||||
} else if (!chordFired) {
|
||||
if (!chordHeldSince) chordHeldSince = t;
|
||||
chordHeldSince ??= t;
|
||||
if (t - chordHeldSince >= EXIT_CHORD_HOLD_MS) {
|
||||
chordFired = true;
|
||||
window.dispatchEvent(new Event("gamepad:exitchord"));
|
||||
|
||||
@@ -438,4 +438,24 @@ describe("Desktop claims that outlive the view", () => {
|
||||
|
||||
expectReleasedOwnClaim();
|
||||
});
|
||||
|
||||
it("hands back a claim that answers while the leave is still resolving", async () => {
|
||||
let answer = (_: unknown) => {};
|
||||
mocks.claimDesktop.mockReturnValue(
|
||||
new Promise((resolve) => {
|
||||
answer = resolve;
|
||||
}),
|
||||
);
|
||||
mocks.releaseSession.mockResolvedValue({});
|
||||
const wrapper = await mountDesktop();
|
||||
|
||||
expect(await mocks.routeLeave?.()).toBe(true);
|
||||
answer(CLAIM);
|
||||
await flushPromises();
|
||||
wrapper.unmount();
|
||||
mounted = null;
|
||||
await flushPromises();
|
||||
|
||||
expectReleasedOwnClaim();
|
||||
});
|
||||
});
|
||||
@@ -10,7 +10,7 @@
|
||||
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 } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { onBeforeRouteLeave, useRoute, useRouter } from "vue-router";
|
||||
import { ROUTES } from "@/plugins/router";
|
||||
@@ -237,6 +237,12 @@ useEventListener(window, "pagehide", onPageHide);
|
||||
onMounted(() => {
|
||||
void openDesktop();
|
||||
});
|
||||
|
||||
// A claim that answered after the leave guard let navigation through, while
|
||||
// the next route was still resolving, is still held here.
|
||||
onBeforeUnmount(() => {
|
||||
if (holdsClaim.value) void release();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -477,6 +477,7 @@ type StreamVm = {
|
||||
claimedAt: string | null;
|
||||
playerState: string;
|
||||
endedDialogOpen: boolean;
|
||||
exitDialogOpen: boolean;
|
||||
holdsClaim: boolean;
|
||||
containerHost: string;
|
||||
errorMessage: string;
|
||||
@@ -627,6 +628,26 @@ describe("Stream session-ended notices", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Stream exit chord", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mocks.claimSession.mockResolvedValue(CLAIM);
|
||||
});
|
||||
|
||||
it("opens the exit dialog from the pad's exit chord", async () => {
|
||||
// B is muted with the rest of the pad, so the chord is the pad's way out.
|
||||
const wrapper = await launch({ picker: false });
|
||||
await vmOf(wrapper).onPlay();
|
||||
await launchReady();
|
||||
expect(vmOf(wrapper).playerState).toBe("playing");
|
||||
|
||||
window.dispatchEvent(new Event("gamepad:exitchord"));
|
||||
await flushPromises();
|
||||
|
||||
expect(vmOf(wrapper).exitDialogOpen).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Stream claim hygiene", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
Reference in new issue
Block a user