Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

fix(update): always answer Check for Updates and install in one click (#1826)

Raymond Chinfc45aa4bad79
diff --git a/app/Sources/BridgeplayApp/App.swift b/app/Sources/BridgeplayApp/App.swift
index a18f7d9..5663fe2 100644
--- a/app/Sources/BridgeplayApp/App.swift
+++ b/app/Sources/BridgeplayApp/App.swift
@@ -48,6 +48,7 @@ struct BridgeplayApp: App {
SetupAssistantView()
.environment(status)
.interactiveDismissDisabled()
+ .overlay(alignment: .top) { UpdateNotice(onlyWhenAsked: true) }
}
}
.defaultSize(width: 900, height: 760)
diff --git a/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings b/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings
index c50b190..92df199 100644
--- a/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings
+++ b/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings
@@ -1020,6 +1020,22 @@
}
}
},
+ "A game is running, so Bridgeplay won't restart. The update installs when you quit." : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "È in esecuzione un gioco, quindi Bridgeplay non si riavvierà. L'aggiornamento verrà installato quando chiudi l'app."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "有游戏正在运行,因此 Bridgeplay 不会重启。退出时会安装更新。"
+ }
+ }
+ }
+ },
"A game or Wine tool is running on build %@. Quit it before removing Bridgeplay." : {
"localizations" : {
"it" : {
@@ -2239,6 +2255,38 @@
"Bridgeplay" : {
"shouldTranslate" : false
},
+ "Bridgeplay %@ is available" : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bridgeplay %@ è disponibile"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bridgeplay %@ 现已可用"
+ }
+ }
+ }
+ },
+ "Bridgeplay %@ is ready to install" : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bridgeplay %@ è pronto per l'installazione"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bridgeplay %@ 已可安装"
+ }
+ }
+ }
+ },
"Bridgeplay Components" : {
"localizations" : {
"it" : {
@@ -2543,6 +2591,22 @@
}
}
},
+ "Bridgeplay is busy, so it won't restart yet. The update installs when you quit." : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bridgeplay è occupato, quindi non si riavvierà ora. L'aggiornamento verrà installato quando chiudi l'app."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bridgeplay 正忙,暂时不会重启。退出时会安装更新。"
+ }
+ }
+ }
+ },
"Bridgeplay is installed in %@. Use Repair Steam to remove it before choosing another copy of Steam." : {
"localizations" : {
"it" : {
@@ -3087,6 +3151,22 @@
}
}
},
+ "Checking for updates…" : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ricerca di aggiornamenti…"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "正在检查更新…"
+ }
+ }
+ }
+ },
"Checking…" : {
"localizations" : {
"it" : {
@@ -4450,6 +4530,22 @@
}
}
},
+ "Downloading Bridgeplay %@" : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Download di Bridgeplay %@ in corso"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "正在下载 Bridgeplay %@"
+ }
+ }
+ }
+ },
"Downloading Steam" : {
"localizations" : {
"it" : {
@@ -5218,6 +5314,22 @@
}
}
},
+ "Getting Bridgeplay %@ ready" : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Preparazione di Bridgeplay %@"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "正在准备 Bridgeplay %@"
+ }
+ }
+ }
+ },
"Getting the game ready…" : {
"localizations" : {
"it" : {
@@ -5858,6 +5970,22 @@
}
}
},
+ "It installs when you quit Bridgeplay, or you can restart now." : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Verrà installato quando chiudi Bridgeplay, oppure puoi riavviare ora."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "退出 Bridgeplay 时会自动安装,也可以现在重启。"
+ }
+ }
+ }
+ },
"It will replace the DLLs used by CrossOver with ones that match your compatibility tool." : {
"localizations" : {
"it" : {
@@ -8546,6 +8674,22 @@
}
}
},
+ "Restart to Update" : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Riavvia per aggiornare"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "重启以更新"
+ }
+ }
+ }
+ },
"Restore Steam to its original state." : {
"localizations" : {
"it" : {
@@ -11413,6 +11557,22 @@
}
}
},
+ "Updated to Bridgeplay %@" : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Aggiornato a Bridgeplay %@"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "已更新到 Bridgeplay %@"
+ }
+ }
+ }
+ },
"Updates" : {
"localizations" : {
"it" : {
@@ -11621,6 +11781,22 @@
}
}
},
+ "View Update…" : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Mostra aggiornamento…"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "查看更新…"
+ }
+ }
+ }
+ },
"Vulkan in a game's own settings" : {
"localizations" : {
"it" : {
@@ -11701,6 +11877,38 @@
}
}
},
+ "What's New" : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Novità"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "新功能"
+ }
+ }
+ }
+ },
+ "What's New in Bridgeplay %@" : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Novità di Bridgeplay %@"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bridgeplay %@ 的新功能"
+ }
+ }
+ }
+ },
"When motion is too fast to track, shows the nearest real frame instead of a smeared one." : {
"localizations" : {
"it" : {
@@ -11915,6 +12123,22 @@
}
}
},
+ "You can keep using Bridgeplay while it downloads." : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Puoi continuare a usare Bridgeplay durante il download."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "下载时可以继续使用 Bridgeplay。"
+ }
+ }
+ }
+ },
"You played %@ for %@. How did it run?" : {
"localizations" : {
"it" : {
diff --git a/app/Sources/BridgeplayApp/Support/AppUpdater.swift b/app/Sources/BridgeplayApp/Support/AppUpdater.swift
index 3d0528c..5643a60 100644
--- a/app/Sources/BridgeplayApp/Support/AppUpdater.swift
+++ b/app/Sources/BridgeplayApp/Support/AppUpdater.swift
@@ -1,15 +1,25 @@
+import AppKit
import Foundation
+import Observation
import Sparkle
@MainActor
+@Observable
final class AppUpdater {
// One updater for the app: the menu and the Status page's Refresh share it.
static let shared = AppUpdater()
- private let controller: SPUStandardUpdaterController
- // Sparkle holds its delegate weakly.
- private let finder: ReleaseFinder
+ private(set) var flow = UpdateFlow()
+ // What the running build brought, until it is dismissed.
+ private(set) var whatsNew: WhatsNew?
+
+ @ObservationIgnored private let controller: SPUStandardUpdaterController
+ // Sparkle holds its delegates weakly.
+ @ObservationIgnored private let finder: ReleaseFinder
+ @ObservationIgnored private var sessionObservation: NSKeyValueObservation?
+ // Sparkle's own install-and-relaunch for an update waiting for quit.
+ @ObservationIgnored private var installNow: (() -> Void)?
init() {
#if DEBUG
@@ -21,22 +31,228 @@ final class AppUpdater {
controller = SPUStandardUpdaterController(
startingUpdater: scheduling,
updaterDelegate: finder,
- userDriverDelegate: nil
+ userDriverDelegate: finder
)
+ finder.report = { [weak self] in self?.flow.apply($0) }
+ finder.installerReady = { [weak self] in self?.installNow = $0 }
+ whatsNew = LatestRelease.takeWhatsNew(
+ build: Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String)
+ // Async because Sparkle changes this mid-way through closing a session.
+ sessionObservation = controller.updater.observe(\.canCheckForUpdates) { [weak self] _, _ in
+ DispatchQueue.main.async {
+ MainActor.assumeIsolated { self?.runQueuedCheck() }
+ }
+ }
}
+ // Sparkle ignores checkForUpdates during a session, and a download started in the
+ // background is one, so a click here has to be answered or kept for later.
func check() {
#if !DEBUG
- controller.checkForUpdates(nil)
+ let updater = controller.updater
+ switch flow.click(busy: updater.sessionInProgress && !updater.canCheckForUpdates) {
+ case .run: controller.checkForUpdates(nil)
+ case .focus: controller.userDriver.showUpdateInFocus()
+ case .wait: showMainWindow()
+ }
#endif
}
+ // One click, no window. A running game is left alone: the update waits for quit instead.
+ func restartToUpdate(busy: Bool) async {
+ await refreshRestartBlock()
+ switch flow.restart(busy: busy, canInstallNow: installNow != nil) {
+ case .install: installNow?()
+ case .offer: check()
+ case .blocked: break
+ }
+ }
+
+ func refreshRestartBlock() async {
+ flow.apply(.gameRunning(await RestartGuard.gameRunning()))
+ }
+
+ func dismissWhatsNew() {
+ whatsNew = nil
+ }
+
+ private func runQueuedCheck() {
+ guard controller.updater.canCheckForUpdates, flow.takeQueuedCheck() else { return }
+ controller.checkForUpdates(nil)
+ }
+
+ // The banner lives in the main window, which may be minimized when the menu is used.
+ private func showMainWindow() {
+ NSApp.activate()
+ let window = NSApp.windows.first {
+ !($0 is NSPanel) && $0.styleMask.contains(.titled) && $0.sheetParent == nil
+ }
+ if window?.isMiniaturized == true { window?.deminiaturize(nil) }
+ window?.makeKeyAndOrderFront(nil)
+ }
+
}
@MainActor
-private final class ReleaseFinder: NSObject, SPUUpdaterDelegate {
+private final class ReleaseFinder: NSObject, SPUUpdaterDelegate, @MainActor SPUStandardUserDriverDelegate {
+ var report: ((UpdateEvent) -> Void)?
+ var installerReady: ((@escaping () -> Void) -> Void)?
+
+ func updater(_ updater: SPUUpdater, mayPerform updateCheck: SPUUpdateCheck) throws {
+ report?(.cycleStarted(byUser: updateCheck == .updates))
+ }
+
func updater(_ updater: SPUUpdater, didFindValidUpdate item: SUAppcastItem) {
- LatestRelease.record(build: item.versionString, version: item.displayVersionString)
+ LatestRelease.record(build: item.versionString, version: item.displayVersionString, notes: item.itemDescription)
+ report?(.found(version: item.displayVersionString))
+ }
+
+ func updater(_ updater: SPUUpdater, willDownloadUpdate item: SUAppcastItem, with request: NSMutableURLRequest) {
+ report?(.downloading(version: item.displayVersionString))
+ }
+
+ func updater(_ updater: SPUUpdater, willExtractUpdate item: SUAppcastItem) {
+ report?(.preparing(version: item.displayVersionString))
+ }
+
+ // True keeps the install block for Restart to Update. It also holds this session open
+ // until quit, so no more checks run; Sparkle still installs on quit.
+ func updater(_ updater: SPUUpdater, willInstallUpdateOnQuit item: SUAppcastItem,
+ immediateInstallationBlock immediateInstallHandler: @escaping () -> Void) -> Bool {
+ installerReady?(immediateInstallHandler)
+ report?(.ready(version: item.displayVersionString))
+ return true
+ }
+
+ func updater(_ updater: SPUUpdater, didFinishUpdateCycleFor updateCheck: SPUUpdateCheck, error: (any Error)?) {
+ report?(.cycleFinished)
+ }
+
+ var supportsGentleScheduledUpdateReminders: Bool { true }
+
+ // A background update never opens a window; the banner is the reminder.
+ func standardUserDriverShouldHandleShowingScheduledUpdate(_ update: SUAppcastItem,
+ andInImmediateFocus immediateFocus: Bool) -> Bool {
+ false
+ }
+
+ func standardUserDriverWillHandleShowingUpdate(_ handleShowingUpdate: Bool, forUpdate update: SUAppcastItem,
+ state: SPUUserUpdateState) {
+ guard !state.userInitiated else { return }
+ report?(.reminder(version: update.displayVersionString, downloaded: state.stage != .notDownloaded))
+ }
+
+ func standardUserDriverWillFinishUpdateSession() {
+ report?(.updateClosed)
+ }
+}
+
+// Where an update has got to.
+enum UpdateStage: Equatable, Sendable {
+ case idle
+ case checking
+ case available(version: String)
+ case downloading(version: String)
+ case preparing(version: String)
+ case ready(version: String)
+}
+
+enum UpdateEvent: Equatable, Sendable {
+ case cycleStarted(byUser: Bool)
+ case found(version: String)
+ case downloading(version: String)
+ case preparing(version: String)
+ case ready(version: String)
+ case reminder(version: String, downloaded: Bool)
+ case updateClosed
+ case cycleFinished
+ case gameRunning(Bool)
+}
+
+// Background sessions have no window of their own, so this is what the banner shows and
+// what decides where a click on Check for Updates goes.
+struct UpdateFlow: Equatable, Sendable {
+ enum Click: Equatable, Sendable {
+ case run
+ // Sparkle's own window is up; bring it forward.
+ case focus
+ // A background session is running, and the banner shows how far it has got.
+ case wait
+ }
+
+ enum Restart: Equatable, Sendable {
+ case install
+ // No installer to call, so Sparkle's window offers the install.
+ case offer
+ case blocked
+ }
+
+ private(set) var stage = UpdateStage.idle
+ private(set) var checkQueued = false
+ private(set) var gameRunning = false
+ private var userSession = false
+
+ private var isReady: Bool {
+ if case .ready = stage { true } else { false }
+ }
+
+ // What the banner shows. A background check that finds nothing stays out of sight unless
+ // someone is waiting for it.
+ var notice: UpdateStage? {
+ switch stage {
+ case .idle, .checking: checkQueued ? .checking : nil
+ default: stage
+ }
+ }
+
+ mutating func apply(_ event: UpdateEvent) {
+ switch event {
+ case .cycleStarted(let byUser):
+ userSession = byUser
+ if !byUser, !isReady { stage = .checking }
+ case .found(let version):
+ if !userSession, !isReady { stage = .available(version: version) }
+ case .downloading(let version):
+ if !userSession, !isReady { stage = .downloading(version: version) }
+ case .preparing(let version):
+ if !userSession, !isReady { stage = .preparing(version: version) }
+ case .ready(let version):
+ stage = .ready(version: version)
+ // This session now lasts until quit, and the banner is the answer to the click.
+ checkQueued = false
+ case .reminder(let version, let downloaded):
+ stage = downloaded ? .ready(version: version) : .available(version: version)
+ case .updateClosed:
+ if case .available = stage { stage = .idle }
+ case .cycleFinished:
+ userSession = false
+ if !isReady { stage = .idle }
+ case .gameRunning(let running):
+ gameRunning = running
+ }
+ }
+
+ func restart(busy: Bool, canInstallNow: Bool) -> Restart {
+ if busy || gameRunning { return .blocked }
+ return canInstallNow ? .install : .offer
+ }
+
+ mutating func click(busy: Bool) -> Click {
+ guard busy else {
+ userSession = true
+ return .run
+ }
+ if isReady { return .wait }
+ if userSession { return .focus }
+ checkQueued = true
+ return .wait
+ }
+
+ mutating func takeQueuedCheck() -> Bool {
+ guard checkQueued else { return false }
+ checkQueued = false
+ userSession = true
+ return true
}
}
@@ -44,10 +260,40 @@ private final class ReleaseFinder: NSObject, SPUUpdaterDelegate {
enum LatestRelease {
static let buildKey = "LatestReleaseBuild"
static let versionKey = "LatestReleaseVersion"
+ static let notesKey = "LatestReleaseNotes"
+ static let whatsNewShownKey = "WhatsNewShownBuild"
- static func record(build: String, version: String, defaults: UserDefaults = .standard) {
+ static func record(build: String, version: String, notes: String? = nil, defaults: UserDefaults = .standard) {
defaults.set(build, forKey: buildKey)
defaults.set(version, forKey: versionKey)
+ defaults.set(notes, forKey: notesKey)
+ }
+
+ // The build before this one recorded the notes when it found the update, so a first
+ // install or a build that never saw its own release shows nothing. Asks once per build.
+ static func takeWhatsNew(build: String?, defaults: UserDefaults = .standard) -> WhatsNew? {
+ guard let build, defaults.string(forKey: buildKey) == build,
+ defaults.string(forKey: whatsNewShownKey) != build,
+ let version = defaults.string(forKey: versionKey) else { return nil }
+ defaults.set(build, forKey: whatsNewShownKey)
+ return WhatsNew(version: version, changes: changes(in: defaults.string(forKey: notesKey) ?? ""))
+ }
+
+ // Release notes are the release's commit subjects. Keeps what a player would notice.
+ static func changes(in notes: String) -> [String] {
+ let subject = /^(?<type>[a-z]+)(\([^)]*\))?!?:\s*(?<text>.+)$/
+ let hidden: Set<Substring> = ["build", "chore", "ci", "docs", "refactor", "style", "test"]
+ return notes.split(whereSeparator: \.isNewline).compactMap { line in
+ var text = line.trimmingCharacters(in: .whitespaces)
+ guard text.hasPrefix("- ") else { return nil }
+ text.removeFirst(2)
+ if let match = text.wholeMatch(of: subject) {
+ if hidden.contains(match.output.type) { return nil }
+ text = String(match.output.text)
+ }
+ text = text.replacing(/\s*\(#\d+\)$/, with: "")
+ return text.prefix(1).uppercased() + text.dropFirst()
+ }
}
// "0.7.38 (55)" when the release found is newer than `build`; releases are ordered by
@@ -59,3 +305,8 @@ enum LatestRelease {
return version.isEmpty ? "build \(found)" : "\(version) (\(found))"
}
}
+
+struct WhatsNew: Equatable, Sendable {
+ let version: String
+ let changes: [String]
+}
diff --git a/app/Sources/BridgeplayApp/Support/RestartGuard.swift b/app/Sources/BridgeplayApp/Support/RestartGuard.swift
new file mode 100644
index 0000000..c6e9d9f
--- /dev/null
+++ b/app/Sources/BridgeplayApp/Support/RestartGuard.swift
@@ -0,0 +1,9 @@
+import Foundation
+
+// Whether a restart would land under a running game. pgrep can take seconds, so it stays off
+// the main actor.
+enum RestartGuard {
+ static func gameRunning() async -> Bool {
+ await Task.detached(priority: .utility) { Shell.processIsRunning(named: "wineserver") }.value
+ }
+}
diff --git a/app/Sources/BridgeplayApp/Views/RootView.swift b/app/Sources/BridgeplayApp/Views/RootView.swift
index 8cbae48..1b89f40 100644
--- a/app/Sources/BridgeplayApp/Views/RootView.swift
+++ b/app/Sources/BridgeplayApp/Views/RootView.swift
@@ -35,75 +35,84 @@ struct RootView: View {
@Binding var pane: Pane
@Environment(SystemStatus.self) private var status
+ @Environment(PrefixesModel.self) private var prefixes
@Environment(\.accessibilityReduceMotion) private var reduceMotion
var body: some View {
- NavigationSplitView {
- List(selection: $pane) {
- ForEach(Pane.allCases) { item in
- Label(item.label, systemImage: item.symbol)
- .tag(item)
- }
+ VStack(spacing: 0) {
+ // Above NavigationSplitView, not inside its detail column: NavigationSplitView
+ // mis-reconciles its two columns' geometry once the detail column's content has
+ // resized more than once after the initial layout pass, which a banner that
+ // only starts showing after launch (the patch check, a background update
+ // finishing) and then keeps changing (an update's progress stages) reliably
+ // triggers, shifting the whole window's content — sidebar included — off-screen.
+ // Living outside the split view entirely sidesteps that.
+ if MigrationLaunch.shared.pending, MigrationLaunch.shared.failure == nil {
+ MigrationBanner()
+ } else if let banner = status.patchBanner {
+ PatchBanner(banner: banner)
}
- .listStyle(.sidebar)
- .listItemTint(.monochrome)
- .scrollContentBackground(.hidden)
- .background(BP.bg)
- .safeAreaInset(edge: .top, spacing: 0) {
- HStack(spacing: 4.4) {
- BridgeplayMark(size: 22)
- Text(verbatim: "Bridgeplay")
- .font(BP.display(13))
- .foregroundStyle(BP.iridescent)
- Spacer()
+ UpdateNotice(busy: status.isBusy || prefixes.isBusy)
+
+ NavigationSplitView {
+ List(selection: $pane) {
+ ForEach(Pane.allCases) { item in
+ Label(item.label, systemImage: item.symbol)
+ .tag(item)
+ }
}
- .padding(.horizontal, 12)
- .padding(.top, 6)
- .padding(.bottom, 10)
- }
- .safeAreaInset(edge: .bottom, spacing: 0) {
- VStack(alignment: .leading, spacing: 10) {
- credits
- libraryCard
- Text(verbatim: ProductVersion.display)
- .font(BP.sans(11, .medium))
- .foregroundStyle(BP.fg3)
- .lineLimit(2)
- .frame(maxWidth: .infinity, alignment: .leading)
- .padding(.horizontal, 6)
+ .listStyle(.sidebar)
+ .listItemTint(.monochrome)
+ .scrollContentBackground(.hidden)
+ .background(BP.bg)
+ .safeAreaInset(edge: .top, spacing: 0) {
+ HStack(spacing: 4.4) {
+ BridgeplayMark(size: 22)
+ Text(verbatim: "Bridgeplay")
+ .font(BP.display(13))
+ .foregroundStyle(BP.iridescent)
+ Spacer()
+ }
+ .padding(.horizontal, 12)
+ .padding(.top, 6)
+ .padding(.bottom, 10)
}
- .padding(.horizontal, 12)
- .padding(.bottom, 12)
- }
- .navigationSplitViewColumnWidth(min: 180, ideal: 200, max: 260)
- } detail: {
- Group {
- switch pane {
- case .status: StatusView()
- case .gameDefaults: GameDefaultsView()
- case .prefixes: PrefixesView()
- case .backups: BackupsView()
- case .guide: GuideView()
+ .safeAreaInset(edge: .bottom, spacing: 0) {
+ VStack(alignment: .leading, spacing: 10) {
+ credits
+ libraryCard
+ Text(verbatim: ProductVersion.display)
+ .font(BP.sans(11, .medium))
+ .foregroundStyle(BP.fg3)
+ .lineLimit(2)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .padding(.horizontal, 6)
+ }
+ .padding(.horizontal, 12)
+ .padding(.bottom, 12)
}
- }
- .safeAreaInset(edge: .top, spacing: 0) {
- // A failed move is reported on the Status page, with its buttons, instead.
- if MigrationLaunch.shared.pending, MigrationLaunch.shared.failure == nil {
- MigrationBanner()
- } else if let banner = status.patchBanner {
- PatchBanner(banner: banner)
+ .navigationSplitViewColumnWidth(min: 180, ideal: 200, max: 260)
+ } detail: {
+ Group {
+ switch pane {
+ case .status: StatusView()
+ case .gameDefaults: GameDefaultsView()
+ case .prefixes: PrefixesView()
+ case .backups: BackupsView()
+ case .guide: GuideView()
+ }
}
- }
- .safeAreaInset(edge: .bottom, spacing: 0) {
- if let nudge = PlayReports.shared.nudge {
- PlayReportCard(nudge: nudge)
- } else if PlayReports.shared.thanking {
- PlayReportThanks()
+ .safeAreaInset(edge: .bottom, spacing: 0) {
+ if let nudge = PlayReports.shared.nudge {
+ PlayReportCard(nudge: nudge)
+ } else if PlayReports.shared.thanking {
+ PlayReportThanks()
+ }
}
+ .scrollContentBackground(.hidden)
+ .background(BP.bg)
+ .toolbarBackground(BP.bg, for: .windowToolbar)
}
- .scrollContentBackground(.hidden)
- .background(BP.bg)
- .toolbarBackground(BP.bg, for: .windowToolbar)
}
// While Report Your Games… is open, it presents the consent sheet itself.
.sheet(isPresented: Binding(get: { PlayReports.shared.consentRequest != nil && PlayReports.shared.bulk == nil },
diff --git a/app/Sources/BridgeplayApp/Views/UpdateBanner.swift b/app/Sources/BridgeplayApp/Views/UpdateBanner.swift
new file mode 100644
index 0000000..d598391
--- /dev/null
+++ b/app/Sources/BridgeplayApp/Views/UpdateBanner.swift
@@ -0,0 +1,178 @@
+import BridgeplayUI
+import SwiftUI
+
+enum RestartBlock: Equatable, Sendable {
+ case game
+ case work
+}
+
+// The updater's state, read from AppUpdater. In the setup assistant it only answers a click,
+// so an update found in the background doesn't interrupt setup.
+struct UpdateNotice: View {
+ var onlyWhenAsked = false
+ // Bridgeplay's own work, which a restart would cut off.
+ var busy = false
+
+ @State private var showsChanges = false
+
+ var body: some View {
+ let updater = AppUpdater.shared
+ if let stage = updater.flow.notice, !onlyWhenAsked || updater.flow.checkQueued {
+ UpdateBanner(stage: stage, block: updater.flow.gameRunning ? .game : busy ? .work : nil) {
+ if case .ready = stage {
+ Task { await updater.restartToUpdate(busy: busy) }
+ } else {
+ updater.check()
+ }
+ }
+ .task(id: stage) {
+ guard case .ready = stage else { return }
+ while !Task.isCancelled {
+ await updater.refreshRestartBlock()
+ try? await Task.sleep(for: .seconds(15))
+ }
+ }
+ } else if !onlyWhenAsked, let whatsNew = updater.whatsNew {
+ WhatsNewBanner(whatsNew: whatsNew, open: { showsChanges = true }, dismiss: updater.dismissWhatsNew)
+ .sheet(isPresented: $showsChanges) { WhatsNewSheet(whatsNew: whatsNew) }
+ }
+ }
+}
+
+// Sparkle downloads in the background without a window, so this says one is on the way.
+// Sparkle reports no progress for those downloads, hence the spinner instead of a bar.
+struct UpdateBanner: View {
+ let stage: UpdateStage
+ var block: RestartBlock?
+ let action: () -> Void
+
+ var body: some View {
+ UpdateBannerRow {
+ if button == nil {
+ ProgressView().controlSize(.small)
+ } else {
+ Image(systemName: "arrow.down.circle.fill")
+ .foregroundStyle(BP.blue)
+ .accessibilityHidden(true)
+ }
+ } text: {
+ Text(title).font(BP.sans(13, .semibold))
+ if let detail {
+ Text(detail)
+ .font(BP.sans(12))
+ .foregroundStyle(BP.fg2)
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ } actions: {
+ if let button {
+ Button(button, action: action)
+ .buttonStyle(.pillSecondary)
+ .disabled(block != nil)
+ }
+ }
+ }
+
+ private var title: String {
+ switch stage {
+ case .idle, .checking: String(localized: "Checking for updates…")
+ case .available(let version): String(localized: "Bridgeplay \(version) is available")
+ case .downloading(let version): String(localized: "Downloading Bridgeplay \(version)")
+ case .preparing(let version): String(localized: "Getting Bridgeplay \(version) ready")
+ case .ready(let version): String(localized: "Bridgeplay \(version) is ready to install")
+ }
+ }
+
+ private var detail: String? {
+ switch stage {
+ case .ready:
+ switch block {
+ case .game: String(localized: "A game is running, so Bridgeplay won't restart. The update installs when you quit.")
+ case .work: String(localized: "Bridgeplay is busy, so it won't restart yet. The update installs when you quit.")
+ case nil: String(localized: "It installs when you quit Bridgeplay, or you can restart now.")
+ }
+ case .downloading: String(localized: "You can keep using Bridgeplay while it downloads.")
+ default: nil
+ }
+ }
+
+ private var button: String? {
+ switch stage {
+ case .available: String(localized: "View Update…")
+ case .ready: String(localized: "Restart to Update")
+ default: nil
+ }
+ }
+}
+
+struct WhatsNewBanner: View {
+ let whatsNew: WhatsNew
+ let open: () -> Void
+ let dismiss: () -> Void
+
+ var body: some View {
+ UpdateBannerRow {
+ Image(systemName: "checkmark.circle.fill")
+ .foregroundStyle(BP.blue)
+ .accessibilityHidden(true)
+ } text: {
+ Text("Updated to Bridgeplay \(whatsNew.version)").font(BP.sans(13, .semibold))
+ } actions: {
+ if !whatsNew.changes.isEmpty {
+ Button("What's New", action: open).buttonStyle(.pillSecondary)
+ }
+ Button(String(localized: "Close"), systemImage: "xmark", action: dismiss)
+ .labelStyle(.iconOnly)
+ .buttonStyle(.plain)
+ .foregroundStyle(BP.fg2)
+ }
+ }
+}
+
+private struct WhatsNewSheet: View {
+ let whatsNew: WhatsNew
+
+ @Environment(\.dismiss) private var dismiss
+
+ var body: some View {
+ VStack(alignment: .leading, spacing: 14) {
+ Text("What's New in Bridgeplay \(whatsNew.version)").font(BP.sans(15, .semibold))
+ ScrollView {
+ VStack(alignment: .leading, spacing: 8) {
+ ForEach(whatsNew.changes, id: \.self) { change in
+ Text(verbatim: "• \(change)")
+ .font(BP.sans(13))
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ }
+ .frame(maxWidth: .infinity, alignment: .leading)
+ }
+ .frame(maxHeight: 280)
+ HStack {
+ Spacer()
+ Button("Done") { dismiss() }.buttonStyle(.pillSecondary)
+ }
+ }
+ .padding(20)
+ .frame(width: 440)
+ }
+}
+
+private struct UpdateBannerRow<Icon: View, Words: View, Actions: View>: View {
+ @ViewBuilder let icon: Icon
+ @ViewBuilder let text: Words
+ @ViewBuilder let actions: Actions
+
+ var body: some View {
+ HStack(alignment: .center, spacing: 12) {
+ icon
+ VStack(alignment: .leading, spacing: 2) { text }
+ Spacer(minLength: 12)
+ actions
+ }
+ .padding(.horizontal, 16)
+ .padding(.vertical, 10)
+ .background(BP.raise)
+ .overlay(alignment: .bottom) { Rectangle().fill(BP.line).frame(height: 1) }
+ .accessibilityElement(children: .contain)
+ }
+}
diff --git a/app/Tests/BridgeplayAppTests/UpdateFlowTests.swift b/app/Tests/BridgeplayAppTests/UpdateFlowTests.swift
new file mode 100644
index 0000000..0af65eb
--- /dev/null
+++ b/app/Tests/BridgeplayAppTests/UpdateFlowTests.swift
@@ -0,0 +1,230 @@
+import Foundation
+import Testing
+@testable import BridgeplayApp
+
+@Suite("Update flow")
+struct UpdateFlowTests {
+ private func backgroundDownload(_ version: String = "0.7.59") -> UpdateFlow {
+ var flow = UpdateFlow()
+ flow.apply(.cycleStarted(byUser: false))
+ flow.apply(.found(version: version))
+ flow.apply(.downloading(version: version))
+ return flow
+ }
+
+ @Test func aBackgroundCheckThatFindsNothingStaysOutOfSight() {
+ var flow = UpdateFlow()
+ flow.apply(.cycleStarted(byUser: false))
+ #expect(flow.notice == nil)
+ flow.apply(.cycleFinished)
+ #expect(flow.notice == nil)
+ }
+
+ @Test func aFoundUpdateShowsBeforeTheDownloadFinishes() {
+ var flow = UpdateFlow()
+ flow.apply(.cycleStarted(byUser: false))
+ flow.apply(.found(version: "0.7.59"))
+ #expect(flow.notice == .available(version: "0.7.59"))
+ flow.apply(.downloading(version: "0.7.59"))
+ #expect(flow.notice == .downloading(version: "0.7.59"))
+ flow.apply(.preparing(version: "0.7.59"))
+ #expect(flow.notice == .preparing(version: "0.7.59"))
+ }
+
+ @Test func readyOutlivesTheSessionThatPreparedIt() {
+ var flow = backgroundDownload()
+ flow.apply(.ready(version: "0.7.59"))
+ flow.apply(.cycleFinished)
+ #expect(flow.notice == .ready(version: "0.7.59"))
+ // Later background checks resume the same waiting installer.
+ flow.apply(.cycleStarted(byUser: false))
+ flow.apply(.found(version: "0.7.59"))
+ #expect(flow.notice == .ready(version: "0.7.59"))
+ }
+
+ @Test func aClickDuringABackgroundSessionIsQueuedAndShown() {
+ var flow = UpdateFlow()
+ flow.apply(.cycleStarted(byUser: false))
+ let click = flow.click(busy: true)
+ #expect(click == .wait)
+ #expect(flow.checkQueued)
+ #expect(flow.notice == .checking)
+ }
+
+ @Test func aClickBeforeSparkleReportsTheSessionStillShows() {
+ var flow = UpdateFlow()
+ let click = flow.click(busy: true)
+ #expect(click == .wait)
+ #expect(flow.notice == .checking)
+ }
+
+ @Test func aQueuedCheckKeepsTheDownloadVisibleAndRunsOnce() {
+ var flow = backgroundDownload()
+ let click = flow.click(busy: true)
+ #expect(click == .wait)
+ #expect(flow.notice == .downloading(version: "0.7.59"))
+ let first = flow.takeQueuedCheck()
+ let second = flow.takeQueuedCheck()
+ #expect(first)
+ #expect(!second)
+ }
+
+ @Test func aFailedDownloadStillRunsTheQueuedCheck() {
+ var flow = backgroundDownload()
+ _ = flow.click(busy: true)
+ flow.apply(.cycleFinished)
+ #expect(flow.notice == .checking)
+ let ran = flow.takeQueuedCheck()
+ #expect(ran)
+ #expect(flow.notice == nil)
+ }
+
+ @Test func nothingQueuedMeansNothingRuns() {
+ var flow = UpdateFlow()
+ let ran = flow.takeQueuedCheck()
+ #expect(!ran)
+ }
+
+ @Test func aClickWhenIdleRuns() {
+ var flow = UpdateFlow()
+ let click = flow.click(busy: false)
+ #expect(click == .run)
+ #expect(!flow.checkQueued)
+ }
+
+ // The session stays open once ready, so anything queued would wait until quit.
+ @Test func readyAnswersAQueuedClickItself() {
+ var flow = backgroundDownload()
+ _ = flow.click(busy: true)
+ flow.apply(.ready(version: "0.7.59"))
+ #expect(!flow.checkQueued)
+ #expect(flow.notice == .ready(version: "0.7.59"))
+ }
+
+ @Test func aClickWhileReadyShowsTheBannerAndQueuesNothing() {
+ var flow = backgroundDownload()
+ flow.apply(.ready(version: "0.7.59"))
+ let click = flow.click(busy: true)
+ #expect(click == .wait)
+ #expect(!flow.checkQueued)
+ }
+
+ @Test func aReminderForADownloadedUpdateLetsSparkleOfferIt() {
+ var flow = UpdateFlow()
+ flow.apply(.reminder(version: "0.7.59", downloaded: true))
+ let click = flow.click(busy: false)
+ #expect(click == .run)
+ #expect(flow.restart(busy: false, canInstallNow: false) == .offer)
+ }
+
+ @Test func restartInstallsInOneClick() {
+ var flow = backgroundDownload()
+ flow.apply(.ready(version: "0.7.59"))
+ #expect(flow.restart(busy: false, canInstallNow: true) == .install)
+ }
+
+ @Test func aRunningGameBlocksTheRestart() {
+ var flow = backgroundDownload()
+ flow.apply(.ready(version: "0.7.59"))
+ flow.apply(.gameRunning(true))
+ #expect(flow.restart(busy: false, canInstallNow: true) == .blocked)
+ flow.apply(.gameRunning(false))
+ #expect(flow.restart(busy: false, canInstallNow: true) == .install)
+ }
+
+ @Test func workInBridgeplayBlocksTheRestart() {
+ var flow = backgroundDownload()
+ flow.apply(.ready(version: "0.7.59"))
+ #expect(flow.restart(busy: true, canInstallNow: true) == .blocked)
+ }
+
+ @Test func aSecondClickDuringAUserCheckFocusesItsWindow() {
+ var flow = UpdateFlow()
+ _ = flow.click(busy: false)
+ flow.apply(.cycleStarted(byUser: true))
+ let click = flow.click(busy: true)
+ #expect(click == .focus)
+ #expect(!flow.checkQueued)
+ }
+
+ @Test func aUserCheckShowsNoBannerOverSparklesWindow() {
+ var flow = UpdateFlow()
+ _ = flow.click(busy: false)
+ flow.apply(.cycleStarted(byUser: true))
+ flow.apply(.found(version: "0.7.59"))
+ flow.apply(.downloading(version: "0.7.59"))
+ #expect(flow.notice == nil)
+ }
+
+ @Test func aQueuedCheckCountsAsTheUsersOwn() {
+ var flow = UpdateFlow()
+ _ = flow.click(busy: true)
+ let ran = flow.takeQueuedCheck()
+ #expect(ran)
+ let click = flow.click(busy: true)
+ #expect(click == .focus)
+ }
+
+ @Test func aGentleReminderFollowsTheUpdatesStage() {
+ var flow = UpdateFlow()
+ flow.apply(.reminder(version: "0.7.59", downloaded: false))
+ #expect(flow.notice == .available(version: "0.7.59"))
+ flow.apply(.updateClosed)
+ #expect(flow.notice == nil)
+ flow.apply(.reminder(version: "0.7.59", downloaded: true))
+ flow.apply(.updateClosed)
+ #expect(flow.notice == .ready(version: "0.7.59"))
+ }
+}
+
+@Suite("What's New")
+struct WhatsNewTests {
+ private func defaults() throws -> UserDefaults {
+ let name = "WhatsNewTests.\(UUID().uuidString)"
+ let defaults = try #require(UserDefaults(suiteName: name))
+ defaults.removePersistentDomain(forName: name)
+ return defaults
+ }
+
+ @Test func showsOncePerBuild() throws {
+ let defaults = try defaults()
+ LatestRelease.record(build: "77", version: "0.7.60", notes: "- fix(panel): show the menu (#1)", defaults: defaults)
+ let first = LatestRelease.takeWhatsNew(build: "77", defaults: defaults)
+ #expect(first == WhatsNew(version: "0.7.60", changes: ["Show the menu"]))
+ #expect(LatestRelease.takeWhatsNew(build: "77", defaults: defaults) == nil)
+ }
+
+ @Test func waitsForTheBuildItDescribes() throws {
+ let defaults = try defaults()
+ LatestRelease.record(build: "77", version: "0.7.60", notes: "- fix: a", defaults: defaults)
+ #expect(LatestRelease.takeWhatsNew(build: "76", defaults: defaults) == nil)
+ #expect(LatestRelease.takeWhatsNew(build: "77", defaults: defaults) != nil)
+ }
+
+ @Test func nothingRecordedShowsNothing() throws {
+ #expect(LatestRelease.takeWhatsNew(build: "77", defaults: try defaults()) == nil)
+ }
+
+ @Test func aReleaseWithoutNotesStillSaysItUpdated() throws {
+ let defaults = try defaults()
+ LatestRelease.record(build: "77", version: "0.7.60", defaults: defaults)
+ #expect(LatestRelease.takeWhatsNew(build: "77", defaults: defaults)?.changes == [])
+ }
+
+ @Test func keepsWhatAPlayerWouldNotice() {
+ let notes = """
+ - chore(release): Bridgeplay 0.7.59
+ - test(prefixes): wait for the first tool scan instead of timing out (#1682)
+ - fix(setup): say Rosetta is still needed when the password window is closed (#1660)
+ - feat!: add a thing
+ - docs(readme): link the guides (#1655)
+ - Plain line with no type
+ not a list item
+ """
+ #expect(LatestRelease.changes(in: notes) == [
+ "Say Rosetta is still needed when the password window is closed",
+ "Add a thing",
+ "Plain line with no type",
+ ])
+ }
+}