diff --git a/frontend/src/v2/components/GameActions/GameActionBtn.test.ts b/frontend/src/v2/components/GameActions/GameActionBtn.test.ts index ad2345f59..7ea47e842 100644 --- a/frontend/src/v2/components/GameActions/GameActionBtn.test.ts +++ b/frontend/src/v2/components/GameActions/GameActionBtn.test.ts @@ -5,6 +5,7 @@ import type { SimpleRom } from "@/stores/roms"; import GameActionBtn from "./GameActionBtn.vue"; const play = vi.fn(); +const needsLaunchConfirm = { value: false }; vi.mock("vue-i18n", () => ({ useI18n: () => ({ t: (key: string) => key }), @@ -18,6 +19,7 @@ vi.mock("@/v2/composables/useGameActions", () => ({ GAME_ACTIONS_KEY: Symbol("game-actions"), useGameActions: () => ({ play, + needsLaunchConfirm, playPath: (player: string) => player === "stream" ? "/rom/1/stream" : "/rom/1/ejs", streamActionLabel: { value: "rom.stream" }, @@ -55,6 +57,7 @@ function click(el: Element, init: MouseEventInit = {}): boolean { beforeEach(() => { play.mockClear(); + needsLaunchConfirm.value = false; }); describe("GameActionBtn: launch links", () => { @@ -90,6 +93,22 @@ describe("GameActionBtn: launch links", () => { expect(play).not.toHaveBeenCalled(); }); + it("leaves a non-primary click to the browser too", () => { + const wrapper = mountBtn({ link: true }); + + expect(click(wrapper.get("a").element, { button: 1 })).toBe(false); + expect(play).not.toHaveBeenCalled(); + }); + + it("keeps a shelved game's launch as a button so it always confirms", () => { + needsLaunchConfirm.value = true; + const wrapper = mountBtn({ link: true }); + + expect(wrapper.find("a").exists()).toBe(false); + click(wrapper.get("button.r-v2-game-btn").element, { ctrlKey: true }); + expect(play).toHaveBeenCalledWith("local"); + }); + it("keeps the other actions as buttons even when asked to link", () => { const wrapper = mountBtn({ link: true, action: "download" }); diff --git a/frontend/src/v2/components/GameActions/GameActionBtn.vue b/frontend/src/v2/components/GameActions/GameActionBtn.vue index 3dbdfa921..2c1cad02e 100644 --- a/frontend/src/v2/components/GameActions/GameActionBtn.vue +++ b/frontend/src/v2/components/GameActions/GameActionBtn.vue @@ -301,9 +301,10 @@ const displayedIcon = computed( ); // Only the launch actions lead to a document of their own; with `link` they -// render as anchors to it so the player can be opened in a new tab. +// render as anchors to it so the player can be opened in a new tab. A shelved +// game keeps the button: every launch must pass `play()`'s confirmation. const linkHref = computed(() => { - if (!props.link) return null; + if (!props.link || actions.needsLaunchConfirm.value) return null; if (props.action === "play") return actions.playPath("local"); if (props.action === "stream") return actions.playPath("stream"); return null; @@ -352,11 +353,11 @@ function clearAllStatus() { statusOpen.value = false; } -// Modified clicks on a launch anchor stay with the browser (new tab); plain -// ones still go through `play()` for its confirmation and full-document load. +// Modified and non-primary clicks on a launch anchor stay with the browser +// (new tab); plain ones still go through `play()` for its full-document load. function onClick(e: MouseEvent) { if (props.action === "more" || props.action === "status") return; - if (linkHref.value && opensInNewContext(e)) return; + if (linkHref.value && (e.button !== 0 || opensInNewContext(e))) return; e.preventDefault(); e.stopPropagation(); if (props.action === "collection") collectionOpen.value = true; diff --git a/frontend/src/v2/composables/useGameActions/index.test.ts b/frontend/src/v2/composables/useGameActions/index.test.ts index 425d5d4ef..bb8c69caa 100644 --- a/frontend/src/v2/composables/useGameActions/index.test.ts +++ b/frontend/src/v2/composables/useGameActions/index.test.ts @@ -387,6 +387,30 @@ describe("useGameActions.play — launch confirmation", () => { }); }); +describe("useGameActions.needsLaunchConfirm", () => { + it.each(["retired", "never_playing"] as const)( + "asks before launching a %s game", + (status) => { + expect( + useGameActions(() => makeRom(status)).needsLaunchConfirm.value, + ).toBe(true); + }, + ); + + it("asks nothing for a game that is not shelved", () => { + expect(useGameActions(() => makeRom()).needsLaunchConfirm.value).toBe( + false, + ); + }); + + it("asks nothing when the preference is disabled", () => { + confirmProtectedLaunch.value = false; + expect( + useGameActions(() => makeRom("retired")).needsLaunchConfirm.value, + ).toBe(false); + }); +}); + describe("useGameActions.playPath", () => { it("points the local launch at EmulatorJS", () => { const actions = useGameActions(() => makeRom()); diff --git a/frontend/src/v2/composables/useGameActions/index.ts b/frontend/src/v2/composables/useGameActions/index.ts index ba62d3bd5..ff4575c56 100644 --- a/frontend/src/v2/composables/useGameActions/index.ts +++ b/frontend/src/v2/composables/useGameActions/index.ts @@ -294,18 +294,23 @@ export function useGameActions( ); }); + // Launching a game the user deliberately shelved asks first. `retired` / + // `never_playing` encode an opt-in "don't play" intent; the prompt is + // gated by a per-user preference (on by default). + const needsLaunchConfirm = computed(() => { + const status = getRom()?.rom_user?.status; + return ( + confirmProtectedLaunch.value && + (status === "retired" || status === "never_playing") + ); + }); + async function play(player: PlayTarget = "auto") { const rom = getRom(); if (!rom) return; - // Guard launching a game the user deliberately shelved. `retired` / - // `never_playing` encode an opt-in "don't play" intent, so confirm - // before booting one. Gated by a per-user preference (on by default). const status = rom.rom_user?.status; - if ( - confirmProtectedLaunch.value && - (status === "retired" || status === "never_playing") - ) { + if (needsLaunchConfirm.value) { const ok = await confirm({ title: t("rom.confirm-launch-protected-title"), body: t("rom.confirm-launch-protected-body", { @@ -598,6 +603,7 @@ export function useGameActions( setStatus, setStatusEnum, setScore, + needsLaunchConfirm, play, playPath, goToPlatform,