fix(plugin): use correct SteamClient.GameSessions.RegisterForAppLifetimeNotifications API for game detection

This commit is contained in:
2026-06-28 21:21:29 +08:00
parent 83ab7fa1e6
commit 0c44b39e9e
2 changed files with 45 additions and 19 deletions
+22 -12
View File
@@ -40,22 +40,33 @@ function Content() {
setGameName, setGameName,
} = useSession() } = useSession()
const gameStartedUnregRef = useRef<{ unregister: () => void } | null>(null) const gameStartedUnregRef = useRef<{ unregister: () => void } | null>(null)
const gameStoppedUnregRef = useRef<{ unregister: () => void } | null>(null)
// ── Register SteamClient game events ────────────────────────── // ── Register SteamClient game events ──────────────────────────
useEffect(() => { useEffect(() => {
try { try {
// Use RegisterForGameStarted/Stopped — these are the most widely used // Use RegisterForAppLifetimeNotifications — the correct API for
// APIs in Decky plugins despite TypeScript type warnings. // detecting when games start/stop on Steam Deck.
const startedReg = SteamClient.Apps.RegisterForGameStarted((appId: number) => { const reg = SteamClient.GameSessions.RegisterForAppLifetimeNotifications(
onGameStart(appId, `App ${appId}`) (notification: AppLifetimeNotification) => {
}) if (notification.bRunning) {
gameStartedUnregRef.current = startedReg // Game started — try to get the display name from appStore
let gameName = `App ${notification.unAppID}`
const stoppedReg = SteamClient.Apps.RegisterForGameStopped((_appId: number) => { try {
const overview = window.appStore?.GetAppOverviewByAppID(notification.unAppID)
if (overview?.display_name) {
gameName = overview.display_name
}
} catch {
// fallback
}
onGameStart(notification.unAppID, gameName)
} else {
// Game stopped
onGameStop() onGameStop()
}) }
gameStoppedUnregRef.current = stoppedReg },
)
gameStartedUnregRef.current = reg
} catch (e) { } catch (e) {
console.warn("[DeckyVault] SteamClient event registration failed:", e) console.warn("[DeckyVault] SteamClient event registration failed:", e)
} }
@@ -63,7 +74,6 @@ function Content() {
return () => { return () => {
try { try {
gameStartedUnregRef.current?.unregister() gameStartedUnregRef.current?.unregister()
gameStoppedUnregRef.current?.unregister()
} catch { } catch {
// ignore // ignore
} }
+22 -6
View File
@@ -4,13 +4,12 @@
declare global { declare global {
const SteamClient: { const SteamClient: {
GameSessions: {
RegisterForAppLifetimeNotifications: (
callback: (notification: AppLifetimeNotification) => void,
) => { unregister: () => void }
}
Apps: { Apps: {
RegisterForGameStarted: (
callback: (appId: number) => void,
) => { unregister: () => void }
RegisterForGameStopped: (
callback: (appId: number) => void,
) => { unregister: () => void }
RegisterForGameActionStart: ( RegisterForGameActionStart: (
callback: (gameActionId: number, appId: string, action: string, source: number) => void, callback: (gameActionId: number, appId: string, action: string, source: number) => void,
) => { unregister: () => void } ) => { unregister: () => void }
@@ -25,6 +24,23 @@ declare global {
GetUIMode: () => Promise<number> GetUIMode: () => Promise<number>
} }
} }
interface AppLifetimeNotification {
unAppID: number
nInstanceID: number
bRunning: boolean
}
interface Window {
appStore: {
GetAppOverviewByAppID: (appId: number) => SteamAppOverview | null
}
}
interface SteamAppOverview {
appid: number
display_name: string
}
} }
export {} export {}