Skip to content

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

Switching an environment's engine opens a page that says what moves, what stays and the steps (highball#254)

Gauthier Piarrettec399e623af92
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index fe64236..4de3b62 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -869,6 +869,7 @@ final class AppState {
runBusy(title, expected: L("usually a few minutes"),
done: DoneState(title: L("Engine updated"), ctaTitle: nil, cta: nil),
stop: .cancelTask(label: L("Stop"))) { [self] in
+ await MainActor.run { self.engineSwitchStep = .download }
let fresh = try await engineStore.install(manifest, accepted: accepted) { name, received, total in
Task { @MainActor in self.reportDownload(name, received: received, total: total) }
}
@@ -961,6 +962,7 @@ final class AppState {
private func performMove(_ stale: Bottle, to target: InstalledEngine) async throws {
guard var bottle = try? bottleStore.get(stale.name) else { throw HighballError.invalid("bottle '\(stale.name)' no longer exists") }
guard bottle.settings.engineID != target.id else { return }
+ await MainActor.run { self.engineSwitchStep = .stopPrograms }
let source = try? engineStore.engine(bottle.settings.engineID)
if let source {
let runnerOld = WineRunner(paths: paths, engine: source, bottle: bottle)
@@ -974,7 +976,7 @@ final class AppState {
await MainActor.run { self.appendLog("bottle '\(bottle.name)' moved to \(target.id) (same Wine, no prefix refresh needed)") }
return
}
- await MainActor.run { self.stage = String(format: L("Refreshing bottle '%@'"), bottle.name) }
+ await MainActor.run { self.stage = String(format: L("Refreshing bottle '%@'"), bottle.name); self.engineSwitchStep = .windowsSetup }
let runner = WineRunner(paths: paths, engine: target, bottle: bottle)
try await BottleStore.refreshPrefix(runner: runner, bottle: bottle)
await MainActor.run { self.appendLog("bottle '\(bottle.name)' moved to \(target.id)") }
@@ -1226,6 +1228,20 @@ final class AppState {
/// or re-runs the Windows setup without asking: the ask offers a new environment on that
/// engine (other programs untouched) or moving this one.
var pendingEngine: (recipe: HighballKit.Recipe, bottle: Bottle, manifest: EngineManifest)?
+ /// The page a player sees after picking another engine on an environment's page (highball#254).
+ /// Only for a switch the player started; the app's own engine questions stay as they are.
+ struct EngineTransition: Identifiable {
+ let bottleName: String
+ let targetID: String
+ var id: String { bottleName + ">" + targetID }
+ }
+ var engineTransition: EngineTransition?
+ /// The step a running switch is on, set by the move itself so the page never parses stage text.
+ var engineSwitchStep: EngineSwitchPlan.Step?
+ /// Whether the last switch the page started finished (true), failed or was stopped (false).
+ var engineSwitchSucceeded: Bool?
+ /// Debug screenshot runs: the switch page presses its own Switch button (HB_SHOW_ENGINE_SWITCH).
+ var debugStartEngineTransition = false
/// How many other programs an environment has installed, the ones a move would carry onto the
/// engine too: Steam games ready to play other than the recipe's own, plus added programs.
func otherProgramCount(in bottle: Bottle, besides recipe: HighballKit.Recipe) -> Int {
@@ -2442,6 +2458,30 @@ final class AppState {
}
}
+ /// Starts the switch the engine page confirmed. The work is the same move as before, on the
+ /// activity strip like every long operation; the page only watches it.
+ func startEngineTransition(_ t: EngineTransition) {
+ guard !busy, let bottle = bottles.first(where: { $0.name == t.bottleName }) else { return }
+ engineSwitchStep = nil
+ engineSwitchSucceeded = nil
+ moveBottle(bottle, toEngineID: t.targetID, done: DoneState(title: L("Engine switched"), ctaTitle: nil, cta: nil))
+ // moveBottle returns at once; the outcome is read when the operation ends.
+ Task { @MainActor [weak self] in
+ while let self, self.busy { try? await Task.sleep(for: .milliseconds(300)) }
+ guard let self else { return }
+ let moved = self.bottles.first { $0.name == t.bottleName }?.settings.engineID == t.targetID
+ self.engineSwitchSucceeded = moved
+ if moved { self.engineSwitchStep = .done }
+ }
+ }
+
+ /// The programs an environment has, by name, for the switch page: Steam games ready to play,
+ /// then the programs added by hand.
+ func programNames(in bottle: Bottle) -> [String] {
+ let games = (gamesByBottle[bottle.name] ?? []).filter(\.isReady).map(\.name)
+ return games + bottle.settings.pins.map(\.name)
+ }
+
/// What the bottle's Engine picker lists: installed engines, then known ones to download.
func offeredEngines(for bottle: Bottle) -> [EngineStore.OfferedEngine] {
EngineStore.offeredEngines(installed: engines, known: Self.knownManifests, current: bottle.settings.engineID)
diff --git a/Sources/HighballApp/BottleView.swift b/Sources/HighballApp/BottleView.swift
index f4a76dd..224ae72 100644
--- a/Sources/HighballApp/BottleView.swift
+++ b/Sources/HighballApp/BottleView.swift
@@ -490,8 +490,8 @@ struct BottleSettingsSheet: View {
set: { newID in
let current = state.bottles.first { $0.name == bottle.name } ?? bottle
guard newID != current.settings.engineID else { return }
- dismiss() // the move runs in the busy sheet; two sheets on one window do not stack
- state.moveBottle(current, toEngineID: newID)
+ dismiss() // the switch page opens from the main window; two sheets on one window do not stack
+ state.engineTransition = AppState.EngineTransition(bottleName: current.name, targetID: newID)
})) {
ForEach(offered, id: \.id) { e in
Text(verbatim: e.missing ? "\(e.id) (\(L("missing")))" : e.installed ? e.id : "\(e.id) (\(L("download")))").tag(e.id)
diff --git a/Sources/HighballApp/EngineTransitionSheet.swift b/Sources/HighballApp/EngineTransitionSheet.swift
new file mode 100644
index 0000000..652105b
--- /dev/null
+++ b/Sources/HighballApp/EngineTransitionSheet.swift
@@ -0,0 +1,155 @@
+import SwiftUI
+import HighballKit
+
+/// The page a player sees after picking another engine on an environment's page (highball#254,
+/// from PR #230 by @matiasmg-ok): what moves, what stays, the steps, and then the steps as they
+/// happen. The work itself is the usual move on the activity strip, so closing the page never
+/// stops anything (UX plan 0.5: what takes time lives on the strip, never modal).
+struct EngineTransitionSheet: View {
+ @Environment(AppState.self) private var state
+ @Environment(\.dismiss) private var dismiss
+ let transition: AppState.EngineTransition
+ @State private var started = false
+ /// The steps as they were when Switch was pressed: afterwards the environment is on the new
+ /// engine and the engine is installed, so a fresh plan would drop the steps that just ran.
+ @State private var frozen: EngineSwitchPlan?
+
+ private var bottle: Bottle? { state.bottles.first { $0.name == transition.bottleName } }
+ private var target: EngineManifest? {
+ state.engines.first { $0.id == transition.targetID }?.manifest
+ ?? AppState.knownManifests.first { $0.id == transition.targetID }
+ }
+ private var installed: Bool { state.engines.contains { $0.id == transition.targetID } }
+ private var plan: EngineSwitchPlan { frozen ?? livePlan }
+ private var livePlan: EngineSwitchPlan {
+ let current = bottle.flatMap { b in state.engines.first { $0.id == b.settings.engineID }?.manifest }
+ let refreshes = target.map { EngineManifest.needsPrefixRefresh(from: current, to: $0) } ?? true
+ return EngineSwitchPlan(engineInstalled: installed, refreshesWindows: refreshes)
+ }
+ private var programs: [String] { bottle.map { state.programNames(in: $0) } ?? [] }
+
+ var body: some View {
+ VStack(alignment: .leading, spacing: 16) {
+ VStack(alignment: .leading, spacing: 4) {
+ HB.eyebrow(L("Engine"))
+ Text(String(format: L("Switch '%@' to %@"), transition.bottleName, targetName))
+ .font(.title2.bold())
+ Text(verbatim: transition.targetID).font(.caption.monospaced()).foregroundStyle(.tertiary)
+ }
+
+ section(L("What moves"), programs.isEmpty
+ ? L("The environment and everything in it. Programs installed later run on the new engine too.")
+ : String(format: L("Everything in this environment moves to the new engine, including %@."), programList))
+ section(L("What stays"), L("Everything installed, your saves and Steam's sign-in. The engine you leave stays installed, so switching back is the same step."))
+
+ VStack(alignment: .leading, spacing: 8) {
+ Text(L("Steps")).font(.callout.weight(.medium))
+ ForEach(plan.steps, id: \.self) { step in
+ stepRow(step)
+ }
+ }
+ .padding(12)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .background(RoundedRectangle(cornerRadius: 10).fill(HB.card))
+ .overlay(RoundedRectangle(cornerRadius: 10).stroke(HB.cardStroke))
+
+ if started, state.engineSwitchSucceeded == false {
+ Text(L("The switch did not finish. The environment keeps the engine it had, and the message at the bottom of the window says why."))
+ .font(.callout).foregroundStyle(HB.bad).fixedSize(horizontal: false, vertical: true)
+ } else if !started, state.busy {
+ Text(L("Something else is running. The switch can start once it finishes."))
+ .font(.caption).foregroundStyle(.secondary)
+ }
+
+ HStack {
+ if started && state.engineSwitchSucceeded == nil {
+ Text(L("You can close this page, the switch carries on at the bottom of the window."))
+ .font(.caption).foregroundStyle(.secondary)
+ }
+ Spacer()
+ if !started {
+ Button(L("Cancel")) { dismiss() }.keyboardShortcut(.cancelAction)
+ Button(L("Switch")) {
+ frozen = livePlan
+ started = true
+ state.startEngineTransition(transition)
+ }
+ .keyboardShortcut(.defaultAction)
+ .buttonStyle(.borderedProminent)
+ .disabled(state.busy || bottle == nil || target == nil)
+ } else if state.engineSwitchSucceeded == nil {
+ Button(L("Hide")) { dismiss() }.keyboardShortcut(.cancelAction)
+ } else {
+ Button(L("Done")) { dismiss() }
+ .keyboardShortcut(.defaultAction)
+ .buttonStyle(.borderedProminent)
+ }
+ }
+ }
+ .padding(22)
+ .frame(width: 520)
+ .onChange(of: state.debugStartEngineTransition) { _, go in
+ guard go, !started else { return }
+ state.debugStartEngineTransition = false
+ frozen = livePlan
+ started = true
+ state.startEngineTransition(transition)
+ }
+ }
+
+ private var targetName: String { target.map(GamePageCopy.shortEngineName) ?? transition.targetID }
+
+ /// Up to four names, then how many more, so a big library does not turn into a wall of text.
+ private var programList: String {
+ let shown = programs.prefix(4).joined(separator: ", ")
+ let rest = programs.count - min(programs.count, 4)
+ return rest > 0 ? String(format: L("%@ and %d more"), shown, rest) : shown
+ }
+
+ @ViewBuilder private func section(_ title: String, _ body: String) -> some View {
+ VStack(alignment: .leading, spacing: 3) {
+ Text(title).font(.callout.weight(.medium))
+ Text(body).font(.callout).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
+ }
+ }
+
+ private func label(_ step: EngineSwitchPlan.Step) -> String {
+ switch step {
+ case .download:
+ let size = target.map(GamePageCopy.downloadSize) ?? ""
+ return size.isEmpty ? L("Download the engine") : String(format: L("Download the engine, about %@"), size)
+ case .stopPrograms: return L("Stop what runs in this environment and switch")
+ case .windowsSetup: return L("Run the Windows setup again, a minute or two")
+ case .done: return L("Ready to play")
+ }
+ }
+
+ @ViewBuilder private func stepRow(_ step: EngineSwitchPlan.Step) -> some View {
+ let steps = plan.steps
+ let currentIndex = state.engineSwitchStep.flatMap { steps.firstIndex(of: $0) }
+ let index = steps.firstIndex(of: step) ?? 0
+ let finished = state.engineSwitchSucceeded == true
+ let isDone = started && (finished || (currentIndex.map { index < $0 } ?? false))
+ let isCurrent = started && !finished && currentIndex == index && state.engineSwitchSucceeded == nil
+ HStack(spacing: 10) {
+ Group {
+ if isDone {
+ Image(systemName: "checkmark.circle.fill").foregroundStyle(HB.good)
+ } else if isCurrent {
+ ProgressView().controlSize(.small)
+ } else {
+ Image(systemName: "circle").foregroundStyle(.tertiary)
+ }
+ }
+ .frame(width: 18)
+ Text(label(step))
+ .font(.callout)
+ .foregroundStyle(isCurrent ? .primary : (isDone ? .secondary : .secondary))
+ if isCurrent, step == .download, let p = state.busyProgress, let total = p.total, total > 0 {
+ Spacer()
+ Text(verbatim: "\(Int(Double(p.received) / Double(total) * 100)) %")
+ .font(.caption.monospacedDigit()).foregroundStyle(.secondary)
+ }
+ }
+ }
+}
diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swift
index 483f912..9047093 100644
--- a/Sources/HighballApp/HighballApp.swift
+++ b/Sources/HighballApp/HighballApp.swift
@@ -215,6 +215,25 @@ struct ContentView: View {
.modesetTrialAsk(state)
.homeMoveAsk(state)
.sheet(isPresented: $state.showEpicSignIn) { EpicSignInSheet() }
+ .sheet(item: $state.engineTransition) { t in EngineTransitionSheet(transition: t) }
+ #if DEBUG
+ // Screenshot runs only: HB_SHOW_ENGINE_SWITCH="<environment>><engine id>" opens the switch
+ // page at launch, since a script cannot click through Settings; a trailing "!" also starts
+ // the switch, to capture the steps as they run. Compiled out of releases.
+ .task {
+ guard var spec = ProcessInfo.processInfo.environment["HB_SHOW_ENGINE_SWITCH"] else { return }
+ let start = spec.hasSuffix("!")
+ if start { spec.removeLast() }
+ guard let cut = spec.firstIndex(of: ">") else { return }
+ try? await Task.sleep(for: .seconds(4))
+ let t = AppState.EngineTransition(bottleName: String(spec[..<cut]), targetID: String(spec[spec.index(after: cut)...]))
+ state.engineTransition = t
+ if start {
+ try? await Task.sleep(for: .seconds(2))
+ state.debugStartEngineTransition = true
+ }
+ }
+ #endif
.errorAlert(state)
.sheet(isPresented: Binding(get: { state.showErrorDetails }, set: { state.showErrorDetails = $0 })) {
ErrorDetailsSheet(text: state.errorDetailsText)
diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swift
index e549f61..06b4dbb 100644
--- a/Sources/HighballApp/L10n.swift
+++ b/Sources/HighballApp/L10n.swift
@@ -205,6 +205,23 @@ enum L10n {
"You can also play without the fix, as before.": "Vous pouvez aussi jouer sans le correctif, comme avant.",
"%@'s fix runs on the %@ engine, and this version of Highball does not ship it yet. Check for Updates gets the version that does.%@": "Le correctif de %@ tourne sur le moteur %@, que cette version de Highball ne fournit pas encore. Rechercher les mises à jour donne la version qui le fournit.%@",
"New environment for %@": "Nouvel environnement pour %@",
+ "Switch '%@' to %@": "Passer '%@' sur %@",
+ "What moves": "Ce qui change",
+ "What stays": "Ce qui reste",
+ "The environment and everything in it. Programs installed later run on the new engine too.": "L'environnement et tout ce qu'il contient. Les programmes installés plus tard tournent aussi sur le nouveau moteur.",
+ "Everything in this environment moves to the new engine, including %@.": "Tout ce que contient cet environnement passe sur le nouveau moteur, y compris %@.",
+ "Everything installed, your saves and Steam's sign-in. The engine you leave stays installed, so switching back is the same step.": "Tout ce qui est installé, vos sauvegardes et la connexion Steam. Le moteur que vous quittez reste installé, donc revenir en arrière se fait de la même façon.",
+ "Steps": "Étapes",
+ "The switch did not finish. The environment keeps the engine it had, and the message at the bottom of the window says why.": "Le changement n'a pas abouti. L'environnement garde son moteur, et le message en bas de la fenêtre dit pourquoi.",
+ "Something else is running. The switch can start once it finishes.": "Une autre opération est en cours. Le changement pourra commencer une fois qu'elle sera terminée.",
+ "You can close this page, the switch carries on at the bottom of the window.": "Vous pouvez fermer cette page, le changement continue en bas de la fenêtre.",
+ "Switch": "Changer",
+ "%@ and %d more": "%@ et %d autres",
+ "Download the engine": "Télécharger le moteur",
+ "Download the engine, about %@": "Télécharger le moteur, environ %@",
+ "Stop what runs in this environment and switch": "Arrêter ce qui tourne dans cet environnement et changer",
+ "Run the Windows setup again, a minute or two": "Refaire la configuration Windows, une minute ou deux",
+ "Ready to play": "Prêt à jouer",
"Move this environment": "Déplacer cet environnement",
"Creating the %@ environment on %@": "Création de l'environnement %@ sur %@",
"a download when the engine is new, then a first boot of about 90 seconds": "un téléchargement si le moteur est nouveau, puis un premier démarrage d'environ 90 secondes",
diff --git a/Sources/HighballKit/EngineSwitchPlan.swift b/Sources/HighballKit/EngineSwitchPlan.swift
new file mode 100644
index 0000000..977fe5c
--- /dev/null
+++ b/Sources/HighballKit/EngineSwitchPlan.swift
@@ -0,0 +1,27 @@
+import Foundation
+
+/// What switching one environment to another engine involves, step by step, for the page a player
+/// sees when they pick an engine themselves (highball#254, from PR #230). Pure, so the page and the
+/// tests agree on the steps: the app runs the same work it always did (AppState.moveBottle).
+public struct EngineSwitchPlan: Equatable, Sendable {
+ public enum Step: String, CaseIterable, Sendable {
+ /// The engine is only known from a bundled manifest: it downloads first.
+ case download
+ /// Programs running in the environment are stopped, so nothing keeps the old Wine open.
+ case stopPrograms
+ /// A different Wine build: the Windows first boot runs again in the environment.
+ case windowsSetup
+ case done
+ }
+
+ public let steps: [Step]
+
+ public init(engineInstalled: Bool, refreshesWindows: Bool) {
+ var steps: [Step] = []
+ if !engineInstalled { steps.append(.download) }
+ steps.append(.stopPrograms)
+ if refreshesWindows { steps.append(.windowsSetup) }
+ steps.append(.done)
+ self.steps = steps
+ }
+}
diff --git a/Tests/HighballKitTests/EngineSwitchPlanTests.swift b/Tests/HighballKitTests/EngineSwitchPlanTests.swift
new file mode 100644
index 0000000..3e33c01
--- /dev/null
+++ b/Tests/HighballKitTests/EngineSwitchPlanTests.swift
@@ -0,0 +1,13 @@
+import XCTest
+@testable import HighballKit
+
+/// The steps the engine switch page lists (highball#254).
+final class EngineSwitchPlanTests: XCTestCase {
+ func testAnInstalledEngineOfTheSameWineSkipsTheDownloadAndTheWindowsSetup() {
+ XCTAssertEqual(EngineSwitchPlan(engineInstalled: true, refreshesWindows: false).steps, [.stopPrograms, .done])
+ }
+
+ func testANewWineBuildToDownloadListsEveryStep() {
+ XCTAssertEqual(EngineSwitchPlan(engineInstalled: false, refreshesWindows: true).steps, [.download, .stopPrograms, .windowsSetup, .done])
+ }
+}