fix(plugin): poll-based game detection via Python backend, remove broken SteamClient events
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user