1
1
/* eslint-disable @typescript-eslint/no-unused-vars */
2
+
3
+ import { dirname , join } from 'node:path'
4
+ import { GlobalConfig } from 'backend/config'
5
+ import { isWindows , steamLogFile , userHome } from 'backend/constants'
6
+
2
7
import { getGameInfo as getSteamLibraryGameInfo } from './library'
3
- import { logError , LogPrefix } from 'backend/logger/logger'
8
+ import { logError , logInfo , LogPrefix , logWarning } from 'backend/logger/logger'
4
9
import {
5
10
GameInfo ,
6
11
GameSettings ,
@@ -13,6 +18,8 @@ import {
13
18
import { existsSync } from 'graceful-fs'
14
19
import { GOGCloudSavesLocation } from 'common/types/gog'
15
20
import { InstallResult , RemoveArgs } from 'common/types/game_manager'
21
+ import { callRunner , setupEnvVars } from 'backend/launcher'
22
+ import { createAbortController } from 'backend/utils/aborthandler/aborthandler'
16
23
17
24
export function getGameInfo ( appName : string ) : GameInfo {
18
25
const info = getSteamLibraryGameInfo ( appName )
@@ -88,8 +95,8 @@ export async function install(
88
95
}
89
96
90
97
export function isNative ( appName : string ) : boolean {
91
- // not used
92
- return false
98
+ // Steam games are considered native if they run on the Steam client
99
+ return true
93
100
}
94
101
95
102
export async function addShortcuts (
@@ -107,8 +114,59 @@ export async function launch(
107
114
appName : string ,
108
115
launchArguments ?: string
109
116
) : Promise < boolean > {
110
- // not used
111
- return false
117
+ const gameInfo = getGameInfo ( appName )
118
+ if ( ! gameInfo || ! gameInfo . is_installed ) {
119
+ logWarning ( `Game ${ appName } is not installed or does not exist` , {
120
+ prefix : LogPrefix . Steam
121
+ } )
122
+ return false
123
+ }
124
+
125
+ const steamBinaryPath = getSteamBinaryPath ( )
126
+ if ( ! existsSync ( steamBinaryPath ) ) {
127
+ logError ( 'Steam binary not found' , { prefix : LogPrefix . Steam } )
128
+ return false
129
+ }
130
+
131
+ const bin = getSteamBinaryPath ( )
132
+ const dir = dirname ( bin )
133
+ const commandParts = [ bin , '-applaunch' , gameInfo . app_name ]
134
+ const gameSettings = await getSettings ( appName )
135
+ const commandEnv = isWindows
136
+ ? process . env
137
+ : { ...process . env , ...setupEnvVars ( gameSettings ) }
138
+ const options = {
139
+ env : {
140
+ ...commandEnv
141
+ } ,
142
+ logMessagePrefix : `Launching ${ gameInfo . title } `
143
+ }
144
+ const abortController = createAbortController ( appName )
145
+
146
+ const { error, abort } = await callRunner (
147
+ [ ...commandParts ] ,
148
+ { name : 'steam' , logPrefix : LogPrefix . Steam , bin, dir } ,
149
+ abortController ,
150
+ {
151
+ ...options ,
152
+ verboseLogFile : steamLogFile
153
+ } ,
154
+ gameInfo
155
+ )
156
+
157
+ if ( error ) {
158
+ logError ( `Failed to launch game ${ appName } : ${ error } ` , {
159
+ prefix : LogPrefix . Steam
160
+ } )
161
+ return false
162
+ }
163
+
164
+ if ( abort ) {
165
+ logWarning ( `Game ${ appName } launch aborted` , { prefix : LogPrefix . Steam } )
166
+ return false
167
+ }
168
+ logInfo ( `Game ${ appName } launched successfully` , { prefix : LogPrefix . Steam } )
169
+ return true
112
170
}
113
171
114
172
export async function moveInstall (
@@ -158,3 +216,33 @@ export async function stop(appName: string): Promise<void> {
158
216
export async function pause ( appName : string ) : Promise < void > {
159
217
// not used
160
218
}
219
+
220
+ function getSteamBinaryPath ( ) : string {
221
+ const { defaultSteamPath } = GlobalConfig . get ( ) . getSettings ( )
222
+ const steamPath = defaultSteamPath . replaceAll ( "'" , '' )
223
+
224
+ if ( process . platform === 'win32' ) {
225
+ return join ( steamPath , 'steam.exe' )
226
+ } else if ( process . platform === 'darwin' ) {
227
+ const steamApp = join ( '/Applications' , 'Steam.app' )
228
+ if ( existsSync ( steamApp ) ) {
229
+ return join ( steamApp , 'Contents' , 'MacOS' , 'steam_osx' )
230
+ }
231
+ } else {
232
+ // For Linux it could be on /usr/bin/steam or in the flatpak path from home/.var/app/com.valvesoftware.Steam/.steam/steam
233
+ const flatpakSteamPath = join (
234
+ userHome ,
235
+ '.var' ,
236
+ 'app' ,
237
+ 'com.valvesoftware.Steam' ,
238
+ '.steam' ,
239
+ 'steam'
240
+ )
241
+
242
+ if ( existsSync ( flatpakSteamPath ) ) {
243
+ return flatpakSteamPath
244
+ }
245
+ return join ( '/usr' , 'bin' , 'steam' )
246
+ }
247
+ return ''
248
+ }
0 commit comments