Skip to content

Commit 059fce0

Browse files
committed
Add support for passing parameters via protocol
The new `arg` parameter can be used (multiple times if necessary) to specify extra parameters to pass to runners/the game
1 parent a884a64 commit 059fce0

File tree

11 files changed

+32
-14
lines changed

11 files changed

+32
-14
lines changed

src/backend/launcher.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ const launchEventCallback: (args: LaunchParams) => StatusPromise = async ({
101101
appName,
102102
launchArguments,
103103
runner,
104-
skipVersionCheck
104+
skipVersionCheck,
105+
args
105106
}) => {
106107
const game = gameManagerMap[runner].getGameInfo(appName)
107108
const gameSettings = await gameManagerMap[runner].getSettings(appName)
@@ -203,6 +204,7 @@ const launchEventCallback: (args: LaunchParams) => StatusPromise = async ({
203204
const command = gameManagerMap[runner].launch(
204205
appName,
205206
launchArguments,
207+
args,
206208
skipVersionCheck
207209
)
208210

src/backend/protocol.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function handlePing(url: URL) {
3535
async function handleLaunch(url: URL) {
3636
let appName
3737
let runnerStr
38+
let args: string[] = []
3839

3940
if (url.pathname) {
4041
// Old-style pathname URLs:
@@ -48,6 +49,7 @@ async function handleLaunch(url: URL) {
4849
// `heroic://launch?appName=Quail&runner=legendary&arg=foo&arg=bar`
4950
appName = url.searchParams.get('appName')
5051
runnerStr = url.searchParams.get('runner')
52+
args = url.searchParams.getAll('arg')
5153
}
5254

5355
if (!appName) {
@@ -75,7 +77,8 @@ async function handleLaunch(url: URL) {
7577
return launchEventCallback({
7678
appName: appName,
7779
runner: gameInfo.runner,
78-
skipVersionCheck: settings.ignoreGameUpdates
80+
skipVersionCheck: settings.ignoreGameUpdates,
81+
args
7982
})
8083
}
8184

src/backend/storeManagers/gog/games.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,8 @@ export async function removeShortcuts(appName: string) {
485485

486486
export async function launch(
487487
appName: string,
488-
launchArguments?: LaunchOption
488+
launchArguments?: LaunchOption,
489+
args: string[] = []
489490
): Promise<boolean> {
490491
const gameSettings = await getSettings(appName)
491492
const gameInfo = getGameInfo(appName)
@@ -600,7 +601,8 @@ export async function launch(
600601
...shlex.split(
601602
(launchArguments as BaseLaunchOption | undefined)?.parameters ?? ''
602603
),
603-
...shlex.split(gameSettings.launcherArgs ?? '')
604+
...shlex.split(gameSettings.launcherArgs ?? ''),
605+
...args
604606
]
605607

606608
if (gameInfo.install.cyberpunk?.modsEnabled) {

src/backend/storeManagers/legendary/games.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ export async function syncSaves(
838838
export async function launch(
839839
appName: string,
840840
launchArguments?: LaunchOption,
841+
args: string[] = [],
841842
skipVersionCheck = false
842843
): Promise<boolean> {
843844
const gameSettings = await getSettings(appName)
@@ -929,6 +930,7 @@ export async function launch(
929930
subcommand: 'launch',
930931
appName: LegendaryAppName.parse(appNameToLaunch),
931932
extraArguments: [
933+
...args,
932934
launchArguments?.type !== 'dlc' ? launchArguments?.parameters : undefined,
933935
gameSettings.launcherArgs
934936
]

src/backend/storeManagers/nile/games.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ export async function removeShortcuts(appName: string) {
310310

311311
export async function launch(
312312
appName: string,
313-
launchArguments?: LaunchOption
313+
launchArguments?: LaunchOption,
314+
args: string[] = []
314315
): Promise<boolean> {
315316
const gameSettings = await getSettings(appName)
316317
const gameInfo = getGameInfo(appName)
@@ -407,7 +408,8 @@ export async function launch(
407408
(launchArguments as BaseLaunchOption | undefined)?.parameters ?? ''
408409
),
409410
...shlex.split(gameSettings.launcherArgs ?? ''),
410-
appName
411+
appName,
412+
...args
411413
]
412414
const fullCommand = getRunnerCallWithoutCredentials(
413415
commandParts,

src/backend/storeManagers/sideload/games.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ export async function isGameAvailable(appName: string): Promise<boolean> {
6868

6969
export async function launch(
7070
appName: string,
71-
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
72-
launchArguments?: LaunchOption
71+
launchArguments?: LaunchOption,
72+
args: string[] = []
7373
): Promise<boolean> {
74-
return launchGame(appName, getGameInfo(appName), 'sideload')
74+
return launchGame(appName, getGameInfo(appName), 'sideload', args)
7575
}
7676

7777
export async function stop(appName: string): Promise<void> {

src/backend/storeManagers/storeManagerCommon/games.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ const openNewBrowserGameWindow = async ({
120120
export async function launchGame(
121121
appName: string,
122122
gameInfo: GameInfo,
123-
runner: Runner
123+
runner: Runner,
124+
args: string[] = []
124125
): Promise<boolean> {
125126
if (!gameInfo) {
126127
return false
@@ -151,7 +152,7 @@ export async function launchGame(
151152

152153
const gameSettings = await getAppSettings(appName)
153154
const { launcherArgs } = gameSettings
154-
const extraArgs = shlex.split(launcherArgs ?? '')
155+
const extraArgs = [...shlex.split(launcherArgs ?? ''), ...args]
155156
const extraArgsJoined = extraArgs.join(' ')
156157

157158
if (executable) {

src/common/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export type LaunchParams = {
2929
launchArguments?: LaunchOption
3030
runner: Runner
3131
skipVersionCheck?: boolean
32+
args?: string[]
3233
}
3334

3435
export type LaunchOption = BaseLaunchOption | DLCLaunchOption

src/common/types/frontend_messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type FrontendMessages = {
3434
status: ConnectivityStatus
3535
retryIn: number
3636
}) => void
37-
launchGame: (appName: string, runner: Runner) => void
37+
launchGame: (appName: string, runner: Runner, args: string[]) => void
3838
installGame: (appName: string, runner: Runner) => void
3939
recentGamesChanged: (newRecentGames: RecentGame[]) => void
4040
pushGameToLibrary: (info: GameInfo) => void

src/common/types/game_manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface GameManager {
4343
launch: (
4444
appName: string,
4545
launchArguments?: LaunchOption,
46+
args?: string[],
4647
skipVersionCheck?: boolean
4748
) => Promise<boolean>
4849
moveInstall: (

0 commit comments

Comments
 (0)