From c0b6cd15c484dff8e4fdae281ac6e4a486ddab2c Mon Sep 17 00:00:00 2001 From: Michael Manganiello Date: Mon, 1 Sep 2025 11:29:59 -0300 Subject: [PATCH 1/2] misc: Add PlayBtn component to unify button logic The Play button logic was duplicated in three different places, including when to run either EmulatorJS or Ruffle. This change centralizes that logic in a new `PlayBtn` component, which internally decides which player to use, and binds to any arguments passed to it. Now all three places also consider platform versions when checking for emulation support. --- frontend/src/components/Details/ActionBar.vue | 57 +-------------- .../components/common/Game/Card/ActionBar.vue | 63 ++++------------- .../src/components/common/Game/PlayBtn.vue | 69 +++++++++++++++++++ frontend/src/components/common/Game/Table.vue | 59 +--------------- frontend/src/stores/config.ts | 1 + frontend/src/utils/index.ts | 35 ++++++++-- 6 files changed, 119 insertions(+), 165 deletions(-) create mode 100644 frontend/src/components/common/Game/PlayBtn.vue diff --git a/frontend/src/components/Details/ActionBar.vue b/frontend/src/components/Details/ActionBar.vue index 96360e4f7..088420abf 100644 --- a/frontend/src/components/Details/ActionBar.vue +++ b/frontend/src/components/Details/ActionBar.vue @@ -1,19 +1,13 @@ + + diff --git a/frontend/src/components/common/Game/Table.vue b/frontend/src/components/common/Game/Table.vue index bcf7bded2..af58eae50 100644 --- a/frontend/src/components/common/Game/Table.vue +++ b/frontend/src/components/common/Game/Table.vue @@ -2,22 +2,15 @@ import PlatformIcon from "@/components/common/Platform/Icon.vue"; import AdminMenu from "@/components/common/Game/AdminMenu.vue"; import FavBtn from "@/components/common/Game/FavBtn.vue"; +import PlayBtn from "@/components/common/Game/PlayBtn.vue"; import RAvatarRom from "@/components/common/Game/RAvatar.vue"; import MissingFromFSIcon from "@/components/common/MissingFromFSIcon.vue"; import romApi from "@/services/api/rom"; -import storeConfig from "@/stores/config"; import storeDownload from "@/stores/download"; -import storeHeartbeat from "@/stores/heartbeat"; import storeAuth from "@/stores/auth"; import storeGalleryFilter from "@/stores/galleryFilter"; import storeRoms, { type SimpleRom } from "@/stores/roms"; -import { - formatBytes, - isEJSEmulationSupported, - isRuffleEmulationSupported, - languageToEmoji, - regionToEmoji, -} from "@/utils"; +import { formatBytes, languageToEmoji, regionToEmoji } from "@/utils"; import { ROUTES } from "@/plugins/router"; import { isNull } from "lodash"; import { storeToRefs } from "pinia"; @@ -40,9 +33,6 @@ const downloadStore = storeDownload(); const romsStore = storeRoms(); const { filteredRoms, selectedRoms, fetchingRoms, fetchTotalRoms } = storeToRefs(romsStore); -const heartbeatStore = storeHeartbeat(); -const configStore = storeConfig(); -const { config } = storeToRefs(configStore); const auth = storeAuth(); const galleryFilterStore = storeGalleryFilter(); @@ -104,22 +94,6 @@ function rowClick(_: Event, row: { item: SimpleRom }) { romsStore.resetSelection(); } -function getTruePlatformSlug(platformSlug: string) { - return platformSlug in config.value.PLATFORMS_VERSIONS - ? config.value.PLATFORMS_VERSIONS[platformSlug] - : platformSlug; -} - -function checkIfEJSEmulationSupported(platformSlug: string) { - const slug = getTruePlatformSlug(platformSlug); - return isEJSEmulationSupported(slug, heartbeatStore.value); -} - -function checkIfRuffleEmulationSupported(platformSlug: string) { - const slug = getTruePlatformSlug(platformSlug); - return isRuffleEmulationSupported(slug, heartbeatStore.value); -} - function updateSelectAll() { if (selectedRoms.value.length === filteredRoms.value.length) { romsStore.resetSelection(); @@ -319,34 +293,7 @@ function updateOptions({ sortBy }: { sortBy: SortBy }) { > mdi-download - - mdi-play - - - mdi-play - + 0 && - gl instanceof WebGLRenderingContext + getSupportedEJSCores(slug).length > 0 && gl instanceof WebGLRenderingContext ); } @@ -521,15 +525,36 @@ export function getControlSchemeForPlatform( * * @param platformSlug The platform slug. * @param heartbeat The heartbeat object. + * @param config Optional configuration object. * @returns True if supported, false otherwise. */ export function isRuffleEmulationSupported( platformSlug: string, heartbeat: Heartbeat, + config?: Config, +) { + if (heartbeat.EMULATION.DISABLE_RUFFLE_RS) return false; + + const slug = config?.PLATFORMS_VERSIONS[platformSlug] || platformSlug; + return ["flash", "browser"].includes(slug.toLowerCase()); +} + +/** + * Check whether any kind of emulation is supported for a given platform. + * + * @param platformSlug The platform slug. + * @param heartbeat The heartbeat object. + * @param config Optional configuration object. + * @returns True if any emulation is supported, false otherwise. + */ +export function isAnyEmulationSupported( + platformSlug: string, + heartbeat: Heartbeat, + config?: Config, ) { return ( - ["flash", "browser"].includes(platformSlug.toLowerCase()) && - !heartbeat.EMULATION.DISABLE_RUFFLE_RS + isEJSEmulationSupported(platformSlug, heartbeat, config) || + isRuffleEmulationSupported(platformSlug, heartbeat, config) ); } From 5cc5227f8eb22cb0e2fbf3045cd169a385f50571 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Wed, 3 Sep 2025 18:18:59 -0400 Subject: [PATCH 2/2] define expost isEmulationSupported from playbtn --- .../components/common/Game/Card/ActionBar.vue | 26 +++----- .../src/components/common/Game/PlayBtn.vue | 62 ++++++++++--------- frontend/src/utils/index.ts | 19 ------ 3 files changed, 43 insertions(+), 64 deletions(-) diff --git a/frontend/src/components/common/Game/Card/ActionBar.vue b/frontend/src/components/common/Game/Card/ActionBar.vue index 624305534..b55f1e96b 100644 --- a/frontend/src/components/common/Game/Card/ActionBar.vue +++ b/frontend/src/components/common/Game/Card/ActionBar.vue @@ -1,46 +1,37 @@ diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index 48c906e92..c871ccd11 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -539,25 +539,6 @@ export function isRuffleEmulationSupported( return ["flash", "browser"].includes(slug.toLowerCase()); } -/** - * Check whether any kind of emulation is supported for a given platform. - * - * @param platformSlug The platform slug. - * @param heartbeat The heartbeat object. - * @param config Optional configuration object. - * @returns True if any emulation is supported, false otherwise. - */ -export function isAnyEmulationSupported( - platformSlug: string, - heartbeat: Heartbeat, - config?: Config, -) { - return ( - isEJSEmulationSupported(platformSlug, heartbeat, config) || - isRuffleEmulationSupported(platformSlug, heartbeat, config) - ); -} - type PlayingStatus = RomUserStatus | "backlogged" | "now_playing" | "hidden"; /**