From 5f91eaf91aff56e60d7dd8bf11e24d50a767a743 Mon Sep 17 00:00:00 2001 From: Sam Dornan Date: Tue, 4 Aug 2026 21:39:26 -0500 Subject: [PATCH 1/3] fix(v2): keep Playmatch selectable when providers are set to All The provider selects represent "All" as an empty model, so the Playmatch gate read no IGDB and forced the switch off. It also meant an All-mode group sent an empty `apis` list, which the backend reads as "no sources". Both scan dialogs now expand All-mode groups before gating Playmatch and building the payload, matching what the Scan view already did. The three surfaces had drifted apart because they each carried their own copy of this logic, so it moves to a shared `useScanProviders` composable. Co-Authored-By: Claude Opus 5 --- .../Dialogs/RefreshMetadataDialog.vue | 204 ++----------- .../components/Gallery/ScanPlatformDialog.vue | 200 ++---------- .../useScanProviders/index.test.ts | 157 ++++++++++ .../v2/composables/useScanProviders/index.ts | 289 ++++++++++++++++++ frontend/src/v2/views/Scan.vue | 250 ++------------- 5 files changed, 513 insertions(+), 587 deletions(-) create mode 100644 frontend/src/v2/composables/useScanProviders/index.test.ts create mode 100644 frontend/src/v2/composables/useScanProviders/index.ts diff --git a/frontend/src/v2/components/Dialogs/RefreshMetadataDialog.vue b/frontend/src/v2/components/Dialogs/RefreshMetadataDialog.vue index bc67b9a13..391f68ca3 100644 --- a/frontend/src/v2/components/Dialogs/RefreshMetadataDialog.vue +++ b/frontend/src/v2/components/Dialogs/RefreshMetadataDialog.vue @@ -15,46 +15,18 @@ import { RSwitch, RTooltip, } from "@v2/lib"; -import { useLocalStorage } from "@vueuse/core"; import type { Emitter } from "mitt"; -import { storeToRefs } from "pinia"; import { computed, inject, onBeforeUnmount, ref, watch } from "vue"; import { useI18n } from "vue-i18n"; import socket from "@/services/socket"; -import storeConfig from "@/stores/config"; -import storeHeartbeat, { type MetadataOption } from "@/stores/heartbeat"; import { type SimpleRom } from "@/stores/roms"; import storeScanning from "@/stores/scanning"; import type { Events } from "@/types/emitter"; +import { useScanProviders } from "@/v2/composables/useScanProviders"; import { useSnackbar } from "@/v2/composables/useSnackbar"; defineOptions({ inheritAttrs: false }); -const LOCAL_STORAGE_METADATA_SOURCES_KEY = "scan.metadataSources"; -const LOCAL_STORAGE_LAUNCHBOX_REMOTE_ENABLED_KEY = - "scan.launchboxRemoteEnabled"; -const LOCAL_STORAGE_HASHEOUS_ENABLED_KEY = "scan.hasheousEnabled"; -const LOCAL_STORAGE_PLAYMATCH_ENABLED_KEY = "scan.playmatchEnabled"; - -// Hash-matcher providers — proxies that match files by hash and feed -// IDs into the primary catalogs. Filtered out of the main provider -// select and rendered as switch pills so users don't read them as -// standalone sources. -const HASH_MATCHER_KEYS = ["hasheous", "playmatch"] as const; - -// Provider categorisation — mirrors the Scan view's split so this -// dialog reads as a sibling surface, not a parallel vocabulary. -const GENERAL_PROVIDER_KEYS = new Set([ - "igdb", - "ss", - "moby", - "launchbox", - "flashpoint", - "gamelist", - "libretro", -]); -const SPECIFIC_PROVIDER_KEYS = new Set(["ra", "sgdb", "hltb"]); - const { t } = useI18n(); const emitter = inject>("emitter"); const snackbar = useSnackbar(); @@ -64,138 +36,24 @@ const show = ref(false); // normalise to an array so the scan emit groups by platform without // branching on the input shape. const roms = ref([]); -const heartbeat = storeHeartbeat(); const scanningStore = storeScanning(); -const configStore = storeConfig(); -const { config } = storeToRefs(configStore); -const calculateHashes = computed(() => !config.value.SKIP_HASH_CALCULATION); - -const metadataOptions = computed(() => - heartbeat - .getMetadataOptionsByPriority() - .filter( - (option) => - !(HASH_MATCHER_KEYS as readonly string[]).includes(option.value), - ) - .map((option) => { - const requiresHashes = option.value === "ra"; - const hashingDisabled = !calculateHashes.value; - let disabled = option.disabled; - if (hashingDisabled && requiresHashes) { - disabled = t("scan.requires-hashes", { source: option.name }); - } - const name = option.value === "igdb" ? "IGDB" : option.name; - return { ...option, name, disabled }; - }), -); - -const generalProviders = computed(() => - metadataOptions.value.filter((o) => GENERAL_PROVIDER_KEYS.has(o.value)), -); -const specificProviders = computed(() => - metadataOptions.value.filter((o) => SPECIFIC_PROVIDER_KEYS.has(o.value)), -); - -const storedMetadataSources = useLocalStorage( - LOCAL_STORAGE_METADATA_SOURCES_KEY, - [] as string[], -); -const launchboxRemoteEnabled = useLocalStorage( - LOCAL_STORAGE_LAUNCHBOX_REMOTE_ENABLED_KEY, - true, -); -const hasheousEnabled = useLocalStorage( - LOCAL_STORAGE_HASHEOUS_ENABLED_KEY, - true, -); -const playmatchEnabled = useLocalStorage( - LOCAL_STORAGE_PLAYMATCH_ENABLED_KEY, - true, -); - -const metadataSources = ref([]); -const isLaunchboxSelected = computed(() => - metadataSources.value.some((s) => s.value === "launchbox"), -); - -watch( - [metadataOptions, storedMetadataSources], - ([newOptions, newStoredMetadataSources]) => { - const filteredMetadataSources = newOptions.filter( - (option) => - newStoredMetadataSources.includes(option.value) && !option.disabled, - ); - metadataSources.value = - filteredMetadataSources.length > 0 - ? filteredMetadataSources - : heartbeat - .getEnabledMetadataOptions() - .filter( - (o) => - !(HASH_MATCHER_KEYS as readonly string[]).includes(o.value), - ); - }, - { immediate: true }, -); - -interface HashMatcher { - value: "hasheous" | "playmatch"; - name: string; - logo: string; - /** Reason the switch is forced off — surfaced in the hover tooltip. - * null when the switch is interactable. */ - blockedReason: string | null; - switchEnabled: boolean; -} - -const hashMatchers = computed(() => { - const sources = heartbeat.value.METADATA_SOURCES; - const igdbSelected = metadataSources.value.some((s) => s.value === "igdb"); - const noHashes = !calculateHashes.value; - - const hasheousAdmin = Boolean(sources?.HASHEOUS_API_ENABLED); - const playmatchAdmin = Boolean(sources?.PLAYMATCH_API_ENABLED); - - return [ - { - value: "hasheous", - name: "Hasheous", - logo: "/assets/scrappers/hasheous.png", - blockedReason: !hasheousAdmin - ? t("scan.disabled-by-admin") - : noHashes - ? t("scan.requires-hashes", { source: "Hasheous" }) - : null, - switchEnabled: hasheousAdmin && !noHashes, - }, - { - value: "playmatch", - name: "Playmatch", - logo: "/assets/scrappers/playmatch.png", - blockedReason: !playmatchAdmin - ? t("scan.disabled-by-admin") - : noHashes - ? t("scan.requires-hashes", { source: "Playmatch" }) - : !igdbSelected - ? t("scan.playmatch-requires-igdb") - : null, - switchEnabled: playmatchAdmin && !noHashes && igdbSelected, - }, - ]; -}); - -function setHashMatcher(value: HashMatcher["value"], next: boolean) { - if (value === "hasheous") hasheousEnabled.value = next; - else playmatchEnabled.value = next; -} - -function isHashMatcherOn(matcher: HashMatcher): boolean { - if (!matcher.switchEnabled) return false; - return matcher.value === "hasheous" - ? hasheousEnabled.value - : playmatchEnabled.value; -} +const { + calculateHashes, + generalProviders, + specificProviders, + metadataSources, + effectiveMetadataSources, + generalAllSelected, + specificAllSelected, + isLaunchboxSelected, + launchboxRemoteEnabled, + hashMatchers, + setHashMatcher, + isHashMatcherOn, + buildScanPayload, + persistSelection, +} = useScanProviders(); // Per-ROM scan types — the Scan view's "new platforms" / "quick" // options don't apply to an already-ingested ROM. We keep `update` @@ -280,7 +138,7 @@ function onScan() { if (roms.value.length === 0) return; scanningStore.setScanning(true); - storedMetadataSources.value = metadataSources.value.map((s) => s.value); + persistSelection(); // Group rom ids by platform — the scan socket event accepts one // platform list + one rom-id list, so a selection that spans @@ -305,31 +163,13 @@ function onScan() { if (!socket.connected) socket.connect(); - // Build the apis payload — providers + hasheous (when its switch is - // on; the backend accepts it as a MetadataSource enum value). - // Playmatch has no enum entry; the backend gates it via the separate - // `playmatch_enabled` flag below. - const apis = metadataSources.value.map((s) => s.value); - const hasheousMatcher = hashMatchers.value.find( - (m) => m.value === "hasheous", - ); - if (hasheousMatcher && isHashMatcherOn(hasheousMatcher)) { - apis.push("hasheous"); - } - const playmatchMatcher = hashMatchers.value.find( - (m) => m.value === "playmatch", - ); - + const payload = buildScanPayload(); for (const [platformId, romIds] of byPlatform) { socket.emit("scan", { platforms: [platformId], roms_ids: romIds, type: scanType.value, - apis, - launchbox_remote_enabled: launchboxRemoteEnabled.value, - playmatch_enabled: playmatchMatcher - ? isHashMatcherOn(playmatchMatcher) - : false, + ...payload, }); } @@ -413,6 +253,7 @@ function closeDialog() { chips chip-tone="plain" show-all-option + @update:all-selected="generalAllSelected = $event" >