diff --git a/backend/endpoints/heartbeat.py b/backend/endpoints/heartbeat.py index bb9eddfb1..bd52ffb66 100644 --- a/backend/endpoints/heartbeat.py +++ b/backend/endpoints/heartbeat.py @@ -172,6 +172,7 @@ async def get_setup_library_info(): Returns: - detected_structure: "A" (roms/{platform}), "B" ({platform}/roms), or None - existing_platforms: list of platform fs_slugs already in filesystem + - platform_game_counts: dict mapping platform fs_slug to game count - supported_platforms: list of all supported platforms with metadata """ @@ -190,12 +191,47 @@ async def get_setup_library_info(): except Exception: existing_platforms = [] + # Count games for each existing platform + platform_game_counts = {} + if detected_structure and existing_platforms: + cnfg = cm.get_config() + for fs_slug in existing_platforms: + try: + # Determine the roms directory based on structure + if detected_structure == "A": + roms_path = os.path.join( + LIBRARY_BASE_PATH, cnfg.ROMS_FOLDER_NAME, fs_slug + ) + else: # Structure B + roms_path = os.path.join( + LIBRARY_BASE_PATH, fs_slug, cnfg.ROMS_FOLDER_NAME + ) + + # Count files and folders in the roms directory + if os.path.exists(roms_path): + items = os.listdir(roms_path) + # Filter out hidden files and system files + game_count = len( + [ + item + for item in items + if not item.startswith(".") + and item not in ["_resources", "_cache"] + ] + ) + platform_game_counts[fs_slug] = game_count + else: + platform_game_counts[fs_slug] = 0 + except Exception: + platform_game_counts[fs_slug] = 0 + # Get all supported platforms with metadata supported_platforms = get_supported_platforms() return { "detected_structure": detected_structure, "existing_platforms": existing_platforms, + "platform_game_counts": platform_game_counts, "supported_platforms": supported_platforms, } diff --git a/backend/handler/filesystem/platforms_handler.py b/backend/handler/filesystem/platforms_handler.py index bd1f1c6d7..66fd33d35 100644 --- a/backend/handler/filesystem/platforms_handler.py +++ b/backend/handler/filesystem/platforms_handler.py @@ -86,9 +86,21 @@ class FSPlatformsHandler(FSHandler): Returns: List of platform slugs. """ + cnfg = cm.get_config() + try: platforms = await self.list_directories(path=self.get_platforms_directory()) except FileNotFoundError as e: raise FolderStructureNotMatchException() from e + # For Structure B, only include directories that have a roms subfolder + if not os.path.exists(cnfg.HIGH_PRIO_STRUCTURE_PATH): + platforms = [ + platform + for platform in platforms + if os.path.exists( + os.path.join(LIBRARY_BASE_PATH, platform, cnfg.ROMS_FOLDER_NAME) + ) + ] + return self._exclude_platforms(platforms) diff --git a/frontend/src/components/Setup/PlatformGroupList.vue b/frontend/src/components/Setup/PlatformGroupList.vue index dd3093bb8..c91b33608 100644 --- a/frontend/src/components/Setup/PlatformGroupList.vue +++ b/frontend/src/components/Setup/PlatformGroupList.vue @@ -9,6 +9,9 @@ const props = defineProps<{ showCheckboxes?: boolean; keyPrefix?: string; baseIndex?: number; + onToggleGroup?: (platforms: Platform[], checked: boolean) => void; + isGroupFullySelected?: (platforms: Platform[]) => boolean; + platformGameCounts?: Record; }>(); const emit = defineEmits<{ @@ -42,18 +45,33 @@ const countSelectedInGroup = (platforms: Platform[]) => { class="bg-transparent" > - {{ groupName }} - ({{ platforms.length }}) - - {{ countSelectedInGroup(platforms) }} selected - + @@ -61,7 +79,6 @@ const countSelectedInGroup = (platforms: Platform[]) => { v-for="platform in platforms" :key="platform.fs_slug" :platform="platform" - :show-rom-count="false" > +