fix(plugin): use correct SteamClient.GameSessions.RegisterForAppLifetimeNotifications API for game detection
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+22
-6
@@ -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 {}
|
||||||
Reference in New Issue
Block a user