fix(plugin): use correct SteamClient API, alwaysRender true, wrap stop in try-catch

This commit is contained in:
2026-06-28 18:51:53 +08:00
parent df66e0405d
commit 80caa167cc
2 changed files with 60 additions and 61 deletions
+56 -53
View File
@@ -42,21 +42,15 @@ function Content() {
// ── Register SteamClient game events ────────────────────────── // ── Register SteamClient game events ──────────────────────────
useEffect(() => { useEffect(() => {
try { try {
const startedReg = SteamClient.Apps.RegisterForGameStarted(async (appId: number) => { const startedReg = SteamClient.Apps.RegisterForGameActionStart(
let gameName = `App ${appId}` (_gameActionId: number, appId: string, _action: string, _source: number) => {
try { const appIdNum = parseInt(appId, 10)
const info = await SteamClient.Apps.GetCurrentGameInfo() onGameStart(appIdNum, `App ${appId}`)
if (info.appId === appId) { },
gameName = info.strAppName )
}
} catch {
// GetCurrentGameInfo may not be available in all contexts
}
onGameStart(appId, gameName)
})
gameStartedUnregRef.current = startedReg gameStartedUnregRef.current = startedReg
const stoppedReg = SteamClient.Apps.RegisterForGameStopped((_appId: number) => { const stoppedReg = SteamClient.Apps.RegisterForGameActionEnd((_gameActionId: number) => {
onGameStop() onGameStop()
}) })
gameStoppedUnregRef.current = stoppedReg gameStoppedUnregRef.current = stoppedReg
@@ -83,49 +77,58 @@ function Content() {
// ── Handle stop recording: parse log + read system info ──────── // ── Handle stop recording: parse log + read system info ────────
async function handleStop() { async function handleStop() {
stopRecording() try {
stopRecording()
// Parse the MangoHud log // Parse the MangoHud log
const logResult = await readAndParseMangohudLog() const logResult = await readAndParseMangohudLog()
if (logResult.error) { if (logResult.error) {
setError(logResult.error) setError(logResult.error)
// Still transition to stopped state so user can see the error + manual fields return
return }
}
// Read system info in parallel // Read system info in parallel
const [hwInfo, osVersion] = await Promise.all([ const [hwInfo, osVersion] = await Promise.all([
getHardwareInfo(), getHardwareInfo(),
getOsVersion(), getOsVersion(),
])
// Read Proton version + launch options if we have an app ID
let protonVersion = ""
let launchOptions = ""
if (session.appId) {
const [pv, lo] = await Promise.all([
getProtonVersion(session.appId),
getLaunchOptions(session.appId),
]) ])
protonVersion = pv
launchOptions = lo // Read Proton version + launch options if we have an app ID
let protonVersion = ""
let launchOptions = ""
const currentAppId = session.appId
if (currentAppId) {
try {
const [pv, lo] = await Promise.all([
getProtonVersion(currentAppId),
getLaunchOptions(currentAppId),
])
protonVersion = pv
launchOptions = lo
} catch {
// Non-critical, continue without
}
}
// Use settings hardware override if set, otherwise auto-detected
const hardwareSlug = settings.hardwareSlug || hwInfo.slug
updateSession({
fpsAvg: logResult.fpsAvg ?? null,
fpsLow: logResult.fpsLow ?? null,
fpsHigh: logResult.fpsHigh ?? null,
fpsOnePercentLow: logResult.fpsOnePercentLow ?? null,
tdpWatts: logResult.tdpWatts ?? null,
hardwareSlug,
hardwareName: hwInfo.name,
osVersion,
protonVersion,
launchOptions,
})
} catch (e) {
console.error("[DeckyVault] Error stopping recording:", e)
setError("Failed to process recording. Check the MangoHud log.")
} }
// Use settings hardware override if set, otherwise auto-detected
const hardwareSlug = settings.hardwareSlug || hwInfo.slug
updateSession({
fpsAvg: logResult.fpsAvg ?? null,
fpsLow: logResult.fpsLow ?? null,
fpsHigh: logResult.fpsHigh ?? null,
fpsOnePercentLow: logResult.fpsOnePercentLow ?? null,
tdpWatts: logResult.tdpWatts ?? null,
hardwareSlug,
hardwareName: hwInfo.name,
osVersion,
protonVersion,
launchOptions,
})
} }
if (!loaded) { if (!loaded) {
@@ -215,7 +218,7 @@ export default definePlugin(() => {
titleView: <div className={staticClasses.Title}>DeckyVault</div>, titleView: <div className={staticClasses.Title}>DeckyVault</div>,
content: <Content />, content: <Content />,
icon: <DeckyVaultIcon />, icon: <DeckyVaultIcon />,
alwaysRender: false, alwaysRender: true,
onDismount() { onDismount() {
console.log("[DeckyVault] Plugin unloading") console.log("[DeckyVault] Plugin unloading")
}, },
+4 -8
View File
@@ -5,16 +5,12 @@
declare global { declare global {
const SteamClient: { const SteamClient: {
Apps: { Apps: {
RegisterForGameStarted: ( RegisterForGameActionStart: (
callback: (appId: number) => void, callback: (gameActionId: number, appId: string, action: string, source: number) => void,
) => { unregister: () => void } ) => { unregister: () => void }
RegisterForGameStopped: ( RegisterForGameActionEnd: (
callback: (appId: number) => void, callback: (gameActionId: number) => void,
) => { unregister: () => void } ) => { unregister: () => void }
GetCurrentGameInfo: () => Promise<{
appId: number
strAppName: string
}>
} }
System: { System: {
GetOSVersion: () => Promise<string> GetOSVersion: () => Promise<string>