A games launcher for GOG, Amazon and Epic Games for Linux, Windows and macOS.
TypeScript amazon-primeelectronepic-games-launcherepic-games-storeepic-storegaminggoggog-galaxyheroic-games-launcherlinuxplay-gamesprotonsteamwine
[Feat] Steam Linux Runtime for Steam games (#6176)
Drackrath84b65fc017dc
diff --git a/meta/downloadHelperBinaries.ts b/meta/downloadHelperBinaries.tsindex d0758e2a3..1ce172525 100644--- a/meta/downloadHelperBinaries.ts+++ b/meta/downloadHelperBinaries.ts@@ -32,7 +32,7 @@ const RELEASE_TAGS = {gogdl: 'v1.4.1',nile: 'v1.2.0',comet: 'v0.4.1',- aurelia: 'v0.4.0',+ aurelia: 'v0.4.1','epic-integration': 'v0.4',// butler is distributed via itch.io's broth channel system rather than// GitHub releases; "LATEST" resolves the channel's newest version atdiff --git a/public/locales/en/translation.json b/public/locales/en/translation.jsonindex 4684bf26a..e63c91ea5 100644--- a/public/locales/en/translation.json+++ b/public/locales/en/translation.json@@ -233,6 +233,9 @@"title": "Are you sure you want to quit?"}},+ "steam": {+ "dlcChangeFailed": "Steam could not apply the DLC change for {{ids}} after {{attempts}} attempts. Toggle the DLC again to retry."+ },"title": "Warning","wine-change": {"message": "We could not find the selected wine version to launch this title ({{selectedWine}}). {{newline}} We found another one, do you want to continue launching using {{foundWine}} ?",@@ -689,6 +692,7 @@"advertiseAvxForRosetta": "Enables AVX instruction set support when running windows games through Rosetta on Apple Silicon macs. This may be required for some games like Death Stranding that need AVX support.","amdfsr": "AMD's FSR 1.0 fullscreen hack only works with GE-Proton/TKG under X11. It is not available in Valve Proton or upstream Wine and is incompatible with Wine-Wayland.","analytics": "Enables Heroic to collect 100% anonymous usage data to help improve the application. Needs restart to take effect.",+ "aureliaLinuxRuntime": "Aurelia runs Steam games in the container Steam would use. Pick another runtime, or none to run the game on the host. Applies on the next launch.","backupSaves": "Backups are incremental and stored in the Saves_Backup folder inside your default install path","button": {"close": "Close help",@@ -1233,6 +1237,13 @@"description": "Share anonymous usage data to help improve Heroic"},"analyticsOptIn": "Send anonymous data to help Heroic development",+ "aureliaLinuxRuntime": {+ "auto": "Auto",+ "autoNative": "Auto ({{name}})",+ "host": "no container",+ "label": "Steam Linux Runtime",+ "none": "None (run on host)"+ },"autodxvk": "Auto install/update DXVK on prefix","autodxvk-description": "Translate DirectX 9, 10 and 11 calls to Vulkan for better performance","autodxvknvapi": "Auto install/update DXVK-NVAPI on prefix",@@ -1525,6 +1536,12 @@"start-in-console-mode": "Start in console mode","start-in-console-mode-description": "Open Heroic in the big-picture interface built for controllers","start-in-tray": "Start minimized",+ "steam_linux_runtime": {+ "auto-install": "Download missing Steam Linux Runtimes before launching",+ "auto-install-description": "When off, a game whose runtime is missing runs without it.",+ "enabled": "Run Steam games in the Steam Linux Runtime",+ "enabled-description": "Like Steam: native games use the runtime Steam picks for them, Proton runs in the runtime it requires. Games can override this in their settings."+ },"steamLaunchTarget": {"automatic": "Automatic","downloadBuild": "Download",diff --git a/src/backend/launcher.ts b/src/backend/launcher.tsindex ca4123d0a..906da3d87 100644--- a/src/backend/launcher.ts+++ b/src/backend/launcher.ts@@ -1647,7 +1647,7 @@ async function runWineCommand({options?.logWriters?.forEach((writer) => writer.writeString(data))if (options?.onOutput) {- options.onOutput(data, child)+ options.onOutput(data, child, 'stdout')}stdout.push(data)@@ -1657,7 +1657,7 @@ async function runWineCommand({options?.logWriters?.forEach((writer) => writer.writeString(data))if (options?.onOutput) {- options.onOutput(data, child)+ options.onOutput(data, child, 'stderr')}stderr.push(data)@@ -1852,7 +1852,7 @@ async function callRunner(options?.logWriters?.forEach((writer) => writer.writeString(stringToLog))if (options?.onOutput) {- options.onOutput(data, child)+ options.onOutput(data, child, 'stdout')}stdout.push(options?.fullOutput ? data : data.trim())@@ -1867,7 +1867,7 @@ async function callRunner(options?.logWriters?.forEach((writer) => writer.writeString(stringToLog))if (options?.onOutput) {- options.onOutput(data, child)+ options.onOutput(data, child, 'stderr')}stderr.push(data.trim())diff --git a/src/backend/storeManagers/steam/__tests__/linux_runtime.test.ts b/src/backend/storeManagers/steam/__tests__/linux_runtime.test.tsnew file mode 100644index 000000000..52bebb9dc--- /dev/null+++ b/src/backend/storeManagers/steam/__tests__/linux_runtime.test.ts@@ -0,0 +1,118 @@+import { sendGameStatusUpdate } from 'backend/utils'+import type LogWriter from 'backend/logger/log_writer'+import type { ChildProcess } from 'child_process'+import {+ linuxRuntimeOutputHandler,+ parseLinuxRuntimeEvent,+ withLinuxRuntimeEvents+} from '../linux_runtime'++jest.mock('backend/utils', () => ({ sendGameStatusUpdate: jest.fn() }))+jest.mock('../aurelia', () => ({}))++const applied =+ '{"event":"linux_runtime","name":"Steam Linux Runtime 1.0 (scout)","runtime":"scout","runtime_app_id":1070560,"state":"applied"}'++function writer() {+ return {+ logInfo: jest.fn(async () => {}),+ logWarning: jest.fn(async () => {})+ }+}++describe('parseLinuxRuntimeEvent', () => {+ it('reads an applied event', () => {+ expect(parseLinuxRuntimeEvent(applied)).toMatchObject({+ state: 'applied',+ runtime: 'scout'+ })+ })++ it('ignores other lines', () => {+ expect(parseLinuxRuntimeEvent('{"event":"progress"}')).toBeUndefined()+ expect(parseLinuxRuntimeEvent('Running in "linux_runtime"')).toBeUndefined()+ })+})++describe('linuxRuntimeOutputHandler', () => {+ beforeEach(() => jest.mocked(sendGameStatusUpdate).mockClear())++ it('logs the runtime across split chunks', () => {+ const log = writer()+ const handle = linuxRuntimeOutputHandler('70', log as unknown as LogWriter)+ handle(applied.slice(0, 40))+ expect(log.logInfo).not.toHaveBeenCalled()+ handle(`${applied.slice(40)}\n`)+ expect(log.logInfo).toHaveBeenCalledWith(+ 'Running in Steam Linux Runtime 1.0 (scout)'+ )+ })++ it('keeps stdout out of a stderr line', () => {+ const log = writer()+ const handle = linuxRuntimeOutputHandler('70', log as unknown as LogWriter)+ handle(applied.slice(0, 40), 'stderr')+ handle('game output\n', 'stdout')+ handle(`${applied.slice(40)}\n`, 'stderr')+ expect(log.logInfo).toHaveBeenCalledWith(+ 'Running in Steam Linux Runtime 1.0 (scout)'+ )+ })++ it('shows a download as a pre-launch step', () => {+ const log = writer()+ const handle = linuxRuntimeOutputHandler('70', log as unknown as LogWriter)+ const name = 'Steam Linux Runtime 2.0 (soldier)'+ handle(+ [+ `{"event":"linux_runtime","state":"installing","runtime":"soldier","name":"${name}"}`,+ `{"event":"linux_runtime","state":"progress","runtime":"soldier","name":"${name}","percent":42.4}`,+ `{"event":"linux_runtime","state":"installed","runtime":"soldier","name":"${name}"}`,+ ''+ ].join('\n')+ )+ const updates = jest+ .mocked(sendGameStatusUpdate)+ .mock.calls.map(([update]) => [update.status, update.context])+ expect(updates).toEqual([+ ['redist', name],+ ['redist', `${name} · 42%`],+ ['playing', undefined]+ ])+ })++ it('warns when a download fails', () => {+ const log = writer()+ const handle = linuxRuntimeOutputHandler('70', log as unknown as LogWriter)+ handle(+ '{"event":"linux_runtime","state":"install_failed","runtime":"sniper","name":"SLR 3.0","error":"offline"}\n'+ )+ expect(log.logWarning).toHaveBeenCalledWith(+ 'Could not install SLR 3.0: offline'+ )+ })+})++describe('withLinuxRuntimeEvents', () => {+ const child = {} as ChildProcess++ it('leaves other commands alone', () => {+ const options = { abortId: '70', logWriters: [] }+ expect(withLinuxRuntimeEvents(['install', '70'], options)).toBe(options)+ })++ it('follows play output and keeps the caller handler', () => {+ const log = writer()+ const onOutput = jest.fn()+ const options = withLinuxRuntimeEvents(['play', '70'], {+ abortId: '70',+ logWriters: [log as unknown as LogWriter],+ onOutput+ })+ options.onOutput?.(`${applied}\n`, child, 'stderr')+ expect(log.logInfo).toHaveBeenCalledWith(+ 'Running in Steam Linux Runtime 1.0 (scout)'+ )+ expect(onOutput).toHaveBeenCalledWith(`${applied}\n`, child, 'stderr')+ })+})diff --git a/src/backend/storeManagers/steam/aurelia.ts b/src/backend/storeManagers/steam/aurelia.tsindex ce1edff75..086409c38 100644--- a/src/backend/storeManagers/steam/aurelia.ts+++ b/src/backend/storeManagers/steam/aurelia.ts@@ -12,6 +12,7 @@ import type {AureliaCloudSyncConfigResponse,AureliaConfigShowResponse,AureliaDownloadLimitResponse,+ AureliaFeaturesResponse,AureliaInfoResponse,AureliaLibrariesResponse,AureliaProgressEvent@@ -599,3 +600,23 @@ export async function getSteamInstallLibraries(): Promise<return []}}++/** Features of the Aurelia binary, cached per binary. */+let featureCache: { stamp: string; features: string[] } | undefined++/** Does Aurelia report this capability feature? */+export async function aureliaHasFeature(feature: string): Promise<boolean> {+ const stamp = aureliaBinaryStamp()+ if (featureCache?.stamp !== stamp) {+ try {+ const { features } = await runAurelia<AureliaFeaturesResponse>([+ 'capabilities'+ ])+ featureCache = { stamp, features: features ?? [] }+ } catch (error) {+ logWarning(['Unable to read Aurelia features', error], LogPrefix.Steam)+ return false+ }+ }+ return featureCache.features.includes(feature)+}diff --git a/src/backend/storeManagers/steam/aurelia_types.ts b/src/backend/storeManagers/steam/aurelia_types.tsindex 2d62e0efe..86ae05126 100644--- a/src/backend/storeManagers/steam/aurelia_types.ts+++ b/src/backend/storeManagers/steam/aurelia_types.ts@@ -1,3 +1,5 @@+import type { SteamLinuxRuntimeChoice } from 'common/types/steam'+// Data shapes/** One `{event:"progress"}` line emitted by install/update/verify/move. */@@ -155,6 +157,37 @@ export interface AureliaLaunchOptionsResponse {launch_options: AureliaLaunchOption[]}+/** Result of `aurelia capabilities --json`. */+export interface AureliaFeaturesResponse {+ features?: string[]+}++/** Result of `aurelia config linux-runtime --json`. */+export interface AureliaLinuxRuntimeResponse {+ linux_runtime?: boolean+}++/** Result of `aurelia config linux-runtime-auto-install --json`. */+export interface AureliaLinuxRuntimeAutoInstallResponse {+ linux_runtime_auto_install?: boolean+}++/** Runtime fields of `aurelia config game <app> --json`. */+export interface AureliaGameLinuxRuntimeResponse {+ linux_runtime?: SteamLinuxRuntimeChoice+ linux_runtime_effective?: string+}++/** `linux_runtime` line from `aurelia play --json`. */+export interface AureliaLinuxRuntimeEvent {+ event: 'linux_runtime'+ state: 'installing' | 'progress' | 'installed' | 'install_failed' | 'applied'+ runtime: string+ name: string+ percent?: number+ error?: string+}+/** Result of `aurelia capabilities <command> --json`. */export interface AureliaCapabilitiesResponse {flags?: Array<{ long: string }>diff --git a/src/backend/storeManagers/steam/games.ts b/src/backend/storeManagers/steam/games.tsindex 703e19c5e..20b42b9de 100644--- a/src/backend/storeManagers/steam/games.ts+++ b/src/backend/storeManagers/steam/games.ts@@ -54,6 +54,7 @@ import {makeAureliaProgressHandler,AureliaError} from './aurelia'+import { applySteamLinuxRuntime } from './linux_runtime'import {aureliaPlatform,describeError,@@ -83,11 +84,15 @@ import type {SteamCloudFile,SteamCloudSyncDirection,SteamCloudSyncStatus,- SteamLaunchTargets+ SteamLaunchTargets,+ SteamPendingDlcChange} from 'common/types/steam'import type LogWriter from 'backend/logger/log_writer'+// Launches before a DLC change stops+const MAX_DLC_ATTEMPTS = 3+/*** Steam game manager.*/@@ -475,24 +480,68 @@ export default class SteamGame implements Game {`Applying ${pending.length} pending Steam DLC change(s) with a Steam restart`,LogPrefix.Steam)- for (const change of pending) {+ // Failed batches retry, then give up+ const remaining: typeof pending = []+ const abandoned: typeof pending = []+ // One Steam restart per direction.+ for (const enable of [false, true]) {+ const ids = pending+ .filter((change) => change.enable === enable)+ .map((change) => change.appId)+ if (!ids.length) {+ continue+ }try {await runAurelia([- change.enable ? 'enable' : 'disable',- change.appId,+ enable ? 'enable' : 'disable',+ ...ids,'--restart-steam'])} catch (error) {logWarning([- `Unable to apply pending DLC change for ${change.appId}`,+ `Unable to apply pending DLC change for ${ids.join(', ')}`,describeError(error)],LogPrefix.Steam)+ for (const change of pending) {+ if (change.enable !== enable) continue+ const attempts = (change.attempts ?? 0) + 1+ if (attempts < MAX_DLC_ATTEMPTS) {+ remaining.push({ ...change, attempts })+ } else {+ abandoned.push(change)+ }+ }}}- configStore.delete('pendingDlc')+ if (abandoned.length) {+ this.reportAbandonedDlcChanges(abandoned)+ }+ if (remaining.length) {+ configStore.set('pendingDlc', remaining)+ } else {+ configStore.delete('pendingDlc')+ }+ }++ /** Warn about DLC changes given up. */+ private reportAbandonedDlcChanges(changes: SteamPendingDlcChange[]): void {+ const ids = changes.map((change) => change.appId).join(', ')+ logWarning(+ `Gave up on DLC change for ${ids} after ${MAX_DLC_ATTEMPTS} attempts`,+ LogPrefix.Steam+ )+ showDialogBoxModalAuto({+ title: t('box.warning.title', 'Warning'),+ message: t(+ 'box.warning.steam.dlcChangeFailed',+ 'Steam could not apply the DLC change for {{ids}} after {{attempts}} attempts. Toggle the DLC again to retry.',+ { ids, attempts: MAX_DLC_ATTEMPTS }+ ),+ type: 'MESSAGE'+ })}/**@@ -681,6 +730,30 @@ export default class SteamGame implements Game {}}+ /** Pass the runtime choice to Aurelia. */+ private async applyLinuxRuntime(+ gameSettings: GameSettings,+ nativeBuild: boolean,+ logWriter: LogWriter+ ): Promise<void> {+ // Proton picks its own runtime+ if (!isLinux || !nativeBuild) return+ const choice = gameSettings.aureliaLinuxRuntime ?? 'auto'+ try {+ const applied = await applySteamLinuxRuntime(this.id, choice)+ if (applied && choice !== 'auto') {+ await logWriter.logInfo(`Steam Linux Runtime: ${choice}`)+ }+ } catch (error) {+ const message = describeError(error)+ logWarning(+ [`Could not set the Steam Linux Runtime for ${this.id}`, message],+ LogPrefix.Steam+ )+ await logWriter.logWarning(`Steam Linux Runtime not applied: ${message}`)+ }+ }+/** Pass the custom prefix to Aurelia. */private async applyPrefix(gameSettings: GameSettings,@@ -1076,6 +1149,11 @@ export default class SteamGame implements Game {logWriter)await this.applyPrefix(gameSettings, logWriter)+ await this.applyLinuxRuntime(+ gameSettings,+ gameInfo.install.platform === 'linux',+ logWriter+ )await this.keepAureliaFromSyncing(logWriter)diff --git a/src/backend/storeManagers/steam/ipc_handler.ts b/src/backend/storeManagers/steam/ipc_handler.tsindex e24f08860..354f89161 100644--- a/src/backend/storeManagers/steam/ipc_handler.ts+++ b/src/backend/storeManagers/steam/ipc_handler.ts@@ -7,6 +7,12 @@ import {setSteamDownloadLimit} from './aurelia'import { describeError } from './utils'+import {+ getSteamLinuxRuntimeSettings,+ setSteamLinuxRuntimeSetting,+ getSteamLinuxRuntime,+ setSteamLinuxRuntime+} from './linux_runtime'import { logError, LogPrefix } from 'backend/logger'addHandler('getSteamUsers', () => SteamUser.getAccounts())@@ -46,6 +52,22 @@ addHandler('setSteamDlcEnabled', async (_e, dlcAppId, enabled) =>libraryManagerMap['steam'].getGame(dlcAppId).setDlcEnabled(dlcAppId, enabled))+addHandler('getSteamLinuxRuntimeSettings', async () =>+ getSteamLinuxRuntimeSettings()+)++addHandler('setSteamLinuxRuntimeSetting', async (_e, key, value) =>+ setSteamLinuxRuntimeSetting(key, value)+)++addHandler('getSteamLinuxRuntime', async (_e, appName) =>+ getSteamLinuxRuntime(appName)+)++addHandler('setSteamLinuxRuntime', async (_e, appName, choice) =>+ setSteamLinuxRuntime(appName, choice)+)+addHandler('getSteamLaunchTargets', async (_e, appName) =>libraryManagerMap['steam'].getGame(appName).getLaunchTargets())diff --git a/src/backend/storeManagers/steam/library.ts b/src/backend/storeManagers/steam/library.tsindex 4919c0272..51956fdfd 100644--- a/src/backend/storeManagers/steam/library.ts+++ b/src/backend/storeManagers/steam/library.ts@@ -49,6 +49,7 @@ import type { SteamInstallLibrary } from 'common/types/steam'import { join } from 'path'import SteamGame from './games'import { dryRunLanguages } from './languages'+import { withLinuxRuntimeEvents } from './linux_runtime'import {notifyRecentGamesChanged,tagRecentGames@@ -91,7 +92,10 @@ export default class SteamLibraryManager implements LibraryManager {commandParts: string[],options?: CallRunnerOptions): Promise<ExecResult> {- return runAureliaCommand(commandParts, options)+ return runAureliaCommand(+ commandParts,+ withLinuxRuntimeEvents(commandParts, options)+ )}async refresh(): Promise<ExecResult | null> {diff --git a/src/backend/storeManagers/steam/linux_runtime.ts b/src/backend/storeManagers/steam/linux_runtime.tsnew file mode 100644index 000000000..548bb6fc5--- /dev/null+++ b/src/backend/storeManagers/steam/linux_runtime.ts@@ -0,0 +1,207 @@+import type LogWriter from 'backend/logger/log_writer'+import { logInfo, logWarning, LogPrefix } from 'backend/logger'+import { sendGameStatusUpdate } from 'backend/utils'+import type { CallRunnerOptions, OutputStream } from 'common/types'+import type {+ SteamLinuxRuntimeChoice,+ SteamLinuxRuntimeGame,+ SteamLinuxRuntimeSettings+} from 'common/types/steam'+import { aureliaHasFeature, runAurelia } from './aurelia'+import type {+ AureliaGameLinuxRuntimeResponse,+ AureliaLinuxRuntimeAutoInstallResponse,+ AureliaLinuxRuntimeEvent,+ AureliaLinuxRuntimeResponse+} from './aurelia_types'++/** Parse one output line as a runtime event. */+export function parseLinuxRuntimeEvent(+ line: string+): AureliaLinuxRuntimeEvent | undefined {+ if (!line.includes('"linux_runtime"')) return undefined+ try {+ const value = JSON.parse(line.trim()) as Partial<AureliaLinuxRuntimeEvent>+ if (value?.event !== 'linux_runtime' || typeof value.name !== 'string') {+ return undefined+ }+ return value as AureliaLinuxRuntimeEvent+ } catch {+ return undefined+ }+}++/**+ * Follows `aurelia play --json` output for Steam Linux Runtime events:+ * logs the runtime in use and shows a runtime download as a pre-launch step.+ */+export function linuxRuntimeOutputHandler(+ appName: string,+ logWriter: LogWriter+): (output: string, stream?: OutputStream) => void {+ // Streams interleave, so buffer separately+ const pending: Record<OutputStream, string> = { stdout: '', stderr: '' }+ const show = (context?: string) =>+ sendGameStatusUpdate({+ appName,+ runner: 'steam',+ status: context === undefined ? 'playing' : 'redist',+ context+ })++ const handle = (event: AureliaLinuxRuntimeEvent) => {+ switch (event.state) {+ case 'applied':+ void logWriter.logInfo(`Running in ${event.name}`)+ break+ case 'installing':+ void logWriter.logInfo(`Installing ${event.name}`)+ show(event.name)+ break+ case 'progress':+ show(+ event.percent === undefined+ ? event.name+ : `${event.name} · ${Math.round(event.percent)}%`+ )+ break+ case 'installed':+ void logWriter.logInfo(`Installed ${event.name}`)+ show()+ break+ case 'install_failed':+ void logWriter.logWarning(+ `Could not install ${event.name}: ${event.error ?? 'unknown error'}`+ )+ show()+ break+ }+ }++ return (output: string, stream: OutputStream = 'stderr') => {+ pending[stream] += output+ const lines = pending[stream].split('\n')+ pending[stream] = lines.pop() ?? ''+ for (const line of lines) {+ const event = parseLinuxRuntimeEvent(line)+ if (event) handle(event)+ }+ }+}++/** Adds runtime events to `play` output. */+export function withLinuxRuntimeEvents(+ commandParts: string[],+ options: CallRunnerOptions = {}+): CallRunnerOptions {+ const { abortId, logWriters, onOutput } = options+ // Play runs use the app id+ if (commandParts[0] !== 'play' || !abortId || !logWriters?.length) {+ return options+ }+ const handleRuntime = linuxRuntimeOutputHandler(abortId, logWriters[0])+ return {+ ...options,+ onOutput: (output, child, stream) => {+ handleRuntime(output, stream)+ onOutput?.(output, child, stream)+ }+ }+}++/** Aurelia's Steam Linux Runtime switches. */+export async function getSteamLinuxRuntimeSettings(): Promise<SteamLinuxRuntimeSettings> {+ const off = { supported: false, enabled: false, autoInstall: false }+ if (!(await aureliaHasFeature('play.linux_runtime'))) return off+ try {+ const [runtime, autoInstall] = await Promise.all([+ runAurelia<AureliaLinuxRuntimeResponse>(['config', 'linux-runtime']),+ runAurelia<AureliaLinuxRuntimeAutoInstallResponse>([+ 'config',+ 'linux-runtime-auto-install'+ ])+ ])+ return {+ supported: true,+ enabled: runtime.linux_runtime ?? true,+ autoInstall: autoInstall.linux_runtime_auto_install ?? true+ }+ } catch (error) {+ logWarning(+ ['Unable to read Steam Linux Runtime settings', error],+ LogPrefix.Steam+ )+ return off+ }+}++/** Set one Steam Linux Runtime switch. */+export async function setSteamLinuxRuntimeSetting(+ key: 'enabled' | 'autoInstall',+ value: boolean+): Promise<SteamLinuxRuntimeSettings> {+ const command =+ key === 'enabled' ? 'linux-runtime' : 'linux-runtime-auto-install'+ await runAurelia(['config', command, value ? 'on' : 'off'])+ logInfo(['Steam Linux Runtime', command, 'set to', value], LogPrefix.Steam)+ return getSteamLinuxRuntimeSettings()+}++/** Read a game's runtime without changing it. */+export async function getSteamLinuxRuntime(+ appId: string+): Promise<SteamLinuxRuntimeGame> {+ if (!(await aureliaHasFeature('play.linux_runtime'))) {+ return { supported: false }+ }+ try {+ const result = await runAurelia<AureliaGameLinuxRuntimeResponse>([+ 'config',+ 'game',+ appId+ ])+ return {+ supported: true,+ choice: result.linux_runtime,+ effective: result.linux_runtime_effective+ }+ } catch (error) {+ logWarning(+ ['Unable to read the Steam Linux Runtime of', appId, error],+ LogPrefix.Steam+ )+ return { supported: true }+ }+}++/** Store a game's choice; return its state. */+export async function setSteamLinuxRuntime(+ appId: string,+ choice: SteamLinuxRuntimeChoice+): Promise<SteamLinuxRuntimeGame> {+ if (!(await aureliaHasFeature('play.linux_runtime'))) {+ return { supported: false }+ }+ const result = await runAurelia<AureliaGameLinuxRuntimeResponse>([+ 'config',+ 'game',+ appId,+ '--linux-runtime',+ choice+ ])+ return {+ supported: true,+ choice: result.linux_runtime,+ effective: result.linux_runtime_effective+ }+}++/** Push a game's runtime choice to Aurelia. */+export async function applySteamLinuxRuntime(+ appId: string,+ choice: SteamLinuxRuntimeChoice+): Promise<boolean> {+ if (!(await aureliaHasFeature('play.linux_runtime'))) return false+ await runAurelia(['config', 'game', appId, '--linux-runtime', choice])+ return true+}diff --git a/src/common/types.ts b/src/common/types.tsindex 9d3e7b08a..1cb741852 100644--- a/src/common/types.ts+++ b/src/common/types.ts@@ -20,7 +20,7 @@ import {ZoomInstalledInfo,ZoomInstallInfo} from './types/zoom'-import { SteamInstallInfo } from './types/steam'+import { SteamInstallInfo, SteamLinuxRuntimeChoice } from './types/steam'import { TitleBarOverlay } from 'electron'import { ChildProcess } from 'child_process'import type { HeroicHowLongToBeatEntry } from 'backend/wiki_game_info/howlongtobeat/utils'@@ -332,6 +332,8 @@ export interface GameSettings {targetExe: stringuseGameMode: booleansteamRuntime: SteamRuntimeName | false+ // Steam games: Aurelia's runtime container+ aureliaLinuxRuntime?: SteamLinuxRuntimeChoice// Steam games: custom compatdata foldersteamPrefix?: stringwineCrossoverBottle: string@@ -576,13 +578,19 @@ export interface RpcClient {destroy(): void}+export type OutputStream = 'stdout' | 'stderr'+export interface CallRunnerOptions {logMessagePrefix?: stringlogWriters?: LogWriter[]logSanitizer?: (line: string) => stringenv?: Record<string, string> | NodeJS.ProcessEnvwrappers?: string[]- onOutput?: (output: string, child: ChildProcess) => void+ onOutput?: (+ output: string,+ child: ChildProcess,+ stream?: OutputStream+ ) => voidabortId?: stringcwd?: stringwaitForChildProcesses?: booleandiff --git a/src/common/types/ipc.ts b/src/common/types/ipc.tsindex 415e95764..c8dc287d4 100644--- a/src/common/types/ipc.ts+++ b/src/common/types/ipc.ts@@ -83,6 +83,9 @@ import type {SteamDLCInfo,SteamInstallLibrary,SteamLaunchTargets,+ SteamLinuxRuntimeChoice,+ SteamLinuxRuntimeGame,+ SteamLinuxRuntimeSettings,SteamLoginData} from './steam'import { ParsedProtonShorctut } from './proton_shorctuts'@@ -276,6 +279,16 @@ interface AsyncIPCFunctions {setSteamDownloadLimit: (kbit: number) => Promise<number>focusGameWindow: () => Promise<void>setSteamDlcEnabled: (dlcAppId: string, enabled: boolean) => Promise<void>+ getSteamLinuxRuntimeSettings: () => Promise<SteamLinuxRuntimeSettings>+ setSteamLinuxRuntimeSetting: (+ key: 'enabled' | 'autoInstall',+ value: boolean+ ) => Promise<SteamLinuxRuntimeSettings>+ getSteamLinuxRuntime: (appName: string) => Promise<SteamLinuxRuntimeGame>+ setSteamLinuxRuntime: (+ appName: string,+ choice: SteamLinuxRuntimeChoice+ ) => Promise<SteamLinuxRuntimeGame>getSteamLaunchTargets: (appName: string) => Promise<SteamLaunchTargets>setSteamLaunchTarget: (appName: string, targetId: string) => voidinstallSteamWineRuntime: () => Promise<{diff --git a/src/common/types/steam.ts b/src/common/types/steam.tsindex 285555a94..564c74f49 100644--- a/src/common/types/steam.ts+++ b/src/common/types/steam.ts@@ -24,6 +24,8 @@ export interface SteamDLCInfo {export interface SteamPendingDlcChange {appId: stringenable: boolean+ // Failed apply attempts so far+ attempts?: number}/** An installed build plus how Steam runs alongside it. */@@ -136,3 +138,28 @@ export interface SteamDataFetchFailure {/** Aurelia reported no login. */authRequired: boolean}++/** Steam Linux Runtime for one Steam game. */+export type SteamLinuxRuntimeChoice =+ | 'auto'+ | 'none'+ | 'scout'+ | 'soldier'+ | 'sniper'+ | 'steamrt4'++/** One game's runtime as Aurelia stores it. */+export interface SteamLinuxRuntimeGame {+ supported: boolean+ choice?: SteamLinuxRuntimeChoice+ // Runtime a native launch uses+ effective?: string+}++/** Aurelia's global Steam Linux Runtime switches. */+export interface SteamLinuxRuntimeSettings {+ // Aurelia supports runtime containers+ supported: boolean+ enabled: boolean+ autoInstall: boolean+}diff --git a/src/frontend/screens/Settings/components/AureliaLinuxRuntime.tsx b/src/frontend/screens/Settings/components/AureliaLinuxRuntime.tsxnew file mode 100644index 000000000..a4d0838ba--- /dev/null+++ b/src/frontend/screens/Settings/components/AureliaLinuxRuntime.tsx@@ -0,0 +1,103 @@+import { useContext, useEffect, useState } from 'react'+import { useTranslation } from 'react-i18next'+import { SelectField } from 'frontend/components/UI'+import useSetting from 'frontend/hooks/useSetting'+import ContextProvider from 'frontend/state/ContextProvider'+import SettingsContext from '../SettingsContext'+import { MenuItem } from '@mui/material'+import type {+ SteamLinuxRuntimeChoice,+ SteamLinuxRuntimeGame+} from 'common/types/steam'++// Names as they appear in the Steam client+const RUNTIME_NAMES: Record<string, string> = {+ scout: 'Steam Linux Runtime 1.0 (scout)',+ soldier: 'Steam Linux Runtime 2.0 (soldier)',+ sniper: 'Steam Linux Runtime 3.0 (sniper)',+ steamrt4: 'Steam Linux Runtime 4.0'+}++const CHOICES: SteamLinuxRuntimeChoice[] = [+ 'auto',+ 'none',+ 'scout',+ 'soldier',+ 'sniper',+ 'steamrt4'+]++/** Steam games: Aurelia's runtime container. */+function AureliaLinuxRuntime() {+ const { t } = useTranslation()+ const { platform } = useContext(ContextProvider)+ const { isDefault, isLinuxNative, runner, appName } =+ useContext(SettingsContext)+ const [choice, setChoice] = useSetting('aureliaLinuxRuntime', 'auto')+ // Aurelia's stored state, read once+ const [stored, setStored] = useState<SteamLinuxRuntimeGame>()++ // Only native builds use these+ const shown =+ platform === 'linux' && !isDefault && runner === 'steam' && isLinuxNative++ useEffect(() => {+ if (!shown) return+ void window.api.getSteamLinuxRuntime(appName).then(setStored)+ }, [shown, appName])++ if (!shown || stored?.supported === false) {+ return <></>+ }++ const change = async (value: SteamLinuxRuntimeChoice) => {+ setChoice(value)+ try {+ setStored(await window.api.setSteamLinuxRuntime(appName, value))+ } catch (error) {+ window.api.logError(+ `Could not set the Steam Linux Runtime: ${String(error)}`+ )+ }+ }++ // Auto's pick, if Aurelia stores auto+ const autoPick = stored?.choice === 'auto' ? stored.effective : undefined+ const autoName =+ autoPick === 'none'+ ? t('setting.aureliaLinuxRuntime.host', 'no container')+ : autoPick && (RUNTIME_NAMES[autoPick] ?? autoPick)+ const autoLabel =+ choice === 'auto' && autoName+ ? t('setting.aureliaLinuxRuntime.autoNative', 'Auto ({{name}})', {+ name: autoName+ })+ : t('setting.aureliaLinuxRuntime.auto', 'Auto')++ return (+ <SelectField+ htmlId="aureliaLinuxRuntime"+ label={t('setting.aureliaLinuxRuntime.label', 'Steam Linux Runtime')}+ info={t(+ 'help.aureliaLinuxRuntime',+ 'Aurelia runs Steam games in the container Steam would use. Pick another runtime, or none to run the game on the host. Applies on the next launch.'+ )}+ onChange={(event) =>+ void change(event.target.value as SteamLinuxRuntimeChoice)+ }+ value={CHOICES.includes(choice) ? choice : 'auto'}+ >+ {CHOICES.map((id) => (+ <MenuItem key={id} value={id}>+ {id === 'auto'+ ? autoLabel+ : id === 'none'+ ? t('setting.aureliaLinuxRuntime.none', 'None (run on host)')+ : RUNTIME_NAMES[id]}+ </MenuItem>+ ))}+ </SelectField>+ )+}++export default AureliaLinuxRuntimediff --git a/src/frontend/screens/Settings/components/SteamLinuxRuntimeSettings.tsx b/src/frontend/screens/Settings/components/SteamLinuxRuntimeSettings.tsxnew file mode 100644index 000000000..414e5fadf--- /dev/null+++ b/src/frontend/screens/Settings/components/SteamLinuxRuntimeSettings.tsx@@ -0,0 +1,70 @@+import { useEffect, useState } from 'react'+import { useTranslation } from 'react-i18next'+import { ToggleSwitch } from 'frontend/components/UI'+import type { SteamLinuxRuntimeSettings as Settings } from 'common/types/steam'++/** Aurelia's global Steam Linux Runtime switches. */+const SteamLinuxRuntimeSettings = () => {+ const { t } = useTranslation()+ const [settings, setSettings] = useState<Settings>()+ const [saving, setSaving] = useState(false)++ useEffect(() => {+ void window.api.getSteamLinuxRuntimeSettings().then(setSettings)+ }, [])++ // Older Aurelia has no runtime support+ if (!settings?.supported) {+ return <></>+ }++ const toggle = async (key: 'enabled' | 'autoInstall') => {+ setSaving(true)+ try {+ setSettings(+ await window.api.setSteamLinuxRuntimeSetting(key, !settings[key])+ )+ } catch (error) {+ window.api.logError(+ `Could not change the Steam Linux Runtime ${key} setting: ${String(error)}`+ )+ } finally {+ setSaving(false)+ }+ }++ return (+ <>+ <ToggleSwitch+ htmlId="steamLinuxRuntime"+ value={settings.enabled}+ disabled={saving}+ handleChange={() => void toggle('enabled')}+ title={t(+ 'setting.steam_linux_runtime.enabled',+ 'Run Steam games in the Steam Linux Runtime'+ )}+ description={t(+ 'setting.steam_linux_runtime.enabled-description',+ 'Like Steam: native games use the runtime Steam picks for them, Proton runs in the runtime it requires. Games can override this in their settings.'+ )}+ />+ <ToggleSwitch+ htmlId="steamLinuxRuntimeAutoInstall"+ value={settings.autoInstall}+ disabled={saving}+ handleChange={() => void toggle('autoInstall')}+ title={t(+ 'setting.steam_linux_runtime.auto-install',+ 'Download missing Steam Linux Runtimes before launching'+ )}+ description={t(+ 'setting.steam_linux_runtime.auto-install-description',+ 'When off, a game whose runtime is missing runs without it.'+ )}+ />+ </>+ )+}++export default SteamLinuxRuntimeSettingsdiff --git a/src/frontend/screens/Settings/components/index.ts b/src/frontend/screens/Settings/components/index.tsindex de9feb3c0..133f8081d 100644--- a/src/frontend/screens/Settings/components/index.ts+++ b/src/frontend/screens/Settings/components/index.ts@@ -67,6 +67,8 @@ export { default as Shortcuts } from './Shortcuts'export { default as StartInConsoleMode } from './StartInConsoleMode'export { default as ShowFPS } from './ShowFPS'export { default as SteamRuntime } from './SteamRuntime'+export { default as AureliaLinuxRuntime } from './AureliaLinuxRuntime'+export { default as SteamLinuxRuntimeSettings } from './SteamLinuxRuntimeSettings'export { default as SteamLaunchTarget } from './SteamLaunchTarget'export { default as TraySettings } from './TraySettings'export { default as UseDarkTrayIcon } from './UseDarkTrayIcon'diff --git a/src/frontend/screens/Settings/sections/GamesSettings/index.tsx b/src/frontend/screens/Settings/sections/GamesSettings/index.tsxindex 75ab3abe1..760fb3f43 100644--- a/src/frontend/screens/Settings/sections/GamesSettings/index.tsx+++ b/src/frontend/screens/Settings/sections/GamesSettings/index.tsx@@ -33,6 +33,7 @@ import {PreferSystemLibs,ShowFPS,SteamRuntime,+ AureliaLinuxRuntime,SteamLaunchTarget,WinePrefix,WineVersionSelector,@@ -290,6 +291,7 @@ export default function GamesSettings({ initialTab }: Props = {}) {>{isLinux && <PreferSystemLibs />}<SteamRuntime />+ <AureliaLinuxRuntime /></SettingsCard>{showSteamCard && (<SettingsCarddiff --git a/src/frontend/screens/Settings/sections/RunnersSettings/index.tsx b/src/frontend/screens/Settings/sections/RunnersSettings/index.tsxindex 94d85ec96..ba8c94c31 100644--- a/src/frontend/screens/Settings/sections/RunnersSettings/index.tsx+++ b/src/frontend/screens/Settings/sections/RunnersSettings/index.tsx@@ -12,7 +12,8 @@ import {DisableGOGPresence,EgsSettings,LegendaryApiTimeout,- ShowValveProton+ ShowValveProton,+ SteamLinuxRuntimeSettings} from '../../components'export default function RunnersSettings() {@@ -47,6 +48,7 @@ export default function RunnersSettings() {<AltAureliaBin /><DefaultSteamPath />{isLinux && <ShowValveProton />}+ {isLinux && <SteamLinuxRuntimeSettings />}</SettingsCard></div>)diff --git a/src/preload/api/steam.ts b/src/preload/api/steam.tsindex 9c2f6e3f9..904911a06 100644--- a/src/preload/api/steam.ts+++ b/src/preload/api/steam.ts@@ -6,6 +6,10 @@ export const getSteamInstallLibraries = makeHandlerInvoker('getSteamInstallLibraexport const getSteamDownloadLimit = makeHandlerInvoker('getSteamDownloadLimit')export const setSteamDownloadLimit = makeHandlerInvoker('setSteamDownloadLimit')export const setSteamDlcEnabled = makeHandlerInvoker('setSteamDlcEnabled')+export const getSteamLinuxRuntimeSettings = makeHandlerInvoker('getSteamLinuxRuntimeSettings')+export const setSteamLinuxRuntimeSetting = makeHandlerInvoker('setSteamLinuxRuntimeSetting')+export const getSteamLinuxRuntime = makeHandlerInvoker('getSteamLinuxRuntime')+export const setSteamLinuxRuntime = makeHandlerInvoker('setSteamLinuxRuntime')export const getSteamLaunchTargets = makeHandlerInvoker('getSteamLaunchTargets')export const setSteamLaunchTarget = makeHandlerInvoker('setSteamLaunchTarget')export const installSteamWineRuntime = makeHandlerInvoker('installSteamWineRuntime')