diff options
| author | xXJSONDeruloXx <danielhimebauch@gmail.com> | 2026-09-11 13:47:52 -0400 |
|---|---|---|
| committer | xXJSONDeruloXx <danielhimebauch@gmail.com> | 2026-09-11 13:47:52 -0400 |
| commit | f3074fbe1427411dc3b5597d2e87918383299e3f (patch) | |
| tree | bf96f3d6f3942327a8a6541b8a7d7a18906a748e /src/utils | |
| parent | d1990a2b630f7161342a9c854bce0fcf7a967a8d (diff) | |
| download | decky-lsfg-vk-f3074fbe1427411dc3b5597d2e87918383299e3f.tar.gz decky-lsfg-vk-f3074fbe1427411dc3b5597d2e87918383299e3f.zip | |
feat: non steam tab, faster bulk actions
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/gameTargets.ts | 75 | ||||
| -rw-r--r-- | src/utils/nowPlaying.ts | 18 |
2 files changed, 89 insertions, 4 deletions
diff --git a/src/utils/gameTargets.ts b/src/utils/gameTargets.ts new file mode 100644 index 0000000..8922e98 --- /dev/null +++ b/src/utils/gameTargets.ts @@ -0,0 +1,75 @@ +import type { GameConfigEntry, InstalledGame, WorkaroundApp } from "../api/lsfgApi"; + +export type GameSource = "steam" | "nonSteam" | "unknown"; +export type KnownGameSource = Exclude<GameSource, "unknown">; + +export interface GameTarget extends InstalledGame { + configured: boolean; + source: GameSource; +} + +export function sourceFromNonSteam(nonSteam: boolean): KnownGameSource { + return nonSteam ? "nonSteam" : "steam"; +} + +export function getTargetSource( + appid: string, + installedGames: InstalledGame[], + workaroundApps: WorkaroundApp[], +): GameSource { + const workaround = workaroundApps.find((item) => item.appid === appid); + if (workaround) return sourceFromNonSteam(workaround.non_steam); + + const installed = installedGames.find((game) => game.appid === appid); + return installed ? sourceFromNonSteam(installed.nonSteam) : "unknown"; +} + +export function mergeGameTargets( + configs: GameConfigEntry[], + installedGames: InstalledGame[], + workaroundApps: WorkaroundApp[], + runningGame: GameTarget | null = null, +): GameTarget[] { + const configuredIds = new Set(configs.map((game) => game.appid)); + const targets = installedGames.map((game) => { + const source = getTargetSource(game.appid, installedGames, workaroundApps); + return { + ...game, + nonSteam: source === "nonSteam", + source, + configured: configuredIds.has(game.appid), + }; + }); + + for (const game of configs) { + if (targets.some((target) => target.appid === game.appid)) continue; + const source = getTargetSource(game.appid, installedGames, workaroundApps); + targets.push({ + appid: game.appid, + name: game.profile || `App ${game.appid}`, + nonSteam: source === "nonSteam", + source, + configured: true, + }); + } + + if ( + runningGame + && !targets.some((target) => target.appid === runningGame.appid) + && (runningGame.configured || runningGame.source !== "unknown") + ) { + targets.unshift(runningGame); + } + + return targets; +} + +export function targetsForSource(targets: GameTarget[], source: KnownGameSource): GameTarget[] { + return targets.filter((target) => target.source === source || (target.source === "unknown" && target.configured)); +} + +export function sourceLabel(source: GameSource): string { + if (source === "nonSteam") return "Non-Steam"; + if (source === "steam") return "Steam"; + return "Unknown source"; +} diff --git a/src/utils/nowPlaying.ts b/src/utils/nowPlaying.ts index 380c9f5..a307f5c 100644 --- a/src/utils/nowPlaying.ts +++ b/src/utils/nowPlaying.ts @@ -1,5 +1,5 @@ import type { FlatpakApp, RunningFlatpakApp } from "../api/lsfgApi"; -import type { GameTarget } from "../hooks/useGameConfiguration"; +import type { GameTarget } from "./gameTargets"; export type NowPlayingTarget = | { @@ -10,6 +10,10 @@ export type NowPlayingTarget = | { kind: "steam"; game: GameTarget; + } + | { + kind: "nonSteam"; + game: GameTarget; }; function numericValue(value: number | null | undefined): number { @@ -65,12 +69,18 @@ export function resolveNowPlayingTarget( runningGame: GameTarget | null, runningFlatpak: FlatpakApp | null, ): NowPlayingTarget | null { - if (runningGame && !runningGame.nonSteam) { + if (runningGame?.source === "steam") { return runningGame.configured ? { kind: "steam", game: runningGame } : null; } if (runningFlatpak) { - return { kind: "flatpak", app: runningFlatpak, launcher: runningGame?.nonSteam ? runningGame : null }; + return { + kind: "flatpak", + app: runningFlatpak, + launcher: runningGame?.source === "nonSteam" ? runningGame : null, + }; + } + if (runningGame?.source === "nonSteam" && runningGame.configured) { + return { kind: "nonSteam", game: runningGame }; } - if (runningGame?.configured) return { kind: "steam", game: runningGame }; return null; } |
