mirror of
https://github.com/rommapp/romm.git
synced 2026-12-02 18:18:47 +01:00
fix(streaming): address Greptile review on the desktop pad handoff
Require a release before a held Select+Start can fire again, so cancelling the exit dialog with the chord still held no longer reopens it. Guard the late desktop claim with useIsAlive instead of a local unmount flag.
This commit is contained in:
@@ -55,6 +55,21 @@ describe("useExitChord", () => {
|
||||
scope.stop();
|
||||
});
|
||||
|
||||
it("waits for a release before a held chord can fire again", () => {
|
||||
const { onChord, scope } = listen(() => true);
|
||||
pads = [pad(CHORD)];
|
||||
|
||||
vi.advanceTimersByTime(5000);
|
||||
expect(onChord).toHaveBeenCalledTimes(1);
|
||||
|
||||
pads = [pad([])];
|
||||
vi.advanceTimersByTime(100);
|
||||
pads = [pad(CHORD)];
|
||||
vi.advanceTimersByTime(1700);
|
||||
expect(onChord).toHaveBeenCalledTimes(2);
|
||||
scope.stop();
|
||||
});
|
||||
|
||||
it("starts the hold over when either button is let go", () => {
|
||||
const { onChord, scope } = listen(() => true);
|
||||
pads = [pad(CHORD)];
|
||||
|
||||
@@ -15,6 +15,9 @@ export function useExitChord(
|
||||
onChord: () => void,
|
||||
): void {
|
||||
let heldSince = 0;
|
||||
// Set once a hold fires, so a chord still held after the dialog is cancelled
|
||||
// waits for a release instead of reopening it.
|
||||
let fired = false;
|
||||
|
||||
function poll(): void {
|
||||
const pads = navigator.getGamepads ? navigator.getGamepads() : [];
|
||||
@@ -29,10 +32,13 @@ export function useExitChord(
|
||||
const now = performance.now();
|
||||
if (!held) {
|
||||
heldSince = 0;
|
||||
fired = false;
|
||||
} else if (fired) {
|
||||
return;
|
||||
} else if (!heldSince) {
|
||||
heldSince = now;
|
||||
} else if (now - heldSince >= HOLD_MS) {
|
||||
heldSince = 0;
|
||||
fired = true;
|
||||
onChord();
|
||||
}
|
||||
}
|
||||
@@ -47,6 +53,7 @@ export function useExitChord(
|
||||
} else {
|
||||
pause();
|
||||
heldSince = 0;
|
||||
fired = false;
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
import { RAlert, RBtn, RSpinner } from "@v2/lib";
|
||||
import { useEventListener, useIntervalFn } from "@vueuse/core";
|
||||
import { isAxiosError } from "axios";
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { onBeforeRouteLeave, useRoute, useRouter } from "vue-router";
|
||||
import { ROUTES } from "@/plugins/router";
|
||||
@@ -22,6 +22,7 @@ import SessionEndedReason from "@/v2/components/Player/SessionEndedReason.vue";
|
||||
import StreamStage from "@/v2/components/Player/StreamStage.vue";
|
||||
import { useConfirm } from "@/v2/composables/useConfirm";
|
||||
import { useExitChord } from "@/v2/composables/useExitChord";
|
||||
import { useIsAlive } from "@/v2/composables/useIsAlive";
|
||||
import { usePageTitle } from "@/v2/composables/usePageTitle";
|
||||
import { useSocketEvent } from "@/v2/composables/useSocketEvent";
|
||||
import { usePlayingWhile } from "@/v2/composables/useStageActive";
|
||||
@@ -68,7 +69,7 @@ useExitChord(sessionActive, () => void handleExit());
|
||||
|
||||
// Leaving mid-claim is allowed, so a claim that answers after unmount is handed
|
||||
// straight back instead of standing unbeaten until it goes stale.
|
||||
let disposed = false;
|
||||
const alive = useIsAlive();
|
||||
|
||||
async function openDesktop(): Promise<void> {
|
||||
if (!containerName.value) {
|
||||
@@ -84,7 +85,7 @@ async function openDesktop(): Promise<void> {
|
||||
platform.value = data.platform;
|
||||
claimedAt.value = data.claimed_at;
|
||||
holdsClaim.value = true;
|
||||
if (disposed) {
|
||||
if (!alive.value) {
|
||||
void release();
|
||||
return;
|
||||
}
|
||||
@@ -237,10 +238,6 @@ useEventListener(window, "pagehide", onPageHide);
|
||||
onMounted(() => {
|
||||
void openDesktop();
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
disposed = true;
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user