Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
feat(app): run the 3.0.0 folder move at launch
raymondchins27caebf4ca2f
diff --git a/app/Sources/BridgeplayApp/App.swift b/app/Sources/BridgeplayApp/App.swiftindex 7434202..47edd7e 100644--- a/app/Sources/BridgeplayApp/App.swift+++ b/app/Sources/BridgeplayApp/App.swift@@ -12,6 +12,7 @@ struct BridgeplayApp: App {init() {AppLog.start()+ MigrationLaunch.shared.logLaunchResult()}var body: some Scene {@@ -24,7 +25,9 @@ struct BridgeplayApp: App {.onChange(of: status.snapshot?.installedRunners.map(\.id)) {if prefixes.hasLoaded { Task { await prefixes.load() } }}+ .task { await MigrationLaunch.shared.finishWhenPossible(status) }.onChange(of: status.snapshot == nil, initial: true) {+ if MigrationLaunch.shared.pending { return }if SetupAssistant.shouldShow(status.snapshot) {showsSetup = true} else if status.snapshot != nil {@@ -55,7 +58,7 @@ struct BridgeplayApp: App {}private func checkSteamPatch(_ trigger: String) {- guard status.snapshot != nil else { return }+ guard status.snapshot != nil, !MigrationLaunch.shared.pending else { return }Task { await status.checkSteamPatch(trigger: trigger, setupShowing: showsSetup) }}@@ -128,7 +131,7 @@ struct BridgeplayApp: App {// After Sparkle relaunches into a newer build, bring the patch in Steam up to date// once it is safe to; the setup assistant handles a first install itself.private func refreshAfterUpdate() {- guard !showsSetup else { return }+ guard !showsSetup, !MigrationLaunch.shared.pending else { return }Task { await PostUpdateRefresh.runIfNeeded(status) }}diff --git a/app/Sources/BridgeplayApp/Support/Launch.swift b/app/Sources/BridgeplayApp/Support/Launch.swiftindex 7313ef0..5de4204 100644--- a/app/Sources/BridgeplayApp/Support/Launch.swift+++ b/app/Sources/BridgeplayApp/Support/Launch.swift@@ -3,6 +3,8 @@ import Foundation@mainenum Launch {static func main() {+ // Before anything opens the support folder: the 3.0.0 move needs the old one intact.+ MainActor.assumeIsolated { MigrationLaunch.shared.runAtLaunch() }if CommandLine.arguments.dropFirst().contains(RemoveEverythingCommand.flag) {RemoveEverythingCommand.run()}diff --git a/app/Sources/BridgeplayApp/Support/MigrationLaunch.swift b/app/Sources/BridgeplayApp/Support/MigrationLaunch.swiftnew file mode 100644index 0000000..6cf936f--- /dev/null+++ b/app/Sources/BridgeplayApp/Support/MigrationLaunch.swift@@ -0,0 +1,77 @@+import Foundation+import Observation++// Runs the 3.0.0 move from the notproton folders to the bridgeplay ones (BrandMigration).+// It starts in Launch.main, before AppLog or anything else opens the support folder. If+// Steam or a game is running it waits: the main window shows a banner, the patch keeper+// and the post-update install stand still, and the move finishes by itself once both are+// closed. Bridgeplay then installs itself into Steam again, because the copy Steam holds+// still points at the old folders.+@MainActor+@Observable+final class MigrationLaunch {+ static let shared = MigrationLaunch()++ private(set) var pending = false+ private(set) var blocker: BrandMigration.Blocker?+ @ObservationIgnored private var launchNote: String?++ // Debug builds run from the source tree and never move the real folders.+ nonisolated static var enabled: Bool {+ #if DEBUG+ false+ #else+ true+ #endif+ }++ func runAtLaunch() {+ guard Self.enabled else { return }+ let migration = BrandMigration.live()+ guard migration.isNeeded else { return }+ if let blocker = migration.canRun() {+ pending = true+ self.blocker = blocker+ launchNote = "migration 3.0.0 waits: \(blocker)"+ return+ }+ launchNote = Self.run(migration)+ }++ // AppLog only exists once the app has started, so the launch result is logged then.+ func logLaunchResult() {+ if let launchNote { AppLog.note(launchNote) }+ launchNote = nil+ }++ func finishWhenPossible(_ status: SystemStatus) async {+ guard pending else { return }+ while !Task.isCancelled {+ try? await Task.sleep(for: .seconds(4))+ let migration = BrandMigration.live()+ guard migration.isNeeded else { pending = false; return }+ blocker = migration.canRun()+ guard blocker == nil else { continue }+ AppLog.note(Self.run(migration))+ pending = false+ await status.refresh()+ await status.installIntoSteam()+ return+ }+ }++ private static func run(_ migration: BrandMigration) -> String {+ do {+ return "migration 3.0.0: \(try migration.run().description)"+ } catch {+ return "migration 3.0.0 failed: \(error)"+ }+ }++ var bannerMessage: String {+ switch blocker {+ case .gameRunning: String(localized: "Quit your game. Bridgeplay finishes moving its files to the new Bridgeplay folders by itself.")+ default: String(localized: "Quit Steam. Bridgeplay finishes moving its files to the new Bridgeplay folders by itself, then adds itself to Steam again.")+ }+ }+}diff --git a/app/Sources/BridgeplayApp/Views/RootView.swift b/app/Sources/BridgeplayApp/Views/RootView.swiftindex 2e68302..227c3bb 100644--- a/app/Sources/BridgeplayApp/Views/RootView.swift+++ b/app/Sources/BridgeplayApp/Views/RootView.swift@@ -76,7 +76,9 @@ struct RootView: View {}}.safeAreaInset(edge: .top, spacing: 0) {- if let banner = status.patchBanner {+ if MigrationLaunch.shared.pending {+ MigrationBanner()+ } else if let banner = status.patchBanner {PatchBanner(banner: banner)}}@@ -114,3 +116,26 @@ struct RootView: View {.accessibilityHidden(true)}}++// Shown while the 3.0.0 folder move waits for Steam or a game to close.+private struct MigrationBanner: View {+ var body: some View {+ HStack(alignment: .center, spacing: 12) {+ ProgressView().controlSize(.small)+ VStack(alignment: .leading, spacing: 2) {+ Text("Finishing the update to Bridgeplay 3")+ .font(BP.sans(13, .semibold))+ Text(MigrationLaunch.shared.bannerMessage)+ .font(BP.sans(12))+ .foregroundStyle(BP.fg2)+ .fixedSize(horizontal: false, vertical: true)+ }+ Spacer(minLength: 0)+ }+ .padding(.horizontal, 16)+ .padding(.vertical, 10)+ .background(BP.raise)+ .overlay(alignment: .bottom) { Rectangle().fill(BP.line).frame(height: 1) }+ .accessibilityElement(children: .combine)+ }+}