Skip to content

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

feat(launch): show a progress panel from Play until the game's first window (#1583)

Raystorms8a602ceed3f5
diff --git a/AGENTS.md b/AGENTS.md
index 1bbe4d6..23ce790 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -59,7 +59,7 @@ The checks the workflows run (`make -s <target>`):
- **C and shell suites:** `sigcheck`, `callscheck`, `webpatch-fixtures`, `peicon-fixtures`,
`panel-behavior`, `spawn-env`, `activatecheck`, `compatcheck`, `compatsvc-check`, `prefixstate-check`,
`shortcutcheck`, `launch-shell`, `envcheck`, `buildcheck`, `settingscheck`, `routecheck`,
- `bridgecheck`, `envpasscheck`, `prefixnotecheck`, `powernotecheck`, `exitcheck`, `gamedrivecheck`, `launchercheck`, `seedcheck`, `gamefixescheck`, `versioncheck`, `cicheck`,
+ `bridgecheck`, `envpasscheck`, `prefixnotecheck`, `powernotecheck`, `exitcheck`, `launchprogresscheck`, `gamedrivecheck`, `launchercheck`, `seedcheck`, `gamefixescheck`, `versioncheck`, `cicheck`,
`compat-reported-check`
`make tests-list` prints the test paths. A check whose tool or input is missing prints
diff --git a/Makefile b/Makefile
index 053ca74..0b74d29 100644
--- a/Makefile
+++ b/Makefile
@@ -85,7 +85,7 @@ DEPS := $(OBJS:.o=.d)
tests-list overlay-shim overlay-shim-install overlay-shim-tests \
overlay-shim-bench iconmaker icon \
appinfo helpers-install ntdll-resolve bridge runcheck compatcheck \
- compatsvc-check prefixstate-check shortcutcheck scriptcheck envcheck buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck powernotecheck exitcheck anticheatcheck gamedrivecheck \
+ compatsvc-check prefixstate-check shortcutcheck scriptcheck envcheck buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck powernotecheck exitcheck anticheatcheck launchprogresscheck gamedrivecheck \
gamefixescheck launchercheck padcheck launch-shell activatecheck stamp-check versioncheck cicheck compat-reported-check FORCE
APP_PAYLOAD := app/Sources/BridgeplayApp/Resources/payload
@@ -168,6 +168,10 @@ anticheatcheck:
@if [ ! -f dylib/tests/anticheatcheck.sh ]; then $(call SKIP,anticheatcheck,dylib/tests/anticheatcheck.sh); exit 0; fi; \
sh dylib/tests/anticheatcheck.sh dylib/feats/compat_run.sh
+launchprogresscheck:
+ @if [ ! -f dylib/tests/launchprogresscheck.sh ]; then $(call SKIP,launchprogresscheck,dylib/tests/launchprogresscheck.sh); exit 0; fi; \
+ sh dylib/tests/launchprogresscheck.sh dylib/feats/compat_run.sh
+
gamedrivecheck:
@if [ ! -f dylib/tests/gamedrivecheck.sh ]; then $(call SKIP,gamedrivecheck,dylib/tests/gamedrivecheck.sh); exit 0; fi; \
sh dylib/tests/gamedrivecheck.sh dylib/feats/compat_run.sh
@@ -912,7 +916,7 @@ np-inventory-check:
CI_CHECKS := mincheck l10ncheck \
sigcheck callscheck np-test-batch-check webpatch-fixtures peicon-fixtures panel-behavior spawn-env \
activatecheck compat-reported-import-check compatcheck compatsvc-check prefixstate-check shortcutcheck launch-shell envcheck \
- buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck powernotecheck exitcheck anticheatcheck gamedrivecheck launchercheck \
+ buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck powernotecheck exitcheck anticheatcheck launchprogresscheck gamedrivecheck launchercheck \
seedcheck gamefixescheck versioncheck cicheck padcheck compat-reported-check np-inventory-check np-native-tests native-shim-tests \
app-tests native-installercheck
diff --git a/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings b/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings
index d139fe5..d8030a3 100644
--- a/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings
+++ b/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings
@@ -2543,6 +2543,38 @@
}
}
},
+ "Bridgeplay is starting %@." : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bridgeplay sta avviando %@."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bridgeplay 正在启动 %@。"
+ }
+ }
+ }
+ },
+ "Bridgeplay is starting this game." : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bridgeplay sta avviando questo gioco."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bridgeplay 正在启动此游戏。"
+ }
+ }
+ }
+ },
"Bridgeplay is still busy with another task. Try again when it finishes." : {
"localizations" : {
"it" : {
@@ -5090,6 +5122,22 @@
}
}
},
+ "Getting the game ready…" : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Preparazione del gioco…"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "正在准备游戏…"
+ }
+ }
+ }
+ },
"Good to know" : {
"localizations" : {
"it" : {
@@ -8818,6 +8866,22 @@
}
}
},
+ "Setting up Windows for this game…" : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Configurazione di Windows per questo gioco…"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "正在为此游戏设置 Windows…"
+ }
+ }
+ }
+ },
"Setting up compatibility tool" : {
"localizations" : {
"it" : {
@@ -9989,6 +10053,22 @@
}
}
},
+ "Still starting…" : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Avvio ancora in corso…"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "仍在启动…"
+ }
+ }
+ }
+ },
"Stopping Steam" : {
"localizations" : {
"it" : {
@@ -10565,6 +10645,22 @@
}
}
},
+ "The first launch takes longer. The game may show a black screen for a while after it opens." : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Il primo avvio richiede più tempo. Una volta aperto, il gioco potrebbe mostrare una schermata nera per un po'."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "首次启动需要更长时间。游戏打开后可能会黑屏一段时间。"
+ }
+ }
+ }
+ },
"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." : {
"localizations" : {
"it" : {
@@ -11413,6 +11509,22 @@
}
}
},
+ "Waiting for the game to open…" : {
+ "localizations" : {
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "In attesa che il gioco si apra…"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "正在等待游戏打开…"
+ }
+ }
+ }
+ },
"Waiting for you to sign in to Steam. Bridgeplay doesn't read or store your password." : {
"localizations" : {
"it" : {
diff --git a/app/Sources/BridgeplayApp/Support/Launch.swift b/app/Sources/BridgeplayApp/Support/Launch.swift
index 9629bff..8abe650 100644
--- a/app/Sources/BridgeplayApp/Support/Launch.swift
+++ b/app/Sources/BridgeplayApp/Support/Launch.swift
@@ -5,6 +5,9 @@ enum Launch {
static func main() {
// A game launch is waiting on this one: post and leave before anything else runs.
if let parts = NotifyCommand.requested() { NotifyCommand.run(parts) }
+ if CommandLine.arguments.dropFirst().first == LaunchProgressCommand.flag {
+ LaunchProgressCommand.run(Array(CommandLine.arguments.dropFirst(2)))
+ }
let rebuilding = CommandLine.arguments.dropFirst().first == RebuildPrefixCommand.flag
// Out of the launching process group, so stopping the game in Steam cannot take
// the rebuild with it.
diff --git a/app/Sources/BridgeplayApp/Support/LaunchProgress.swift b/app/Sources/BridgeplayApp/Support/LaunchProgress.swift
new file mode 100644
index 0000000..0d3682a
--- /dev/null
+++ b/app/Sources/BridgeplayApp/Support/LaunchProgress.swift
@@ -0,0 +1,206 @@
+import AppKit
+
+// Between Play and the game's first window Steam only says Running, and a first launch spends
+// most of a minute building the prefix before Wine opens anything. The run script starts this
+// beside the launch, after any anti-cheat prompt, and writes the step it is on to
+// bridgeplay-launch-step. Nothing here can hold the launch up: the script never waits on it.
+enum LaunchProgressCommand {
+ // compat_run.sh looks for it in this binary before passing it, so it must stay over 15
+ // bytes: Swift keeps shorter strings inside the code, where the search cannot find them.
+ static let flag = "--launch-progress"
+ // Shared with compat_run.sh.
+ static let stepName = "bridgeplay-launch-step"
+
+ // <compatdata> <1 when the prefix is new> <the launcher's Wine log> <the run script's pid>.
+ // Never returns.
+ static func run(_ arguments: [String]) -> Never {
+ guard arguments.count == 4, arguments[0].hasPrefix("/"), arguments[2].hasPrefix("/"),
+ let launcher = pid_t(arguments[3])
+ else { exit(1) }
+ let compatdata = arguments[0]
+ // The run script started this, so any other parent means the launch has ended, even
+ // one that ended before this got here.
+ guard getppid() == launcher else { exit(0) }
+ MainActor.assumeIsolated {
+ NSApplication.shared.setActivationPolicy(.accessory)
+ let watcher = LaunchProgressWatcher(
+ compatdata: compatdata, progress: LaunchProgress(firstLaunch: arguments[1] == "1"),
+ launcher: launcher, wineLog: arguments[2])
+ let timer = Timer(timeInterval: 0.5, repeats: true) { _ in
+ MainActor.assumeIsolated { watcher.tick() }
+ }
+ RunLoop.main.add(timer, forMode: .common)
+ NSApp.run()
+ }
+ exit(0)
+ }
+}
+
+enum LaunchStep: String {
+ case setup, prepare, start
+ // A Bridgeplay alert is up, which the panel must not cover.
+ case dialog
+ case ended
+}
+
+struct LaunchProgress {
+ // A later launch that shows its window within this many seconds shows nothing. Hell Maiden
+ // took 12s from the run script to its window on an M4, its first launch 27 to 76s.
+ static let laterDelay: TimeInterval = 20
+ // Long enough that a launch failing straight away does not flash the panel.
+ static let firstDelay: TimeInterval = 1
+ // In case the game hangs before opening anything; Steam's Stop still ends it.
+ static let limit: TimeInterval = 15 * 60
+
+ let firstLaunch: Bool
+
+ enum Action: Equatable {
+ case hidden
+ case shown(LaunchStep?)
+ case quit
+ }
+
+ func action(step: LaunchStep?, elapsed: TimeInterval, launchEnded: Bool, gameWindow: Bool) -> Action {
+ if launchEnded || gameWindow || step == .ended || elapsed >= Self.limit { return .quit }
+ if step == .dialog || elapsed < (firstLaunch ? Self.firstDelay : Self.laterDelay) { return .hidden }
+ return .shown(step)
+ }
+
+ static func message(game name: String?) -> String {
+ name.map { String(localized: "Bridgeplay is starting \($0).") }
+ ?? String(localized: "Bridgeplay is starting this game.")
+ }
+
+ // Without a step the script is somewhere it does not report, so this says no more than that.
+ static func phase(_ step: LaunchStep?) -> String {
+ switch step {
+ case .setup: String(localized: "Setting up Windows for this game…")
+ case .prepare: String(localized: "Getting the game ready…")
+ case .start: String(localized: "Waiting for the game to open…")
+ default: String(localized: "Still starting…")
+ }
+ }
+
+ var note: String? {
+ firstLaunch
+ ? String(localized: "The first launch takes longer. The game may show a black screen for a while after it opens.")
+ : nil
+ }
+}
+
+@MainActor
+final class LaunchProgressWatcher {
+ private let compatdata: String
+ private let progress: LaunchProgress
+ private let launcher: pid_t
+ private let wineLog: String
+ private let started = ProcessInfo.processInfo.systemUptime
+ private lazy var name = Self.gameName(compatdata: compatdata)
+ private var panel: ProgressPanel?
+ // The step on screen, nil while hidden.
+ private var showing: LaunchStep??
+ // Whether each window owner is this game's, by pid and start time so a reused pid is
+ // looked at again. A process keeps the files it was started with.
+ private var owners: [pid_t: (started: UInt64, game: Bool)] = [:]
+
+ init(compatdata: String, progress: LaunchProgress, launcher: pid_t, wineLog: String) {
+ self.compatdata = compatdata
+ self.progress = progress
+ self.launcher = launcher
+ self.wineLog = wineLog
+ }
+
+ func tick() {
+ let text = try? String(contentsOfFile: compatdata + "/" + LaunchProgressCommand.stepName, encoding: .utf8)
+ let step = text.flatMap { LaunchStep(rawValue: $0.trimmingCharacters(in: .whitespacesAndNewlines)) }
+ let action = progress.action(
+ step: step, elapsed: ProcessInfo.processInfo.systemUptime - started,
+ launchEnded: getppid() != launcher, gameWindow: gameWindowShown())
+ switch action {
+ case .quit:
+ exit(0)
+ case .hidden:
+ guard showing != nil else { return }
+ panel?.panel.orderOut(nil)
+ showing = nil
+ case .shown(let step):
+ guard showing != .some(step) else { return }
+ let panel = panel ?? makePanel()
+ panel.show(message: LaunchProgress.message(game: name), phase: LaunchProgress.phase(step),
+ note: progress.note)
+ panel.present()
+ showing = .some(step)
+ }
+ }
+
+ private func makePanel() -> ProgressPanel {
+ let made = ProgressPanel(title: "Bridgeplay", activates: false)
+ // Closed by the player: the launch goes on without it.
+ NotificationCenter.default.addObserver(
+ forName: NSWindow.willCloseNotification, object: made.panel, queue: .main) { _ in exit(0) }
+ panel = made
+ return made
+ }
+
+ // Any window of this game's Wine, the game's own or an error Wine shows. Wine forks its
+ // processes away from the launcher, and macOS hides other processes' environments, but
+ // they all keep the launcher's log as stderr, and that log is this game's alone.
+ private func gameWindowShown() -> Bool {
+ var log = stat()
+ // The launcher creates it, so before the game starts there is nothing to find.
+ guard stat(wineLog, &log) == 0 else { return false }
+ let windows = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID)
+ as? [[String: Any]] ?? []
+ for window in windows {
+ guard (window[kCGWindowLayer as String] as? Int) == 0,
+ let pid = window[kCGWindowOwnerPID as String] as? pid_t, pid != getpid(),
+ let bounds = window[kCGWindowBounds as String] as? [String: Double],
+ (bounds["Width"] ?? 0) >= 32, (bounds["Height"] ?? 0) >= 32
+ else { continue }
+ let started = Self.startTime(of: pid)
+ let game: Bool
+ if let started, let known = owners[pid], known.started == started {
+ game = known.game
+ } else {
+ game = Self.holdsOpen(device: log.st_dev, inode: log.st_ino, pid: pid)
+ if let started { owners[pid] = (started, game) }
+ }
+ if game { return true }
+ }
+ return false
+ }
+
+ // Microseconds since 1970 at which the process started, nil when it cannot be read.
+ nonisolated static func startTime(of pid: pid_t) -> UInt64? {
+ var info = proc_bsdinfo()
+ let size = Int32(MemoryLayout<proc_bsdinfo>.size)
+ guard proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, &info, size) == size else { return nil }
+ return info.pbi_start_tvsec * 1_000_000 + info.pbi_start_tvusec
+ }
+
+ nonisolated static func holdsOpen(device: dev_t, inode: ino_t, pid: pid_t) -> Bool {
+ let stride = MemoryLayout<proc_fdinfo>.stride
+ let size = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, nil, 0)
+ guard size > 0 else { return false }
+ var fds = [proc_fdinfo](repeating: proc_fdinfo(), count: Int(size) / stride + 8)
+ let filled = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, &fds, Int32(fds.count * stride))
+ guard filled > 0 else { return false }
+ for fd in fds.prefix(Int(filled) / stride) where fd.proc_fdtype == PROX_FDTYPE_VNODE {
+ var info = vnode_fdinfowithpath()
+ let wanted = Int32(MemoryLayout<vnode_fdinfowithpath>.size)
+ guard proc_pidfdinfo(pid, fd.proc_fd, PROC_PIDFDVNODEPATHINFO, &info, wanted) == wanted else { continue }
+ let file = info.pvip.vip_vi.vi_stat
+ if file.vst_dev == device && file.vst_ino == inode { return true }
+ }
+ return false
+ }
+
+ nonisolated static func gameName(compatdata: String) -> String? {
+ let root = URL(filePath: compatdata)
+ let steamapps = root.deletingLastPathComponent().deletingLastPathComponent()
+ guard root.deletingLastPathComponent().lastPathComponent == "compatdata",
+ steamapps.lastPathComponent == "steamapps"
+ else { return nil }
+ return PrefixStore.appName(appID: root.lastPathComponent, in: SteamLibrary(root: steamapps.deletingLastPathComponent()))
+ }
+}
diff --git a/app/Sources/BridgeplayApp/Support/RebuildProgressWindow.swift b/app/Sources/BridgeplayApp/Support/RebuildProgressWindow.swift
index 5853cb6..e7b2727 100644
--- a/app/Sources/BridgeplayApp/Support/RebuildProgressWindow.swift
+++ b/app/Sources/BridgeplayApp/Support/RebuildProgressWindow.swift
@@ -13,7 +13,8 @@ enum RebuildProgressCommand {
MainActor.assumeIsolated {
let app = NSApplication.shared
app.setActivationPolicy(.accessory)
- let window = RebuildProgressWindow()
+ let window = ProgressPanel(title: String(localized: "Rebuilding the prefix"))
+ window.show(game: nil, phase: .settingUp)
DispatchQueue.main.async { MainActor.assumeIsolated { window.present() } }
Thread.detachNewThread {
var code: Int32 = 0
@@ -36,25 +37,36 @@ enum RebuildProgressCommand {
}
// Laid out like the alert that asked for the rebuild, so the one reads as following the other.
+// The launch progress uses it too, without activating, so the keyboard stays with Steam.
@MainActor
-final class RebuildProgressWindow {
+final class ProgressPanel {
private static let width: CGFloat = 440
private static let textWidth: CGFloat = width - 20 - 64 - 16 - 20
- private let panel: NSPanel
+ let panel: NSPanel
+ private let activates: Bool
+ private var placed = false
private let message = NSTextField(wrappingLabelWithString: "")
private let phase = NSTextField(labelWithString: "")
+ private let note = NSTextField(wrappingLabelWithString: "")
private let bar = NSProgressIndicator()
- init() {
+ init(title: String, activates: Bool = true) {
+ self.activates = activates
panel = NSPanel(contentRect: NSRect(x: 0, y: 0, width: Self.width, height: 120),
- styleMask: [.titled], backing: .buffered, defer: false)
- panel.title = String(localized: "Rebuilding the prefix")
+ styleMask: activates ? [.titled] : [.titled, .closable, .nonactivatingPanel],
+ backing: .buffered, defer: false)
+ panel.title = title
panel.level = .floating
panel.isReleasedWhenClosed = false
// macOS may refuse to activate a background helper while Steam is in front, and a
// panel that hides on deactivate then never shows.
panel.hidesOnDeactivate = false
+ if !activates {
+ panel.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]
+ panel.standardWindowButton(.miniaturizeButton)?.isHidden = true
+ panel.standardWindowButton(.zoomButton)?.isHidden = true
+ }
let icon = NSImageView(image: NSApp.applicationIconImage)
icon.imageScaling = .scaleProportionallyUpOrDown
@@ -66,15 +78,20 @@ final class RebuildProgressWindow {
message.cell?.truncatesLastVisibleLine = true
phase.font = .systemFont(ofSize: NSFont.smallSystemFontSize)
phase.textColor = .secondaryLabelColor
+ note.font = .systemFont(ofSize: NSFont.smallSystemFontSize)
+ note.textColor = .secondaryLabelColor
+ note.preferredMaxLayoutWidth = Self.textWidth
+ note.isHidden = true
bar.style = .bar
bar.isIndeterminate = true
bar.startAnimation(nil)
- let text = NSStackView(views: [message, bar, phase])
+ let text = NSStackView(views: [message, bar, phase, note])
text.orientation = .vertical
text.alignment = .leading
text.spacing = 8
text.setCustomSpacing(12, after: message)
+ text.detachesHiddenViews = true
let content = NSView()
for view in [icon, text] as [NSView] {
view.translatesAutoresizingMaskIntoConstraints = false
@@ -91,31 +108,47 @@ final class RebuildProgressWindow {
text.topAnchor.constraint(equalTo: content.topAnchor, constant: 20),
bar.widthAnchor.constraint(equalTo: text.widthAnchor),
message.widthAnchor.constraint(equalTo: text.widthAnchor),
+ note.widthAnchor.constraint(equalTo: text.widthAnchor),
content.bottomAnchor.constraint(greaterThanOrEqualTo: icon.bottomAnchor, constant: 20),
content.bottomAnchor.constraint(greaterThanOrEqualTo: text.bottomAnchor, constant: 20),
])
panel.contentView = content
- show(game: nil, phase: .settingUp)
- panel.center()
}
// Ordering the panel front before the application has finished launching leaves it
// off screen, so this waits for the run loop.
func present() {
+ if !placed {
+ // Top right, where notifications show, so a panel that does not activate stays clear
+ // of the dialogs Steam centers in its window, such as Exit game.
+ if activates {
+ panel.center()
+ } else if let area = (NSScreen.main ?? NSScreen.screens.first)?.visibleFrame {
+ panel.setFrameTopLeftPoint(NSPoint(x: area.maxX - panel.frame.width - 16, y: area.maxY - 16))
+ }
+ placed = true
+ }
panel.orderFrontRegardless()
- NSApp.activate()
+ if activates { NSApp.activate() }
+ }
+
+ func show(message text: String, phase current: String, note detail: String? = nil) {
+ message.stringValue = text
+ phase.stringValue = current
+ note.stringValue = detail ?? ""
+ note.isHidden = detail == nil
+ bar.setAccessibilityLabel(current)
+ panel.setContentSize(panel.contentView?.fittingSize ?? panel.frame.size)
}
func show(game name: String?, phase current: RebuildPhase) {
- message.stringValue = name.map {
- String(localized: "Bridgeplay is rebuilding the prefix for \($0).")
- } ?? String(localized: "Bridgeplay is rebuilding this game's prefix.")
- phase.stringValue = switch current {
+ let text = name.map { String(localized: "Bridgeplay is rebuilding the prefix for \($0).") }
+ ?? String(localized: "Bridgeplay is rebuilding this game's prefix.")
+ let step = switch current {
case .settingUp: String(localized: "Rebuilding…")
case .copying: String(localized: "Copying your files…")
case .finishing: String(localized: "Finishing…")
}
- bar.setAccessibilityLabel(phase.stringValue)
- panel.setContentSize(panel.contentView?.fittingSize ?? panel.frame.size)
+ show(message: text, phase: step)
}
}
diff --git a/app/Tests/BridgeplayAppTests/LaunchProgressTests.swift b/app/Tests/BridgeplayAppTests/LaunchProgressTests.swift
new file mode 100644
index 0000000..fab1aa4
--- /dev/null
+++ b/app/Tests/BridgeplayAppTests/LaunchProgressTests.swift
@@ -0,0 +1,122 @@
+import Foundation
+import Testing
+
+@testable import BridgeplayApp
+
+@Suite("The panel between Play and the game's first window")
+struct LaunchProgressTests {
+
+ private let first = LaunchProgress(firstLaunch: true)
+ private let later = LaunchProgress(firstLaunch: false)
+
+ @Test("A first launch shows almost at once, a later one only when it is slow")
+ func delays() {
+ #expect(first.action(step: .setup, elapsed: 0.5, launchEnded: false, gameWindow: false) == .hidden)
+ #expect(first.action(step: .setup, elapsed: 1, launchEnded: false, gameWindow: false) == .shown(.setup))
+ // Hell Maiden's relaunch opened its window 12s in, which must not flash a panel.
+ #expect(later.action(step: .start, elapsed: 12, launchEnded: false, gameWindow: false) == .hidden)
+ #expect(later.action(step: .start, elapsed: 20, launchEnded: false, gameWindow: false) == .shown(.start))
+ }
+
+ @Test("The game's window, the end of the launch or its end take the panel away")
+ func quits() {
+ #expect(first.action(step: .start, elapsed: 30, launchEnded: false, gameWindow: true) == .quit)
+ #expect(first.action(step: .setup, elapsed: 30, launchEnded: true, gameWindow: false) == .quit)
+ #expect(first.action(step: .ended, elapsed: 30, launchEnded: false, gameWindow: false) == .quit)
+ // Before its delay too, so a fast launch never shows it.
+ #expect(later.action(step: .start, elapsed: 3, launchEnded: false, gameWindow: true) == .quit)
+ #expect(later.action(step: .start, elapsed: LaunchProgress.limit, launchEnded: false, gameWindow: false) == .quit)
+ }
+
+ @Test("A Bridgeplay alert hides it until the next step")
+ func dialogs() {
+ #expect(first.action(step: .dialog, elapsed: 30, launchEnded: false, gameWindow: false) == .hidden)
+ #expect(first.action(step: .prepare, elapsed: 31, launchEnded: false, gameWindow: false) == .shown(.prepare))
+ }
+
+ @Test("An unknown step says only that the game is still starting")
+ func unknownStep() {
+ #expect(first.action(step: nil, elapsed: 5, launchEnded: false, gameWindow: false) == .shown(nil))
+ #expect(LaunchProgress.phase(nil) == "Still starting…")
+ #expect(LaunchProgress.phase(.setup) == "Setting up Windows for this game…")
+ #expect(LaunchProgress.message(game: "Hell Maiden") == "Bridgeplay is starting Hell Maiden.")
+ #expect(LaunchProgress.message(game: nil) == "Bridgeplay is starting this game.")
+ #expect(first.note != nil)
+ #expect(later.note == nil)
+ }
+
+ @Test("The steps are the words compat_run.sh writes")
+ func stepsMatchTheRunScript() throws {
+ let script = try String(
+ contentsOf: URL(filePath: #filePath).deletingLastPathComponent()
+ .appending(path: "../../../dylib/feats/compat_run.sh").standardizedFileURL, encoding: .utf8)
+ #expect(script.contains("/\(LaunchProgressCommand.stepName)\""))
+ #expect(script.contains(LaunchProgressCommand.flag))
+ for step in ["setup", "prepare", "start", "dialog", "ended"] {
+ #expect(LaunchStep(rawValue: step) != nil)
+ #expect(script.contains("launch_progress \(step)") || script.contains("launch_step \(step)"))
+ }
+ }
+
+ @Test("The game's processes are told by the launcher log they keep as stderr")
+ func findsTheLauncherLog() throws {
+ let dir = try scratchDirectory("launch-log")
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let log = dir.appending(path: "bridgeplay-wine.log")
+ let other = dir.appending(path: "other.log")
+ FileManager.default.createFile(atPath: log.path(percentEncoded: false), contents: nil)
+ FileManager.default.createFile(atPath: other.path(percentEncoded: false), contents: nil)
+ var file = stat()
+ #expect(stat(log.path(percentEncoded: false), &file) == 0)
+
+ func sleeper(writingTo url: URL) throws -> Process {
+ let child = Process()
+ child.executableURL = URL(filePath: "/bin/sleep")
+ child.arguments = ["5"]
+ child.standardError = try FileHandle(forWritingTo: url)
+ try child.run()
+ return child
+ }
+ let game = try sleeper(writingTo: log)
+ defer { game.terminate() }
+ let stranger = try sleeper(writingTo: other)
+ defer { stranger.terminate() }
+ #expect(LaunchProgressWatcher.holdsOpen(device: file.st_dev, inode: file.st_ino, pid: game.processIdentifier))
+ #expect(!LaunchProgressWatcher.holdsOpen(device: file.st_dev, inode: file.st_ino, pid: stranger.processIdentifier))
+ #expect(!LaunchProgressWatcher.holdsOpen(device: file.st_dev, inode: file.st_ino, pid: -1))
+ }
+
+ @Test("A process is known by its start time, so a reused pid is looked at again")
+ func startTimes() throws {
+ let own = LaunchProgressWatcher.startTime(of: getpid())
+ #expect(own != nil)
+ #expect(LaunchProgressWatcher.startTime(of: getpid()) == own)
+ #expect(LaunchProgressWatcher.startTime(of: -1) == nil)
+ let child = Process()
+ child.executableURL = URL(filePath: "/bin/sleep")
+ child.arguments = ["5"]
+ try child.run()
+ defer { child.terminate() }
+ #expect(LaunchProgressWatcher.startTime(of: child.processIdentifier) != own)
+ }
+
+ // The run script checks the app binary for the flag before passing it.
+ @Test("The flag is long enough to sit in the binary's strings")
+ func flagIsFindable() {
+ #expect(LaunchProgressCommand.flag.utf8.count > 15)
+ }
+
+ @Test("The game is named from its library's appmanifest")
+ func namesTheGame() throws {
+ let dir = try scratchDirectory("launch")
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let library = SteamLibrary(root: dir)
+ try FileManager.default.createDirectory(at: library.steamapps, withIntermediateDirectories: true)
+ try Data("\"AppState\"\n{\n\t\"appid\"\t\t\"3372060\"\n\t\"name\"\t\t\"Hell Maiden\"\n}\n".utf8)
+ .write(to: library.steamapps.appending(path: "appmanifest_3372060.acf"))
+ let compatdata = library.compatdata.path(percentEncoded: false)
+ #expect(LaunchProgressWatcher.gameName(compatdata: compatdata + "/3372060") == "Hell Maiden")
+ #expect(LaunchProgressWatcher.gameName(compatdata: compatdata + "/1") == nil)
+ #expect(LaunchProgressWatcher.gameName(compatdata: "/elsewhere/3372060") == nil)
+ }
+}
diff --git a/dylib/AGENTS.md b/dylib/AGENTS.md
index 12807a9..023c545 100644
--- a/dylib/AGENTS.md
+++ b/dylib/AGENTS.md
@@ -22,7 +22,8 @@ down for the user. The constructor in `core/loader.c` only does work in `steam_o
allow-list in `gamefix_reason`, a row in [docs/GAMEFIXES.md](../docs/GAMEFIXES.md), and
a passing `make gamefixescheck`.
- Checks for the run script: `runcheck`, `envcheck`, `settingscheck`, `routecheck`,
- `gamedrivecheck`, `prefixnotecheck`, `powernotecheck`, `exitcheck`, `launchercheck`, `gamefixescheck`.
+ `gamedrivecheck`, `prefixnotecheck`, `powernotecheck`, `exitcheck`, `launchprogresscheck`,
+ `launchercheck`, `gamefixescheck`.
- **Tests** live in `dylib/tests/`. They run without Steam or Dobby; several `#include` the
`.c` file under test for that reason. Add a new check as a Makefile target and to the
check list in `.github/workflows/app.yml`.
diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.sh
index 14e8eb1..fa369b0 100755
--- a/dylib/feats/compat_run.sh
+++ b/dylib/feats/compat_run.sh
@@ -1007,27 +1007,37 @@ running_name() {
# Steam passes "run" for helpers such as install scripts, which get no dialog.
show_alert() {
[ "$verb" != run ] || return 0
+ launch_step dialog
exec 8>&- 9>&-
osascript >/dev/null 2>&1 <<APPLESCRIPT || true
display alert "$1" message "$2" as critical
APPLESCRIPT
}
-# A game's first launch builds its prefix and then compiles its shaders into the Metal cache,
-# which can leave a black screen for minutes. Says so once, without holding up the launch.
-# First means no prefix yet, or neither our marker nor a Metal cache for the game's launcher
-# bundle (games from before the marker existed have the cache, so they stay quiet).
-first_launch_notice() {
+# Bridgeplay's panel says the launch is still going until the game shows a window or this
+# script ends, and what it is doing as launch_step writes it. It runs beside the launch and
+# only reads a file, so it never holds the launch up. Later launches show it only when slow
+# (LaunchProgress.swift). Without the app, a new prefix still gets the old notice.
+launch_progress() {
[ "$verb" = waitforexitandrun ] && [ "$app_id" != 0 ] || return 0
- marker="$STEAM_COMPAT_DATA_PATH/bridgeplay-first-launch"
- [ -e "$marker" ] && return 0
- : > "$marker" 2>/dev/null || true
- if [ -f "$STEAM_COMPAT_DATA_PATH/pfx/system.reg" ]; then
- metal_cache="$(getconf DARWIN_USER_CACHE_DIR 2>/dev/null)com.notproton.launcher.$app_id/com.apple.metal"
- [ -d "$metal_cache" ] && return 0
+ launch_step_file="$STEAM_COMPAT_DATA_PATH/bridgeplay-launch-step"
+ launch_step "$1"
+ progress_app=$(cat "$np_support/app-executable" 2>/dev/null) || progress_app=""
+ # An app from before the panel would open its main window for a flag it does not know.
+ if [ -x "$progress_app" ] && LC_ALL=C grep -q -a -F -- --launch-progress "$progress_app" 2>/dev/null; then
+ # A child of this script, so the panel can tell when the script is gone.
+ env -i HOME="$HOME" TMPDIR="${TMPDIR:-/tmp}" PATH=/usr/bin:/bin:/usr/sbin:/sbin \
+ "$progress_app" --launch-progress "$STEAM_COMPAT_DATA_PATH" "$prefix_was_new" \
+ "$np_support/launchers/$app_id/bridgeplay-wine.log" "$$" \
+ < /dev/null > /dev/null 2>&1 7>&- 8>&- 9>&- &
+ echo "launch: progress panel started (new prefix: $prefix_was_new)" >> "$log" 2>&1 || true
+ elif [ "$prefix_was_new" = 1 ]; then
+ notify_user "Getting this game ready" "The first launch sets the game up and prepares its graphics. It can take a few minutes, and the screen may stay black until it is ready."
fi
- echo "=== first launch, notice shown ===" >> "$log" 2>&1 || true
- notify_user "Getting this game ready" "The first launch sets the game up and prepares its graphics. It can take a few minutes, and the screen may stay black until it is ready."
+}
+
+launch_step() {
+ [ -z "${launch_step_file:-}" ] || printf '%s\n' "$1" > "$launch_step_file" 2>/dev/null || true
}
# Prints 1 when Low Power Mode is on, 0 when off, nothing when pmset does not say. pmset's
@@ -1083,6 +1093,7 @@ alert_safe() {
# The log path reaches AppleScript as an argument, so a quote in it cannot end a string.
show_rebuild_failure() {
[ "$verb" != run ] || return 0
+ launch_step dialog
exec 8>&- 9>&-
answer=$(osascript - "$log" <<'APPLESCRIPT'
on run argv
@@ -1203,6 +1214,7 @@ rebuild_prefix() {
show_rebuild_failure
exit 1
}
+ launch_step dialog
exec 8>&- 9>&-
# AppleScript run from a shell has no icon of its own, so caution comes badged with a folder.
icon=$(cat "$np_support/app-executable" 2>/dev/null) || icon=""
@@ -2370,7 +2382,7 @@ if [ -n "$STEAM_COMPAT_DATA_PATH" ]; then
echo "avx: ROSETTA_ADVERTISE_AVX=$ROSETTA_ADVERTISE_AVX from $avx_from" >> "$log" 2>&1 || true
fi
without_lock_fds "$WINESERVER" -k >> "$log" 2>&1 || true
- first_launch_notice
+ if [ "$prefix_was_new" = 1 ]; then launch_progress setup; else launch_progress prepare; fi
stage_step="prefix seed"
seed_prefix_from_template
stage_step="profile layout"
@@ -2392,6 +2404,7 @@ if [ -n "$STEAM_COMPAT_DATA_PATH" ]; then
refuse_broken_prefix
fi
low_power_notice
+launch_step prepare
stage_step="graphics backend"
select_backend "$1"
@@ -2909,6 +2922,7 @@ lsregister="$lsregister/Frameworks/LaunchServices.framework/Support/lsregister"
[ -x "$lsregister" ] && "$lsregister" -f "$loader_app" >> "$log" 2>&1 || true
np_started=$(date +%s)
np_terminated=0
+launch_step start
if [ "${NOTPROTON_LAUNCH_SERVICES:-0}" = "1" ]; then
open -n -W -a "$loader_app" "$@" >> "$log" 2>&1 &
else
@@ -2945,6 +2959,7 @@ open_pid=$!
/usr/bin/caffeinate -d -i -w "$open_pid" >> "$log" 2>&1 &
status=0
wait "$open_pid" || status=$?
+launch_step ended
np_ran=$(($(date +%s) - np_started))
echo "=== game exited status=$status, killing wine prefix ===" >> "$log" 2>&1 || true
kill_wine_prefix
diff --git a/dylib/tests/buildcheck.sh b/dylib/tests/buildcheck.sh
index e19f46f..4110991 100644
--- a/dylib/tests/buildcheck.sh
+++ b/dylib/tests/buildcheck.sh
@@ -98,6 +98,8 @@ CrossOver 26.3
echo "== alerts =="
alert=$(extract show_alert)
[ -n "$alert" ] || { echo "FAIL: show_alert not found in $SRC"; exit 1; }
+alert="$(extract launch_step)
+$alert"
data=$(mktemp -d "$work/compatdata.XXXXXX")
(
verb=waitforexitandrun
@@ -146,7 +148,8 @@ is "a tool name's own arch suffix is not repeated" 'rebuild: This game needs its
Do you want to rebuild the prefix for CrossOver Preview 2026 10 15‑ARM64, running through FEX? Your save games will be preserved and not lost.' "$(arch_case aarch64-unix 'CrossOver 2026 10 15-ARM64 - Rosetta')"
is "a matching architecture needs no rebuild" "" "$(arch_case x86_64-unix)"
-rebuild="$(extract run_rebuild)
+rebuild="$(extract launch_step)
+$(extract run_rebuild)
$(extract rebuild_prefix)"
mkdir -p "$work/app with spaces"
cat > "$work/app with spaces/NotProtonApp" <<'SH'
diff --git a/dylib/tests/launchprogresscheck.sh b/dylib/tests/launchprogresscheck.sh
new file mode 100644
index 0000000..d3fe7bf
--- /dev/null
+++ b/dylib/tests/launchprogresscheck.sh
@@ -0,0 +1,123 @@
+#!/bin/sh
+# launchprogresscheck: the panel between Play and the game's first window (launch_progress and
+# launch_step in compat_run.sh). It starts beside the launch without holding it up or taking
+# the prefix locks, only for a game launch, and only after the kernel anti-cheat prompt.
+# shellcheck disable=SC2016 # the sh -ec programs expand their own variables
+set -e
+SRC="${1:-$(dirname "$0")/../feats/compat_run.sh}"
+[ -f "$SRC" ] || { echo "launchprogresscheck: $SRC not present, skipped"; exit 0; }
+
+extract() { sed -n "/^$1() {\$/,/^}\$/p" "$SRC"; }
+functions=""
+for name in launch_progress launch_step; do
+ body=$(extract "$name")
+ [ -n "$body" ] || { echo "FAIL: $name not found in $SRC"; exit 1; }
+ functions="$functions
+$body"
+done
+
+work=$(mktemp -d) && work=$(cd "$work" && pwd -P) || exit 1
+trap 'rm -rf "$work"' EXIT
+
+fails=0
+ok() { printf ' ok %s\n' "$1"; }
+bad() { printf ' FAIL %s\n want [%s]\n got [%s]\n' "$1" "$2" "$3"; fails=$((fails + 1)); }
+is() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1" "$2" "$3"; fi; }
+
+support="$work/support"
+compat="$work/steamapps/compatdata/3372060"
+mkdir -p "$support" "$compat"
+# The app stand-in records its arguments, whether its parent is the pid it was given, and the
+# descriptors it was handed, then outlives the launch so a launch that waited on it would show.
+# Like the real app, it carries the flag in its file.
+app="$work/Bridgeplay.app/Contents/MacOS/BridgeplayApp"
+mkdir -p "$(dirname "$app")"
+cat > "$app" <<'APP'
+#!/bin/sh
+# knows --launch-progress
+out="$(dirname "$0")/started"
+printf '%s\n' "$@" > "$out.args"
+[ "$5" = "$PPID" ] && echo yes > "$out.parent"
+for fd in 7 8 9; do { true >&"$fd"; } 2>/dev/null && echo "$fd" >> "$out.fds"; done
+mv "$out.args" "$out"
+sleep 5
+APP
+chmod +x "$app"
+started="$(dirname "$app")/started"
+# An app from before the panel, which would open its main window for the flag.
+old_app="$work/Old.app/Contents/MacOS/BridgeplayApp"
+mkdir -p "$(dirname "$old_app")"
+sed 's/^# knows --launch-progress$/# an older app/; s|/started"|/old-started"|' "$app" > "$old_app"
+chmod +x "$old_app"
+
+# run VERB NEW [APP]: one launch up to the panel, with lock-like descriptors 8 and 9 open
+run() {
+ rm -f "$started" "$started.fds" "$started.parent" "$compat/bridgeplay-launch-step" "$work/notes"
+ if [ -n "${3:-}" ]; then printf '%s' "$3" > "$support/app-executable"; else rm -f "$support/app-executable"; fi
+ # The launch lives on after starting the panel, as the run script does while the game runs.
+ env verb="$1" prefix_was_new="$2" app_id=3372060 np_support="$support" log="$work/log" \
+ STEAM_COMPAT_DATA_PATH="$compat" notes="$work/notes" functions="$functions" work="$work" \
+ sh -ec 'eval "$functions"
+notify_user() { printf "%s\n" "$1" >> "$notes"; }
+exec 8>> "$notes.lock" 9>> "$notes.lock"
+before=$(date +%s)
+if [ "$prefix_was_new" = 1 ]; then launch_progress setup; else launch_progress prepare; fi
+launch_step start
+echo $(($(date +%s) - before)) > "$work/took"
+sleep 1'
+ took=$(cat "$work/took")
+}
+wait_started() { i=0; while [ ! -f "$started" ] && [ "$i" -lt 50 ]; do sleep 0.1; i=$((i + 1)); done; }
+
+echo "== starting it =="
+run waitforexitandrun 1 "$app"
+is "the launch does not wait for the panel" yes "$([ "$took" -le 1 ] && echo yes || echo no)"
+wait_started
+is "the app is asked for the panel with the prefix, new prefix and Wine log" \
+ "--launch-progress|$compat|1|$support/launchers/3372060/bridgeplay-wine.log" \
+ "$(sed -n 1,4p "$started" 2>/dev/null | paste -sd '|' -)"
+is "and with the pid of the script that started it, its parent" yes "$(cat "$started.parent" 2>/dev/null)"
+is "the prefix locks are not handed to it" "" "$(cat "$started.fds" 2>/dev/null)"
+is "the last step is in the step file" start "$(cat "$compat/bridgeplay-launch-step")"
+is "no notice when the panel shows" "" "$(cat "$work/notes" 2>/dev/null)"
+run waitforexitandrun 0 "$app"
+wait_started
+is "a known prefix is passed as not new" 0 "$(sed -n 3p "$started" 2>/dev/null)"
+
+echo "== without it =="
+run run 1 "$app"
+sleep 0.5
+is "Steam's helpers (verb run) get no panel" no "$([ -f "$started" ] && echo yes || echo no)"
+is "nor a step file" no "$([ -f "$compat/bridgeplay-launch-step" ] && echo yes || echo no)"
+run waitforexitandrun 1 ""
+is "no app: a new prefix gets the first-launch notice" "Getting this game ready" "$(cat "$work/notes" 2>/dev/null)"
+run waitforexitandrun 0 "$work/missing"
+is "no app: a known prefix gets nothing" "" "$(cat "$work/notes" 2>/dev/null)"
+run waitforexitandrun 1 "$old_app"
+sleep 0.5
+is "an app without the flag is not started" no "$([ -f "$work/Old.app/Contents/MacOS/old-started" ] && echo yes || echo no)"
+is "and a new prefix gets the notice instead" "Getting this game ready" "$(cat "$work/notes" 2>/dev/null)"
+out=$(env functions="$functions" sh -ec 'eval "$functions"; launch_step dialog; echo fine')
+is "a step before the panel started writes nothing" fine "$out"
+
+echo "== order =="
+# The anti-cheat prompt and the rebuild offer come first, and Bridgeplay's alerts hide the panel.
+at() { grep -n "$1" "$SRC" | head -1 | cut -d: -f1; }
+notice_at=$(at '^ kernel_anticheat_notice$')
+switch_at=$(at '^ offer_switch_rebuild$')
+panel_at=$(at 'launch_progress setup')
+if [ -n "$notice_at" ] && [ -n "$switch_at" ] && [ -n "$panel_at" ] \
+ && [ "$notice_at" -lt "$panel_at" ] && [ "$switch_at" -lt "$panel_at" ]; then
+ ok "the panel starts after the anti-cheat prompt and the rebuild offer"
+else
+ bad "the panel starts after the anti-cheat prompt and the rebuild offer" "$notice_at, $switch_at < panel" "${panel_at:-missing}"
+fi
+for name in show_alert show_rebuild_failure rebuild_prefix; do
+ case "$(extract "$name")" in
+ *"launch_step dialog"*) ok "$name hides the panel" ;;
+ *) bad "$name hides the panel" "launch_step dialog" "missing" ;;
+ esac
+done
+
+[ "$fails" -eq 0 ] || { echo "launchprogresscheck: $fails failed"; exit 1; }
+echo "==> launchprogresscheck: the launch panel starts beside the launch"