Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

cli: run <bottle> Steam -- <args> hands the arguments to a running client (#75)

Gauthier Piarrette16e61343c5e4
diff --git a/Sources/HighballKit/WineRunner.swift b/Sources/HighballKit/WineRunner.swift
index d208ae6..f900626 100644
--- a/Sources/HighballKit/WineRunner.swift
+++ b/Sources/HighballKit/WineRunner.swift
@@ -340,6 +340,24 @@ public struct WineRunner: Sendable {
argv0.replacingOccurrences(of: "\\", with: "/").lowercased().hasSuffix("/steam.exe")
}
+ /// What a `run <bottle> Steam [args]` should do. A running client stays: a second
+ /// steam.exe forwards its command line to it over Steam's own IPC and exits, so arguments
+ /// such as `-applaunch` still reach the game (highball#75); without arguments the only
+ /// thing to do is show the window (#33). No client: start one with the arguments.
+ public enum SteamInvocation: Equatable { case start, showWindow, forward }
+ public static func steamInvocation(clientRunning: Bool, arguments: [String]) -> SteamInvocation {
+ guard clientRunning else { return .start }
+ return arguments.isEmpty ? .showWindow : .forward
+ }
+
+ /// Hands a command line to the running Steam client: a second steam.exe forwards it and
+ /// exits. Nil when no client runs.
+ public func forwardToRunningSteam(_ arguments: [String], onOutput: (@Sendable (String) -> Void)? = nil) async throws -> LaunchResult? {
+ guard steamIsRunning() else { return nil }
+ let steam = bottle.driveC.appending(path: "Program Files (x86)/Steam/steam.exe")
+ return try await start(steam, arguments: arguments, onOutput: onOutput)
+ }
+
/// If a Steam client is already running in the bottle, asks it to show its window and
/// returns that launch; nil when no client runs (the caller then starts one).
///
diff --git a/Sources/highball/main.swift b/Sources/highball/main.swift
index c9ca6a2..077fb53 100644
--- a/Sources/highball/main.swift
+++ b/Sources/highball/main.swift
@@ -325,10 +325,16 @@ struct Run: AsyncParsableCommand {
if let renderer { p.renderer = renderer }
p.arguments += arguments
if p.path.lowercased().hasSuffix("steam/steam.exe") {
- if let shown = try await runner.showRunningSteam(onOutput: out) {
+ switch WineRunner.steamInvocation(clientRunning: runner.steamIsRunning(), arguments: p.arguments) {
+ case .forward:
+ print("Steam is already running in this bottle; handed it: \(p.arguments.joined(separator: " "))")
+ if let forwarded = try await runner.forwardToRunningSteam(p.arguments, onOutput: out) { result = forwarded }
+ else { result = try await runner.start(pin: p, onOutput: out) }
+ case .showWindow:
print("Steam is already running in this bottle; asked it to show its window")
- result = shown
- } else {
+ if let shown = try await runner.showRunningSteam(onOutput: out) { result = shown }
+ else { result = try await runner.start(pin: p, onOutput: out) }
+ case .start:
result = try await runner.startResumingKnownSteamCrash(pin: p, onOutput: out ?? { _ in }).result
}
} else {
diff --git a/Tests/HighballKitTests/RegressionTests.swift b/Tests/HighballKitTests/RegressionTests.swift
index 1a97965..47351e1 100644
--- a/Tests/HighballKitTests/RegressionTests.swift
+++ b/Tests/HighballKitTests/RegressionTests.swift
@@ -1485,4 +1485,15 @@ extension RegressionTests {
e.rendererMinMacOS = nil
XCTAssertEqual(e.effectiveRenderer(osMajor: 14), .dxmt, "no gate: the renderer applies everywhere")
}
+
+ /// highball#75: `run <bottle> Steam -- -applaunch 4465480` with the client already running
+ /// only showed the window and dropped the arguments. A second steam.exe forwards its
+ /// command line to the running client, so arguments are handed over; the window is shown
+ /// only when there is nothing to hand over.
+ func testRunningSteamGetsTheArgumentsForwarded() {
+ XCTAssertEqual(WineRunner.steamInvocation(clientRunning: false, arguments: []), .start)
+ XCTAssertEqual(WineRunner.steamInvocation(clientRunning: false, arguments: ["-applaunch", "730"]), .start)
+ XCTAssertEqual(WineRunner.steamInvocation(clientRunning: true, arguments: []), .showWindow)
+ XCTAssertEqual(WineRunner.steamInvocation(clientRunning: true, arguments: ["-applaunch", "730"]), .forward)
+ }
}