mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
fix(v2): keep a shelved game's Play a button and pass non-primary clicks through
A modified click on the launch anchor skipped play(), which is where the protected-launch confirmation lives, so a retired or never-playing game could reach its player page without the prompt. useGameActions now exposes needsLaunchConfirm and GameActionBtn renders a button instead of an anchor while it holds, so every launch of a shelved game confirms. The anchor also leaves non-primary clicks to the browser, matching the other v2 link handlers. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MozJiij1oQbu12GvtAPBFR
This commit is contained in:
@@ -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" });
|
||||
|
||||
|
||||
@@ -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<string | null>(() => {
|
||||
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;
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user