Skip to content

Commit

Permalink
Add support for passing parameters via protocol
Browse files Browse the repository at this point in the history
The new `arg` parameter can be used (multiple times if necessary) to specify
extra parameters to pass to runners/the game
  • Loading branch information
CommandMC committed Jan 4, 2025
1 parent a884a64 commit 059fce0
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/backend/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ const launchEventCallback: (args: LaunchParams) => StatusPromise = async ({
appName,
launchArguments,
runner,
skipVersionCheck
skipVersionCheck,
args
}) => {
const game = gameManagerMap[runner].getGameInfo(appName)
const gameSettings = await gameManagerMap[runner].getSettings(appName)
Expand Down Expand Up @@ -203,6 +204,7 @@ const launchEventCallback: (args: LaunchParams) => StatusPromise = async ({
const command = gameManagerMap[runner].launch(
appName,
launchArguments,
args,
skipVersionCheck
)

Expand Down
5 changes: 4 additions & 1 deletion src/backend/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function handlePing(url: URL) {
async function handleLaunch(url: URL) {
let appName
let runnerStr
let args: string[] = []

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

if (!appName) {
Expand Down Expand Up @@ -75,7 +77,8 @@ async function handleLaunch(url: URL) {
return launchEventCallback({
appName: appName,
runner: gameInfo.runner,
skipVersionCheck: settings.ignoreGameUpdates
skipVersionCheck: settings.ignoreGameUpdates,
args
})
}

Expand Down
6 changes: 4 additions & 2 deletions src/backend/storeManagers/gog/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ export async function removeShortcuts(appName: string) {

export async function launch(
appName: string,
launchArguments?: LaunchOption
launchArguments?: LaunchOption,
args: string[] = []
): Promise<boolean> {
const gameSettings = await getSettings(appName)
const gameInfo = getGameInfo(appName)
Expand Down Expand Up @@ -600,7 +601,8 @@ export async function launch(
...shlex.split(
(launchArguments as BaseLaunchOption | undefined)?.parameters ?? ''
),
...shlex.split(gameSettings.launcherArgs ?? '')
...shlex.split(gameSettings.launcherArgs ?? ''),
...args
]

if (gameInfo.install.cyberpunk?.modsEnabled) {
Expand Down
2 changes: 2 additions & 0 deletions src/backend/storeManagers/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ export async function syncSaves(
export async function launch(
appName: string,
launchArguments?: LaunchOption,
args: string[] = [],
skipVersionCheck = false
): Promise<boolean> {
const gameSettings = await getSettings(appName)
Expand Down Expand Up @@ -929,6 +930,7 @@ export async function launch(
subcommand: 'launch',
appName: LegendaryAppName.parse(appNameToLaunch),
extraArguments: [
...args,
launchArguments?.type !== 'dlc' ? launchArguments?.parameters : undefined,
gameSettings.launcherArgs
]
Expand Down
6 changes: 4 additions & 2 deletions src/backend/storeManagers/nile/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ export async function removeShortcuts(appName: string) {

export async function launch(
appName: string,
launchArguments?: LaunchOption
launchArguments?: LaunchOption,
args: string[] = []
): Promise<boolean> {
const gameSettings = await getSettings(appName)
const gameInfo = getGameInfo(appName)
Expand Down Expand Up @@ -407,7 +408,8 @@ export async function launch(
(launchArguments as BaseLaunchOption | undefined)?.parameters ?? ''
),
...shlex.split(gameSettings.launcherArgs ?? ''),
appName
appName,
...args
]
const fullCommand = getRunnerCallWithoutCredentials(
commandParts,
Expand Down
6 changes: 3 additions & 3 deletions src/backend/storeManagers/sideload/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export async function isGameAvailable(appName: string): Promise<boolean> {

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

export async function stop(appName: string): Promise<void> {
Expand Down
5 changes: 3 additions & 2 deletions src/backend/storeManagers/storeManagerCommon/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ const openNewBrowserGameWindow = async ({
export async function launchGame(
appName: string,
gameInfo: GameInfo,
runner: Runner
runner: Runner,
args: string[] = []
): Promise<boolean> {
if (!gameInfo) {
return false
Expand Down Expand Up @@ -151,7 +152,7 @@ export async function launchGame(

const gameSettings = await getAppSettings(appName)
const { launcherArgs } = gameSettings
const extraArgs = shlex.split(launcherArgs ?? '')
const extraArgs = [...shlex.split(launcherArgs ?? ''), ...args]
const extraArgsJoined = extraArgs.join(' ')

if (executable) {
Expand Down
1 change: 1 addition & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type LaunchParams = {
launchArguments?: LaunchOption
runner: Runner
skipVersionCheck?: boolean
args?: string[]
}

export type LaunchOption = BaseLaunchOption | DLCLaunchOption
Expand Down
2 changes: 1 addition & 1 deletion src/common/types/frontend_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type FrontendMessages = {
status: ConnectivityStatus
retryIn: number
}) => void
launchGame: (appName: string, runner: Runner) => void
launchGame: (appName: string, runner: Runner, args: string[]) => void
installGame: (appName: string, runner: Runner) => void
recentGamesChanged: (newRecentGames: RecentGame[]) => void
pushGameToLibrary: (info: GameInfo) => void
Expand Down
1 change: 1 addition & 0 deletions src/common/types/game_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface GameManager {
launch: (
appName: string,
launchArguments?: LaunchOption,
args?: string[],
skipVersionCheck?: boolean
) => Promise<boolean>
moveInstall: (
Expand Down
8 changes: 6 additions & 2 deletions src/frontend/helpers/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ type LaunchOptions = {
runner: Runner
hasUpdate: boolean
showDialogModal: (options: DialogModalOptions) => void
args?: string[]
}

const launch = async ({
Expand All @@ -176,7 +177,8 @@ const launch = async ({
launchArguments,
runner,
hasUpdate,
showDialogModal
showDialogModal,
args
}: LaunchOptions): Promise<{ status: 'done' | 'error' | 'abort' }> => {
if (hasUpdate) {
const { ignoreGameUpdates } = await window.api.requestGameSettings(appName)
Expand All @@ -186,6 +188,7 @@ const launch = async ({
appName,
runner,
launchArguments,
args,
skipVersionCheck: true
})
}
Expand Down Expand Up @@ -216,6 +219,7 @@ const launch = async ({
appName,
runner,
launchArguments,
args,
skipVersionCheck: true
})
)
Expand All @@ -229,7 +233,7 @@ const launch = async ({
return launchFinished
}

return window.api.launch({ appName, launchArguments, runner })
return window.api.launch({ appName, launchArguments, runner, args })
}

const updateGame = (args: UpdateParams) => {
Expand Down

0 comments on commit 059fce0

Please sign in to comment.