Skip to content

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

feat(app): re-apply Bridgeplay after Steam updates and guide controller setup

raymondchinsf32a5902f82a
diff --git a/app/Sources/NotProtonApp/App.swift b/app/Sources/NotProtonApp/App.swift
index 50414c8..bc72c3f 100644
--- a/app/Sources/NotProtonApp/App.swift
+++ b/app/Sources/NotProtonApp/App.swift
@@ -25,7 +25,22 @@ struct NotProtonApp: App {
if prefixes.hasLoaded { Task { await prefixes.load() } }
}
.onChange(of: status.snapshot == nil, initial: true) {
- if SetupAssistant.shouldShow(status.snapshot) { showsSetup = true }
+ if SetupAssistant.shouldShow(status.snapshot) {
+ showsSetup = true
+ } else if status.snapshot != nil {
+ checkSteamPatch("launch")
+ }
+ }
+ // A Steam client update rewrites Steam.app and drops Bridgeplay with it, so
+ // look again whenever the user comes back and every few minutes.
+ .onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in
+ checkSteamPatch("foreground")
+ }
+ .task {
+ while !Task.isCancelled {
+ try? await Task.sleep(for: SteamPatchKeeper.pollInterval)
+ checkSteamPatch("timer")
+ }
}
.sheet(isPresented: $showsSetup) {
SetupAssistantView()
@@ -37,6 +52,11 @@ struct NotProtonApp: App {
.commands { menus }
}
+ private func checkSteamPatch(_ trigger: String) {
+ guard status.snapshot != nil else { return }
+ Task { await status.checkSteamPatch(trigger: trigger, setupShowing: showsSetup) }
+ }
+
@CommandsBuilder
private var menus: some Commands {
CommandGroup(replacing: .newItem) {}
diff --git a/app/Sources/NotProtonApp/Model/SteamPatchKeeper.swift b/app/Sources/NotProtonApp/Model/SteamPatchKeeper.swift
new file mode 100644
index 0000000..446e413
--- /dev/null
+++ b/app/Sources/NotProtonApp/Model/SteamPatchKeeper.swift
@@ -0,0 +1,116 @@
+import Foundation
+
+// Notices when Steam no longer carries Bridgeplay (a Steam client update rewrites
+// Steam.app) or carries an older build (Bridgeplay itself updated), and decides whether to
+// put it back silently or to ask. It never touches Steam while Steam or a game runs, so it
+// cannot fight Steam's own updater, and it tries on its own at most once per cooldown.
+enum SteamPatchKeeper {
+
+ // Set by Repair Steam, cleared by any install: a Steam the user restored on purpose
+ // stays restored.
+ static let pausedKey = "steamPatchKeeperPaused"
+ static let cooldown: TimeInterval = 15 * 60
+ // Window focus can arrive in bursts; checks closer together than this are skipped.
+ static let checkInterval: TimeInterval = 20
+ static let pollInterval: Duration = .seconds(300)
+
+ enum Kind: Equatable, Sendable {
+ // Steam's update replaced the bundle, so the patch is gone.
+ case removedBySteam
+ // This Bridgeplay has a newer patch than the one in Steam.
+ case outdated
+ }
+
+ enum Blocker: Equatable, Sendable {
+ case steamRunning
+ case gameRunning
+ case lastTryFailed
+ }
+
+ enum Decision: Equatable, Sendable {
+ case nothing
+ case reapply(Kind)
+ case ask(Kind, Blocker)
+ }
+
+ struct Inputs: Sendable {
+ var deployment: SteamDeployment
+ // dylib.version exists, so Bridgeplay was installed into Steam from this account.
+ var previouslyDeployed: Bool
+ var steamRunning: Bool
+ var gameRunning: Bool
+ var paused = false
+ var installBlocked = false
+ var lastAttempt: Date?
+ var lastAttemptFailed = false
+ var now = Date()
+ }
+
+ static func kind(of deployment: SteamDeployment, previouslyDeployed: Bool) -> Kind? {
+ switch deployment {
+ case .notInstalled: previouslyDeployed ? .removedBySteam : nil
+ case .outdated: .outdated
+ case .installed, .steamMissing, .foreign: nil
+ }
+ }
+
+ static func decide(_ inputs: Inputs) -> Decision {
+ guard !inputs.paused, !inputs.installBlocked,
+ let kind = kind(of: inputs.deployment, previouslyDeployed: inputs.previouslyDeployed)
+ else { return .nothing }
+ if inputs.gameRunning { return .ask(kind, .gameRunning) }
+ if inputs.steamRunning { return .ask(kind, .steamRunning) }
+ if inputs.lastAttemptFailed { return .ask(kind, .lastTryFailed) }
+ if let last = inputs.lastAttempt, inputs.now.timeIntervalSince(last) < cooldown {
+ return .ask(kind, .lastTryFailed)
+ }
+ return .reapply(kind)
+ }
+
+ // Reads only what decide() needs: the plist, two process lists and one small file.
+ static func capture(
+ bundledVersion: String,
+ versionFile: URL = SupportPaths.deployedVersion
+ ) -> (deployment: SteamDeployment, previouslyDeployed: Bool, steamRunning: Bool, gameRunning: Bool) {
+ let gameRunning = Shell.processIsRunning(named: "wineserver")
+ || RunnerStore.clonedBuilds().contains { RunnerInstaller.isRunning(from: SupportPaths.runnerRoot(forBuild: $0)) }
+ return (SteamBundle.deployment(bundledVersion: bundledVersion, versionFile: versionFile),
+ SteamBundle.deployedVersion(at: versionFile) != nil,
+ SteamBundle.isRunning,
+ gameRunning)
+ }
+
+ struct Banner: Equatable, Sendable {
+ let kind: Kind
+ let blocker: Blocker
+
+ var title: String {
+ switch kind {
+ case .removedBySteam: String(localized: "Steam updated")
+ case .outdated: String(localized: "Bridgeplay update for Steam")
+ }
+ }
+
+ var message: String {
+ let lead = switch kind {
+ case .removedBySteam: String(localized: "Steam's update removed Bridgeplay, so Windows games won't start.")
+ case .outdated: String(localized: "This version of Bridgeplay has newer files for Steam.")
+ }
+ let next = switch blocker {
+ case .steamRunning: String(localized: "Steam closes for a moment and opens again.")
+ case .gameRunning: String(localized: "Quit your game first.")
+ case .lastTryFailed: String(localized: "Bridgeplay couldn't do this on its own.")
+ }
+ return "\(lead) \(next)"
+ }
+
+ var button: String {
+ switch blocker {
+ case .lastTryFailed: String(localized: "Try Again")
+ case .steamRunning, .gameRunning: String(localized: "Re-apply Bridgeplay")
+ }
+ }
+
+ var canApply: Bool { blocker != .gameRunning }
+ }
+}
diff --git a/app/Sources/NotProtonApp/SetupAssistant.swift b/app/Sources/NotProtonApp/SetupAssistant.swift
index 26af04e..98bccfd 100644
--- a/app/Sources/NotProtonApp/SetupAssistant.swift
+++ b/app/Sources/NotProtonApp/SetupAssistant.swift
@@ -43,8 +43,8 @@ final class SetupAssistant {
let freeBytes = SetupChecks.freeBytes()
// Graphics
- var gptk: WinecxD3DMetal.Payload? = WinecxD3DMetal.locate()
- var gptkImages: [URL] = GPTKImport.candidates()
+ var gptk: WinecxD3DMetal.Payload?
+ var gptkImages: [URL]
var skippedGraphics = false
// Steam
@@ -52,6 +52,10 @@ final class SetupAssistant {
var signedIn = SetupChecks.steamSignedIn()
@ObservationIgnored private var signInWatch: Task<Void, Never>?
+ // The keychain identity that keeps Steam's controller permission across updates.
+ enum TrustState: Equatable { case unknown, needed, working, done, declined(String) }
+ var trust: TrustState = .unknown
+
// Finish
var tasks: [SetupTask] = SetupAssistant.plannedTasks
var needsAppManagement = false
@@ -63,6 +67,12 @@ final class SetupAssistant {
SetupTask(id: "default", title: String(localized: "Make WineCX Steam's default")),
]
+ init() {
+ let located = WinecxD3DMetal.locate()
+ gptk = located
+ gptkImages = GPTKImport.candidatesIfMissing(installed: located != nil)
+ }
+
var macReady: Bool { appleSilicon && macOSSupported && rosettaInstalled && hasSpace }
var hasSpace: Bool { (freeBytes ?? .max) >= SetupChecks.requiredBytes }
@@ -79,7 +89,10 @@ final class SetupAssistant {
guard let next = Step(rawValue: step.rawValue + 1) else { return }
message = nil
step = next
- if step == .steam { watchSignIn() }
+ if step == .steam {
+ watchSignIn()
+ Task { await checkTrust() }
+ }
}
func back() {
@@ -96,7 +109,8 @@ final class SetupAssistant {
do {
try await Task.detached(priority: .userInitiated) { try SetupChecks.installRosetta() }.value
} catch {
- message = String(localized: "Rosetta wasn't installed. \(error.localizedDescription)")
+ AppLog.note("setup: Rosetta install failed: \(error.localizedDescription)")
+ message = SetupChecks.rosettaFailure(error)
}
rosettaInstalled = SetupChecks.rosettaInstalled()
}
@@ -148,6 +162,29 @@ final class SetupAssistant {
}
}
+ func checkTrust() async {
+ guard trust == .unknown else { return }
+ let present = await Task.detached(priority: .utility) { LocalSigning.existingHash() != nil }.value
+ if trust == .unknown { trust = present ? .done : .needed }
+ }
+
+ // One click, no password: see LocalSigning for why no prompt is needed. A failure keeps
+ // ad hoc signing, which works but loses the controller permission on every update.
+ func trustThisMac() async {
+ guard trust != .working, trust != .done else { return }
+ trust = .working
+ do {
+ _ = try await Task.detached(priority: .userInitiated) { try LocalSigning.ensure() }.value
+ trust = .done
+ } catch {
+ AppLog.note("setup: signing identity not created: \(error.localizedDescription)")
+ trust = .declined(Self.untrustedNote)
+ }
+ }
+
+ static let untrustedNote =
+ String(localized: "Not set up. Bridgeplay still works, but after each update you'll need to allow your controller again.")
+
// MARK: Finish
func finish(with status: SystemStatus) async {
diff --git a/app/Sources/NotProtonApp/SystemStatus.swift b/app/Sources/NotProtonApp/SystemStatus.swift
index 3fff859..589a7bd 100644
--- a/app/Sources/NotProtonApp/SystemStatus.swift
+++ b/app/Sources/NotProtonApp/SystemStatus.swift
@@ -594,6 +594,7 @@ final class SystemStatus {
}
func installIntoSteam() async {
+ var failedInputResets: [String]?
await perform(from: InstallPhase.checkingPayload.label) { progress in
let lock = try DeploymentContent.acquireInstallationLock()
defer { lock.release() }
@@ -635,9 +636,130 @@ final class SystemStatus {
try await Task.detached(priority: .userInitiated) {
try SteamInstaller.finish(result)
}.value
+ failedInputResets = result.failedInputResets
return parts.joined(separator: " ")
}
+ if failure == nil {
+ UserDefaults.standard.removeObject(forKey: SteamPatchKeeper.pausedKey)
+ }
+ // Only an install that changed Steam's signature tried a reset, so only it decides.
+ if let failedInputResets, failure == nil, !failedInputResets.isEmpty || !controllerResetFailures.isEmpty {
+ controllerResetFailures = failedInputResets
+ }
+ }
+
+ // MARK: Controller permission
+
+ static let inputMonitoringPane =
+ URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_ListenEvent")!
+
+ static func openInputMonitoring() {
+ AppLog.note("opening Input Monitoring settings")
+ NSWorkspace.shared.open(inputMonitoringPane)
+ }
+
+ private static let controllerResetFailuresKey = "steamInputResetFailures"
+
+ // What macOS refused to reset after the last install changed Steam's signature. Kept
+ // across launches: until it is fixed, controllers stay silently blocked.
+ var controllerResetFailures: [String] = UserDefaults.standard.stringArray(forKey: SystemStatus.controllerResetFailuresKey) ?? [] {
+ didSet {
+ if controllerResetFailures.isEmpty {
+ UserDefaults.standard.removeObject(forKey: Self.controllerResetFailuresKey)
+ } else {
+ UserDefaults.standard.set(controllerResetFailures, forKey: Self.controllerResetFailuresKey)
+ AppLog.note("controller permission: macOS kept \(controllerResetFailures.joined(separator: ", ")) for Steam")
+ }
+ }
+ }
+
+ // MARK: Signing identity
+
+ // nil until checked.
+ private(set) var signingIdentityReady: Bool?
+
+ func refreshSigningIdentity() async {
+ signingIdentityReady = await Task.detached(priority: .utility) { LocalSigning.existingHash() != nil }.value
+ }
+
+ func trustThisMac() async {
+ guard isIdle else { return }
+ await perform(from: LocalSigning.step) { _ in
+ _ = try await Task.detached(priority: .userInitiated) { try LocalSigning.ensure() }.value
+ return String(localized: "Bridgeplay is trusted on this Mac. Controllers keep their permission after the next update.")
+ }
+ await refreshSigningIdentity()
+ }
+
+ // MARK: Keeping Bridgeplay in Steam
+
+ var patchBanner: SteamPatchKeeper.Banner?
+ @ObservationIgnored private var lastPatchCheck: Date?
+ @ObservationIgnored private var lastAutoReapply: Date?
+ @ObservationIgnored private var autoReapplyFailed = false
+
+ // Called at launch, when the app comes to the front and every few minutes. Re-applies
+ // Bridgeplay on its own only while Steam and every game are closed; otherwise it shows
+ // a banner with one button.
+ func checkSteamPatch(trigger: String, setupShowing: Bool = false, now: Date = Date()) async {
+ if let last = lastPatchCheck, now.timeIntervalSince(last) < SteamPatchKeeper.checkInterval { return }
+ guard isIdle, !setupShowing else { return }
+ lastPatchCheck = now
+ let version = AppVersion.bundled
+ let seen = await Task.detached(priority: .utility) { SteamPatchKeeper.capture(bundledVersion: version) }.value
+ let decision = SteamPatchKeeper.decide(SteamPatchKeeper.Inputs(
+ deployment: seen.deployment,
+ previouslyDeployed: seen.previouslyDeployed,
+ steamRunning: seen.steamRunning,
+ gameRunning: seen.gameRunning,
+ paused: UserDefaults.standard.bool(forKey: SteamPatchKeeper.pausedKey),
+ installBlocked: snapshot?.installContent.blocksInstallation == true,
+ lastAttempt: lastAutoReapply,
+ lastAttemptFailed: autoReapplyFailed,
+ now: now))
+
+ switch decision {
+ case .nothing:
+ if patchBanner != nil { AppLog.note("patch keeper (\(trigger)): Steam carries Bridgeplay again") }
+ patchBanner = nil
+ autoReapplyFailed = false
+ case .ask(let kind, let blocker):
+ let banner = SteamPatchKeeper.Banner(kind: kind, blocker: blocker)
+ if banner != patchBanner { AppLog.note("patch keeper (\(trigger)): \(kind) waits, \(blocker)") }
+ patchBanner = banner
+ case .reapply(let kind):
+ guard isIdle else { return }
+ AppLog.note("patch keeper (\(trigger)): re-applying on its own, \(kind)")
+ lastAutoReapply = now
+ await installIntoSteam()
+ settleReapply(kind)
+ }
+ }
+
+ func reapplyFromBanner() async {
+ guard isIdle, let banner = patchBanner, banner.canApply else { return }
+ AppLog.note("patch keeper: re-applying on request, \(banner.kind)")
+ let wasRunning = await Task.detached(priority: .userInitiated) { SteamBundle.isRunning }.value
+ await installIntoSteam()
+ settleReapply(banner.kind)
+ if failure == nil, wasRunning {
+ let stillRunning = await Task.detached(priority: .userInitiated) { SteamBundle.isRunning }.value
+ if !stillRunning { NSWorkspace.shared.open(SupportPaths.Steam.app) }
+ }
+ }
+
+ private func settleReapply(_ kind: SteamPatchKeeper.Kind) {
+ autoReapplyFailed = failure != nil
+ if autoReapplyFailed {
+ AppLog.note("patch keeper: re-apply failed")
+ patchBanner = SteamPatchKeeper.Banner(kind: kind, blocker: .lastTryFailed)
+ } else {
+ patchBanner = nil
+ outcome = kind == .removedBySteam
+ ? String(localized: "Steam updated, so Bridgeplay put itself back into Steam.")
+ : String(localized: "Bridgeplay updated its files in Steam.")
+ }
}
func setUpdateBlock(_ blocked: Bool) async {
@@ -658,6 +780,8 @@ final class SystemStatus {
let lock = try DeploymentContent.acquireInstallationLock()
defer { lock.release() }
let result = try await SteamRepair.run(report: { progress($0.label) })
+ UserDefaults.standard.set(true, forKey: SteamPatchKeeper.pausedKey)
+ AppLog.note("patch keeper: paused until Bridgeplay is installed again")
var parts = [String(localized: "Steam restored to its original state.")]
if result.stoppedClient { parts.append(Self.restartHint) }
@@ -668,6 +792,7 @@ final class SystemStatus {
func resetControllerPermission() async {
await perform(from: String(localized: "Resetting Steam's controller permission")) { _ in
let failed = SteamInstaller.failedInputAccessResets()
+ controllerResetFailures = failed
guard failed.isEmpty else {
throw StepFailure(
step: String(localized: "Reset controller permission"),
@@ -701,6 +826,7 @@ final class SystemStatus {
}.value
snapshot = captured
AppLog.note(captured)
+ await refreshSigningIdentity()
await refreshRunnerStorage(cleanTemplates: !captured.installContent.blocksInstallation)
}
diff --git a/app/Sources/NotProtonApp/Views/RootView.swift b/app/Sources/NotProtonApp/Views/RootView.swift
index 5040c47..e121290 100644
--- a/app/Sources/NotProtonApp/Views/RootView.swift
+++ b/app/Sources/NotProtonApp/Views/RootView.swift
@@ -27,6 +27,7 @@ enum Pane: String, CaseIterable, Identifiable, Hashable {
struct RootView: View {
@Binding var pane: Pane
+ @Environment(SystemStatus.self) private var status
var body: some View {
NavigationSplitView {
@@ -39,10 +40,17 @@ struct RootView: View {
.listStyle(.sidebar)
.navigationSplitViewColumnWidth(min: 180, ideal: 200, max: 260)
} detail: {
- switch pane {
- case .status: StatusView()
- case .prefixes: PrefixesView()
- case .backups: BackupsView()
+ Group {
+ switch pane {
+ case .status: StatusView()
+ case .prefixes: PrefixesView()
+ case .backups: BackupsView()
+ }
+ }
+ .safeAreaInset(edge: .top, spacing: 0) {
+ if let banner = status.patchBanner {
+ PatchBanner(banner: banner)
+ }
}
}
}
diff --git a/app/Sources/NotProtonApp/Views/SetupAssistantView.swift b/app/Sources/NotProtonApp/Views/SetupAssistantView.swift
index b3ecdd3..271bed4 100644
--- a/app/Sources/NotProtonApp/Views/SetupAssistantView.swift
+++ b/app/Sources/NotProtonApp/Views/SetupAssistantView.swift
@@ -184,12 +184,36 @@ struct SetupAssistantView: View {
value: model.signedIn ? String(localized: "Signed in.") : String(localized: "Waiting for you to sign in. Bridgeplay never sees your password."),
tone: model.signedIn ? .ok : .info,
action: model.signedIn || !model.steamInstalled ? nil : StatusAction(label: String(localized: "Open Steam")) { model.openSteam() }))
+ checked(2, trustRow)
} header: {
StepHeader(title: "Sign in to Steam",
detail: "Sign in with your account in Steam. Bridgeplay continues on its own once you're in.")
}
}
+ // Optional: Continue does not wait for it. No password is asked for.
+ private var trustRow: StatusRow {
+ let title = String(localized: "Trust Bridgeplay on this Mac")
+ switch model.trust {
+ case .unknown, .needed:
+ return StatusRow(title: title,
+ value: String(localized: "Keeps your controller working after Bridgeplay updates. Adds a certificate for this Mac to your login keychain."),
+ tone: .info,
+ action: StatusAction(label: String(localized: "Trust"), isEnabled: !model.isWorking && model.trust == .needed) {
+ Task { await model.trustThisMac() }
+ })
+ case .working:
+ return StatusRow(title: title, value: String(localized: "Adding the certificate…"), tone: .info)
+ case .done:
+ return StatusRow(title: title, value: String(localized: "Done. Your controller keeps working after updates."), tone: .ok)
+ case .declined(let note):
+ return StatusRow(title: title, value: note, tone: .warning,
+ action: StatusAction(label: String(localized: "Try Again"), isEnabled: !model.isWorking) {
+ Task { await model.trustThisMac() }
+ })
+ }
+ }
+
@ViewBuilder
private var finishStep: some View {
Section {
@@ -225,6 +249,7 @@ struct SetupAssistantView: View {
StatusRow(title: String(localized: "App Management"),
value: String(localized: "Turn on Bridgeplay in Privacy & Security › App Management. Setup continues by itself once it's on."),
tone: .warning,
+ detail: String(localized: "After a Bridgeplay update the switch can look on but no longer work. Turn it off and on again, or remove Bridgeplay from the list with − and add it back with +."),
action: StatusAction(label: Remedy.settingsButton, isProminent: true) { model.openAppManagement() })
}
}
@@ -238,6 +263,10 @@ struct SetupAssistantView: View {
checked(2, StatusRow(title: String(localized: "Game Porting Toolkit"),
value: model.gptk == nil ? String(localized: "Skipped. Games use DXMT; add it later from Status.") : String(localized: "Linked."),
tone: model.gptk == nil ? .neutral : .ok))
+ checked(3, StatusRow(title: String(localized: "Controllers"),
+ value: String(localized: "The first time a game uses a controller, macOS asks to let Steam use Input Monitoring. Click Allow. If you missed it, turn on Steam in Input Monitoring."),
+ tone: .info,
+ action: StatusAction(label: String(localized: "Open Input Monitoring")) { SystemStatus.openInputMonitoring() }))
} header: {
StepHeader(title: "You're all set",
detail: "Open Steam, install a Windows game and press Play. Status, Prefixes and Prefix Backups in this window change engines, fix a game or undo everything.")
diff --git a/app/Sources/NotProtonApp/Views/StatusView.swift b/app/Sources/NotProtonApp/Views/StatusView.swift
index 785bfc1..9934731 100644
--- a/app/Sources/NotProtonApp/Views/StatusView.swift
+++ b/app/Sources/NotProtonApp/Views/StatusView.swift
@@ -333,14 +333,18 @@ struct StatusView: View {
)
}
updateBlockRow(snapshot.updateBlocked)
- StatusRow(
- title: String(localized: "Controller permission"),
- value: String(localized: "Clear Steam's controller permission so macOS asks for it again."),
- action: StatusAction(
- label: String(localized: "Reset"),
- isEnabled: status.isIdle
- ) { Task { await status.resetControllerPermission() } }
- )
+ controllerRow
+ if status.signingIdentityReady == false {
+ StatusRow(
+ title: String(localized: "Trust Bridgeplay on this Mac"),
+ value: String(localized: "Keeps your controller working after Bridgeplay updates. Adds a certificate for this Mac to your login keychain."),
+ tone: .info,
+ action: StatusAction(
+ label: String(localized: "Trust"),
+ isEnabled: status.isIdle
+ ) { Task { await status.trustThisMac() } }
+ )
+ }
}
Section {
@@ -363,6 +367,38 @@ struct StatusView: View {
.formStyle(.grouped)
}
+ // A reset macOS refused leaves Steam's old approval in place, and macOS then blocks the
+ // controller without asking. Only the user can clear it in System Settings.
+ @ViewBuilder
+ private var controllerRow: some View {
+ if status.controllerResetFailures.isEmpty {
+ StatusRow(
+ title: String(localized: "Controller permission"),
+ value: String(localized: "Clear Steam's controller permission so macOS asks for it again."),
+ secondaryAction: StatusAction(label: String(localized: "Open Input Monitoring")) {
+ SystemStatus.openInputMonitoring()
+ },
+ action: StatusAction(
+ label: String(localized: "Reset"),
+ isEnabled: status.isIdle
+ ) { Task { await status.resetControllerPermission() } }
+ )
+ } else {
+ StatusRow(
+ title: String(localized: "Controllers may not work"),
+ value: String(localized: "macOS kept Steam's old controller permission. In Input Monitoring, turn Steam off and on again, then restart Steam."),
+ tone: .warning,
+ secondaryAction: StatusAction(
+ label: String(localized: "Try Again"),
+ isEnabled: status.isIdle
+ ) { Task { await status.resetControllerPermission() } },
+ action: StatusAction(label: String(localized: "Open Input Monitoring"), isProminent: true) {
+ SystemStatus.openInputMonitoring()
+ }
+ )
+ }
+ }
+
private var dangerSection: some View {
Section {
StatusRow(
@@ -808,3 +844,36 @@ struct StatusView: View {
}
}
}
+
+// Shown above every pane when Steam lost Bridgeplay (or has an older copy) and Bridgeplay
+// could not put it back on its own. One button; the install flow does the rest.
+struct PatchBanner: View {
+ @Environment(SystemStatus.self) private var status
+ let banner: SteamPatchKeeper.Banner
+
+ var body: some View {
+ HStack(alignment: .center, spacing: 12) {
+ Image(systemName: "exclamationmark.triangle.fill")
+ .foregroundStyle(.orange)
+ .accessibilityHidden(true)
+ VStack(alignment: .leading, spacing: 2) {
+ Text(banner.title).font(.headline)
+ Text(banner.message)
+ .foregroundStyle(.secondary)
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ Spacer(minLength: 12)
+ if status.activity != nil {
+ ProgressView().controlSize(.small)
+ }
+ Button(banner.button) { Task { await status.reapplyFromBanner() } }
+ .buttonStyle(.borderedProminent)
+ .disabled(!banner.canApply || !status.isIdle)
+ }
+ .padding(.horizontal, 16)
+ .padding(.vertical, 10)
+ .background(.bar)
+ .overlay(alignment: .bottom) { Divider() }
+ .accessibilityElement(children: .combine)
+ }
+}
diff --git a/app/Tests/NotProtonAppTests/SteamPatchKeeperTests.swift b/app/Tests/NotProtonAppTests/SteamPatchKeeperTests.swift
new file mode 100644
index 0000000..27764cc
--- /dev/null
+++ b/app/Tests/NotProtonAppTests/SteamPatchKeeperTests.swift
@@ -0,0 +1,83 @@
+import Foundation
+import Testing
+
+@testable import NotProtonApp
+
+@Suite("Keeping Bridgeplay in Steam")
+struct SteamPatchKeeperTests {
+
+ private func inputs(
+ _ deployment: SteamDeployment = .notInstalled,
+ previouslyDeployed: Bool = true,
+ steamRunning: Bool = false,
+ gameRunning: Bool = false,
+ paused: Bool = false,
+ installBlocked: Bool = false,
+ lastAttempt: Date? = nil,
+ lastAttemptFailed: Bool = false,
+ now: Date = Date(timeIntervalSince1970: 1_000_000)
+ ) -> SteamPatchKeeper.Inputs {
+ SteamPatchKeeper.Inputs(
+ deployment: deployment, previouslyDeployed: previouslyDeployed, steamRunning: steamRunning,
+ gameRunning: gameRunning, paused: paused, installBlocked: installBlocked,
+ lastAttempt: lastAttempt, lastAttemptFailed: lastAttemptFailed, now: now)
+ }
+
+ @Test("Steam closed and no game running: the patch goes back on its own")
+ func reappliesSilently() {
+ #expect(SteamPatchKeeper.decide(inputs()) == .reapply(.removedBySteam))
+ #expect(SteamPatchKeeper.decide(inputs(.outdated(deployed: "1.0", bundled: "1.1"))) == .reapply(.outdated))
+ }
+
+ @Test("Steam running: ask, never stop Steam unasked")
+ func asksWhileSteamRuns() {
+ #expect(SteamPatchKeeper.decide(inputs(steamRunning: true)) == .ask(.removedBySteam, .steamRunning))
+ }
+
+ @Test("A running game wins over everything, and its banner cannot apply")
+ func waitsForTheGame() {
+ let decision = SteamPatchKeeper.decide(inputs(steamRunning: true, gameRunning: true))
+ #expect(decision == .ask(.removedBySteam, .gameRunning))
+ #expect(!SteamPatchKeeper.Banner(kind: .removedBySteam, blocker: .gameRunning).canApply)
+ #expect(SteamPatchKeeper.Banner(kind: .removedBySteam, blocker: .steamRunning).canApply)
+ }
+
+ @Test("A Steam that never had Bridgeplay is left to the Setup Assistant")
+ func leavesFreshSteamAlone() {
+ #expect(SteamPatchKeeper.decide(inputs(previouslyDeployed: false)) == .nothing)
+ }
+
+ @Test("Installed, missing, foreign or repaired Steam is left alone")
+ func nothingToDo() {
+ #expect(SteamPatchKeeper.decide(inputs(.installed(version: "1.0"))) == .nothing)
+ #expect(SteamPatchKeeper.decide(inputs(.steamMissing)) == .nothing)
+ #expect(SteamPatchKeeper.decide(inputs(.foreign(insert: "/other.dylib"))) == .nothing)
+ #expect(SteamPatchKeeper.decide(inputs(paused: true)) == .nothing)
+ #expect(SteamPatchKeeper.decide(inputs(installBlocked: true)) == .nothing)
+ }
+
+ @Test("A failed or recent attempt is not repeated on its own")
+ func debounces() {
+ let now = Date(timeIntervalSince1970: 1_000_000)
+ #expect(SteamPatchKeeper.decide(inputs(lastAttemptFailed: true)) == .ask(.removedBySteam, .lastTryFailed))
+ #expect(SteamPatchKeeper.decide(inputs(lastAttempt: now.addingTimeInterval(-60), now: now))
+ == .ask(.removedBySteam, .lastTryFailed))
+ #expect(SteamPatchKeeper.decide(inputs(lastAttempt: now.addingTimeInterval(-SteamPatchKeeper.cooldown - 1), now: now))
+ == .reapply(.removedBySteam))
+ }
+
+ @Test("Banner text names Bridgeplay and says what happens next")
+ func bannerText() {
+ let banner = SteamPatchKeeper.Banner(kind: .removedBySteam, blocker: .steamRunning)
+ #expect(banner.title == "Steam updated")
+ #expect(banner.message.contains("Bridgeplay"))
+ #expect(banner.button == "Re-apply Bridgeplay")
+ }
+
+ @Test("The Input Monitoring link opens the ListenEvent list")
+ @MainActor
+ func inputMonitoringLink() {
+ #expect(SystemStatus.inputMonitoringPane.scheme == "x-apple.systempreferences")
+ #expect(SystemStatus.inputMonitoringPane.query == "Privacy_ListenEvent")
+ }
+}