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
First launch is one button; the empty library asks where your games are
Gauthier Piarrette86a1f361120c
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex ae5f6c9..a90fb9d 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -158,6 +158,12 @@ final class AppState {func play(_ item: LibraryItem) {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 {+ pendingD3DMetal = (item, bottle, engine)+ return+ }if let recipe = fixRecipe(for: item), !bottle.settings.recipes.contains(recipe.id),let engine = engine(for: bottle) {if recipe.isAutoApplicable {@@ -560,25 +566,96 @@ final class AppState {// MARK: Actions- func installDefaultEngine(acceptGPTK: Bool) {+ /// The name of the environment Highball makes for everyone; bottles stay a power feature.+ static let defaultEnvironmentName = "Games"++ /// First launch, one button (UX plan §3.2): Rosetta if the Mac lacks it, the engine+ /// download, then one Windows environment, all on the strip with Stop. No licence question+ /// here: D3DMetal is asked for at the first game that needs it.+ func getStarted() {guard let manifestURL = Self.bundledManifest else {errorMessage = "No engine manifest found. Reinstall Highball."; return}- runBusy(L("Downloading the Windows engine"),+ runBusy(L("Setting up Highball"),expected: L("usually 5–15 minutes"),- done: DoneState(title: L("Engine ready"), ctaTitle: L("Create your first bottle"),- cta: { [weak self] in self?.requestCreateBottle = true }),+ done: DoneState(title: L("Highball is ready"), ctaTitle: nil, cta: nil),stop: .cancelTask(label: L("Stop"))) { [self] in- let manifest = try EngineManifest.load(from: manifestURL)- var accepted: Set<String> = []- if acceptGPTK { accepted.insert("apple-gptk-license-2023-08-17") }- _ = try await engineStore.install(manifest, accepted: accepted) { name, received, total in- Task { @MainActor in self.reportDownload(name, received: received, total: total) }+ if !rosettaInstalled {+ await MainActor.run { self.stage = L("Installing Rosetta, Apple's compatibility layer") }+ try await Self.installRosetta()+ await MainActor.run { self.rosettaInstalled = true; self.appendLog("Rosetta installed") }+ }+ if engines.isEmpty {+ let manifest = try EngineManifest.load(from: manifestURL)+ _ = try await engineStore.install(manifest, accepted: []) { name, received, total in+ Task { @MainActor in self.reportDownload(name, received: received, total: total) }+ }+ await MainActor.run { self.appendLog("engine installed"); self.refresh() }+ }+ if bottles.isEmpty, let engine = defaultEngine {+ await MainActor.run { self.stage = L("Preparing your Windows environment"); self.busyExpected = L("about 90 seconds") }+ _ = try await bottleStore.create(name: Self.defaultEnvironmentName, engine: engine)+ await MainActor.run { self.appendLog("environment ready"); self.selectedBottle = Self.defaultEnvironmentName; self.pane = .library }}- await MainActor.run { self.appendLog("engine installed") }}}+ /// `softwareupdate` installs Rosetta for a normal user on Apple silicon; when it cannot,+ /// the error names the one command that does, so the recovery card can show it.+ static func installRosetta() async throws {+ let out = try await Task.detached { () -> (Int32, String) in+ let p = Process(); p.executableURL = URL(fileURLWithPath: "/usr/sbin/softwareupdate")+ p.arguments = ["--install-rosetta", "--agree-to-license"]+ let pipe = Pipe(); p.standardOutput = pipe; p.standardError = pipe+ try p.run(); p.waitUntilExit()+ return (p.terminationStatus, String(decoding: pipe.fileHandleForReading.readDataToEndOfFile(), as: UTF8.self))+ }.value+ let installed = FileManager.default.fileExists(atPath: "/Library/Apple/usr/share/rosetta/rosetta")+ guard out.0 == 0 || installed else {+ throw HighballError.failed("Rosetta did not install. In Terminal, run: softwareupdate --install-rosetta --agree-to-license, then press Get started again. (\(out.1.trimmingCharacters(in: .whitespacesAndNewlines).suffix(200)))")+ }+ }++ /// The environment new games go into: the one named Games, else the first.+ var defaultBottle: Bottle? {+ bottles.first { $0.name == Self.defaultEnvironmentName } ?? bottles.first+ }++ /// Makes the default environment for a Mac that has the engine but no bottle yet.+ func makeDefaultEnvironment() {+ guard let engine = defaultEngine else { return }+ runBusy(L("Preparing your Windows environment"), expected: L("about 90 seconds"),+ done: DoneState(title: L("Highball is ready"), ctaTitle: nil, cta: nil)) { [self] in+ _ = try await bottleStore.create(name: Self.defaultEnvironmentName, engine: engine)+ await MainActor.run { self.selectedBottle = Self.defaultEnvironmentName; self.pane = .library }+ }+ }++ /// Installs Steam into the default environment and opens its window (the "Where are your+ /// games?" card). Steam's own first start follows, on the strip.+ func installSteam() {+ guard let bottle = defaultBottle else { makeDefaultEnvironment(); return }+ let steam = bottle.driveC.appending(path: "Program Files (x86)/Steam/steam.exe")+ applyRecipe("steam", to: bottle, then: DoneState(+ title: L("Steam is installed"), ctaTitle: L("Open Steam"),+ cta: { [weak self] in+ guard let self, let fresh = self.bottles.first(where: { $0.name == bottle.name }) else { return }+ self.launch(pin: Pin(name: "Steam", path: Pin.storagePath(for: steam, driveC: fresh.driveC)), in: fresh)+ }))+ }++ /// A game the row says needs D3DMetal, on an engine where it is not enabled yet: Play asks+ /// once, in context, with the consequence from the row (UX plan §3.5, canvas "Asked in+ /// context"). Nothing downloads; the files are in the engine and accepting flips the flag.+ var pendingD3DMetal: (item: LibraryItem, bottle: Bottle, engine: InstalledEngine)?++ func enableD3DMetalAndPlay() {+ guard let (item, bottle, engine) = pendingD3DMetal else { return }+ pendingD3DMetal = nil+ acceptGPTK(engine: engine)+ if let fresh = bottles.first(where: { $0.name == bottle.name }) { launch(item, in: fresh) }+ }+func acceptGPTK(engine: InstalledEngine) {do { _ = try engineStore.accept(license: "apple-gptk-license-2023-08-17", engine: engine); refresh() }catch { fail(error) }diff --git a/Sources/HighballApp/BottleView.swift b/Sources/HighballApp/BottleView.swiftindex fdaae61..4da8247 100644--- a/Sources/HighballApp/BottleView.swift+++ b/Sources/HighballApp/BottleView.swift@@ -437,7 +437,6 @@ struct BottleSettingsSheet: View {struct OnboardingView: View {@Environment(AppState.self) private var state- @State private var acceptGPTK = falsevar body: some View {ZStack {@@ -450,45 +449,24 @@ struct OnboardingView: View {Image(systemName: "wineglass.fill").font(.system(size: 52)).foregroundStyle(.tint)}Text("Highball").font(.system(size: 36, weight: .heavy, design: .rounded))- Text(L("Run Windows games on your Mac. Highball downloads a verified Wine engine (~500 MB) from public upstream releases — nothing is hosted by Highball itself."))- .multilineTextAlignment(.center).frame(maxWidth: 440).foregroundStyle(.secondary)-- if !state.rosettaInstalled {- GroupBox {- VStack(alignment: .leading, spacing: 6) {- Label(L("Rosetta 2 is required"), systemImage: "exclamationmark.triangle")- Text("softwareupdate --install-rosetta --agree-to-license").font(.caption.monospaced())- }- }.frame(maxWidth: 440)- }-- Toggle(isOn: $acceptGPTK) {- VStack(alignment: .leading, spacing: 2) {- Text(L("Enable D3DMetal (DirectX 12 support)"))- HStack(spacing: 4) {- Text(L("Requires accepting")).font(.caption).foregroundStyle(.secondary)- Button(L("Apple’s Game Porting Toolkit license")) {- Task { @MainActor in- state.loadGPTKLicense()- state.showGPTKLicense = true- }- }.buttonStyle(.link).font(.caption)- }- }- }- .toggleStyle(.checkbox)- .frame(maxWidth: 440, alignment: .leading)-+ Text(L("Play Windows games on your Mac."))+ .font(.title3).foregroundStyle(.secondary)Button {- state.installDefaultEngine(acceptGPTK: acceptGPTK)+ state.getStarted()} label: {- Text(state.busy ? L("Installing…") : L("Install engine")).frame(minWidth: 190)+ Text(state.busy ? L("Setting up…") : L("Get started")).frame(minWidth: 190)}- .buttonStyle(.borderedProminent)- .controlSize(.large)- .disabled(state.busy || !state.rosettaInstalled)-- Text(L("Wine LGPL · DXMT MIT · DXVK Zlib · engine builds by Gcenx / Sikarugir — consider sponsoring them."))+ .buttonStyle(.borderedProminent).controlSize(.large).tint(HB.amber)+ .disabled(state.busy)+ .padding(.top, 6)+ Text(state.rosettaInstalled+ ? L("Nothing to choose. The download takes a few minutes on most connections.")+ : L("Nothing to choose. Highball installs Rosetta for you, then the download takes a few minutes."))+ .font(.callout).foregroundStyle(.secondary).multilineTextAlignment(.center).frame(maxWidth: 440)+ Spacer().frame(height: 30)+ Text(L("Highball downloads a Wine engine from public upstream releases. Nothing is hosted by us."))+ .font(.caption).foregroundStyle(.tertiary)+ Text(L("Wine LGPL · DXMT MIT · DXVK Zlib · engine builds by Gcenx and Sikarugir")).font(.caption2).foregroundStyle(.tertiary)}.padding(40)diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swiftindex 983a45a..b916b00 100644--- a/Sources/HighballApp/HighballApp.swift+++ b/Sources/HighballApp/HighballApp.swift@@ -281,6 +281,21 @@ struct ContentView: View {}.sheet(isPresented: $state.showLog) { LogSheet() }.sheet(isPresented: $state.showGPTKLicense) { GPTKLicenseSheet() }+ // Asked at the first game that needs it, never at install (UX plan §3.5). Nothing+ // downloads: D3DMetal is already inside the engine and accepting flips a flag.+ .alert(String(format: L("%@ needs Apple's DirectX 12 support"), state.pendingD3DMetal?.item.title ?? ""),+ 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() }+ Button(L("Read Apple's licence")) {+ state.pendingD3DMetal = nil+ state.loadGPTKLicense(); state.showGPTKLicense = true+ }+ Button(L("Not now"), role: .cancel) { state.pendingD3DMetal = nil }+ } message: { pending in+ let entry = pending.item.steamAppID.flatMap { state.gameDB[$0] }+ Text(GamePageCopy.d3dMetalAsk(title: pending.item.title, entry: entry))+ }.sheet(isPresented: $state.showEpicSignIn) { EpicSignInSheet() }// A partial delete succeeded — the bottle is gone and the name is free — so framing it as// a failure, with an invitation to file a bug, misreads what happened. Same alert, honestdiff --git a/Sources/HighballApp/LibraryView.swift b/Sources/HighballApp/LibraryView.swiftindex 1c7d7b3..6ae575b 100644--- a/Sources/HighballApp/LibraryView.swift+++ b/Sources/HighballApp/LibraryView.swift@@ -97,25 +97,66 @@ struct LibraryView: View {@ViewBuilder private var emptyState: some View {VStack(alignment: .leading, spacing: 10) {if state.bottles.isEmpty {- Text(L("No bottles yet. A bottle is a private Windows environment for your games."))+ // An engine without an environment: an older install, or a stopped first run.+ Text(L("One more step: Highball prepares a Windows environment for your games.")).foregroundStyle(.secondary)- Button(L("Create your first bottle")) { state.requestCreateBottle = true }- .buttonStyle(.borderedProminent)+ Button(L("Prepare it now")) { state.makeDefaultEnvironment() }+ .buttonStyle(.borderedProminent).tint(HB.amber).disabled(state.busy)} else if state.libraryItems.isEmpty {- Text(L("No games yet. Install Steam in a bottle, or connect your Epic account."))- .foregroundStyle(.secondary)- HStack(spacing: 10) {- if let bottle = state.bottles.first(where: { $0.name == state.selectedBottle }) ?? state.bottles.first {- Button(L("Install Steam")) { state.applyRecipe("steam", to: bottle) }- }- Button(L("Connect Epic account…")) { state.showEpicSignIn = true }- }+ whereAreYourGames} else {Text(L("Nothing matches these filters.")).foregroundStyle(.secondary)}}.padding(.vertical, 24)}++ /// Where your games are is a question anyone can answer (UX plan §3.2); Steam is not+ /// installed unasked, and a GOG or standalone user never waits for its first boot.+ private var whereAreYourGames: some View {+ VStack(alignment: .center, spacing: 22) {+ VStack(spacing: 6) {+ Text(L("Where are your games?")).font(.title.weight(.semibold))+ Text(L("Pick one to start. You can add the others any time.")).foregroundStyle(.secondary)+ }+ HStack(alignment: .top, spacing: 14) {+ sourceCard(symbol: "gamecontroller.fill", accent: true, title: L("Steam"),+ text: L("Install Steam and sign in. Your Steam library shows up here. Its first start takes 15 to 25 minutes."),+ button: L("Install Steam")) { state.installSteam() }+ sourceCard(symbol: "bag.fill", accent: false, title: L("Epic Games"),+ text: L("Connect your Epic account. Your games install straight into Highball."),+ button: L("Connect Epic")) { state.showEpicSignIn = true }+ sourceCard(symbol: "folder.fill", accent: false, title: L("A Windows program I have"),+ text: L("An installer or game from your Mac. Or drop it onto this window."),+ button: L("Choose a file…")) { state.chooseProgramToRun() }+ }+ Text(L("Battle.net, GOG Galaxy, the EA app, Ubisoft Connect and Rockstar are on the environment's page."))+ .font(.caption).foregroundStyle(.tertiary)+ }+ .frame(maxWidth: .infinity)+ .padding(.top, 40)+ }++ private func sourceCard(symbol: String, accent: Bool, title: String, text: String, button: String, action: @escaping () -> Void) -> some View {+ VStack(alignment: .leading, spacing: 12) {+ Image(systemName: symbol).font(.title3)+ .frame(width: 42, height: 42)+ .background(Circle().fill(accent ? HB.amber : Color.white.opacity(0.08)))+ .foregroundStyle(accent ? Color.black : Color.secondary)+ Text(title).font(.headline)+ Text(text).font(.callout).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)+ Spacer(minLength: 0)+ if accent {+ Button(button, action: action).buttonStyle(.borderedProminent).tint(HB.amber).disabled(state.busy)+ } else {+ Button(button, action: action).buttonStyle(.bordered).disabled(state.busy)+ }+ }+ .padding(18)+ .frame(width: 250, height: 230, alignment: .topLeading)+ .background(RoundedRectangle(cornerRadius: 12).fill(HB.card))+ .overlay(RoundedRectangle(cornerRadius: 12).stroke(accent ? HB.amber.opacity(0.5) : HB.cardStroke))+ }}struct FilterChip: View {diff --git a/Sources/HighballKit/GamePageCopy.swift b/Sources/HighballKit/GamePageCopy.swiftindex 0eeea00..918db0a 100644--- a/Sources/HighballKit/GamePageCopy.swift+++ b/Sources/HighballKit/GamePageCopy.swift@@ -129,3 +129,15 @@ public enum GamePageCopy {}}}++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."+ 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."+ }+}diff --git a/Tests/HighballKitTests/GamePageCopyTests.swift b/Tests/HighballKitTests/GamePageCopyTests.swiftindex b25999b..ae801cd 100644--- a/Tests/HighballKitTests/GamePageCopyTests.swift+++ b/Tests/HighballKitTests/GamePageCopyTests.swift@@ -59,3 +59,12 @@ final class GamePageCopyTests: XCTestCase {XCTAssertTrue(done[2].done); XCTAssertNil(done[2].cost)}}++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"))+ 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"))+ }+}