fix(plugin): poll-based game detection via Python backend, remove broken SteamClient events

This commit is contained in:
2026-06-28 21:25:57 +08:00
parent 0c44b39e9e
commit 9b6b37f8a4
3 changed files with 80 additions and 62 deletions
+37 -1
View File
@@ -1,6 +1,6 @@
import { useState, useEffect, useCallback, useRef } from "react"
import type { DeckyVaultImportV1, HardwareSlug } from "@deckyvault/shared"
import { getSettings, setSetting } from "./api"
import { getSettings, setSetting, detectCurrentGame } from "./api"
// ── Types ───────────────────────────────────────────────────────
@@ -195,6 +195,42 @@ export function useSession() {
}
}
// ── Game Detection Hook ──────────────────────────────────────────
// Polls the Python backend to detect the currently running game.
// Falls back to manual input if no game is detected.
export function useGameDetection(
setGameName: (name: string, appId?: number) => void,
recordingState: RecordingState,
) {
const [detecting, setDetecting] = useState(false)
const lastDetectedRef = useRef<string>("")
useEffect(() => {
// Don't poll while recording (user is already in-game)
if (recordingState !== "idle") return
const interval = setInterval(async () => {
try {
setDetecting(true)
const result = await detectCurrentGame()
if (result.name && result.name !== lastDetectedRef.current) {
lastDetectedRef.current = result.name
setGameName(result.name, result.appId ?? undefined)
}
} catch {
// Silently retry
} finally {
setDetecting(false)
}
}, 3000)
return () => clearInterval(interval)
}, [recordingState, setGameName])
return { detecting }
}
// ── Payload Builder ─────────────────────────────────────────────
export function buildImportPayload(sess: SessionData): DeckyVaultImportV1 {