fix(plugin): auto-detect device via DMI, remove selector, fall back to global
This commit is contained in:
@@ -1,18 +1,17 @@
|
|||||||
import { useEffect, useState, useRef } from "react"
|
import { useEffect, useState, useRef } from "react"
|
||||||
import { PanelSectionRow, DropdownItem, ButtonItem, staticClasses } from "@decky/ui"
|
import { PanelSectionRow, ButtonItem, staticClasses } from "@decky/ui"
|
||||||
import { Router } from "@decky/ui"
|
import { Router } from "@decky/ui"
|
||||||
import {
|
import {
|
||||||
fetchPluginGame,
|
fetchPluginGame,
|
||||||
fetchPluginDevices,
|
|
||||||
setPluginApiBaseUrl,
|
setPluginApiBaseUrl,
|
||||||
type PluginGameResponse,
|
type PluginGameResponse,
|
||||||
type PluginDeviceRow,
|
|
||||||
} from "../lib/plugin-api"
|
} from "../lib/plugin-api"
|
||||||
|
import { getHardwareInfo } from "../lib/api"
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
appId: number
|
appId: number
|
||||||
title: string
|
title: string
|
||||||
hardwareSlug: string | null // detected device
|
hardwareSlug: string | null // detected device (from settings, may be null)
|
||||||
baseUrl: string
|
baseUrl: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,10 +33,9 @@ function openExternalUrl(url: string) {
|
|||||||
|
|
||||||
export default function LibraryAppPanel({ appId, title, hardwareSlug, baseUrl }: Props) {
|
export default function LibraryAppPanel({ appId, title, hardwareSlug, baseUrl }: Props) {
|
||||||
const [data, setData] = useState<PluginGameResponse | null>(null)
|
const [data, setData] = useState<PluginGameResponse | null>(null)
|
||||||
const [devices, setDevices] = useState<PluginDeviceRow[]>([])
|
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [device, setDevice] = useState<string>(hardwareSlug ?? "") // "" = all devices
|
|
||||||
const [fetchError, setFetchError] = useState<string>("")
|
const [fetchError, setFetchError] = useState<string>("")
|
||||||
|
const [detectedSlug, setDetectedSlug] = useState<string | null>(hardwareSlug ?? null)
|
||||||
const reqIdRef = useRef(0)
|
const reqIdRef = useRef(0)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -47,13 +45,23 @@ export default function LibraryAppPanel({ appId, title, hardwareSlug, baseUrl }:
|
|||||||
async function load() {
|
async function load() {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
try {
|
try {
|
||||||
const d = await fetchPluginGame(appId, device || null, 3)
|
// Detect hardware if not set in settings
|
||||||
|
let slug = hardwareSlug ?? null
|
||||||
|
if (!slug) {
|
||||||
|
try {
|
||||||
|
const hw = await getHardwareInfo()
|
||||||
|
if (hw.slug && hw.slug !== "unknown") slug = hw.slug
|
||||||
|
} catch {
|
||||||
|
// Fall back to global
|
||||||
|
}
|
||||||
|
if (!cancelled) setDetectedSlug(slug)
|
||||||
|
}
|
||||||
|
|
||||||
|
const d = await fetchPluginGame(appId, slug, 3)
|
||||||
if (cancelled || id !== reqIdRef.current) return
|
if (cancelled || id !== reqIdRef.current) return
|
||||||
setFetchError(d.error && !d.game ? d.error : "")
|
setFetchError(d.error && !d.game ? d.error : "")
|
||||||
setData(d)
|
setData(d)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
const devs = await fetchPluginDevices(appId)
|
|
||||||
if (!cancelled && id === reqIdRef.current) setDevices(devs)
|
|
||||||
} catch {
|
} catch {
|
||||||
if (!cancelled && id === reqIdRef.current) {
|
if (!cancelled && id === reqIdRef.current) {
|
||||||
setData(null)
|
setData(null)
|
||||||
@@ -64,15 +72,7 @@ export default function LibraryAppPanel({ appId, title, hardwareSlug, baseUrl }:
|
|||||||
}
|
}
|
||||||
load()
|
load()
|
||||||
return () => { cancelled = true }
|
return () => { cancelled = true }
|
||||||
}, [appId, device, baseUrl])
|
}, [appId, baseUrl]) // re-fetch only when app changes
|
||||||
|
|
||||||
const deviceOptions = [
|
|
||||||
{ label: "All devices", data: "" },
|
|
||||||
...(hardwareSlug ? [{ label: `Your device (${hardwareSlug})`, data: hardwareSlug }] : []),
|
|
||||||
...devices
|
|
||||||
.filter((d) => d.slug !== hardwareSlug)
|
|
||||||
.map((d) => ({ label: `${d.name} (${d.count})`, data: d.slug })),
|
|
||||||
]
|
|
||||||
|
|
||||||
const gameUrl = data?.game?.steamAppId
|
const gameUrl = data?.game?.steamAppId
|
||||||
? `${baseUrl}/game/${data.game.steamAppId}`
|
? `${baseUrl}/game/${data.game.steamAppId}`
|
||||||
@@ -81,7 +81,7 @@ export default function LibraryAppPanel({ appId, title, hardwareSlug, baseUrl }:
|
|||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
<PanelSectionRow>
|
<PanelSectionRow>
|
||||||
<div className={staticClasses.Text} style={{ padding: "8px 0", fontSize: "12px", opacity: 0.5, textAlign: "center" }}>
|
<div className={staticClasses.Text} style={{ padding: "8px 16px", fontSize: "12px", opacity: 0.5, textAlign: "center" }}>
|
||||||
DeckyVault loading…
|
DeckyVault loading…
|
||||||
</div>
|
</div>
|
||||||
</PanelSectionRow>
|
</PanelSectionRow>
|
||||||
@@ -91,7 +91,7 @@ export default function LibraryAppPanel({ appId, title, hardwareSlug, baseUrl }:
|
|||||||
if (fetchError) {
|
if (fetchError) {
|
||||||
return (
|
return (
|
||||||
<PanelSectionRow>
|
<PanelSectionRow>
|
||||||
<div className={staticClasses.Text} style={{ fontSize: "12px", padding: "8px 0", opacity: 0.5, color: "#e74c3c", textAlign: "center" }}>
|
<div className={staticClasses.Text} style={{ fontSize: "12px", padding: "8px 16px", opacity: 0.5, color: "#e74c3c", textAlign: "center" }}>
|
||||||
DeckyVault: {fetchError}
|
DeckyVault: {fetchError}
|
||||||
</div>
|
</div>
|
||||||
</PanelSectionRow>
|
</PanelSectionRow>
|
||||||
@@ -101,7 +101,7 @@ export default function LibraryAppPanel({ appId, title, hardwareSlug, baseUrl }:
|
|||||||
if (!data || !data.game) {
|
if (!data || !data.game) {
|
||||||
return (
|
return (
|
||||||
<PanelSectionRow>
|
<PanelSectionRow>
|
||||||
<div className={staticClasses.Text} style={{ fontSize: "12px", padding: "8px 0", opacity: 0.5, textAlign: "center" }}>
|
<div className={staticClasses.Text} style={{ fontSize: "12px", padding: "8px 16px", opacity: 0.5, textAlign: "center" }}>
|
||||||
Not on DeckyVault — <a href={`${baseUrl}/games`}>add it</a>
|
Not on DeckyVault — <a href={`${baseUrl}/games`}>add it</a>
|
||||||
</div>
|
</div>
|
||||||
</PanelSectionRow>
|
</PanelSectionRow>
|
||||||
@@ -110,12 +110,11 @@ export default function LibraryAppPanel({ appId, title, hardwareSlug, baseUrl }:
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Stats + device dropdown — space-between, with padding */}
|
{/* Stats row */}
|
||||||
<PanelSectionRow>
|
<PanelSectionRow>
|
||||||
<div className={staticClasses.Text} style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: "12px", padding: "4px 16px", fontSize: "13px" }}>
|
<div className={staticClasses.Text} style={{ padding: "4px 16px", fontSize: "13px", textAlign: "center" }}>
|
||||||
<span style={{ flex: 1, textAlign: "left" }}>
|
|
||||||
{data.estFps ? (
|
{data.estFps ? (
|
||||||
<span style={{ display: "inline-flex", flexWrap: "wrap", gap: "4px 8px" }}>
|
<span style={{ display: "inline-flex", flexWrap: "wrap", gap: "4px 8px", justifyContent: "center" }}>
|
||||||
<span><strong>{data.estFps.avg}</strong> <span style={{ opacity: 0.4 }}>avg</span></span>
|
<span><strong>{data.estFps.avg}</strong> <span style={{ opacity: 0.4 }}>avg</span></span>
|
||||||
{data.estFps.onePct != null && <span><strong>{data.estFps.onePct}</strong> <span style={{ opacity: 0.4 }}>1% low</span></span>}
|
{data.estFps.onePct != null && <span><strong>{data.estFps.onePct}</strong> <span style={{ opacity: 0.4 }}>1% low</span></span>}
|
||||||
{data.estFps.low != null && <span><strong>{data.estFps.low}</strong> <span style={{ opacity: 0.4 }}>min</span></span>}
|
{data.estFps.low != null && <span><strong>{data.estFps.low}</strong> <span style={{ opacity: 0.4 }}>min</span></span>}
|
||||||
@@ -126,14 +125,6 @@ export default function LibraryAppPanel({ appId, title, hardwareSlug, baseUrl }:
|
|||||||
) : (
|
) : (
|
||||||
<span style={{ opacity: 0.4, fontSize: "12px" }}>No data yet</span>
|
<span style={{ opacity: 0.4, fontSize: "12px" }}>No data yet</span>
|
||||||
)}
|
)}
|
||||||
</span>
|
|
||||||
<span style={{ flexShrink: 0 }}>
|
|
||||||
<DropdownItem
|
|
||||||
rgOptions={deviceOptions}
|
|
||||||
selectedOption={device}
|
|
||||||
onChange={(opt) => setDevice(opt.data as string)}
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</PanelSectionRow>
|
</PanelSectionRow>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user