Skip to content

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

Crash alert offers the other installed engine as a second way out

Gauthier Piarretted55589bd5f26
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index 1b0c615..9201d78 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -52,6 +52,13 @@ final class AppState {
let bottleName: String
let renderer: Renderer
let logPath: String
+ /// Another installed engine to offer as the second way out, when there is one.
+ var alternateEngine: InstalledEngine? = nil
+ }
+
+ /// The engine the crash alert offers next to the renderer suggestion, if another one is installed.
+ func alternateEngine(for bottle: Bottle) -> InstalledEngine? {
+ EngineStore.alternateEngine(for: bottle.settings.engineID, installed: engines, defaultID: defaultEngine?.id)
}
var errorMessage: String?
@@ -516,7 +523,8 @@ final class AppState {
await MainActor.run {
self.crashSuggestion = CrashSuggestion(program: pin.name, bottleName: bottle.name,
renderer: Renderer.suggestion(after: current),
- logPath: result.log.path)
+ logPath: result.log.path,
+ alternateEngine: self.alternateEngine(for: bottle))
}
}
}
@@ -614,7 +622,8 @@ final class AppState {
await MainActor.run {
self.crashSuggestion = CrashSuggestion(program: game.name, bottleName: bottle.name,
renderer: Renderer.suggestion(after: current),
- logPath: result.log.path)
+ logPath: result.log.path,
+ alternateEngine: self.alternateEngine(for: bottle))
}
}
}
@@ -749,7 +758,8 @@ final class AppState {
await MainActor.run {
self.crashSuggestion = CrashSuggestion(program: game.app_title, bottleName: bottle.name,
renderer: Renderer.suggestion(after: current),
- logPath: result.log.path)
+ logPath: result.log.path,
+ alternateEngine: self.alternateEngine(for: bottle))
}
}
}
diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swift
index 817fa2d..e7cc954 100644
--- a/Sources/HighballApp/HighballApp.swift
+++ b/Sources/HighballApp/HighballApp.swift
@@ -304,19 +304,33 @@ struct ContentView: View {
}
}
} message: { Text(state.errorMessage ?? "") }
- .alert(item: $state.crashSuggestion) { s in
- Alert(title: Text("\(s.program) exited right away"),
- message: Text("That usually means the graphics backend doesn't suit it. Try \(s.renderer.rawValue.uppercased())? The log is at \(s.logPath)."),
- primaryButton: .default(Text("Use \(s.renderer.rawValue.uppercased())")) {
- if var bottle = state.bottles.first(where: { $0.name == s.bottleName }) {
- bottle.settings.renderer = s.renderer
- bottle.settings.rendererExplicit = true // the user picked it; recipes must not clobber it (#29)
- state.update(bottle)
- }
- },
- secondaryButton: .cancel(Text(L("Keep current"))))
+ .alert(crashTitle, isPresented: Binding(get: { state.crashSuggestion != nil }, set: { if !$0 { state.crashSuggestion = nil } }),
+ presenting: state.crashSuggestion) { s in
+ Button("Use \(s.renderer.rawValue.uppercased())") {
+ if var bottle = state.bottles.first(where: { $0.name == s.bottleName }) {
+ bottle.settings.renderer = s.renderer
+ bottle.settings.rendererExplicit = true // the user picked it; recipes must not clobber it (#29)
+ state.update(bottle)
+ }
+ }
+ if let alt = s.alternateEngine {
+ Button(String(format: L("Try engine %@"), alt.id)) {
+ if let bottle = state.bottles.first(where: { $0.name == s.bottleName }) { state.moveBottle(bottle, to: alt) }
+ }
+ }
+ Button(L("Keep current"), role: .cancel) {}
+ } message: { s in
+ if let alt = s.alternateEngine {
+ Text("That usually means the graphics backend doesn't suit it. Try \(s.renderer.rawValue.uppercased())? If that fails too, the bottle can move to engine \(alt.id) and back. The log is at \(s.logPath).")
+ } else {
+ Text("That usually means the graphics backend doesn't suit it. Try \(s.renderer.rawValue.uppercased())? The log is at \(s.logPath).")
+ }
}
}
+ private var crashTitle: String {
+ guard let s = state.crashSuggestion else { return "" }
+ return "\(s.program) exited right away"
+ }
}
struct CreateBottleSheet: View {
diff --git a/Sources/HighballKit/EngineStore.swift b/Sources/HighballKit/EngineStore.swift
index e8b4f76..aeda183 100644
--- a/Sources/HighballKit/EngineStore.swift
+++ b/Sources/HighballKit/EngineStore.swift
@@ -64,6 +64,15 @@ public struct EngineStore: Sendable {
installed.filter { $0.id != defaultID && !referencedIDs.contains($0.id) }
}
+ /// The engine to offer when a program fails on `currentID`: the default engine when the
+ /// bottle is not on it (the newer one, usually), else the newest other installed engine.
+ /// nil with a single engine installed.
+ public static func alternateEngine(for currentID: String, installed: [InstalledEngine], defaultID: String?) -> InstalledEngine? {
+ if let d = installed.first(where: { $0.id == defaultID }), d.id != currentID { return d }
+ return installed.filter { $0.id != currentID }
+ .max { $0.id.compare($1.id, options: .numeric) == .orderedAscending }
+ }
+
public func engine(_ id: String) throws -> InstalledEngine {
let root = paths.engine(id)
let m = try EngineManifest.load(from: root.appending(path: "manifest.json"))
diff --git a/Tests/HighballKitTests/RegressionTests.swift b/Tests/HighballKitTests/RegressionTests.swift
index 68d554a..1816511 100644
--- a/Tests/HighballKitTests/RegressionTests.swift
+++ b/Tests/HighballKitTests/RegressionTests.swift
@@ -860,6 +860,20 @@ extension RegressionTests {
XCTAssertEqual(EngineStore.unreferencedEngines(installed: all, referencedIDs: [], defaultID: nil).map(\.id), all.map(\.id))
}
+ // The crash alert's second way out: the default engine when the bottle is not on it, else the
+ // newest other engine, and nothing with a single engine installed.
+ func testAlternateEngineForCrashAlert() throws {
+ func engine(_ id: String) throws -> InstalledEngine {
+ let json = #"{"id":"\#(id)","displayName":"e","arch":"x86_64","minMacOS":"14.0","components":{}}"#
+ let m = try JSONDecoder().decode(EngineManifest.self, from: Data(json.utf8))
+ return InstalledEngine(manifest: m, root: URL(fileURLWithPath: "/tmp/\(id)"))
+ }
+ let r1 = try engine("x64-sikarugir10.0_6-r1"), r2 = try engine("x64-sikarugir11.0_0-r0")
+ XCTAssertEqual(EngineStore.alternateEngine(for: r1.id, installed: [r1, r2], defaultID: r2.id)?.id, r2.id, "old bottle: offer the default")
+ XCTAssertEqual(EngineStore.alternateEngine(for: r2.id, installed: [r1, r2], defaultID: r2.id)?.id, r1.id, "on the default: offer the previous engine")
+ XCTAssertNil(EngineStore.alternateEngine(for: r1.id, installed: [r1], defaultID: r1.id), "single engine: nothing to offer")
+ }
+
func testDefaultEnginePrefersBundledManifestID() throws {
func engine(_ id: String) throws -> InstalledEngine {
let json = #"{"id":"\#(id)","displayName":"e","arch":"x86_64","minMacOS":"14.0","components":{}}"#