Skip to content

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

Show a running Steam client on the activity strip

Gauthier Piarrettee8e801d334e3
diff --git a/Sources/HighballApp/ActivityStrip.swift b/Sources/HighballApp/ActivityStrip.swift
index a9e1108..c7f12c4 100644
--- a/Sources/HighballApp/ActivityStrip.swift
+++ b/Sources/HighballApp/ActivityStrip.swift
@@ -9,7 +9,7 @@ struct ActivityStrip: View {
@Environment(AppState.self) private var state
var body: some View {
- if state.busy || state.doneState != nil || !state.runningSessions.isEmpty {
+ if state.busy || state.doneState != nil || !state.runningSessions.isEmpty || !steamBottles.isEmpty {
VStack(spacing: 0) {
Divider()
VStack(spacing: 0) {
@@ -19,9 +19,11 @@ struct ActivityStrip: View {
doneRow(done)
}
ForEach(state.runningSessions) { session in
- if state.busy || state.doneState != nil || session.id != state.runningSessions.first?.id { Divider().opacity(0.5) }
sessionRow(session)
}
+ ForEach(steamBottles, id: \.name) { bottle in
+ steamRow(bottle)
+ }
}
}
.background(.bar)
@@ -29,6 +31,9 @@ struct ActivityStrip: View {
}
}
+ /// Bottles whose Steam client runs, in sidebar order.
+ private var steamBottles: [Bottle] { state.bottles.filter { state.steamClients.contains($0.name) } }
+
// MARK: Rows
private var busyRow: some View {
@@ -95,6 +100,22 @@ struct ActivityStrip: View {
.padding(.horizontal, 14).padding(.vertical, 8)
}
+ /// A Steam client with no window of its own in the app: Show brings its window forward,
+ /// Quit ends it (hidden while a known game runs in that bottle, since it would go too).
+ private func steamRow(_ bottle: Bottle) -> some View {
+ HStack(spacing: 10) {
+ Circle().fill(Color.secondary).frame(width: 8, height: 8).padding(.horizontal, 4)
+ Text(state.bottles.count > 1 ? String(format: L("Steam is running in %@"), bottle.name) : L("Steam is running"))
+ .font(.callout.weight(.medium)).lineLimit(1)
+ Spacer(minLength: 12)
+ Button(L("Show")) { state.showSteam(in: bottle) }.controlSize(.small).disabled(state.busy)
+ if !state.sessionRuns(in: bottle) {
+ Button(L("Quit")) { state.killBottle(bottle) }.controlSize(.small).disabled(state.busy)
+ }
+ }
+ .padding(.horizontal, 14).padding(.vertical, 8)
+ }
+
private func sessionRow(_ session: GameSession) -> some View {
HStack(spacing: 10) {
Circle().fill(HB.good).frame(width: 8, height: 8).padding(.horizontal, 4)
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index e6f5558..e4952f3 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -322,6 +322,7 @@ final class AppState {
gamesByBottle = Dictionary(bottles.map { ($0.name, SteamLibrary.games(in: $0)) }, uniquingKeysWith: { a, _ in a })
if installWatcher == nil { installWatcher = DirectoryWatcher { [weak self] in self?.refreshInstalledGames() } }
installWatcher?.watch(bottles.flatMap(installDirectories))
+ startSteamClientWatch()
libraryPlays = libraryStore.load()
rebuildLibrary()
epicRefresh()
@@ -626,6 +627,37 @@ final class AppState {
} catch { fail(error) }
}
+ // MARK: Steam clients (UX plan §3.3, issue #33)
+
+ /// Bottles with a Steam client running right now. A client left behind by a game launch is
+ /// invisible otherwise, and a new steam.exe only forwards to it (#33); the strip shows it
+ /// with Show and Quit.
+ var steamClients: Set<String> = []
+ @ObservationIgnored private var steamClientWatch: Task<Void, Never>?
+
+ private func startSteamClientWatch() {
+ guard steamClientWatch == nil else { return }
+ steamClientWatch = Task.detached(priority: .utility) { [weak self] in
+ while !Task.isCancelled {
+ guard let self else { return }
+ let bottles = await MainActor.run { [self] in self.bottles }
+ let running = Set(bottles.filter { WineRunner.steamIsRunning(inPrefix: $0.url) }.map(\.name))
+ await MainActor.run { [self] in if self.steamClients != running { self.steamClients = running } }
+ try? await Task.sleep(for: .seconds(8))
+ }
+ }
+ }
+
+ /// Brings the bottle's Steam window forward (the running client is asked to show it; with
+ /// none running this is a normal Steam start).
+ func showSteam(in bottle: Bottle) {
+ let steam = bottle.driveC.appending(path: "Program Files (x86)/Steam/steam.exe")
+ launch(pin: Pin(name: "Steam", path: Pin.storagePath(for: steam, driveC: bottle.driveC)), in: bottle)
+ }
+
+ /// Whether a game the app knows about runs in the bottle: Quit on the Steam row hides then.
+ func sessionRuns(in bottle: Bottle) -> Bool { runningSessions.contains { $0.bottleName == bottle.name } }
+
// MARK: Sessions (UX plan 0.6)
/// Games running right now, from their processes. The library shows them and offers Stop;
diff --git a/Sources/HighballKit/SteamRestart.swift b/Sources/HighballKit/SteamRestart.swift
index f8a5a12..4f4ce01 100644
--- a/Sources/HighballKit/SteamRestart.swift
+++ b/Sources/HighballKit/SteamRestart.swift
@@ -25,6 +25,15 @@ public enum SteamRestart {
}
extension WineRunner {
+ /// Whether a Steam client runs in the prefix, by its command line. Static so the app can
+ /// poll every bottle without resolving engines.
+ public static func steamIsRunning(inPrefix prefix: URL) -> Bool {
+ ProcessTable.processes(ofPrefix: prefix).contains { pid in
+ guard let first = ProcessTable.commandLineAndEnvironment(of: pid)?.arguments.first else { return false }
+ return isSteamExecutable(first)
+ }
+ }
+
/// The environment of the bottle's running Steam client, nil when none runs (or the
/// kernel would not show it, which it does for Wine's processes).
public func runningSteamEnvironment() -> [String: String]? {
diff --git a/Sources/HighballKit/WineRunner.swift b/Sources/HighballKit/WineRunner.swift
index 5bc5da4..1cafaed 100644
--- a/Sources/HighballKit/WineRunner.swift
+++ b/Sources/HighballKit/WineRunner.swift
@@ -306,12 +306,7 @@ public struct WineRunner: Sendable {
/// itself, which is normally none (see `ProcessTable` for why it is not always none).
@discardableResult
/// Whether a Steam client already runs in this bottle, by its command line.
- public func steamIsRunning() -> Bool {
- ProcessTable.processes(ofPrefix: bottle.url).contains { pid in
- guard let first = ProcessTable.commandLineAndEnvironment(of: pid)?.arguments.first else { return false }
- return Self.isSteamExecutable(first)
- }
- }
+ public func steamIsRunning() -> Bool { Self.steamIsRunning(inPrefix: bottle.url) }
/// Pure: does a command line's program name end in steam.exe (Windows or Unix separators).
public static func isSteamExecutable(_ argv0: String) -> Bool {