Skip to content

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

Whole-app review, batch 1: launch correctness and reachability

Gauthier Piarrette60c73d5d2d01
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index c281a28..1c92dc5 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -159,7 +159,8 @@ final class AppState {
func play(_ item: LibraryItem, renderer: Renderer? = nil) {
guard let bottleName = item.bottleName,
let bottle = bottles.first(where: { $0.name == bottleName }) else { return }
- if renderer == nil, let appid = item.steamAppID, gameDB[appid]?.effectiveRenderer() == .d3dmetal,
+ if renderer == nil, !bottle.settings.rendererExplicit,
+ 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
@@ -583,7 +584,7 @@ final class AppState {
/// 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
+ fail(HighballError.failed("No engine manifest is bundled. Reinstall Highball.")); return
}
runBusy(L("Setting up Highball"),
expected: L("usually 5–15 minutes"),
@@ -643,6 +644,21 @@ final class AppState {
/// 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.
+ /// Opens a launcher's window if it is installed in the default environment, else installs it.
+ /// The launcher's pin is named by its short label (see BottleView.launcherMeta / recipes).
+ func openOrInstallLauncher(_ id: String, short: String) {
+ guard let bottle = defaultBottle else { makeDefaultEnvironment(); return }
+ let fresh = bottles.first { $0.name == bottle.name } ?? bottle
+ if fresh.settings.recipes.contains(id),
+ let pin = fresh.settings.pins.first(where: { $0.name.lowercased().hasPrefix(short.lowercased().prefix(5)) }) {
+ launch(pin: pin, in: fresh)
+ } else {
+ applyRecipe(id, to: fresh)
+ }
+ }
+
+ func launcherInstalled(_ id: String) -> Bool { defaultBottle?.settings.recipes.contains(id) ?? false }
+
func installSteam() {
guard let bottle = defaultBottle else { makeDefaultEnvironment(); return }
let steam = bottle.driveC.appending(path: "Program Files (x86)/Steam/steam.exe")
@@ -671,7 +687,7 @@ final class AppState {
guard let (item, _, engine) = pendingD3DMetal else { return }
pendingD3DMetal = nil
acceptGPTK(engine: engine)
- play(item) // through play, so a fix recipe still applies
+ play(item, renderer: .d3dmetal) // through play, so a fix recipe still applies
}
/// The other graphics mode the row recorded as working, when the person declines D3DMetal.
@@ -869,7 +885,10 @@ final class AppState {
/// Ends the game's own processes and leaves Steam and the server running, so the next
/// Play needs no cold start.
func stopSession(_ session: GameSession) {
- guard let bottle = bottles.first(where: { $0.name == session.bottleName }) else { return }
+ guard let bottle = bottles.first(where: { $0.name == session.bottleName }) else {
+ // The environment was deleted while the game "ran": end the record, no ghost prompt.
+ endSession(session, reason: "stopped"); postPlay = nil; return
+ }
let prefix = bottle.url, markers = session.markers
// terminate waits out a grace period: off the main thread, then the record.
Task.detached {
@@ -883,6 +902,12 @@ final class AppState {
func quitSteam(in bottle: Bottle) {
guard let engine = engine(for: bottle) else { return }
let runner = WineRunner(paths: paths, engine: engine, bottle: bottle)
+ // A game may be running under Steam even when Highball did not start it (launched from
+ // Steam's own window); killing the wineserver would take it down. Refuse then.
+ guard !runner.steamGameIsRunning() else {
+ fail(HighballError.failed("A game is still running in this environment. Quit it first, then quit Steam."))
+ return
+ }
steamClients.remove(bottle.name)
Task.detached { try? runner.kill() }
}
@@ -890,7 +915,7 @@ final class AppState {
func launch(pin: Pin, in bottle: Bottle) {
guard let engine = engine(for: bottle) else { return }
guard !launchingPins.contains(pin.id) else {
- errorMessage = "\(pin.name) is already starting or running. If its window never appeared, use Stop all processes on the bottle, then try again."
+ fail(HighballError.failed("\(pin.name) is already starting or running. If its window never appeared, stop the environment's processes in Settings, then try again."))
return
}
// runBusy refuses a second operation silently; the pin must not be marked as launching then.
@@ -955,7 +980,7 @@ final class AppState {
} crashed: { result in
let current = pin.renderer ?? bottle.settings.renderer
self.crashSuggestion = CrashSuggestion(program: pin.name, bottleName: bottle.name,
- renderer: Renderer.suggestion(after: current),
+ renderer: Renderer.suggestion(after: current, d3dmetalAvailable: engine.rendererDir("d3dmetal") != nil),
logPath: result.log.path, current: current, seconds: Int(result.duration),
alternateEngine: self.alternateEngine(for: bottle))
}
@@ -1080,7 +1105,7 @@ final class AppState {
} crashed: { result in
let current = renderer ?? bottle.settings.renderer
self.crashSuggestion = CrashSuggestion(program: game.name, bottleName: bottle.name,
- renderer: Renderer.suggestion(after: current),
+ renderer: Renderer.suggestion(after: current, d3dmetalAvailable: engine.rendererDir("d3dmetal") != nil),
logPath: result.log.path, current: current, seconds: Int(result.duration),
alternateEngine: self.alternateEngine(for: bottle))
}
@@ -1274,7 +1299,7 @@ final class AppState {
} crashed: { result in
let current = renderer ?? bottle.settings.renderer
self.crashSuggestion = CrashSuggestion(program: game.app_title, bottleName: bottle.name,
- renderer: Renderer.suggestion(after: current),
+ renderer: Renderer.suggestion(after: current, d3dmetalAvailable: engine.rendererDir("d3dmetal") != nil),
logPath: result.log.path, current: current, seconds: Int(result.duration),
alternateEngine: self.alternateEngine(for: bottle))
}
diff --git a/Sources/HighballApp/GameDetailView.swift b/Sources/HighballApp/GameDetailView.swift
index 2daf647..e2eda62 100644
--- a/Sources/HighballApp/GameDetailView.swift
+++ b/Sources/HighballApp/GameDetailView.swift
@@ -5,8 +5,10 @@ import HighballKit
/// honest list of what Play will do, and every identifier behind one Advanced triangle.
struct GameDetailView: View {
@Environment(AppState.self) private var state
- let item: LibraryItem
+ let passedItem: LibraryItem
@State private var showBottleSettings = false
+ /// The live row: after an install, a delete or a rename, the passed-in copy goes stale.
+ private var item: LibraryItem { state.libraryItems.first { $0.id == passedItem.id } ?? passedItem }
@State private var showWhy = false
@State private var showAdvanced = false
@@ -122,9 +124,12 @@ struct GameDetailView: View {
} else if item.source == .epic {
Button(L("Install")) { state.install(item) }.buttonStyle(.borderedProminent).controlSize(.large).tint(HB.amber)
.disabled(state.busy)
- Text(L("Installs into your Highball environment.")).font(.callout).foregroundStyle(.secondary)
+ Text(String(format: L("Installs into %@."), state.defaultBottle?.name ?? L("your environment"))).font(.callout).foregroundStyle(.secondary)
+ } else if item.source == .steam {
+ Text(L("Not downloaded yet. Install it from the Steam window.")).font(.callout).foregroundStyle(.secondary)
+ if let b = bottle ?? state.defaultBottle { Button(L("Open Steam")) { state.showSteam(in: b) }.controlSize(.large) }
} else {
- Text(L("Not installed in any environment.")).font(.callout).foregroundStyle(.secondary)
+ Text(L("Not installed.")).font(.callout).foregroundStyle(.secondary)
}
}
}
diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swift
index a3eae1d..3d4e920 100644
--- a/Sources/HighballApp/HighballApp.swift
+++ b/Sources/HighballApp/HighballApp.swift
@@ -132,8 +132,8 @@ struct ContentView: View {
Button(L("Connect Epic account…")) { state.showEpicSignIn = true }
Divider()
ForEach(BottleView.launcherMeta.filter { $0.id != "steam" }, id: \.id) { meta in
- Button(String(format: L("Install %@"), meta.short)) {
- if let b = state.defaultBottle { state.applyRecipe(meta.id, to: b) }
+ Button(String(format: state.launcherInstalled(meta.id) ? L("Open %@") : L("Install %@"), meta.short)) {
+ state.openOrInstallLauncher(meta.id, short: meta.short)
}
}
Divider()
diff --git a/Sources/HighballApp/LibraryView.swift b/Sources/HighballApp/LibraryView.swift
index 21b60dc..20af709 100644
--- a/Sources/HighballApp/LibraryView.swift
+++ b/Sources/HighballApp/LibraryView.swift
@@ -76,7 +76,7 @@ struct LibraryView: View {
}
.background(BottleBackdrop())
.searchable(text: $search, prompt: L("Search your games"))
- .navigationDestination(for: LibraryItem.self) { GameDetailView(item: $0) }
+ .navigationDestination(for: LibraryItem.self) { GameDetailView(passedItem: $0) }
}
private func entry(for item: LibraryItem) -> GameDBEntry? {
diff --git a/Sources/HighballKit/Bottle.swift b/Sources/HighballKit/Bottle.swift
index bec7ecc..f9d7c40 100644
--- a/Sources/HighballKit/Bottle.swift
+++ b/Sources/HighballKit/Bottle.swift
@@ -67,12 +67,17 @@ public enum Renderer: String, Codable, CaseIterable, Sendable {
/// The backend to offer after `current` failed on launch, cycling through the Metal-backed
/// options. Direct3D 9 no longer constrains this: `withD9VK` attaches DXVK's d3d9 to every
/// renderer, so switching backend can't drop D3D9 support the way it could before 0.7.17.
- public static func suggestion(after current: Renderer) -> Renderer {
+ public static func suggestion(after current: Renderer, d3dmetalAvailable: Bool = true) -> Renderer {
+ let next: Renderer
switch current {
- case .dxmt: return .d3dmetal
- case .d3dmetal: return .dxvk
- case .dxvk, .wined3d: return .dxmt
+ case .dxmt: next = .d3dmetal
+ case .d3dmetal: next = .dxvk
+ case .dxvk, .wined3d: next = .dxmt
}
+ // Never suggest D3DMetal on an engine that does not ship it (or has not accepted the
+ // licence): setting it would make every launch in the environment fail (review #2).
+ if next == .d3dmetal && !d3dmetalAvailable { return current == .dxmt ? .dxvk : .dxmt }
+ return next
}
}