Skip to content

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

Steam: say when a launch is parked on a dialog, and fix the CRLF log reads

Gauthier Piarrettef4984f75f5fa
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index 34a0fad..6a9a98a 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -1079,8 +1079,15 @@ final class AppState {
await MainActor.run { [self] in if self.steamClients != running { self.steamClients = running } }
// A first start that deadlocked after its bootstrap (issue #9) is restarted once.
for bottle in bottles where running.contains(bottle.name) {
- guard let root = SteamLibrary.steamRoot(of: bottle), SteamFirstStart.isHung(steamRoot: root) else { continue }
- await MainActor.run { [self] in self.restartHungFirstStart(bottle) }
+ guard let root = SteamLibrary.steamRoot(of: bottle) else { continue }
+ if SteamFirstStart.isHung(steamRoot: root) {
+ await MainActor.run { [self] in self.restartHungFirstStart(bottle) }
+ continue
+ }
+ // Steam can park a launch on a dialog nobody sees (issue #74).
+ if let waiting = SteamGameAction.pending(steamRoot: root) {
+ await MainActor.run { [self] in self.steamIsWaitingForAnAnswer(waiting, in: bottle) }
+ }
}
try? await Task.sleep(for: .seconds(8))
}
@@ -1105,6 +1112,24 @@ final class AppState {
}
}
+ /// Launch attempts already reported, so one dialog is mentioned once and not every 8 seconds.
+ @ObservationIgnored private var steamWaitsReported: Set<String> = []
+
+ /// Steam stopped a launch and is waiting for the player to answer something in its own window
+ /// — usually a publisher licence agreement (issue #74). Nothing is wrong with the game: the
+ /// process starts and then sits there, every log is clean, and if the Steam window is behind
+ /// another one the dialog is never seen. Say what is happening and put the window in front.
+ func steamIsWaitingForAnAnswer(_ waiting: SteamGameAction.Pending, in bottle: Bottle) {
+ let key = "\(bottle.name)#\(waiting.appID)#\(waiting.actionID)#\(waiting.task)"
+ guard !steamWaitsReported.contains(key) else { return }
+ steamWaitsReported.insert(key)
+ let name = SteamLibrary.games(in: bottle).first { $0.appid == waiting.appID }?.name
+ let message = SteamGameAction.message(for: waiting, name: name)
+ appendLog(message)
+ stage = message
+ showSteam(in: bottle)
+ }
+
/// 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) {
diff --git a/Sources/HighballKit/SteamFirstStart.swift b/Sources/HighballKit/SteamFirstStart.swift
index 89627c8..3a40101 100644
--- a/Sources/HighballKit/SteamFirstStart.swift
+++ b/Sources/HighballKit/SteamFirstStart.swift
@@ -31,12 +31,16 @@ public enum SteamFirstStart {
/// The newest `[YYYY-MM-DD HH:MM:SS]` stamp in the file (on a line containing `matching`,
/// when given). Steam writes local time without a zone.
+ ///
+ /// Split on `isNewline`, never on the character `"\n"`. Steam's logs are CRLF and Swift
+ /// treats CRLF as one Character, so splitting on `"\n"` returns the whole file as a single
+ /// line: every timestamp read came back nil and this check silently never fired.
static func lastTimestamp(in file: URL, matching: String?) -> Date? {
guard let text = try? String(contentsOf: file, encoding: .utf8) else { return nil }
let f = DateFormatter()
f.dateFormat = "yyyy-MM-dd HH:mm:ss"; f.locale = Locale(identifier: "en_US_POSIX"); f.timeZone = .current
var newest: Date?
- for line in text.split(separator: "\n").reversed() {
+ for line in text.split(whereSeparator: \.isNewline).reversed() {
if let m = matching, !line.contains(m) { continue }
guard line.hasPrefix("["), let close = line.firstIndex(of: "]") else { continue }
let stamp = String(line[line.index(after: line.startIndex)..<close])
diff --git a/Sources/HighballKit/SteamGameAction.swift b/Sources/HighballKit/SteamGameAction.swift
new file mode 100644
index 0000000..3a56f3b
--- /dev/null
+++ b/Sources/HighballKit/SteamGameAction.swift
@@ -0,0 +1,120 @@
+import Foundation
+
+/// Steam can stop a launch dead and wait for an answer the player never sees.
+///
+/// A publisher licence agreement is the common one: Steam draws an "EULA … Accept / Cancel"
+/// dialog inside its own window, and until it is answered the game process starts and then
+/// sits at a few megabytes forever. From outside, that is indistinguishable from a hang — the
+/// run log is clean, the process exists, and if the Steam window is behind something else the
+/// dialog is never seen at all (issue #74). Seen with two different publishers on first launch
+/// after install.
+///
+/// Steam says so plainly in `logs/console_log.txt`:
+///
+/// GameAction [AppID 1174180, ActionID 1] : LaunchApp changed task to ShowEula with ""
+/// GameAction [AppID 1174180, ActionID 1] : LaunchApp waiting for user response to ShowEula ""
+///
+/// and, once answered, either continues the same action:
+///
+/// GameAction [AppID 3240220, ActionID 2] : LaunchApp continues with user response "ShowInterstitials"
+///
+/// or starts a new one. So the newest GameAction line tells the whole story.
+///
+/// The catch is that Steam passes through several "waiting for user response" states it answers
+/// itself within the same second (ShowInterstitials, CreatingProcess). Only a wait that *stands*
+/// is a wait on a person, which is what `patience` is for.
+public enum SteamGameAction {
+ /// How long a wait must stand before it counts as waiting on a person rather than on Steam.
+ public static let patience: TimeInterval = 10
+
+ public struct Pending: Equatable, Sendable {
+ /// The Steam app being launched.
+ public var appID: Int
+ /// Steam's own name for what it is waiting on, e.g. `ShowEula`.
+ public var task: String
+ /// When the wait started.
+ public var since: Date
+ /// Identifies one launch attempt, so a caller can act once per attempt.
+ public var actionID: Int
+
+ public init(appID: Int, task: String, since: Date, actionID: Int) {
+ self.appID = appID; self.task = task; self.since = since; self.actionID = actionID
+ }
+ }
+
+ /// Pure decision over `console_log.txt` lines in file order. Returns the wait only if the
+ /// newest GameAction line is a wait that has stood for `patience`.
+ public static func pending(lines: [String], now: Date) -> Pending? {
+ guard let last = lines.reversed().lazy.compactMap(parse).first else { return nil }
+ guard case .waiting(let task) = last.step else { return nil }
+ guard now.timeIntervalSince(last.at) >= patience else { return nil }
+ return Pending(appID: last.appID, task: task, since: last.at, actionID: last.actionID)
+ }
+
+ /// Reads the bottle's Steam console log and decides. No log means nothing to judge.
+ public static func pending(steamRoot: URL, now: Date = Date()) -> Pending? {
+ let log = steamRoot.appending(path: "logs/console_log.txt")
+ guard let text = try? String(contentsOf: log, encoding: .utf8) else { return nil }
+ // Split on isNewline, never on the character "\n": Steam's logs are CRLF and Swift treats
+ // CRLF as one Character, so splitting on "\n" hands back the whole file as one line.
+ return pending(lines: text.split(whereSeparator: \.isNewline).map(String.init), now: now)
+ }
+
+ /// A sentence for the player. `name` is the game's title when we know it.
+ public static func message(for pending: Pending, name: String?) -> String {
+ let game = name ?? "this game"
+ switch pending.task {
+ case "ShowEula":
+ return "Steam is waiting for you to accept the licence agreement for \(game). It is in the Steam window."
+ default:
+ return "Steam is waiting for an answer before it starts \(game). It is in the Steam window."
+ }
+ }
+
+ // MARK: - Parsing
+
+ enum Step: Equatable {
+ case waiting(String) // waiting for user response to <task>
+ case other // changed task to …, continues with user response …
+ }
+
+ struct Line: Equatable {
+ var at: Date
+ var appID: Int
+ var actionID: Int
+ var step: Step
+ }
+
+ /// `[2026-09-10 02:42:04] GameAction [AppID 1174180, ActionID 1] : LaunchApp waiting for user response to ShowEula ""`
+ static func parse(_ line: String) -> Line? {
+ guard line.contains("GameAction [AppID ") else { return nil }
+ guard let at = timestamp(line) else { return nil }
+ guard let ids = line.range(of: "GameAction [AppID ") else { return nil }
+ let rest = line[ids.upperBound...]
+ guard let close = rest.firstIndex(of: "]") else { return nil }
+ let inside = rest[rest.startIndex..<close] // "1174180, ActionID 1"
+ let parts = inside.split(separator: ",").map { $0.trimmingCharacters(in: .whitespaces) }
+ guard let appID = Int(parts.first ?? "") else { return nil }
+ let actionID = Int(parts.count > 1 ? parts[1].replacingOccurrences(of: "ActionID ", with: "") : "") ?? 0
+
+ let tail = String(rest[rest.index(after: close)...])
+ let marker = "waiting for user response to "
+ guard let m = tail.range(of: marker) else {
+ return Line(at: at, appID: appID, actionID: actionID, step: .other)
+ }
+ let task = tail[m.upperBound...]
+ .prefix { !$0.isWhitespace }
+ .trimmingCharacters(in: CharacterSet(charactersIn: "\""))
+ guard !task.isEmpty else { return Line(at: at, appID: appID, actionID: actionID, step: .other) }
+ return Line(at: at, appID: appID, actionID: actionID, step: .waiting(task))
+ }
+
+ /// Steam writes `[yyyy-MM-dd HH:MM:SS]` in local time, with no zone.
+ static func timestamp(_ line: String) -> Date? {
+ guard line.first == "[", let close = line.firstIndex(of: "]") else { return nil }
+ let stamp = String(line[line.index(after: line.startIndex)..<close])
+ let f = DateFormatter()
+ f.dateFormat = "yyyy-MM-dd HH:mm:ss"; f.locale = Locale(identifier: "en_US_POSIX"); f.timeZone = .current
+ return f.date(from: stamp)
+ }
+}
diff --git a/Tests/HighballKitTests/SteamFirstStartTests.swift b/Tests/HighballKitTests/SteamFirstStartTests.swift
index ed94d28..fd10738 100644
--- a/Tests/HighballKitTests/SteamFirstStartTests.swift
+++ b/Tests/HighballKitTests/SteamFirstStartTests.swift
@@ -27,4 +27,23 @@ final class SteamFirstStartTests: XCTestCase {
.write(to: logs.appending(path: "connection_log.txt"), atomically: true, encoding: .utf8)
XCTAssertFalse(SteamFirstStart.isHung(steamRoot: root), "it connected after the bootstrap")
}
+
+ /// Steam's logs are CRLF and Swift treats CRLF as a single Character, so a split on "\n"
+ /// returns the whole file as one line and every timestamp read came back nil. This check
+ /// silently never fired on a real machine until that was fixed.
+ func testReadsTimestampsOutOfCRLFLogs() throws {
+ let dir = URL(fileURLWithPath: NSTemporaryDirectory()).appending(path: UUID().uuidString)
+ try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let file = dir.appending(path: "bootstrap_log.txt")
+ let crlf = "[2026-09-10 02:41:50] Startup\r\n[2026-09-10 02:41:57] Update complete, launching Steam...\r\n"
+ try crlf.write(to: file, atomically: true, encoding: .utf8)
+
+ let got = SteamFirstStart.lastTimestamp(in: file, matching: "Update complete")
+ XCTAssertNotNil(got, "CRLF logs must still yield a timestamp")
+
+ let f = DateFormatter()
+ f.dateFormat = "yyyy-MM-dd HH:mm:ss"; f.locale = Locale(identifier: "en_US_POSIX"); f.timeZone = .current
+ XCTAssertEqual(got, f.date(from: "2026-09-10 02:41:57"))
+ }
}
diff --git a/Tests/HighballKitTests/SteamGameActionTests.swift b/Tests/HighballKitTests/SteamGameActionTests.swift
new file mode 100644
index 0000000..0c09441
--- /dev/null
+++ b/Tests/HighballKitTests/SteamGameActionTests.swift
@@ -0,0 +1,74 @@
+import XCTest
+@testable import HighballKit
+
+final class SteamGameActionTests: XCTestCase {
+ /// Real lines from a bottle's console_log.txt, 2026-09-10 (Red Dead Redemption 2) and
+ /// 2026-09-05 (a launch that went all the way through).
+ private let eula = [
+ #"[2026-09-10 02:42:04] GameAction [AppID 1174180, ActionID 1] : LaunchApp changed task to ShowEula with """#,
+ #"[2026-09-10 02:42:04] GameAction [AppID 1174180, ActionID 1] : LaunchApp waiting for user response to ShowEula """#,
+ ]
+ private let completed = [
+ #"[2026-09-05 06:08:57] GameAction [AppID 3240220, ActionID 2] : LaunchApp changed task to ShowInterstitials with """#,
+ #"[2026-09-05 06:08:57] GameAction [AppID 3240220, ActionID 2] : LaunchApp waiting for user response to ShowInterstitials """#,
+ #"[2026-09-05 06:08:57] GameAction [AppID 3240220, ActionID 2] : LaunchApp continues with user response "ShowInterstitials""#,
+ #"[2026-09-05 06:08:57] GameAction [AppID 3240220, ActionID 2] : LaunchApp changed task to CreatingProcess with """#,
+ #"[2026-09-05 06:08:57] GameAction [AppID 3240220, ActionID 2] : LaunchApp changed task to Completed with """#,
+ ]
+
+ private func at(_ s: String) -> Date { SteamGameAction.timestamp("[\(s)] x")! }
+
+ func testParsesAppAndActionAndTask() {
+ let line = SteamGameAction.parse(eula[1])
+ XCTAssertEqual(line?.appID, 1174180)
+ XCTAssertEqual(line?.actionID, 1)
+ XCTAssertEqual(line?.step, .waiting("ShowEula"))
+ XCTAssertEqual(SteamGameAction.parse(eula[0])?.step, .other)
+ }
+
+ func testStandingWaitIsReported() {
+ let now = at("2026-09-10 02:43:00")
+ let p = SteamGameAction.pending(lines: eula, now: now)
+ XCTAssertEqual(p?.appID, 1174180)
+ XCTAssertEqual(p?.task, "ShowEula")
+ XCTAssertEqual(p?.actionID, 1)
+ }
+
+ func testFreshWaitIsGivenTimeToResolveItself() {
+ // Steam answers several of these itself within the same second.
+ let now = at("2026-09-10 02:42:05")
+ XCTAssertNil(SteamGameAction.pending(lines: eula, now: now))
+ }
+
+ func testAnsweredWaitIsNotReported() {
+ let now = at("2026-09-05 07:00:00")
+ XCTAssertNil(SteamGameAction.pending(lines: completed, now: now),
+ "the launch went on past the wait")
+ }
+
+ func testNewerActionSupersedesAnEarlierWait() {
+ let now = at("2026-09-05 07:00:00")
+ XCTAssertNil(SteamGameAction.pending(lines: eula + completed, now: now),
+ "a later launch that completed is the current truth")
+ }
+
+ func testNonGameActionNoiseIsIgnored() {
+ let noise = [
+ "[2026-09-10 02:41:57] Client version: 1788652215",
+ "[2026-09-10 02:41:57] SSGL: UI mode (0->7)",
+ "",
+ ]
+ XCTAssertNil(SteamGameAction.pending(lines: noise, now: at("2026-09-10 03:00:00")))
+ XCTAssertEqual(SteamGameAction.pending(lines: eula + noise, now: at("2026-09-10 03:00:00"))?.task,
+ "ShowEula",
+ "noise after the wait does not answer it")
+ }
+
+ func testMessageNamesTheLicenceForEula() {
+ let p = SteamGameAction.Pending(appID: 1174180, task: "ShowEula", since: Date(), actionID: 1)
+ XCTAssertEqual(SteamGameAction.message(for: p, name: "Red Dead Redemption 2"),
+ "Steam is waiting for you to accept the licence agreement for Red Dead Redemption 2. It is in the Steam window.")
+ let other = SteamGameAction.Pending(appID: 1, task: "SomethingElse", since: Date(), actionID: 1)
+ XCTAssertTrue(SteamGameAction.message(for: other, name: nil).contains("this game"))
+ }
+}