fix(steam): gate Open in Steam on ownership again

#5362 dropped this gating when master reverted the action it gated, so
merging the action back in offered it on every Steam-matched game. The
store re-exposes owns(), and a loaded library narrows the action to the
games the linked account owns; with no linked account it behaves as it
does on #5368 alone.

Restores the gating and its test from e072cf7, lost in the revert merge
4e22325.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NH5s4gb7QNE7xa4pRUsBzx
This commit is contained in:
Claude
2026-11-03 20:26:49 +00:00
parent bdd99d9f40
commit 7bc84b2dae
3 changed files with 41 additions and 2 deletions

View File

@@ -72,6 +72,15 @@ vi.mock("@/stores/auth", () => ({
vi.mock("@/stores/heartbeat", () => ({
default: () => ({ value: { DEVICE_INSTALL: deviceInstall } }),
}));
const steamLibrary = { isLoaded: false, owned: new Set<number>() };
vi.mock("@/stores/steamLibrary", () => ({
default: () => ({
get isLoaded() {
return steamLibrary.isLoaded;
},
owns: (appId: number) => steamLibrary.owned.has(appId),
}),
}));
vi.mock("@/stores/roms", () => ({
default: () => ({ update: vi.fn(), removeFromContinuePlaying: vi.fn() }),
}));
@@ -258,6 +267,24 @@ describe("useGameActions: Open in Steam", () => {
expect(opened).toEqual(["steam://run/220"]);
});
it("offers only owned games once a linked library has loaded", () => {
steamLibrary.isLoaded = true;
steamLibrary.owned = new Set([220]);
try {
expect(
useGameActions(() => romFixture({ steam_id: 220 })).canOpenInSteam
.value,
).toBe(true);
expect(
useGameActions(() => romFixture({ steam_id: 400 })).canOpenInSteam
.value,
).toBe(false);
} finally {
steamLibrary.isLoaded = false;
steamLibrary.owned = new Set();
}
});
it.each([null, 0, -5, 1.5])("offers nothing for steam_id %s", (steamId) => {
const actions = useGameActions(() => romFixture({ steam_id: steamId }));

View File

@@ -20,6 +20,7 @@ import storeFormatConversions from "@/stores/formatConversions";
import storeHeartbeat from "@/stores/heartbeat";
import storeRoms from "@/stores/roms";
import type { DetailedRom, SimpleRom } from "@/stores/roms";
import useSteamLibrary from "@/stores/steamLibrary";
import { useStreamingStore } from "@/stores/streaming";
import type { Events } from "@/types/emitter";
import type { PlayingStatus } from "@/utils";
@@ -76,6 +77,7 @@ export function useGameActions(
useRomSync();
const auth = storeAuth();
const heartbeat = storeHeartbeat();
const steamLibrary = useSteamLibrary();
const canCreateCollection = useCan("collection.create");
const canEditCollection = useCan("collection.edit");
// Write/destructive gates, mirroring the backend grants. Surfaces that
@@ -326,7 +328,13 @@ export function useGameActions(
);
});
const canOpenInSteam = computed(() => isSteamAppId(getRom()?.steam_id));
// Once a linked account's library has loaded, only games it owns open in
// Steam; without one, ownership is unknown and every Steam game qualifies.
const canOpenInSteam = computed(() => {
const appId = getRom()?.steam_id;
if (!isSteamAppId(appId)) return false;
return !steamLibrary.isLoaded || steamLibrary.owns(appId);
});
// Launching a game the user deliberately shelved asks first. `retired` /
// `never_playing` encode an opt-in "don't play" intent; the prompt is

View File

@@ -23,6 +23,10 @@ const useSteamLibrary = defineStore("steamLibrary", () => {
);
const count = computed(() => ownedAppIds.value.size);
function owns(appId: number): boolean {
return ownedAppIds.value.has(appId);
}
// Only the newest request may write, so a slow earlier reply can't win.
let latestRequest = 0;
@@ -71,7 +75,7 @@ const useSteamLibrary = defineStore("steamLibrary", () => {
{ connect: false },
);
return { isLoaded, count, load };
return { isLoaded, count, owns, load };
});
export default useSteamLibrary;