mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 02:22:44 +01:00
style to my liking
This commit is contained in:
@@ -50,6 +50,11 @@ class PlatformSchema(BaseModel):
|
||||
def display_name(self) -> str:
|
||||
return self.custom_name or self.name
|
||||
|
||||
@computed_field # type: ignore
|
||||
@property
|
||||
def firmware_count(self) -> int:
|
||||
return len(self.firmware)
|
||||
|
||||
@field_validator("firmware")
|
||||
def sort_files(cls, v: list[FirmwareSchema]) -> list[FirmwareSchema]:
|
||||
return sorted(v, key=lambda x: x.file_name)
|
||||
|
||||
@@ -490,13 +490,6 @@ async def _identify_platform(
|
||||
if MetadataSource.GAMELIST in metadata_sources:
|
||||
await meta_gamelist_handler.populate_cache(platform)
|
||||
|
||||
await socket_manager.emit(
|
||||
"scan:scanning_platform",
|
||||
PlatformSchema.model_validate(platform).model_dump(
|
||||
include={"id", "name", "display_name", "slug", "fs_slug", "is_identified"}
|
||||
),
|
||||
)
|
||||
|
||||
# Scanning firmware
|
||||
try:
|
||||
fs_firmware = await fs_firmware_handler.get_firmware(platform.fs_slug)
|
||||
@@ -517,18 +510,20 @@ async def _identify_platform(
|
||||
fs_fw=fs_fw,
|
||||
)
|
||||
|
||||
# Emit a single event per platform with the firmware count
|
||||
if fs_firmware:
|
||||
await socket_manager.emit(
|
||||
"scan:scanning_firmware",
|
||||
{
|
||||
"platform_id": platform.id,
|
||||
"platform_fs_slug": platform.fs_slug,
|
||||
"platform_slug": platform.slug,
|
||||
"platform_display_name": platform.custom_name or platform.name,
|
||||
"firmware_count": len(fs_firmware),
|
||||
},
|
||||
)
|
||||
await socket_manager.emit(
|
||||
"scan:scanning_platform",
|
||||
PlatformSchema.model_validate(platform).model_dump(
|
||||
include={
|
||||
"id",
|
||||
"name",
|
||||
"display_name",
|
||||
"slug",
|
||||
"fs_slug",
|
||||
"is_identified",
|
||||
"firmware_count",
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
# This reduces the number of socket emissions
|
||||
await scan_stats.increment(
|
||||
|
||||
@@ -37,5 +37,6 @@ export type PlatformSchema = {
|
||||
is_identified: boolean;
|
||||
missing_from_fs: boolean;
|
||||
readonly display_name: string;
|
||||
readonly firmware_count: number;
|
||||
};
|
||||
|
||||
|
||||
@@ -22,7 +22,9 @@ const { t } = useI18n();
|
||||
/>
|
||||
</v-avatar>
|
||||
</template>
|
||||
{{ platform.display_name }}
|
||||
<div class="text-no-wrap">
|
||||
{{ platform.display_name }}
|
||||
</div>
|
||||
<template #append>
|
||||
<v-chip class="ml-3" color="primary" size="x-small" label>
|
||||
{{ platform.roms.length }}
|
||||
|
||||
@@ -9,8 +9,7 @@ import socket from "@/services/socket";
|
||||
import storeAuth from "@/stores/auth";
|
||||
import storeNavigation from "@/stores/navigation";
|
||||
import storeRoms, { type SimpleRom } from "@/stores/roms";
|
||||
import storeScanning from "@/stores/scanning";
|
||||
import type { ScanningPlatformFirmwareEvent } from "@/stores/scanning";
|
||||
import storeScanning, { type ScanningPlatform } from "@/stores/scanning";
|
||||
import type { Events } from "@/types/emitter";
|
||||
|
||||
withDefaults(
|
||||
@@ -61,6 +60,7 @@ const processRomUpdates = debounce(() => {
|
||||
// Add the platform if the socket dropped and it's missing
|
||||
if (!scannedPlatform) {
|
||||
scanningPlatforms.value.push({
|
||||
name: rom.platform_display_name,
|
||||
display_name: rom.platform_display_name,
|
||||
slug: rom.platform_slug,
|
||||
id: rom.platform_id,
|
||||
@@ -89,29 +89,26 @@ const processRomUpdates = debounce(() => {
|
||||
socket.on(
|
||||
"scan:scanning_platform",
|
||||
({
|
||||
name,
|
||||
display_name,
|
||||
slug,
|
||||
id,
|
||||
fs_slug,
|
||||
is_identified,
|
||||
}: {
|
||||
display_name: string;
|
||||
slug: string;
|
||||
id: number;
|
||||
fs_slug: string;
|
||||
is_identified: boolean;
|
||||
}) => {
|
||||
firmware_count,
|
||||
}: ScanningPlatform) => {
|
||||
scanningStore.setScanning(true);
|
||||
scanningPlatforms.value = scanningPlatforms.value.filter(
|
||||
(platform) => platform.display_name !== display_name,
|
||||
);
|
||||
scanningPlatforms.value.push({
|
||||
name,
|
||||
display_name,
|
||||
slug,
|
||||
id,
|
||||
fs_slug,
|
||||
roms: [],
|
||||
firmware_count: 0,
|
||||
firmware_count,
|
||||
is_identified,
|
||||
});
|
||||
},
|
||||
@@ -125,33 +122,6 @@ socket.on("scan:scanning_rom", (rom: SimpleRom) => {
|
||||
processRomUpdates();
|
||||
});
|
||||
|
||||
socket.on(
|
||||
"scan:scanning_firmware",
|
||||
(event: ScanningPlatformFirmwareEvent) => {
|
||||
scanningStore.setScanning(true);
|
||||
|
||||
let scannedPlatform = scanningPlatforms.value.find(
|
||||
(p) => p.fs_slug === event.platform_fs_slug,
|
||||
);
|
||||
|
||||
// Add the platform if the socket dropped and it's missing
|
||||
if (!scannedPlatform) {
|
||||
scanningPlatforms.value.push({
|
||||
display_name: event.platform_display_name,
|
||||
slug: event.platform_slug,
|
||||
id: event.platform_id,
|
||||
fs_slug: event.platform_fs_slug,
|
||||
is_identified: true,
|
||||
roms: [],
|
||||
firmware_count: 0,
|
||||
});
|
||||
scannedPlatform = scanningPlatforms.value.at(-1)!;
|
||||
}
|
||||
|
||||
scannedPlatform.firmware_count = event.firmware_count;
|
||||
},
|
||||
);
|
||||
|
||||
socket.on("scan:done", () => {
|
||||
scanningStore.setScanning(false);
|
||||
socket.disconnect();
|
||||
@@ -183,7 +153,6 @@ socket.on("scan:update_stats", (stats: ScanStats) => {
|
||||
onBeforeUnmount(() => {
|
||||
socket.off("scan:scanning_platform");
|
||||
socket.off("scan:scanning_rom");
|
||||
socket.off("scan:scanning_firmware");
|
||||
socket.off("scan:done");
|
||||
socket.off("scan:done_ko");
|
||||
processRomUpdates.cancel();
|
||||
|
||||
@@ -3,17 +3,17 @@ import type { ScanStats } from "@/__generated__";
|
||||
import type { SimpleRom } from "@/stores/roms";
|
||||
import type { Platform } from "./platforms";
|
||||
|
||||
export interface ScanningPlatformFirmwareEvent {
|
||||
platform_id: number;
|
||||
platform_fs_slug: string;
|
||||
platform_slug: string;
|
||||
platform_display_name: string;
|
||||
firmware_count: number;
|
||||
}
|
||||
|
||||
export interface ScanningPlatform extends Partial<Platform> {
|
||||
export interface ScanningPlatform extends Pick<
|
||||
Platform,
|
||||
| "id"
|
||||
| "name"
|
||||
| "display_name"
|
||||
| "slug"
|
||||
| "fs_slug"
|
||||
| "is_identified"
|
||||
| "firmware_count"
|
||||
> {
|
||||
roms: SimpleRom[];
|
||||
firmware_count: number;
|
||||
}
|
||||
|
||||
export default defineStore("scanning", {
|
||||
|
||||
@@ -90,9 +90,9 @@ watch(metadataOptions, (newOptions) => {
|
||||
);
|
||||
});
|
||||
|
||||
// Track which platforms have ROMs or firmware without a deep watch on the entire array.
|
||||
// Track which platforms have ROMs/firmware without a deep watch on the entire array.
|
||||
// The computed returns a stable string that only changes when a platform
|
||||
// transitions from 0→>0 ROMs/firmware (or back), so the watch fires O(n_platforms)
|
||||
// transitions from 0→1+ ROMs/firmware (or back), so the watch fires O(n_platforms)
|
||||
// times rather than O(n_roms) times.
|
||||
const platformsWithRomsKey = computed(() =>
|
||||
scanningPlatforms.value
|
||||
@@ -101,9 +101,7 @@ const platformsWithRomsKey = computed(() =>
|
||||
);
|
||||
watch(platformsWithRomsKey, () => {
|
||||
panels.value = scanningPlatforms.value
|
||||
.map((p, index) =>
|
||||
p.roms.length > 0 || p.firmware_count > 0 ? index : -1,
|
||||
)
|
||||
.map((p, index) => (p.roms.length > 0 || p.firmware_count > 0 ? index : -1))
|
||||
.filter((index) => index !== -1);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user