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): post the first-launch notice under Bridgeplay's own name and icon
raymondchins1f00c1b8d768
diff --git a/app/Sources/BridgeplayApp/Support/Launch.swift b/app/Sources/BridgeplayApp/Support/Launch.swiftindex 6c95840..61f43f3 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() {+ // A game launch is waiting on this one: post and leave before anything else runs.+ if let parts = NotifyCommand.requested() { NotifyCommand.run(parts) }// Before anything opens the support folder: the 3.0.0 move needs the old one intact.MainActor.assumeIsolated { MigrationLaunch.shared.runAtLaunch() }#if DEBUGdiff --git a/app/Sources/BridgeplayApp/Support/NotifyCommand.swift b/app/Sources/BridgeplayApp/Support/NotifyCommand.swiftnew file mode 100644index 0000000..1168460--- /dev/null+++ b/app/Sources/BridgeplayApp/Support/NotifyCommand.swift@@ -0,0 +1,36 @@+import Foundation+import UserNotifications++// Posts one notification under Bridgeplay's own name and icon, for the run script:+// `open -n -g -b com.bridgeplay.Bridgeplay --args --notify <title> <subtitle> <body>`.+// Runs before the migration and the log so a game launch never waits on either, and exits+// without opening a window. macOS asks once whether Bridgeplay may send notifications.+enum NotifyCommand {+ static let flag = "--notify"++ static func requested() -> [String]? {+ let arguments = CommandLine.arguments+ guard let index = arguments.firstIndex(of: flag) else { return nil }+ return Array(arguments[(index + 1)...])+ }++ static func run(_ parts: [String]) -> Never {+ Task.detached { exit(await post(parts) ? 0 : 1) }+ dispatchMain()+ }++ private static func post(_ parts: [String]) async -> Bool {+ let center = UNUserNotificationCenter.current()+ guard (try? await center.requestAuthorization(options: [.alert, .sound])) == true else { return false }+ let content = UNMutableNotificationContent()+ content.title = parts.first ?? "Bridgeplay"+ if parts.count > 2 {+ content.subtitle = parts[1]+ content.body = parts[2...].joined(separator: " ")+ } else if parts.count == 2 {+ content.body = parts[1]+ }+ let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)+ return (try? await center.add(request)) != nil+ }+}diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex 743c0b7..e7b542a 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -1024,9 +1024,14 @@ first_launch_notice() {[ -d "$metal_cache" ] && return 0fiecho "=== first launch, notice shown ===" >> "$log" 2>&1 || true+ # Posted by the Bridgeplay app, so it carries Bridgeplay's name and icon; osascript (shown+ # as Script Editor) only when the app cannot be found.(exec 8>&- 9>&-- osascript -e 'display notification "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." with title "Bridgeplay" subtitle "Getting this game ready"'+ title="Bridgeplay" subtitle="Getting this game ready"+ body="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."+ open -n -g -b com.bridgeplay.Bridgeplay --args --notify "$title" "$subtitle" "$body" ||+ osascript -e "display notification \"$body\" with title \"$title\" subtitle \"$subtitle\"") >/dev/null 2>&1 &}