Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.
Swift apple-silicond3dmetaldxmtdxvkfexgame-porting-toolkitgamingmac-gamingmacosmetalmoltenvksteamswiftuivkd3d-protonwhisky-alternativewindows-gameswinewine-wrapper
Launchers and pinned programs no longer hold the app busy
Gauthier Piarrette0e89f8719d5d
diff --git a/Sources/HighballApp/ActivityStrip.swift b/Sources/HighballApp/ActivityStrip.swiftindex 3dfdc01..5bb68a2 100644--- a/Sources/HighballApp/ActivityStrip.swift+++ b/Sources/HighballApp/ActivityStrip.swift@@ -128,7 +128,12 @@ struct ActivityStrip: View {Button(L("It played fine")) { state.reportPlay(record) }.controlSize(.small)Button(L("Had problems")) {state.postPlay = nil- NSWorkspace.shared.open(BugReport.url(version: Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "dev"))+ let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "dev"+ // The report samples live games for a few seconds; never on the main thread.+ Task.detached {+ let url = BugReport.url(version: version)+ await MainActor.run { NSWorkspace.shared.open(url) }+ }}.controlSize(.small)Button(L("Not now")) { state.postPlay = nil }.controlSize(.small).buttonStyle(.link)}diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex 0878ff0..399c69c 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -33,6 +33,9 @@ final class AppState {var title: Stringvar ctaTitle: String?var cta: (() -> Void)?+ /// No done row: a session or the Steam row took over from the busy operation.+ var silent = false+ static let handedOff = DoneState(title: "", ctaTitle: nil, cta: nil, silent: true)}// The activity strip (UX plan 0.5): what the busy operation can show beyond its title.struct Transfer: Equatable { var received: Int64; var total: Int64? }@@ -503,7 +506,8 @@ final class AppState {// and hid the alert until the user clicked Close (issues #27/#28).do {try await work()- doneState = done ?? DoneState(title: L("Done"), ctaTitle: nil, cta: nil)+ let d = done ?? DoneState(title: L("Done"), ctaTitle: nil, cta: nil)+ doneState = d.silent ? nil : d} catch {showLog = falseif stopRequested || error is CancellationError || (error as? URLError)?.code == .cancelled {@@ -750,8 +754,10 @@ final class AppState {// expectations instead of launching silently into what reads as a hang.let steamFirstBoot = isSteamUI(pin) && !FileManager.default.fileExists(atPath: bottle.driveC.appending(path: "Program Files (x86)/Steam/bin/cef").path)- runBusy(steamFirstBoot ? L("Starting Steam for the first time — it downloads and unpacks its own client") : "Running \(pin.name)",+ let cef = bottle.driveC.appending(path: "Program Files (x86)/Steam/bin/cef")+ runBusy(steamFirstBoot ? L("Starting Steam for the first time — it downloads and unpacks its own client") : "Starting \(pin.name)",expected: steamFirstBoot ? L("usually 15–25 minutes; long quiet stretches are normal") : nil,+ done: .handedOff,stop: .killBottle(bottle, label: L("Stop")),cleanup: { [weak self] in self?.launchingPins.remove(pin.id) }) { [self] inlet runner = WineRunner(paths: paths, engine: engine, bottle: bottle)@@ -770,29 +776,53 @@ final class AppState {try? await Task.sleep(for: .seconds(2))extra = ["WINEMSYNC": "0", "WINEESYNC": "0"]}- let result: LaunchResult- if isSteamUI(pin) {- let (r, resumed) = try await runner.startResumingKnownSteamCrash(pin: pin, extraEnvironment: extra) { line in- Task { @MainActor in- self.appendLog(line)- if line.contains("relaunching so it resumes") {- self.stage = L("Steam crashed at a known spot — relaunching to resume the update")+ // The process outlives "starting": busy covers the start only, then the Steam row+ // (a client) or a session (anything else) carries it, and the app stays free (0.6).+ let launch = Task<LaunchResult, Error> {+ if isSteamUI(pin) {+ let (r, resumed) = try await runner.startResumingKnownSteamCrash(pin: pin, extraEnvironment: extra) { line in+ Task { @MainActor in+ self.appendLog(line)+ if line.contains("relaunching so it resumes") {+ self.stage = L("Steam crashed at a known spot — relaunching to resume the update")+ }}}+ if resumed { await MainActor.run { self.appendLog("resumed after the known crash") } }+ return r}- result = r- if resumed { await MainActor.run { self.appendLog("resumed after the known crash") } }- } else {- result = try await runner.start(pin: pin, extraEnvironment: extra) { line in Task { @MainActor in self.appendLog(line) } }+ return try await runner.start(pin: pin, extraEnvironment: extra) { line in Task { @MainActor in self.appendLog(line) } }}- if result.crashedEarly {- let current = pin.renderer ?? bottle.settings.renderer- await MainActor.run {- self.crashSuggestion = CrashSuggestion(program: pin.name, bottleName: bottle.name,- renderer: Renderer.suggestion(after: current),- logPath: result.log.path, current: current, seconds: Int(result.duration),- alternateEngine: self.alternateEngine(for: bottle))+ let markers = SessionWatch.markers(executable: bottle.resolve(windowsPath: pin.path))+ var waited = 0+ while true {+ if let result = await Self.finished(launch) {+ if result.crashedEarly {+ let current = pin.renderer ?? bottle.settings.renderer+ await MainActor.run {+ self.crashSuggestion = CrashSuggestion(program: pin.name, bottleName: bottle.name,+ renderer: Renderer.suggestion(after: current),+ logPath: result.log.path, current: current, seconds: Int(result.duration),+ alternateEngine: self.alternateEngine(for: bottle))+ }+ }+ return+ }+ if isSteamUI(pin) {+ // A first boot is "started" once the client is unpacked and running; the+ // Steam row shows it from then on.+ if runner.steamIsRunning(), FileManager.default.fileExists(atPath: cef.path) { return }+ } else if waited >= 6, SessionWatch.isAlive(markers: markers, ps: SessionWatch.currentProcessList()) {+ await MainActor.run {+ self.beginSession(GameSession(title: pin.name, bottleName: bottle.name, appid: nil, markers: markers,+ renderer: (pin.renderer ?? bottle.settings.renderer).rawValue))+ }+ return}+ if !isSteamUI(pin), waited >= 360 {+ throw HighballError.failed("\(pin.name) never started: no process of its own appeared in six minutes. Its log is in Details.")+ }+ try await Task.sleep(for: .seconds(2)); waited += 2}}}@@ -888,7 +918,7 @@ final class AppState {// call says nothing about it, so the game's own processes decide when "starting" ends// and a session begins, and the app is free while the game runs (UX plan 0.6).runBusy("Starting \(game.name)", expected: L("a cold Steam client can take a couple of minutes"),- done: DoneState(title: L("Running"), ctaTitle: nil, cta: nil),+ done: .handedOff,stop: .killBottle(bottle, label: L("Stop"))) { [self] inlet runner = WineRunner(paths: paths, engine: engine, bottle: bottle)// A running client would serve the launch with its own environment; when that is@@ -1047,25 +1077,43 @@ final class AppState {// renderer nil = the bottle's own renderer (the old hardcoded .dxvk default ignored it).func epicPlay(_ game: EpicStore.Game, in bottle: Bottle, renderer: Renderer? = nil) {guard let engine = engine(for: bottle) else { return }- runBusy("Running \(game.app_title)", showLogSheet: false) { [self] in+ runBusy("Starting \(game.app_title)", done: .handedOff, stop: .killBottle(bottle, label: L("Stop"))) { [self] inlet store = epicStore// Fresh single-use token, fetched off the main thread right before launch.let info = try await Task.detached { try store.launchInfo(game.app_name) }.valuelet runner = WineRunner(paths: paths, engine: engine, bottle: bottle)- let result = try await runner.start(info.executable, arguments: info.arguments,- renderer: renderer, extraEnvironment: info.environment,- workingDirectory: info.workingDirectory) { line in- Task { @MainActor in self.appendLog(line) }+ let launch = Task {+ try await runner.start(info.executable, arguments: info.arguments,+ renderer: renderer, extraEnvironment: info.environment,+ workingDirectory: info.workingDirectory) { line in+ Task { @MainActor in self.appendLog(line) }+ }}- if result.crashedEarly {- let current = renderer ?? bottle.settings.renderer- await MainActor.run {- self.crashSuggestion = CrashSuggestion(program: game.app_title, bottleName: bottle.name,- renderer: Renderer.suggestion(after: current),- logPath: result.log.path, current: current, seconds: Int(result.duration),- alternateEngine: self.alternateEngine(for: bottle))+ let markers = SessionWatch.markers(executable: info.executable)+ var waited = 0+ while waited < 360 {+ if let result = await Self.finished(launch) {+ if result.crashedEarly {+ let current = renderer ?? bottle.settings.renderer+ await MainActor.run {+ self.crashSuggestion = CrashSuggestion(program: game.app_title, bottleName: bottle.name,+ renderer: Renderer.suggestion(after: current),+ logPath: result.log.path, current: current, seconds: Int(result.duration),+ alternateEngine: self.alternateEngine(for: bottle))+ }+ }+ return}+ if waited >= 6, SessionWatch.isAlive(markers: markers, ps: SessionWatch.currentProcessList()) {+ await MainActor.run {+ self.beginSession(GameSession(title: game.app_title, bottleName: bottle.name, appid: nil, markers: markers,+ renderer: (renderer ?? bottle.settings.renderer).rawValue))+ }+ return+ }+ try await Task.sleep(for: .seconds(2)); waited += 2}+ throw HighballError.failed("\(game.app_title) never started: no process of its own appeared in six minutes. Its log is in Details.")}}diff --git a/Sources/HighballKit/Sessions.swift b/Sources/HighballKit/Sessions.swiftindex 02149f4..a26896e 100644--- a/Sources/HighballKit/Sessions.swift+++ b/Sources/HighballKit/Sessions.swift@@ -44,6 +44,12 @@ public enum SessionWatch {["steamapps/common/\(installdir)/", "steamapps\\common\\\(installdir)\\"]}+ /// The marker of a program launched by path (a pin, an Epic game): its file name, which+ /// its Wine process carries in its command line whatever the separators.+ public static func markers(executable: URL) -> [String] {+ [executable.lastPathComponent]+ }+/// True when any process listing line carries one of the markers. `ps` is the text of/// `ps axww`; kept as a parameter so the rule is testable without processes.public static func isAlive(markers: [String], ps: String) -> Bool {diff --git a/Tests/HighballKitTests/SessionMarkersTests.swift b/Tests/HighballKitTests/SessionMarkersTests.swiftnew file mode 100644index 0000000..5a946b9--- /dev/null+++ b/Tests/HighballKitTests/SessionMarkersTests.swift@@ -0,0 +1,12 @@+import XCTest+@testable import HighballKit++final class SessionMarkersTests: XCTestCase {+ func testExecutableMarkerIsTheFileName() {+ let m = SessionWatch.markers(executable: URL(fileURLWithPath: "/b/drive_c/Games/Warframe/Tools/Launcher.exe"))+ XCTAssertEqual(m, ["Launcher.exe"])+ let ps = #" 123 ?? 0:01.00 C:\Games\Warframe\Tools\Launcher.exe -cluster:public"#+ XCTAssertTrue(SessionWatch.isAlive(markers: m, ps: ps))+ XCTAssertFalse(SessionWatch.isAlive(markers: m, ps: " 9 ?? 0:00.10 C:\\windows\\system32\\services.exe"))+ }+}