Skip to content

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

feat(update): install updates silently and refresh the Steam patch after

raymondchinsb7ce4977cfbc
diff --git a/app/Info.plist b/app/Info.plist
index eb45fa3..698ca29 100644
--- a/app/Info.plist
+++ b/app/Info.plist
@@ -32,17 +32,25 @@
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
<string>15.0</string>
+ <key>NSDownloadsFolderUsageDescription</key>
+ <string>Bridgeplay looks in Downloads for Apple's Game Porting Toolkit disk image so you don't have to find it.</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NotProtonVersion</key>
<string>0.0.0</string>
+ <key>SUAutomaticallyUpdate</key>
+ <true/>
<key>SUEnableAutomaticChecks</key>
- <false/>
+ <true/>
<key>SUFeedURL</key>
<string>https://github.com/raymondchins/Bridgeplay/releases/latest/download/appcast.xml</string>
<key>SUPublicEDKey</key>
<string>KrO6vVqAJozBSnfrLuyhBU/Kfhg8klI8ftl7CQ2sV98=</string>
+ <key>SUScheduledCheckInterval</key>
+ <integer>86400</integer>
+ <key>SUVerifyUpdateBeforeExtraction</key>
+ <true/>
</dict>
</plist>
diff --git a/app/Sources/NotProtonApp/App.swift b/app/Sources/NotProtonApp/App.swift
index 50414c8..0490677 100644
--- a/app/Sources/NotProtonApp/App.swift
+++ b/app/Sources/NotProtonApp/App.swift
@@ -27,6 +27,8 @@ struct NotProtonApp: App {
.onChange(of: status.snapshot == nil, initial: true) {
if SetupAssistant.shouldShow(status.snapshot) { showsSetup = true }
}
+ .onChange(of: status.snapshot?.steam, initial: true) { refreshAfterUpdate() }
+ .onChange(of: status.isIdle) { refreshAfterUpdate() }
.sheet(isPresented: $showsSetup) {
SetupAssistantView()
.environment(status)
@@ -41,7 +43,8 @@ struct NotProtonApp: App {
private var menus: some Commands {
CommandGroup(replacing: .newItem) {}
- CommandGroup(after: .appInfo) {
+ CommandGroup(replacing: .appInfo) {
+ Button("About Bridgeplay") { AboutPanel.show() }
Button("Check for Updates…") { updater.check() }
}
@@ -102,6 +105,13 @@ struct NotProtonApp: App {
prefixMenu
}
+ // 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 }
+ Task { await PostUpdateRefresh.runIfNeeded(status) }
+ }
+
@CommandsBuilder
private var prefixMenu: some Commands {
CommandMenu("Prefix") {
diff --git a/app/Sources/NotProtonApp/Support/AppLog.swift b/app/Sources/NotProtonApp/Support/AppLog.swift
index 08387c1..4607c7b 100644
--- a/app/Sources/NotProtonApp/Support/AppLog.swift
+++ b/app/Sources/NotProtonApp/Support/AppLog.swift
@@ -15,7 +15,7 @@ enum AppLog {
static func start() {
queue.async {
isOn = true
- append("--- Bridgeplay \(AppVersion.bundled) started ---\n")
+ append("--- \(ProductVersion.display) started ---\n")
}
}
diff --git a/app/Sources/NotProtonApp/Support/PostUpdateRefresh.swift b/app/Sources/NotProtonApp/Support/PostUpdateRefresh.swift
new file mode 100644
index 0000000..0a529da
--- /dev/null
+++ b/app/Sources/NotProtonApp/Support/PostUpdateRefresh.swift
@@ -0,0 +1,83 @@
+// Re-applying the Steam patch after Sparkle installs a newer Bridgeplay
+
+import Foundation
+import Sparkle
+
+// Sparkle replaces the app, but the patch inside Steam is still the one the previous
+// version installed. On the first launch of a newer build this runs the normal install
+// once, and only when nothing would be interrupted or asked: Steam is closed, no game or
+// Wine tool is running, a compatibility tool exists (so no activation question), and the
+// installed content does not block installation. Otherwise the Status row keeps showing
+// "Update available" with its install button, as before.
+enum PostUpdateRefresh {
+
+ enum Decision: Equatable, Sendable {
+ case install
+ // Steam or a game is running; try again on the next launch.
+ case wait
+ case nothing
+ }
+
+ static let lastBuildKey = "PostUpdateRefresh.lastBuild"
+
+ nonisolated static func decide(
+ steam: SteamDeployment,
+ steamRunning: Bool,
+ workloadRunning: Bool,
+ contentBlocks: Bool,
+ hasRunner: Bool,
+ build: String?,
+ lastBuild: String?
+ ) -> Decision {
+ // An unstamped development build never touches Steam on its own.
+ guard let build else { return .nothing }
+ if let lastBuild,
+ SUStandardVersionComparator().compareVersion(build, toVersion: lastBuild) != .orderedDescending {
+ return .nothing
+ }
+ // Only an older recorded Bridgeplay counts; a missing record or the same version
+ // with a stale Info.plist is left to the Status row.
+ guard case .outdated(let deployed, let bundled) = steam, !deployed.isEmpty, deployed != bundled else {
+ return .nothing
+ }
+ guard hasRunner, !contentBlocks else { return .nothing }
+ return steamRunning || workloadRunning ? .wait : .install
+ }
+
+ @MainActor private static var handled = false
+
+ // Called whenever the status snapshot or idleness changes; acts once per launch, on the
+ // first idle snapshot.
+ @MainActor
+ static func runIfNeeded(_ status: SystemStatus, defaults: UserDefaults = .standard) async {
+ guard !handled, status.isIdle, let snapshot = status.snapshot else { return }
+ handled = true
+
+ let build = ProductVersion.build
+ let workloadRunning = await Task.detached(priority: .utility) {
+ RunnerStore.clonedBuilds().contains {
+ RunnerInstaller.isRunning(from: SupportPaths.runnerRoot(forBuild: $0))
+ }
+ }.value
+ let decision = decide(
+ steam: snapshot.steam,
+ steamRunning: snapshot.steamRunning || SteamBundle.isRunning,
+ workloadRunning: workloadRunning,
+ contentBlocks: snapshot.installContent.blocksInstallation,
+ hasRunner: snapshot.runner != .none,
+ build: build,
+ lastBuild: defaults.string(forKey: lastBuildKey)
+ )
+
+ switch decision {
+ case .nothing:
+ if let build { defaults.set(build, forKey: lastBuildKey) }
+ case .wait:
+ AppLog.note("post-update: Steam patch is outdated; waiting for Steam and games to close")
+ case .install:
+ AppLog.note("post-update: re-applying the Steam patch for \(ProductVersion.display)")
+ if let build { defaults.set(build, forKey: lastBuildKey) }
+ await status.requestInstall()
+ }
+ }
+}
diff --git a/app/Sources/NotProtonApp/Support/ProductVersion.swift b/app/Sources/NotProtonApp/Support/ProductVersion.swift
new file mode 100644
index 0000000..a79e5b9
--- /dev/null
+++ b/app/Sources/NotProtonApp/Support/ProductVersion.swift
@@ -0,0 +1,57 @@
+// Bridgeplay's version as make app stamps it from dylib/version.h
+
+import AppKit
+import Foundation
+
+enum ProductVersion {
+
+ // CFBundleShortVersionString: Bridgeplay semver, the same string recorded as the
+ // installed build in Steam.
+ static var short: String { AppVersion.bundled }
+
+ // CFBundleVersion: the release counter Sparkle orders updates by.
+ static var build: String? { stamped(Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion")) }
+
+ // The NotProton release this build is based on.
+ static var upstream: String? { stamped(Bundle.main.object(forInfoDictionaryKey: "NotProtonVersion")) }
+
+ static var display: String { display(short: short, build: build, upstream: upstream) }
+
+ // "Bridgeplay 2.0.0 (32) · based on NotProton 1.2.0"
+ static func display(short: String, build: String?, upstream: String?) -> String {
+ var text = "Bridgeplay \(short)"
+ if let build { text += " (\(build))" }
+ if let upstream { text += " · based on NotProton \(upstream)" }
+ return text
+ }
+
+ // app/Info.plist carries placeholders that only make app replaces.
+ private static func stamped(_ value: Any?) -> String? {
+ guard let text = value as? String, !text.isEmpty, text != "0", text != "0.0.0" else { return nil }
+ return text
+ }
+}
+
+@MainActor
+enum AboutPanel {
+
+ // The standard panel already reads "Version 2.0.0 (32)"; the credits line adds the
+ // upstream release.
+ static func show() {
+ var options: [NSApplication.AboutPanelOptionKey: Any] = [:]
+ if let upstream = ProductVersion.upstream {
+ let centered = NSMutableParagraphStyle()
+ centered.alignment = .center
+ options[.credits] = NSAttributedString(
+ string: "Based on NotProton \(upstream)",
+ attributes: [
+ .font: NSFont.systemFont(ofSize: NSFont.smallSystemFontSize),
+ .foregroundColor: NSColor.secondaryLabelColor,
+ .paragraphStyle: centered,
+ ]
+ )
+ }
+ NSApp.orderFrontStandardAboutPanel(options: options)
+ NSApp.activate()
+ }
+}
diff --git a/app/Tests/NotProtonAppTests/VersioningTests.swift b/app/Tests/NotProtonAppTests/VersioningTests.swift
new file mode 100644
index 0000000..8aba819
--- /dev/null
+++ b/app/Tests/NotProtonAppTests/VersioningTests.swift
@@ -0,0 +1,88 @@
+import Foundation
+import Testing
+
+@testable import NotProtonApp
+
+@Suite("Product version")
+struct ProductVersionTests {
+
+ private static func define(_ name: String) throws -> String {
+ let header = URL(fileURLWithPath: #filePath)
+ .deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()
+ .deletingLastPathComponent().appending(path: "dylib/version.h")
+ let text = try String(contentsOf: header, encoding: .utf8)
+ let line = try #require(text.split(separator: "\n").first { $0.hasPrefix("#define \(name) ") })
+ return String(line.dropFirst("#define \(name) ".count)).trimmingCharacters(in: CharacterSet(charactersIn: "\""))
+ }
+
+ // The last version of the old scheme, as an installed build record in Steam says it.
+ private static let lastLegacy = "1.2.0-winehq.1-ray.32"
+
+ @Test("The Bridgeplay version reads as newer than any build of the old scheme")
+ func newerThanLegacy() throws {
+ let version = try Self.define("BRIDGEPLAY_VERSION")
+ #expect(version.split(separator: ".").count == 3)
+ let bundled = DeploymentContent.Build(version: version, builtAt: 1)
+ let installed = DeploymentContent.Build(version: Self.lastLegacy, builtAt: 2)
+ #expect(bundled.isNewer(than: installed))
+ #expect(!installed.isNewer(than: bundled))
+ }
+
+ @Test("The build number is a plain integer past the old ray counter")
+ func buildContinuesCounter() throws {
+ let build = try #require(Int(try Self.define("BRIDGEPLAY_BUILD")))
+ #expect(build >= 32)
+ }
+
+ @Test("The display names the build and the NotProton release")
+ func display() {
+ #expect(ProductVersion.display(short: "2.0.0", build: "32", upstream: "1.2.0")
+ == "Bridgeplay 2.0.0 (32) · based on NotProton 1.2.0")
+ #expect(ProductVersion.display(short: "0.1.0-dev", build: nil, upstream: nil) == "Bridgeplay 0.1.0-dev")
+ }
+}
+
+@Suite("Post-update refresh")
+struct PostUpdateRefreshTests {
+
+ private func decide(
+ steam: SteamDeployment = .outdated(deployed: "1.1.9-winehq.1-ray.31", bundled: "2.0.0"),
+ steamRunning: Bool = false,
+ workloadRunning: Bool = false,
+ contentBlocks: Bool = false,
+ hasRunner: Bool = true,
+ build: String? = "32",
+ lastBuild: String? = nil
+ ) -> PostUpdateRefresh.Decision {
+ PostUpdateRefresh.decide(steam: steam, steamRunning: steamRunning, workloadRunning: workloadRunning,
+ contentBlocks: contentBlocks, hasRunner: hasRunner,
+ build: build, lastBuild: lastBuild)
+ }
+
+ @Test("The first launch after an update re-applies an older patch")
+ func installsAfterUpdate() {
+ #expect(decide() == .install)
+ // Sparkle's own ordering: build 32 follows the old dotted 1.1.9.31.
+ #expect(decide(lastBuild: "1.1.9.31") == .install)
+ #expect(decide(build: "33", lastBuild: "32") == .install)
+ }
+
+ @Test("Steam or a running game defers it to a later launch")
+ func waitsForSteamAndGames() {
+ #expect(decide(steamRunning: true) == .wait)
+ #expect(decide(workloadRunning: true) == .wait)
+ }
+
+ @Test("Nothing happens without an update or when installing would need the user")
+ func leavesOtherCasesAlone() {
+ #expect(decide(lastBuild: "32") == .nothing)
+ #expect(decide(build: "32", lastBuild: "33") == .nothing)
+ #expect(decide(build: nil) == .nothing)
+ #expect(decide(steam: .installed(version: "2.0.0")) == .nothing)
+ #expect(decide(steam: .notInstalled) == .nothing)
+ #expect(decide(steam: .outdated(deployed: "", bundled: "2.0.0")) == .nothing)
+ #expect(decide(steam: .outdated(deployed: "2.0.0", bundled: "2.0.0")) == .nothing)
+ #expect(decide(contentBlocks: true) == .nothing)
+ #expect(decide(hasRunner: false) == .nothing)
+ }
+}