Skip to content

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

steam: a restart stops the client alone, never the whole environment (#152)

Gauthier Piarrettec64b4e182063
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index c5c6a63..c46c812 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -295,10 +295,10 @@ final class AppState {
}
if recipe.changesLaunchEnvironment {
// A running Steam keeps the environment it started with; the game we are
- // about to launch through it would never see the recipe's settings.
- try? WineRunner(paths: paths, engine: engine, bottle: bottle).kill()
- try? await Task.sleep(for: .seconds(2))
- logLines.append("stopped the bottle so the new settings apply to this launch")
+ // about to launch through it would never see the recipe's settings. Only
+ // the client stops: other programs in the environment keep running.
+ try? await WineRunner(paths: paths, engine: engine, bottle: bottle).stopSteam()
+ logLines.append("stopped the Steam client so the new settings apply to this launch")
}
refresh()
let fresh = bottles.first { $0.name == bottleName } ?? runner.bottle
diff --git a/Sources/HighballKit/SteamRestart.swift b/Sources/HighballKit/SteamRestart.swift
index 2e36563..6583cd7 100644
--- a/Sources/HighballKit/SteamRestart.swift
+++ b/Sources/HighballKit/SteamRestart.swift
@@ -31,6 +31,14 @@ public enum SteamRestart {
/// The renderer a running client was started with, read off its overlay path: each entry is
/// `<...>/<renderer>/wine`, under `frameworks/renderer/` or `renderers/`. "wined3d" when it
/// has no overlay. The d9vk entry rides along with every renderer and names none.
+ /// Whether a prefix process belongs to the Steam client itself: the client, its browser
+ /// helpers, its service and its overlay. Games the client started are not in this list,
+ /// which is the point: stopping the client must never take a running game with it.
+ public static func isClientProcess(argv0: String) -> Bool {
+ let name = argv0.replacingOccurrences(of: "\\", with: "/").lowercased().split(separator: "/").last.map(String.init) ?? ""
+ return ["steam.exe", "steamwebhelper.exe", "steamservice.exe", "steamerrorreporter.exe", "steamerrorreporter64.exe", "gameoverlayui.exe"].contains(name)
+ }
+
public static func rendererName(ofLive env: [String: String]) -> String {
let dirs = (env["WINEDLLPATH_PREPEND"] ?? "").split(separator: ":").compactMap { entry -> String? in
let parts = entry.split(separator: "/")
@@ -115,10 +123,27 @@ extension WineRunner {
wantedRenderer: (renderer ?? bottle.settings.renderer).rawValue,
custom: Array(bottle.settings.environment.keys)) else { return .serves }
if !mayRestart || steamGameIsRunning() { return .kept(why, live: SteamRestart.rendererName(ofLive: live)) }
- try kill()
- // `kill` waits for the server; give the client's own exit a moment too, so the launch
- // that follows does not forward to a client on its way out.
- for _ in 0..<50 where runningSteamEnvironment() != nil { try await Task.sleep(for: .milliseconds(100)) }
+ try await stopSteam()
return .restarted(why)
}
+
+ /// Stops the Steam client and nothing else. Until 2026-09-18 this killed the whole
+ /// wineserver, which took every other program running in the environment down with the
+ /// client (highball#152: launching a second program ended the first). Steam's own
+ /// `-shutdown` closes the client cleanly; when it does not go within thirty seconds, its
+ /// processes alone are signalled. Games and other programs keep running throughout.
+ public func stopSteam() async throws {
+ let steam = bottle.driveC.appending(path: "Program Files (x86)/Steam/steam.exe")
+ _ = try? await run([steam.path, "-shutdown"], renderer: nil, label: "steam-shutdown")
+ for _ in 0..<300 where runningSteamEnvironment() != nil { try await Task.sleep(for: .milliseconds(100)) }
+ guard runningSteamEnvironment() != nil else { return }
+ let clientPIDs = ProcessTable.processes(ofPrefix: bottle.url).filter { pid in
+ guard let first = ProcessTable.commandLineAndEnvironment(of: pid)?.arguments.first else { return false }
+ return SteamRestart.isClientProcess(argv0: first)
+ }
+ for pid in clientPIDs { Darwin.kill(pid, SIGTERM) }
+ for _ in 0..<50 where runningSteamEnvironment() != nil { try await Task.sleep(for: .milliseconds(100)) }
+ for pid in clientPIDs where Darwin.kill(pid, 0) == 0 { Darwin.kill(pid, SIGKILL) }
+ for _ in 0..<20 where runningSteamEnvironment() != nil { try await Task.sleep(for: .milliseconds(100)) }
+ }
}
diff --git a/Tests/HighballKitTests/SteamRestartTests.swift b/Tests/HighballKitTests/SteamRestartTests.swift
index aa2f488..e91c3ac 100644
--- a/Tests/HighballKitTests/SteamRestartTests.swift
+++ b/Tests/HighballKitTests/SteamRestartTests.swift
@@ -71,6 +71,15 @@ final class SteamRestartTests: XCTestCase {
XCTAssertNil(SteamRestart.reason(live: dxvk, wanted: wanted, wantedRenderer: "dxvk"))
}
+ func testOnlyTheClientsOwnProcessesCountAsTheClient() {
+ XCTAssertTrue(SteamRestart.isClientProcess(argv0: "C:\\Program Files (x86)\\Steam\\steam.exe"))
+ XCTAssertTrue(SteamRestart.isClientProcess(argv0: "C:\\Program Files (x86)\\Steam\\bin\\cef\\cef.win7x64\\steamwebhelper.exe"))
+ XCTAssertTrue(SteamRestart.isClientProcess(argv0: "/b/drive_c/Program Files (x86)/Steam/GameOverlayUI.exe"))
+ XCTAssertFalse(SteamRestart.isClientProcess(argv0: "C:\\Program Files (x86)\\Steam\\steamapps\\common\\PEAK\\PEAK.exe"), "a game the client started")
+ XCTAssertFalse(SteamRestart.isClientProcess(argv0: "C:\\Games\\Tool\\steam_helper_for_mods.exe"), "a name that merely contains steam")
+ XCTAssertFalse(SteamRestart.isClientProcess(argv0: ""))
+ }
+
func testRendererNameComesFromTheOverlayPath() {
let base = "/e/x64-crossover26.3-r8/frameworks/renderer"
XCTAssertEqual(SteamRestart.rendererName(ofLive: ["WINEDLLPATH_PREPEND": "/e/x/renderers/d3dmetal-tsshim/wine:\(base)/d3dmetal/wine:\(base)/d9vk/wine"]), "d3dmetal")