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
Whole-app review, batch 2: Stop reaches long operations; dropped games are sessions
Gauthier Piarrette5f249e859fea
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex 1c92dc5..582891e 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -223,10 +223,7 @@ final class AppState {func install(_ item: LibraryItem) {guard item.source == .epic,let game = epicOwned.first(where: { $0.app_name == item.epicAppName }) else { return }- let target = item.bottleName.flatMap { name in bottles.first { $0.name == name } }- ?? selectedBottle.flatMap { name in bottles.first { $0.name == name } }- ?? bottles.first- guard let target else { return }+ guard let target = item.bottleName.flatMap({ name in bottles.first { $0.name == name } }) ?? defaultBottle else { return }epicInstall(game, in: target)}@@ -707,8 +704,9 @@ final class AppState {func createBottle(name: String, recipeID: String?) {guard let engine = defaultEngine else { return }- runBusy("Creating bottle '\(name)' — first boot takes about 90 seconds",- done: DoneState(title: String(format: L("Bottle '%@' is ready"), name), ctaTitle: nil, cta: nil)) { [self] in+ runBusy(String(format: L("Creating the %@ environment — first boot takes about 90 seconds"), name),+ done: DoneState(title: String(format: L("The %@ environment is ready"), name), ctaTitle: nil, cta: nil),+ stop: .cancelTask(label: L("Stop"))) { [self] inlet bottle = try await bottleStore.create(name: name, engine: engine)await MainActor.run { self.appendLog("bottle created") }if let recipeID, let recipe = Self.recipe(recipeID) {@@ -1171,32 +1169,35 @@ final class AppState {/// Handle an .exe/.msi dropped on a bottle: run it (installer) inside the bottle.func runDropped(_ url: URL, in bottle: Bottle, andPin: Bool) {+ guard engine(for: bottle) != nil else { return }+ let ext = url.pathExtension.lowercased()+ if ext == "exe" {+ // A game runs as a session: the app stays free, Stop and the post-play question+ // work, and the window hands off like any other launch (review #4).+ let pin = Pin(name: url.deletingPathExtension().lastPathComponent,+ path: Pin.storagePath(for: url, driveC: bottle.driveC))+ if andPin {+ var copy = bottle; copy.settings.pins.append(pin); update(copy)+ launch(pin: pin, in: bottles.first { $0.name == bottle.name } ?? copy)+ } else {+ launch(pin: pin, in: bottle)+ }+ return+ }+ // .msi / .bat: an installer, which cannot stop cleanly, so it stays a blocking op.guard let engine = engine(for: bottle) else { return }runBusy("Running \(url.lastPathComponent)", stop: .killBottleThenRepair(bottle, label: L("Stop and repair"))) { [self] inlet runner = WineRunner(paths: paths, engine: engine, bottle: bottle)- let ext = url.pathExtension.lowercased()- let isMSI = ext == "msi"- let args = isMSI ? ["msiexec", "/i", url.path] : [url.path]- // Installers get the boring reliable backend; a game exe gets the bottle's- // real renderer and runs from its own folder so relative asset paths work.- let renderer: Renderer? = (ext == "exe") ? nil : .wined3d- _ = try await runner.run(args, renderer: renderer, label: url.lastPathComponent,+ let args = ext == "msi" ? ["msiexec", "/i", url.path] : [url.path]+ _ = try await runner.run(args, renderer: .wined3d, label: url.lastPathComponent,workingDirectory: url.deletingLastPathComponent()) { line inTask { @MainActor in self.appendLog(line) }}- if andPin {- await MainActor.run {- var copy = bottle- copy.settings.pins.append(Pin(name: url.deletingPathExtension().lastPathComponent,- path: Pin.storagePath(for: url, driveC: bottle.driveC)))- self.update(copy)- }- }}}func duplicateBottle(_ bottle: Bottle) {- runBusy("Duplicating '\(bottle.name)'", showLogSheet: false) { [self] in+ runBusy(String(format: L("Duplicating the %@ environment"), bottle.name)) { [self] inkillBottle(bottle) // flush registry files before copyingtry? await Task.sleep(for: .seconds(1))let store = bottleStore, name = bottle.name@@ -1207,8 +1208,11 @@ final class AppState {}func repairBottle(_ bottle: Bottle) {+ _repairBottle(bottle, stop: .killBottle(bottle, label: L("Stop")))+ }+ private func _repairBottle(_ bottle: Bottle, stop: BusyStop?) {guard let engine = engine(for: bottle) else { return }- runBusy("Repairing '\(bottle.name)' — re-running the Windows first boot") { [self] in+ runBusy(String(format: L("Repairing the %@ environment — re-running the Windows first boot"), bottle.name), stop: stop) { [self] inlet runner = WineRunner(paths: paths, engine: engine, bottle: bottle)try? runner.kill()try? await Task.sleep(for: .seconds(2))@@ -1251,7 +1255,7 @@ final class AppState {}func epicSignIn(code: String) {- runBusy("Connecting your Epic account", showLogSheet: false) { [self] in+ runBusy(L("Connecting your Epic account"), stop: .cancelTask(label: L("Stop"))) { [self] inlet store = epicStore_ = try await store.ensureInstalled()try await Task.detached { try store.authenticate(code: code) }.value@@ -1260,7 +1264,8 @@ final class AppState {}func epicInstall(_ game: EpicStore.Game, in bottle: Bottle) {- runBusy("Installing \(game.app_title)") { [self] in+ runBusy("Installing \(game.app_title)", expected: L("a large download; you can leave it running"),+ stop: .cancelTask(label: L("Stop"))) { [self] inlet store = epicStorelet status = try await Task.detached {try store.install(game.app_name, into: bottle) { line indiff --git a/Sources/HighballKit/WineRunner.swift b/Sources/HighballKit/WineRunner.swiftindex 1cafaed..b5c1718 100644--- a/Sources/HighballKit/WineRunner.swift+++ b/Sources/HighballKit/WineRunner.swift@@ -142,7 +142,8 @@ public struct WineRunner: Sendable {// The exit code used to be computed and thrown away: a failed install produced a log// shape-identical to a successful one, so user-submitted reports were undiagnosable// (issue #36 cost two research passes to answer). It is now a footer, written below.- let status: Int32 = await withCheckedContinuation { cont in+ let status: Int32 = await withTaskCancellationHandler {+ await withCheckedContinuation { cont inprocess.terminationHandler = { p in cont.resume(returning: p.terminationStatus) }// Drain on a background thread. The drain is the log handle's SOLE owner: it closes it// only after EOF. Closing from the main flow raced the last writes — FileHandle's@@ -165,6 +166,11 @@ public struct WineRunner: Sendable {if !buffer.isEmpty { onOutput?(String(decoding: buffer, as: UTF8.self)) }try? logHandle.close()}+ }+ } onCancel: {+ // The busy op was stopped: end the process so the wait returns instead of hanging+ // on a wineboot/installer that ignores its parent (review #12).+ process.terminate()}let duration = Date().timeIntervalSince(start)// Footer with the exit code. Written here, not in the drain: the drain blocks on