Skip to content

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

Review fixes: the D3DMetal ask fires on real engines; programs run from the main window

Gauthier Piarrettea4472ae6d18c
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index 93b8982..c281a28 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -70,7 +70,6 @@ final class AppState {
@ObservationIgnored private var busyTask: Task<Void, Never>?
@ObservationIgnored private var transferSamples: [ActivityText.Sample] = []
@ObservationIgnored private var stopRequested = false
- var requestCreateBottle = false // engine-done CTA → ContentView opens the sheet
// Onboarding
var rosettaInstalled = true
@@ -155,12 +154,13 @@ final class AppState {
/// the db verified it": an unapplied fix recipe whose steps are all harmless (config
/// files, renderer — no wine processes, no installs) is applied silently first; one
/// with heavy steps asks, with the cost stated.
- func play(_ item: LibraryItem) {
+ /// `renderer` forces one graphics mode for this launch (the D3DMetal ask's "play with the
+ /// other mode"); nil lets the row and the environment decide.
+ func play(_ item: LibraryItem, renderer: Renderer? = nil) {
guard let bottleName = item.bottleName,
let bottle = bottles.first(where: { $0.name == bottleName }) else { return }
- if let appid = item.steamAppID, gameDB[appid]?.effectiveRenderer() == .d3dmetal,
- let engine = engine(for: bottle), engine.rendererDir("d3dmetal") == nil,
- engine.manifest.components["d3dmetal"] != nil {
+ if renderer == nil, let appid = item.steamAppID, gameDB[appid]?.effectiveRenderer() == .d3dmetal,
+ let engine = engine(for: bottle), engine.ships("d3dmetal"), engine.rendererDir("d3dmetal") == nil {
pendingD3DMetal = (item, bottle, engine)
return
}
@@ -182,7 +182,7 @@ final class AppState {
}
refresh()
let fresh = bottles.first { $0.name == bottleName } ?? runner.bottle
- launch(item, in: fresh)
+ launch(item, in: fresh, renderer: renderer)
}
return
}
@@ -198,19 +198,19 @@ final class AppState {
}))
return
}
- launch(item, in: bottle)
+ launch(item, in: bottle, renderer: renderer)
}
- private func launch(_ item: LibraryItem, in bottle: Bottle) {
+ private func launch(_ item: LibraryItem, in bottle: Bottle, renderer: Renderer? = nil) {
recordPlay(item)
if !FunnelLog.records(in: paths.logs).contains(where: { $0.event == .firstLaunch }) { funnel(.firstLaunch) }
switch item.source {
case .steam:
guard let game = (gamesByBottle[bottle.name] ?? []).first(where: { $0.appid == item.steamAppID }) else { return }
- launchGame(game, in: bottle)
+ launchGame(game, in: bottle, renderer: renderer)
case .epic:
guard let game = epicOwned.first(where: { $0.app_name == item.epicAppName }) else { return }
- epicPlay(game, in: bottle)
+ epicPlay(game, in: bottle, renderer: renderer)
case .pin:
guard let pin = bottle.settings.pins.first(where: { $0.id == item.pinID }) else { return }
launch(pin: pin, in: bottle)
@@ -267,6 +267,8 @@ final class AppState {
/// A Windows program awaiting the run/pin choice (from drag-drop, the File menu, or the button).
var pendingRun: URL?
+ /// The environment a dropped program runs in: the page it was dropped on, else the default.
+ var pendingRunBottle: String?
func chooseProgramToRun() {
let panel = NSOpenPanel()
@@ -583,11 +585,11 @@ final class AppState {
guard let manifestURL = Self.bundledManifest else {
errorMessage = "No engine manifest found. Reinstall Highball."; return
}
- funnel(.installStarted)
runBusy(L("Setting up Highball"),
expected: L("usually 5–15 minutes"),
done: DoneState(title: L("Highball is ready"), ctaTitle: nil, cta: nil),
stop: .cancelTask(label: L("Stop"))) { [self] in
+ funnel(.installStarted)
if !rosettaInstalled {
await MainActor.run { self.stage = L("Installing Rosetta, Apple's compatibility layer") }
try await Self.installRosetta()
@@ -666,12 +668,22 @@ final class AppState {
var pendingD3DMetal: (item: LibraryItem, bottle: Bottle, engine: InstalledEngine)?
func enableD3DMetalAndPlay() {
- guard let (item, bottle, engine) = pendingD3DMetal else { return }
+ guard let (item, _, engine) = pendingD3DMetal else { return }
pendingD3DMetal = nil
acceptGPTK(engine: engine)
- if let fresh = bottles.first(where: { $0.name == bottle.name }) { launch(item, in: fresh) }
+ play(item) // through play, so a fix recipe still applies
}
+ /// The other graphics mode the row recorded as working, when the person declines D3DMetal.
+ func playPendingD3DMetal(with renderer: Renderer) {
+ guard let (item, _, _) = pendingD3DMetal else { return }
+ pendingD3DMetal = nil
+ play(item, renderer: renderer)
+ }
+
+ /// The engine the licence sheet enables D3DMetal on: the one the ask was about.
+ var licenseEngine: InstalledEngine?
+
func acceptGPTK(engine: InstalledEngine) {
do { _ = try engineStore.accept(license: "apple-gptk-license-2023-08-17", engine: engine); refresh() }
catch { fail(error) }
@@ -844,12 +856,12 @@ final class AppState {
started: session.started, ended: Date(), reason: reason, renderer: session.renderer)
SessionWatch.append(record, to: paths.logs)
lastEndedSession = record
- let firstSession = !FunnelLog.records(in: paths.logs).contains { $0.event == .sessionEnded }
funnel(.sessionEnded, detail: "\(record.seconds) s, \(reason)")
if record.seconds >= 60 {
postPlay = record
- // The consent question comes after the first successful game, never before (0.7).
- if !funnelAsked, firstSession { funnelOffer = true }
+ // The consent question comes after the first game that ran for a minute, never
+ // before (0.7); asked once, whatever the answer.
+ if !funnelAsked { funnelOffer = true }
}
appendLog("\(session.title) \(reason) after \(record.seconds / 60) min")
}
@@ -1032,7 +1044,7 @@ final class AppState {
}
/// Launch a Steam game by appid through the bottle's Steam client.
- func launchGame(_ game: SteamGame, in bottle: Bottle) {
+ func launchGame(_ game: SteamGame, in bottle: Bottle, renderer preferred: Renderer? = nil) {
guard let engine = engine(for: bottle) else { return }
if let running = session(forAppID: game.appid) {
fail(HighballError.failed("\(running.title) is already running."))
@@ -1040,7 +1052,9 @@ final class AppState {
}
let steam = bottle.driveC.appending(path: "Program Files (x86)/Steam/steam.exe")
let entry = gameDB[game.appid]
- let renderer = entry?.effectiveRenderer()
+ // A mode the user set on the environment is respected, as the page promises; the row's
+ // verified mode applies otherwise, and a forced mode (the D3DMetal ask) beats both.
+ let renderer = preferred ?? (bottle.settings.rendererExplicit ? nil : entry?.effectiveRenderer())
// Per-game launch args ride the db (e.g. windowed for legacy CS:GO on macOS 26, #21).
let extraArgs = entry?.effectiveLaunchArgs() ?? []
let markers = SessionWatch.markers(installdir: game.installdir)
diff --git a/Sources/HighballApp/BottleView.swift b/Sources/HighballApp/BottleView.swift
index 4da8247..b920ec4 100644
--- a/Sources/HighballApp/BottleView.swift
+++ b/Sources/HighballApp/BottleView.swift
@@ -85,7 +85,7 @@ struct BottleView: View {
_ = provider.loadObject(ofClass: URL.self) { url, _ in
guard let url else { return }
if ["exe", "msi", "bat"].contains(url.pathExtension.lowercased()) {
- Task { @MainActor in state.pendingRun = url }
+ Task { @MainActor in state.pendingRunBottle = bottle.name; state.pendingRun = url }
} else {
// Silently ignoring a drop reads as "nothing happened" (Reddit report) — say why.
Task { @MainActor in
@@ -95,13 +95,6 @@ struct BottleView: View {
}
return true
}
- .confirmationDialog("Run \(state.pendingRun?.lastPathComponent ?? "") in this bottle?",
- isPresented: .init(get: { state.pendingRun != nil }, set: { if !$0 { state.pendingRun = nil } }),
- titleVisibility: .visible) {
- Button(L("Run")) { if let u = state.pendingRun { state.runDropped(u, in: bottle, andPin: false) }; state.pendingRun = nil }
- Button(L("Run and add to Programs")) { if let u = state.pendingRun { state.runDropped(u, in: bottle, andPin: true) }; state.pendingRun = nil }
- Button(L("Cancel"), role: .cancel) { state.pendingRun = nil }
- }
}
// MARK: Launchers
@@ -494,7 +487,7 @@ struct GPTKLicenseSheet: View {
.font(.caption).foregroundStyle(.secondary)
Spacer()
Button(L("Close")) { dismiss() }
- if let engine = state.engines.first, engine.rendererDir("d3dmetal") == nil {
+ if let engine = state.licenseEngine ?? state.defaultEngine ?? state.engines.first, engine.rendererDir("d3dmetal") == nil {
Button(L("Accept & enable D3DMetal")) {
state.acceptGPTK(engine: engine)
dismiss()
diff --git a/Sources/HighballApp/GameDetailView.swift b/Sources/HighballApp/GameDetailView.swift
index a5bdc36..c2bb0e4 100644
--- a/Sources/HighballApp/GameDetailView.swift
+++ b/Sources/HighballApp/GameDetailView.swift
@@ -24,7 +24,8 @@ struct GameDetailView: View {
}
private var verdict: GamePageCopy.Verdict { GamePageCopy.verdict(entry, myChip: state.machineChip) }
private var willDo: [GamePageCopy.WillDo] {
- GamePageCopy.willDo(entry, recipe: fixRecipe, applied: fixApplied, bottleRenderer: bottle?.settings.renderer ?? .dxvk)
+ GamePageCopy.willDo(entry, recipe: fixRecipe, applied: fixApplied, bottleRenderer: bottle?.settings.renderer ?? .dxvk,
+ explicit: bottle?.settings.rendererExplicit ?? false)
}
private var engineName: String? { bottle.flatMap { state.engine(for: $0) }?.displayName }
diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swift
index 7282fbc..a3eae1d 100644
--- a/Sources/HighballApp/HighballApp.swift
+++ b/Sources/HighballApp/HighballApp.swift
@@ -111,6 +111,11 @@ struct ContentView: View {
@State private var showCreate = false
@State private var pendingDelete: String?
+ /// Where a dropped or chosen program runs: the environment page it came from, else the default.
+ private var runTarget: Bottle? {
+ state.bottles.first { $0.name == state.pendingRunBottle } ?? state.defaultBottle
+ }
+
var body: some View {
@Bindable var state = state
Group {
@@ -147,8 +152,28 @@ struct ContentView: View {
// Everything that takes time lives on one strip at the bottom, never modal (UX plan 0.5).
.safeAreaInset(edge: .bottom, spacing: 0) { ActivityStrip() }
.sheet(isPresented: $showCreate) { CreateBottleSheet() }
- .onChange(of: state.requestCreateBottle) { _, wants in
- if wants { showCreate = true; state.requestCreateBottle = false }
+ // A Windows program dropped anywhere on the window, or picked from Add games and ⌘O,
+ // runs in the environment it was dropped on, else the default one.
+ .onDrop(of: [.fileURL], isTargeted: nil) { providers in
+ guard let provider = providers.first else { return false }
+ _ = provider.loadObject(ofClass: URL.self) { url, _ in
+ guard let url else { return }
+ if ["exe", "msi", "bat"].contains(url.pathExtension.lowercased()) {
+ Task { @MainActor in state.pendingRunBottle = nil; state.pendingRun = url }
+ } else {
+ Task { @MainActor in
+ state.errorMessage = String(format: L("'%@' isn't a Windows program. You can drop .exe, .msi or .bat files here."), url.lastPathComponent)
+ }
+ }
+ }
+ return true
+ }
+ .confirmationDialog(String(format: L("Run %@ in %@?"), state.pendingRun?.lastPathComponent ?? "", runTarget?.name ?? ""),
+ isPresented: .init(get: { state.pendingRun != nil }, set: { if !$0 { state.pendingRun = nil; state.pendingRunBottle = nil } }),
+ titleVisibility: .visible) {
+ Button(L("Run")) { if let u = state.pendingRun, let b = runTarget { state.runDropped(u, in: b, andPin: false) }; state.pendingRun = nil }
+ Button(L("Run and add to Programs")) { if let u = state.pendingRun, let b = runTarget { state.runDropped(u, in: b, andPin: true) }; state.pendingRun = nil }
+ Button(L("Cancel"), role: .cancel) { state.pendingRun = nil }
}
.confirmationDialog("Delete bottle \"\(pendingDelete ?? "")\"? This removes its Windows drive and everything installed in it.",
isPresented: .init(get: { pendingDelete != nil }, set: { if !$0 { pendingDelete = nil } }),
@@ -164,7 +189,11 @@ struct ContentView: View {
isPresented: .init(get: { state.pendingD3DMetal != nil }, set: { if !$0 { state.pendingD3DMetal = nil } }),
presenting: state.pendingD3DMetal) { pending in
Button(L("Turn it on and play")) { state.enableD3DMetalAndPlay() }
+ if let other = GamePageCopy.otherWorkingRenderer(pending.item.steamAppID.flatMap { state.gameDB[$0] }) {
+ Button(String(format: L("Play with %@"), GamePageCopy.plainName(other))) { state.playPendingD3DMetal(with: other) }
+ }
Button(L("Read Apple's licence")) {
+ state.licenseEngine = pending.engine
state.pendingD3DMetal = nil
state.loadGPTKLicense(); state.showGPTKLicense = true
}
diff --git a/Sources/HighballApp/SettingsView.swift b/Sources/HighballApp/SettingsView.swift
index ab4cc4a..7e4a617 100644
--- a/Sources/HighballApp/SettingsView.swift
+++ b/Sources/HighballApp/SettingsView.swift
@@ -104,6 +104,7 @@ struct EnvironmentsPane: View {
struct EnginePane: View {
@Environment(AppState.self) private var state
+ @State private var showLicense = false
var body: some View {
VStack(alignment: .leading, spacing: 14) {
@@ -116,9 +117,9 @@ struct EnginePane: View {
Text(engine.id).font(.caption.monospaced()).foregroundStyle(.secondary)
Text(String(format: L("Graphics layers: %@"), ["dxmt", "dxvk", "d3dmetal"].filter { engine.rendererDir($0) != nil }.map { GamePageCopy.plainName(Renderer(rawValue: $0) ?? .dxvk) }.joined(separator: ", ")))
.font(.caption).foregroundStyle(.secondary)
- if engine.rendererDir("d3dmetal") == nil, engine.manifest.components["d3dmetal"] != nil {
+ if engine.ships("d3dmetal"), engine.rendererDir("d3dmetal") == nil {
Button(L("Read Apple's licence and turn on DirectX 12 support…")) {
- state.loadGPTKLicense(); state.showGPTKLicense = true
+ state.licenseEngine = engine; state.loadGPTKLicense(); showLicense = true
}.buttonStyle(.link).font(.caption)
}
}.frame(maxWidth: .infinity, alignment: .leading)
@@ -143,11 +144,13 @@ struct EnginePane: View {
Spacer()
}
.padding(20)
+ .sheet(isPresented: $showLicense) { GPTKLicenseSheet() }
}
}
struct TroubleshootingPane: View {
@Environment(AppState.self) private var state
+ @State private var showLog = false
var body: some View {
VStack(alignment: .leading, spacing: 14) {
@@ -162,7 +165,7 @@ struct TroubleshootingPane: View {
await MainActor.run { NSWorkspace.shared.open(url) }
}
}
- Button(L("Show the activity log")) { state.showLog = true }
+ Button(L("Show the activity log")) { showLog = true }
}
if let b = state.defaultBottle {
Divider()
@@ -173,5 +176,6 @@ struct TroubleshootingPane: View {
Spacer()
}
.padding(20)
+ .sheet(isPresented: $showLog) { LogSheet() }
}
}
diff --git a/Sources/HighballKit/BottleStore.swift b/Sources/HighballKit/BottleStore.swift
index 9198ca1..241ced9 100644
--- a/Sources/HighballKit/BottleStore.swift
+++ b/Sources/HighballKit/BottleStore.swift
@@ -70,9 +70,19 @@ public struct BottleStore: Sendable {
try bottle.save()
let runner = WineRunner(paths: paths, engine: engine, bottle: bottle)
let result = try await runner.wineboot()
+ // A boot that failed, or one the user stopped, must not leave a half-made bottle that
+ // the next attempt mistakes for a finished one ("already exists", or a library that
+ // says ready over an environment that never booted).
guard result.exitStatus == 0 else {
+ try? runner.kill()
+ _ = try? discard(url, name: name)
throw HighballError.processFailed(command: "wineboot -u", status: result.exitStatus, output: "see \(result.log.path)")
}
+ if Task.isCancelled {
+ try? runner.kill()
+ _ = try? discard(url, name: name)
+ throw CancellationError()
+ }
do {
try await Self.ensureWoW64(runner: runner, bottle: bottle, log: result.log)
} catch {
diff --git a/Sources/HighballKit/EngineStore.swift b/Sources/HighballKit/EngineStore.swift
index ee9364d..b346cd3 100644
--- a/Sources/HighballKit/EngineStore.swift
+++ b/Sources/HighballKit/EngineStore.swift
@@ -363,6 +363,14 @@ public struct InstalledEngine: Sendable {
}
/// Renderer overlay directory: Gin's own `renderers/<name>` wins over the Template's `frameworks/renderer/<name>`.
+ /// Whether the engine carries a renderer at all, licence aside: D3DMetal ships inside the
+ /// runtime template and `rendererDir` hides it until the licence is accepted.
+ public func ships(_ name: String) -> Bool {
+ let own = renderersDir.appending(path: name, directoryHint: .isDirectory).appending(path: "wine")
+ let template = frameworksDir.appending(path: "renderer/\(name)", directoryHint: .isDirectory).appending(path: "wine")
+ return FileManager.default.fileExists(atPath: own.path) || FileManager.default.fileExists(atPath: template.path)
+ }
+
public func rendererDir(_ name: String) -> URL? {
if let gate = EngineManifest.gatedRenderers[name], !(manifest.acceptedLicenses ?? []).contains(gate) { return nil }
let own = renderersDir.appending(path: name, directoryHint: .isDirectory)
diff --git a/Sources/HighballKit/GamePageCopy.swift b/Sources/HighballKit/GamePageCopy.swift
index 918db0a..8347992 100644
--- a/Sources/HighballKit/GamePageCopy.swift
+++ b/Sources/HighballKit/GamePageCopy.swift
@@ -56,9 +56,12 @@ public enum GamePageCopy {
/// What Play applies, in order, from the row and the fix recipe. `applied` means the recipe
/// already ran in this environment, so its steps read as done.
public static func willDo(_ entry: GameDBEntry?, recipe: Recipe?, applied: Bool,
- bottleRenderer: Renderer, osMajor: Int = ProcessInfo.processInfo.operatingSystemVersion.majorVersion) -> [WillDo] {
+ bottleRenderer: Renderer, explicit: Bool = false,
+ osMajor: Int = ProcessInfo.processInfo.operatingSystemVersion.majorVersion) -> [WillDo] {
var items: [WillDo] = []
- if let wanted = entry?.effectiveRenderer(osMajor: osMajor) {
+ if explicit {
+ items.append(WillDo(text: "Use \(plainName(bottleRenderer)), the environment's setting (set by you)"))
+ } else if let wanted = entry?.effectiveRenderer(osMajor: osMajor) {
items.append(WillDo(text: wanted == bottleRenderer
? "Use \(plainName(wanted)), the way it was verified"
: "Use \(plainName(wanted)) for this game, the way it was verified, instead of the environment's \(wanted == bottleRenderer ? "" : plainName(bottleRenderer))"))
@@ -134,10 +137,18 @@ extension GamePageCopy {
/// The consequence sentence of the D3DMetal ask, from the row: "will not start" only when
/// no other renderer is recorded as working, "runs faster with it" when one is.
public static func d3dMetalAsk(title: String, entry: GameDBEntry?) -> String {
- let other = entry?.rendererResults?.contains { key, r in key != "d3dmetal" && r.verdict == "works" } ?? false
- let consequence = other
- ? "Without it, \(title) still runs on the other graphics mode that was verified, but slower."
- : "Without it, \(title) will not start: it needs DirectX 12, and the other graphics modes only cover DirectX 11."
+ let consequence = otherWorkingRenderer(entry).map {
+ "Without it, \(title) still runs on \(plainName($0)), which was recorded as working, but slower."
+ } ?? "The database records no other graphics mode as working for \(title), so without it Highball has nothing else to try."
return "Highball already includes it. Turning it on means accepting Apple's licence, which allows non-commercial use. \(consequence) Nothing to download and nothing sent to Apple."
}
+
+ /// A graphics mode other than D3DMetal that the row recorded as working, if any.
+ public static func otherWorkingRenderer(_ entry: GameDBEntry?) -> Renderer? {
+ guard let results = entry?.rendererResults else { return nil }
+ for key in ["dxmt", "dxvk", "wined3d"] where results[key]?.verdict == "works" {
+ if let r = Renderer(rawValue: key) { return r }
+ }
+ return nil
+ }
}
diff --git a/Tests/HighballKitTests/GamePageCopyTests.swift b/Tests/HighballKitTests/GamePageCopyTests.swift
index ae801cd..f77c8a1 100644
--- a/Tests/HighballKitTests/GamePageCopyTests.swift
+++ b/Tests/HighballKitTests/GamePageCopyTests.swift
@@ -63,8 +63,13 @@ final class GamePageCopyTests: XCTestCase {
extension GamePageCopyTests {
func testD3DMetalAskConsequenceComesFromTheRow() throws {
let only = try entry(#"{"id":"x","title":"X","steam_appid":1,"status":"verified-local","renderer":"d3dmetal"}"#)
- XCTAssertTrue(GamePageCopy.d3dMetalAsk(title: "X", entry: only).contains("will not start"))
+ XCTAssertTrue(GamePageCopy.d3dMetalAsk(title: "X", entry: only).contains("no other graphics mode"))
+ XCTAssertNil(GamePageCopy.otherWorkingRenderer(only))
let alt = try entry(#"{"id":"x","title":"X","steam_appid":1,"status":"verified-local","renderer":"d3dmetal","rendererResults":{"dxvk":{"verdict":"works","detail":"slower"}}}"#)
XCTAssertTrue(GamePageCopy.d3dMetalAsk(title: "X", entry: alt).contains("but slower"))
+ XCTAssertEqual(GamePageCopy.otherWorkingRenderer(alt), .dxvk)
+ let e = try entry(#"{"id":"x","title":"X","steam_appid":1,"status":"verified-local","renderer":"dxmt"}"#)
+ XCTAssertEqual(GamePageCopy.willDo(e, recipe: nil, applied: false, bottleRenderer: .dxvk, explicit: true, osMajor: 26).first?.text,
+ "Use DXVK (Vulkan on Metal), the environment's setting (set by you)")
}
}