diff --git a/frontend/src/components/GameActions/GameActionBtn.vue b/frontend/src/components/GameActions/GameActionBtn.vue index 6ea94b56a..9f5312b4f 100644 --- a/frontend/src/components/GameActions/GameActionBtn.vue +++ b/frontend/src/components/GameActions/GameActionBtn.vue @@ -72,6 +72,7 @@ export type GameAction = | "copy-link" | "qr" | "flashpoint" + | "steam" | "favorite" | "collection" | "status" @@ -233,6 +234,16 @@ const preset = computed(() => { active: false, }; } + if (props.action === "steam") { + return { + icon: "mdi-steam", + image: "/assets/scrappers/steam.png", + label: t("rom.open-in-steam"), + activeIcon: null, + onClick: actions.openInSteam, + active: false, + }; + } if (props.action === "favorite") { return { icon: "mdi-heart-outline", diff --git a/frontend/src/components/GameActions/GameActions.vue b/frontend/src/components/GameActions/GameActions.vue index b1b9acb38..1860b4ba4 100644 --- a/frontend/src/components/GameActions/GameActions.vue +++ b/frontend/src/components/GameActions/GameActions.vue @@ -112,6 +112,13 @@ useGridNav(rootEl, { :size="btnSize" variant="surface" /> + { }); }); +describe("GameActionsList: opening in Steam", () => { + it("offers it for a rom matched to a Steam app", () => { + const shown = labels(mountList({ canOpenInSteam: true })); + expect(shown).toContain("rom.open-in-steam"); + }); + + it("hides it otherwise", () => { + const shown = labels(mountList({ canOpenInSteam: false })); + expect(shown).not.toContain("rom.open-in-steam"); + }); +}); + describe("GameActionsList: joining someone else's session", () => { it("renders the join label the composable resolved", () => { const wrapper = mountList({ canJoinStream: true }, "rom.join-session-of"); diff --git a/frontend/src/components/GameActions/GameActionsList.vue b/frontend/src/components/GameActions/GameActionsList.vue index 1ffcbd16b..1e05d74ca 100644 --- a/frontend/src/components/GameActions/GameActionsList.vue +++ b/frontend/src/components/GameActions/GameActionsList.vue @@ -89,6 +89,12 @@ function run(fn: () => void | Promise) { icon="mdi-rocket-launch-outline" @click="run(actions.openInFlashpoint)" /> + diff --git a/frontend/src/composables/useGameActions/index.test.ts b/frontend/src/composables/useGameActions/index.test.ts index b9ca541fa..4922712f4 100644 --- a/frontend/src/composables/useGameActions/index.test.ts +++ b/frontend/src/composables/useGameActions/index.test.ts @@ -238,6 +238,35 @@ describe("useGameActions.canInstallOnDevice", () => { }); }); +describe("useGameActions: Open in Steam", () => { + let opened: string[]; + + beforeEach(() => { + opened = []; + vi.spyOn(HTMLAnchorElement.prototype, "click").mockImplementation(function ( + this: HTMLAnchorElement, + ) { + opened.push(this.href); + }); + }); + + it("launches the matched app through the Steam client", () => { + const actions = useGameActions(() => romFixture({ steam_id: 220 })); + + expect(actions.canOpenInSteam.value).toBe(true); + actions.openInSteam(); + expect(opened).toEqual(["steam://run/220"]); + }); + + it.each([null, 0, -5, 1.5])("offers nothing for steam_id %s", (steamId) => { + const actions = useGameActions(() => romFixture({ steam_id: steamId })); + + expect(actions.canOpenInSteam.value).toBe(false); + actions.openInSteam(); + expect(opened).toEqual([]); + }); +}); + describe("useGameActions.joinStream", () => { beforeEach(() => { streamContainer.value = { host: "http://stream" }; diff --git a/frontend/src/composables/useGameActions/index.ts b/frontend/src/composables/useGameActions/index.ts index 5da22b274..81929a5f4 100644 --- a/frontend/src/composables/useGameActions/index.ts +++ b/frontend/src/composables/useGameActions/index.ts @@ -55,6 +55,10 @@ const pendingFormatDownloads = new Set(); const FLASHPOINT_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; +function isSteamAppId(id: number | null | undefined): id is number { + return Number.isSafeInteger(id) && (id as number) > 0; +} + export function useGameActions( getRom: () => SimpleRom | null | undefined, options: GameActionsOptions = {}, @@ -322,6 +326,8 @@ export function useGameActions( ); }); + const canOpenInSteam = computed(() => isSteamAppId(getRom()?.steam_id)); + // 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). @@ -517,16 +523,26 @@ export function useGameActions( emitter?.emit("showQRCodeDialog", rom); } + function openAppLink(href: string) { + const a = document.createElement("a"); + a.href = href; + document.body.appendChild(a); + a.click(); + a.remove(); + } + // Launch the game in installed Flashpoint function openInFlashpoint() { const rom = getRom(); if (!rom?.flashpoint_id || !FLASHPOINT_ID_RE.test(rom.flashpoint_id)) return; - const a = document.createElement("a"); - a.href = `flashpoint://${rom.flashpoint_id}`; - document.body.appendChild(a); - a.click(); - a.remove(); + openAppLink(`flashpoint://${rom.flashpoint_id}`); + } + + function openInSteam() { + const steamId = getRom()?.steam_id; + if (!isSteamAppId(steamId)) return; + openAppLink(`steam://run/${steamId}`); } // Copies the API download URL (origin + /api/roms/.../content/...) so @@ -639,6 +655,7 @@ export function useGameActions( canShareQR, canInstallOnDevice, canOpenInFlashpoint, + canOpenInSteam, canDownload, downloadFormats, canPlay, @@ -671,6 +688,7 @@ export function useGameActions( shareQR, installOnDevice, openInFlashpoint, + openInSteam, copyDownloadLink, manageCollections, refreshMetadata, diff --git a/frontend/src/locales/bg_BG/rom.json b/frontend/src/locales/bg_BG/rom.json index 5fbdd79c3..e197b0ffe 100644 --- a/frontend/src/locales/bg_BG/rom.json +++ b/frontend/src/locales/bg_BG/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "Обновена {date}", "open-game": "Отвори {name}", "open-in-flashpoint": "Отвори във Flashpoint", + "open-in-steam": "Отвори в Steam", "pdf-toggle-sidebar": "Превключи страничната лента", "physical-game-add-failed": "Неуспешно добавяне на физическата игра", "physical-game-added": "Физическата игра е добавена", diff --git a/frontend/src/locales/cs_CZ/rom.json b/frontend/src/locales/cs_CZ/rom.json index 6a725c0c3..50923a466 100644 --- a/frontend/src/locales/cs_CZ/rom.json +++ b/frontend/src/locales/cs_CZ/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "Aktualizováno {date}", "open-game": "Otevřít {name}", "open-in-flashpoint": "Otevřít ve Flashpointu", + "open-in-steam": "Otevřít ve Steamu", "pdf-toggle-sidebar": "Přepnout postranní panel", "physical-game-add-failed": "Fyzickou hru se nepodařilo přidat", "physical-game-added": "Fyzická hra byla přidána", diff --git a/frontend/src/locales/de_DE/rom.json b/frontend/src/locales/de_DE/rom.json index 11b9dc0e3..1bc67e247 100644 --- a/frontend/src/locales/de_DE/rom.json +++ b/frontend/src/locales/de_DE/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "Aktualisiert {date}", "open-game": "{name} öffnen", "open-in-flashpoint": "In Flashpoint öffnen", + "open-in-steam": "In Steam öffnen", "pdf-toggle-sidebar": "Seitenleiste umschalten", "physical-game-add-failed": "Physisches Spiel konnte nicht hinzugefügt werden", "physical-game-added": "Physisches Spiel hinzugefügt", diff --git a/frontend/src/locales/en_GB/rom.json b/frontend/src/locales/en_GB/rom.json index f47f1fc7f..a64e423a1 100644 --- a/frontend/src/locales/en_GB/rom.json +++ b/frontend/src/locales/en_GB/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "Updated {date}", "open-game": "Open {name}", "open-in-flashpoint": "Open in Flashpoint", + "open-in-steam": "Open in Steam", "pdf-toggle-sidebar": "Toggle sidebar", "physical-game-add-failed": "Failed to add physical game", "physical-game-added": "Physical game added", diff --git a/frontend/src/locales/en_US/rom.json b/frontend/src/locales/en_US/rom.json index 139a7600a..da9cfc948 100644 --- a/frontend/src/locales/en_US/rom.json +++ b/frontend/src/locales/en_US/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "Updated {date}", "open-game": "Open {name}", "open-in-flashpoint": "Open in Flashpoint", + "open-in-steam": "Open in Steam", "pdf-toggle-sidebar": "Toggle sidebar", "physical-game-add-failed": "Failed to add physical game", "physical-game-added": "Physical game added", diff --git a/frontend/src/locales/es_ES/rom.json b/frontend/src/locales/es_ES/rom.json index 5b97f5858..ed6c9a588 100644 --- a/frontend/src/locales/es_ES/rom.json +++ b/frontend/src/locales/es_ES/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "Actualizada {date}", "open-game": "Abrir {name}", "open-in-flashpoint": "Abrir en Flashpoint", + "open-in-steam": "Abrir en Steam", "pdf-toggle-sidebar": "Mostrar/ocultar barra lateral", "physical-game-add-failed": "No se pudo añadir el juego físico", "physical-game-added": "Juego físico añadido", diff --git a/frontend/src/locales/fr_FR/rom.json b/frontend/src/locales/fr_FR/rom.json index 5f1e95e8c..31594385e 100644 --- a/frontend/src/locales/fr_FR/rom.json +++ b/frontend/src/locales/fr_FR/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "Mise à jour le {date}", "open-game": "Ouvrir {name}", "open-in-flashpoint": "Ouvrir dans Flashpoint", + "open-in-steam": "Ouvrir dans Steam", "pdf-toggle-sidebar": "Basculer la barre latérale", "physical-game-add-failed": "Échec de l'ajout du jeu physique", "physical-game-added": "Jeu physique ajouté", diff --git a/frontend/src/locales/hu_HU/rom.json b/frontend/src/locales/hu_HU/rom.json index 8d7be30be..790f96859 100644 --- a/frontend/src/locales/hu_HU/rom.json +++ b/frontend/src/locales/hu_HU/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "Frissítve: {date}", "open-game": "{name} megnyitása", "open-in-flashpoint": "Megnyitás Flashpointban", + "open-in-steam": "Megnyitás Steamben", "pdf-toggle-sidebar": "Oldalsáv ki/be", "physical-game-add-failed": "Nem sikerült hozzáadni a fizikai játékot", "physical-game-added": "Fizikai játék hozzáadva", diff --git a/frontend/src/locales/it_IT/rom.json b/frontend/src/locales/it_IT/rom.json index ebc430b67..1ce960edd 100644 --- a/frontend/src/locales/it_IT/rom.json +++ b/frontend/src/locales/it_IT/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "Aggiornata il {date}", "open-game": "Apri {name}", "open-in-flashpoint": "Apri in Flashpoint", + "open-in-steam": "Apri in Steam", "pdf-toggle-sidebar": "Mostra/nascondi barra laterale", "physical-game-add-failed": "Impossibile aggiungere il gioco fisico", "physical-game-added": "Gioco fisico aggiunto", diff --git a/frontend/src/locales/ja_JP/rom.json b/frontend/src/locales/ja_JP/rom.json index 37745a847..df2acd0f5 100644 --- a/frontend/src/locales/ja_JP/rom.json +++ b/frontend/src/locales/ja_JP/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "更新日 {date}", "open-game": "{name}を開く", "open-in-flashpoint": "Flashpointで開く", + "open-in-steam": "Steamで開く", "pdf-toggle-sidebar": "サイドバーを切り替え", "physical-game-add-failed": "実物のゲームの追加に失敗しました", "physical-game-added": "実物のゲームを追加しました", diff --git a/frontend/src/locales/ko_KR/rom.json b/frontend/src/locales/ko_KR/rom.json index 67e2656cd..ea6e2160e 100644 --- a/frontend/src/locales/ko_KR/rom.json +++ b/frontend/src/locales/ko_KR/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "업데이트: {date}", "open-game": "{name} 열기", "open-in-flashpoint": "Flashpoint에서 열기", + "open-in-steam": "Steam에서 열기", "pdf-toggle-sidebar": "사이드바 전환", "physical-game-add-failed": "실물 게임을 추가하지 못했습니다", "physical-game-added": "실물 게임이 추가되었습니다", diff --git a/frontend/src/locales/pl_PL/rom.json b/frontend/src/locales/pl_PL/rom.json index 7eabd8f0e..76c973fb0 100644 --- a/frontend/src/locales/pl_PL/rom.json +++ b/frontend/src/locales/pl_PL/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "Zaktualizowano {date}", "open-game": "Otwórz {name}", "open-in-flashpoint": "Otwórz w Flashpoint", + "open-in-steam": "Otwórz w Steam", "pdf-toggle-sidebar": "Przełącz pasek boczny", "physical-game-add-failed": "Nie udało się dodać gry fizycznej", "physical-game-added": "Dodano grę fizyczną", diff --git a/frontend/src/locales/pt_BR/rom.json b/frontend/src/locales/pt_BR/rom.json index 982554a44..21ea57c22 100644 --- a/frontend/src/locales/pt_BR/rom.json +++ b/frontend/src/locales/pt_BR/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "Atualizada {date}", "open-game": "Abrir {name}", "open-in-flashpoint": "Abrir no Flashpoint", + "open-in-steam": "Abrir no Steam", "pdf-toggle-sidebar": "Alternar barra lateral", "physical-game-add-failed": "Falha ao adicionar jogo físico", "physical-game-added": "Jogo físico adicionado", diff --git a/frontend/src/locales/ro_RO/rom.json b/frontend/src/locales/ro_RO/rom.json index e49216986..9a39aba9e 100644 --- a/frontend/src/locales/ro_RO/rom.json +++ b/frontend/src/locales/ro_RO/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "Actualizată {date}", "open-game": "Deschide {name}", "open-in-flashpoint": "Deschide în Flashpoint", + "open-in-steam": "Deschide în Steam", "pdf-toggle-sidebar": "Comută bara laterală", "physical-game-add-failed": "Nu s-a putut adăuga jocul fizic", "physical-game-added": "Joc fizic adăugat", diff --git a/frontend/src/locales/ru_RU/rom.json b/frontend/src/locales/ru_RU/rom.json index 558752191..d78de97e5 100644 --- a/frontend/src/locales/ru_RU/rom.json +++ b/frontend/src/locales/ru_RU/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "Обновлено {date}", "open-game": "Открыть {name}", "open-in-flashpoint": "Открыть в Flashpoint", + "open-in-steam": "Открыть в Steam", "pdf-toggle-sidebar": "Переключить боковую панель", "physical-game-add-failed": "Не удалось добавить физическую игру", "physical-game-added": "Физическая игра добавлена", diff --git a/frontend/src/locales/tr_TR/rom.json b/frontend/src/locales/tr_TR/rom.json index a87e51442..43370a73a 100644 --- a/frontend/src/locales/tr_TR/rom.json +++ b/frontend/src/locales/tr_TR/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "{date} tarihinde güncellendi", "open-game": "{name} oyununu aç", "open-in-flashpoint": "Flashpoint'te aç", + "open-in-steam": "Steam'de aç", "pdf-toggle-sidebar": "Kenar çubuğunu aç/kapat", "physical-game-add-failed": "Fiziksel oyun eklenemedi", "physical-game-added": "Fiziksel oyun eklendi", diff --git a/frontend/src/locales/zh_CN/rom.json b/frontend/src/locales/zh_CN/rom.json index 2cd7b1806..a7dfcdc0f 100644 --- a/frontend/src/locales/zh_CN/rom.json +++ b/frontend/src/locales/zh_CN/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "更新于 {date}", "open-game": "打开 {name}", "open-in-flashpoint": "在 Flashpoint 中打开", + "open-in-steam": "在 Steam 中打开", "pdf-toggle-sidebar": "切换侧边栏", "physical-game-add-failed": "添加实体游戏失败", "physical-game-added": "已添加实体游戏", diff --git a/frontend/src/locales/zh_TW/rom.json b/frontend/src/locales/zh_TW/rom.json index 71636f952..e29a7d1d1 100644 --- a/frontend/src/locales/zh_TW/rom.json +++ b/frontend/src/locales/zh_TW/rom.json @@ -289,6 +289,7 @@ "notes-updated-at": "更新於 {date}", "open-game": "開啟 {name}", "open-in-flashpoint": "在 Flashpoint 中開啟", + "open-in-steam": "在 Steam 中開啟", "pdf-toggle-sidebar": "切換側邊欄", "physical-game-add-failed": "新增實體遊戲失敗", "physical-game-added": "已新增實體遊戲",