diff --git a/frontend/src/composables/useGameActions/index.test.ts b/frontend/src/composables/useGameActions/index.test.ts index 4922712f4..d38d4eda6 100644 --- a/frontend/src/composables/useGameActions/index.test.ts +++ b/frontend/src/composables/useGameActions/index.test.ts @@ -72,6 +72,15 @@ vi.mock("@/stores/auth", () => ({ vi.mock("@/stores/heartbeat", () => ({ default: () => ({ value: { DEVICE_INSTALL: deviceInstall } }), })); +const steamLibrary = { isLoaded: false, owned: new Set() }; +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 })); diff --git a/frontend/src/composables/useGameActions/index.ts b/frontend/src/composables/useGameActions/index.ts index 81929a5f4..eb968c38f 100644 --- a/frontend/src/composables/useGameActions/index.ts +++ b/frontend/src/composables/useGameActions/index.ts @@ -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 diff --git a/frontend/src/stores/steamLibrary.ts b/frontend/src/stores/steamLibrary.ts index 60d8474a8..8433aba34 100644 --- a/frontend/src/stores/steamLibrary.ts +++ b/frontend/src/stores/steamLibrary.ts @@ -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;