Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.
Swift apple-silicond3dmetaldxmtdxvkfexgame-porting-toolkitgamingmac-gamingmacosmetalmoltenvksteamswiftuivkd3d-protonwhisky-alternativewindows-gameswinewine-wrapper
Play from outside the app: play links and Make a Mac app
Gauthier Piarrettec4d6c58fc038
diff --git a/Scripts/make-app.sh b/Scripts/make-app.shindex 0bdd55a..55c7998 100755--- a/Scripts/make-app.sh+++ b/Scripts/make-app.sh@@ -62,6 +62,11 @@ cat > "$APP/Contents/Info.plist" <<PLIST<key>SUPublicEDKey</key><string>${ED_PUBLIC_KEY}</string><key>SUEnableInstallerLauncherService</key><false/><key>NSHumanReadableCopyright</key><string>GPL-3.0 — no paid tier, ever.</string>+ <key>CFBundleURLTypes</key>+ <array><dict>+ <key>CFBundleURLName</key><string>Highball play link</string>+ <key>CFBundleURLSchemes</key><array><string>highball</string></array>+ </dict></array><key>NSMicrophoneUsageDescription</key><string>Windows games and apps running in a bottle need the microphone for voice chat and recording. macOS asks the first time one uses it.</string></dict></plist>PLISTdiff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex b8f2864..d5bf998 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -514,6 +514,33 @@ final class AppState {/// wineserver under the live session (issue #13's crash sequence), so it's refused instead.private var launchingPins: Set<UUID> = []+ // MARK: Play from outside the app (UX plan §3.9)++ /// A play request that arrived without this install's token: confirm before running.+ var pendingPlayLink: LibraryItem?++ func open(url: URL) {+ guard let request = PlayLink.parse(url) else { return }+ refresh()+ guard let item = libraryItems.first(where: { $0.id == request.target.libraryID }) else {+ fail(HighballError.failed("That game is not in this Highball's library."))+ return+ }+ if request.token == PlayLink.token(in: paths) { play(item) } else { pendingPlayLink = item }+ }++ /// Writes the game's Mac app into ~/Applications/Highball and reveals it.+ func makeMacApp(for item: LibraryItem) {+ guard let target = PlayLink.target(for: item) else { return }+ let url = PlayLink.url(for: target, token: PlayLink.token(in: paths))+ let cover = coverStore.coverURL(for: item.id) ?? item.artworkTall+ do {+ let app = try MacAppStub.write(title: item.title, libraryID: item.id, url: url, cover: cover)+ appendLog("made \(app.lastPathComponent) in ~/Applications/Highball")+ NSWorkspace.shared.activateFileViewerSelecting([app])+ } catch { fail(error) }+ }+// MARK: Sessions (UX plan 0.6)/// Games running right now, from their processes. The library shows them and offers Stop;diff --git a/Sources/HighballApp/GameDetailView.swift b/Sources/HighballApp/GameDetailView.swiftindex febae2d..ea83eb5 100644--- a/Sources/HighballApp/GameDetailView.swift+++ b/Sources/HighballApp/GameDetailView.swift@@ -122,6 +122,10 @@ struct GameDetailView: View {Button(L("Play")) { state.play(item) }.buttonStyle(.borderedProminent).disabled(state.busy || blocked)}+ if bottle != nil, PlayLink.target(for: item) != nil {+ Button { state.makeMacApp(for: item) } label: { Image(systemName: "macwindow.badge.plus") }+ .help(L("Make a Mac app for this game in ~/Applications/Highball: open it from the Dock, Spotlight or Launchpad to play without opening Highball first."))+ }if bottle != nil {Button { showBottleSettings = true } label: { Image(systemName: "gearshape") }Button { if let b = bottle { NSWorkspace.shared.open(b.driveC) } } label: {diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swiftindex 1956132..57495d6 100644--- a/Sources/HighballApp/HighballApp.swift+++ b/Sources/HighballApp/HighballApp.swift@@ -16,6 +16,12 @@ struct HighballApp: App {.preferredColorScheme(.dark).frame(minWidth: 820, minHeight: 560).onAppear { state.refresh(); state.sweepTrash(); delegate.appState = state }+ .onOpenURL { url in state.open(url: url) }+ .alert(String(format: L("Open %@ in Highball?"), state.pendingPlayLink?.title ?? ""),+ isPresented: Binding(get: { state.pendingPlayLink != nil }, set: { if !$0 { state.pendingPlayLink = nil } })) {+ Button(L("Play")) { if let item = state.pendingPlayLink { state.pendingPlayLink = nil; state.play(item) } }+ Button(L("Cancel"), role: .cancel) { state.pendingPlayLink = nil }+ } message: { Text(L("This link did not come from one of your Highball apps, so it asks first.")) }}.windowResizability(.contentSize).commands {diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swiftindex 45deb71..aec07e0 100644--- a/Sources/HighballApp/L10n.swift+++ b/Sources/HighballApp/L10n.swift@@ -178,6 +178,10 @@ enum L10n {"Details": "Détails","Run and add to Programs": "Lancer et ajouter aux programmes","Keep current": "Garder l’actuel",+ "Make a Mac app…": "Créer une app Mac…",+ "Open %@ in Highball?": "Ouvrir %@ dans Highball ?",+ "This link did not come from one of your Highball apps, so it asks first.": "Ce lien ne vient pas d'une de vos apps Highball, donc il demande d'abord.",+ "Make a Mac app for this game in ~/Applications/Highball: open it from the Dock, Spotlight or Launchpad to play without opening Highball first.": "Crée une app Mac pour ce jeu dans ~/Applications/Highball : ouvrez-la depuis le Dock, Spotlight ou Launchpad pour jouer sans ouvrir Highball.","Running": "En cours","Stop": "Arrêter","a cold Steam client can take a couple of minutes": "un client Steam à froid peut prendre quelques minutes",diff --git a/Sources/HighballApp/LibraryView.swift b/Sources/HighballApp/LibraryView.swiftindex cab3847..e202fe7 100644--- a/Sources/HighballApp/LibraryView.swift+++ b/Sources/HighballApp/LibraryView.swift@@ -221,6 +221,9 @@ struct LibraryTile: View {if let appid = item.steamAppID, let running = state.session(forAppID: appid) {Button(L("Stop")) { state.stopSession(running) }} else if playable { Button(L("Play")) { state.play(item) } }+ if playable, PlayLink.target(for: item) != nil {+ Button(L("Make a Mac app…")) { state.makeMacApp(for: item) }+ }Button(L("Choose cover image…")) { state.chooseCover(for: item) }if state.coverStore.coverURL(for: item.id) != nil {Button(L("Reset cover")) { state.resetCover(for: item) }diff --git a/Sources/HighballKit/MacAppStub.swift b/Sources/HighballKit/MacAppStub.swiftnew file mode 100644index 0000000..5a30df5--- /dev/null+++ b/Sources/HighballKit/MacAppStub.swift@@ -0,0 +1,88 @@+import Foundation++/// "Make a Mac app": a real, tiny app bundle in ~/Applications/Highball named after the game,+/// with its cover as the icon, whose only job is to open one play URL and exit. Locally created,+/// ad-hoc signed with the system's codesign, so it has a stable identity and no quarantine flag.+/// Nothing touches the Dock's preferences: the person drags it there like any app (UX plan §3.9).+public enum MacAppStub {+ public static func folder() -> URL {+ FileManager.default.homeDirectoryForCurrentUser.appending(path: "Applications/Highball", directoryHint: .isDirectory)+ }++ /// A file-system-safe app name from a title ("Portal 2" -> "Portal 2", "Half-Life: Alyx" -> "Half-Life Alyx").+ public static func appName(for title: String) -> String {+ let cleaned = title.replacingOccurrences(of: "[/:\\\\]", with: " ", options: .regularExpression)+ .replacingOccurrences(of: "\\s+", with: " ", options: .regularExpression)+ .trimmingCharacters(in: .whitespaces)+ return cleaned.isEmpty ? "Highball game" : String(cleaned.prefix(60))+ }++ public static func infoPlist(appName: String, bundleID: String) -> String {+ """+ <?xml version="1.0" encoding="UTF-8"?>+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+ <plist version="1.0"><dict>+ <key>CFBundleExecutable</key><string>launch</string>+ <key>CFBundleIdentifier</key><string>\(bundleID)</string>+ <key>CFBundleName</key><string>\(appName)</string>+ <key>CFBundleDisplayName</key><string>\(appName)</string>+ <key>CFBundlePackageType</key><string>APPL</string>+ <key>CFBundleShortVersionString</key><string>1.0</string>+ <key>CFBundleVersion</key><string>1</string>+ <key>CFBundleIconFile</key><string>icon</string>+ <key>LSMinimumSystemVersion</key><string>14.0</string>+ <key>LSUIElement</key><true/>+ </dict></plist>+ """+ }++ /// The launcher: opens the play URL and exits. `open` hands the URL to Highball whether it+ /// is running or not.+ public static func launchScript(url: URL) -> String {+ "#!/bin/sh\nexec /usr/bin/open \"\(url.absoluteString)\"\n"+ }++ public static func bundleID(for libraryID: String) -> String {+ let safe = libraryID.lowercased().replacingOccurrences(of: "[^a-z0-9]+", with: "-", options: .regularExpression)+ return "app.highball.stub.\(safe)"+ }++ /// Writes (or rewrites) the bundle and returns its location. `cover` is any image file; it+ /// becomes the icon when sips and iconutil can convert it, and the stub still works without.+ @discardableResult+ public static func write(title: String, libraryID: String, url: URL, cover: URL?) throws -> URL {+ let fm = FileManager.default+ let name = appName(for: title)+ let app = folder().appending(path: "\(name).app", directoryHint: .isDirectory)+ let contents = app.appending(path: "Contents", directoryHint: .isDirectory)+ try? fm.removeItem(at: app)+ try fm.createDirectory(at: contents.appending(path: "MacOS"), withIntermediateDirectories: true)+ try fm.createDirectory(at: contents.appending(path: "Resources"), withIntermediateDirectories: true)+ try infoPlist(appName: name, bundleID: bundleID(for: libraryID)).write(to: contents.appending(path: "Info.plist"), atomically: true, encoding: .utf8)+ let script = contents.appending(path: "MacOS/launch")+ try launchScript(url: url).write(to: script, atomically: true, encoding: .utf8)+ try fm.setAttributes([.posixPermissions: 0o755], ofItemAtPath: script.path)+ if let cover { try? makeIcon(from: cover, to: contents.appending(path: "Resources/icon.icns")) }+ // Ad-hoc signature: a stable identity for macOS, no certificate needed for a local file.+ _ = try? Shell.run("/usr/bin/codesign", ["--force", "--sign", "-", app.path])+ return app+ }++ /// Cover to .icns through the system's own tools; a square crop at 512 and the standard set.+ static func makeIcon(from cover: URL, to icns: URL) throws {+ let work = FileManager.default.temporaryDirectory.appending(path: "hb-icon-\(UUID().uuidString)")+ let iconset = work.appending(path: "icon.iconset", directoryHint: .isDirectory)+ try FileManager.default.createDirectory(at: iconset, withIntermediateDirectories: true)+ defer { try? FileManager.default.removeItem(at: work) }+ let base = work.appending(path: "base.png")+ try Shell.run("/usr/bin/sips", ["-s", "format", "png", "-Z", "1024", cover.path, "--out", base.path])+ // Square it: sips crops from the center when both dimensions are given.+ try Shell.run("/usr/bin/sips", ["-c", "1024", "1024", base.path, "--out", base.path])+ for (size, name) in [(16, "icon_16x16"), (32, "icon_16x16@2x"), (32, "icon_32x32"), (64, "icon_32x32@2x"),+ (128, "icon_128x128"), (256, "icon_128x128@2x"), (256, "icon_256x256"), (512, "icon_256x256@2x"),+ (512, "icon_512x512"), (1024, "icon_512x512@2x")] {+ try Shell.run("/usr/bin/sips", ["-z", String(size), String(size), base.path, "--out", iconset.appending(path: "\(name).png").path])+ }+ try Shell.run("/usr/bin/iconutil", ["-c", "icns", iconset.path, "-o", icns.path])+ }+}diff --git a/Sources/HighballKit/PlayLink.swift b/Sources/HighballKit/PlayLink.swiftnew file mode 100644index 0000000..8019118--- /dev/null+++ b/Sources/HighballKit/PlayLink.swift@@ -0,0 +1,80 @@+import Foundation++/// Play from outside the app (UX plan §3.9): a `highball://play/...` URL that names something+/// already in the library by a typed id, never a path or an argument list, and carries a+/// per-install token so a web page opening the scheme gets a confirmation instead of a launch.+public enum PlayLink {+ public static let scheme = "highball"++ public enum Target: Equatable, Sendable {+ case steam(appid: Int)+ case epic(appName: String)+ case pin(bottle: String, id: UUID)++ /// The library item id this target maps to ("steam:620", "epic:Duck", "pin:Gaming:<uuid>").+ public var libraryID: String {+ switch self {+ case let .steam(appid): return "steam:\(appid)"+ case let .epic(name): return "epic:\(name)"+ case let .pin(bottle, id): return "pin:\(bottle):\(id.uuidString)"+ }+ }+ }++ public struct Request: Equatable, Sendable {+ public let target: Target+ public let token: String?+ }++ /// Parses `highball://play/steam/620?t=<token>`, `highball://play/epic/<name>?t=...`,+ /// `highball://play/pin/<bottle>/<uuid>?t=...`. Anything else is nil: no other action+ /// exists behind the scheme.+ public static func parse(_ url: URL) -> Request? {+ guard url.scheme?.lowercased() == scheme, url.host?.lowercased() == "play" else { return nil }+ let parts = url.pathComponents.filter { $0 != "/" }+ let token = URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems?.first { $0.name == "t" }?.value+ switch parts.first {+ case "steam":+ guard parts.count == 2, let appid = Int(parts[1]), appid > 0 else { return nil }+ return Request(target: .steam(appid: appid), token: token)+ case "epic":+ guard parts.count == 2, !parts[1].isEmpty else { return nil }+ return Request(target: .epic(appName: parts[1]), token: token)+ case "pin":+ guard parts.count == 3, !parts[1].isEmpty, let id = UUID(uuidString: parts[2]) else { return nil }+ return Request(target: .pin(bottle: parts[1], id: id), token: token)+ default:+ return nil+ }+ }++ public static func url(for target: Target, token: String) -> URL {+ var c = URLComponents()+ c.scheme = scheme; c.host = "play"+ switch target {+ case let .steam(appid): c.path = "/steam/\(appid)"+ case let .epic(name): c.path = "/epic/\(name)"+ case let .pin(bottle, id): c.path = "/pin/\(bottle)/\(id.uuidString)"+ }+ c.queryItems = [URLQueryItem(name: "t", value: token)]+ return c.url!+ }++ public static func target(for item: LibraryItem) -> Target? {+ if let appid = item.steamAppID { return .steam(appid: appid) }+ if let name = item.epicAppName { return .epic(appName: name) }+ if let id = item.pinID, let bottle = item.bottleName { return .pin(bottle: bottle, id: id) }+ return nil+ }++ /// The per-install token, created on first use in Highball's data folder. Stubs embed it;+ /// a request without it, or with another install's, gets a confirmation.+ public static func token(in paths: HighballPaths) -> String {+ let file = paths.home.appending(path: "launch-token")+ if let t = try? String(contentsOf: file, encoding: .utf8).trimmingCharacters(in: .whitespacesAndNewlines), !t.isEmpty { return t }+ let fresh = UUID().uuidString.replacingOccurrences(of: "-", with: "").lowercased()+ try? paths.ensure()+ try? fresh.write(to: file, atomically: true, encoding: .utf8)+ return fresh+ }+}diff --git a/Tests/HighballKitTests/RegressionTests.swift b/Tests/HighballKitTests/RegressionTests.swiftindex 1cbf499..7cf0f45 100644--- a/Tests/HighballKitTests/RegressionTests.swift+++ b/Tests/HighballKitTests/RegressionTests.swift@@ -1057,6 +1057,28 @@ extension RegressionTests {XCTAssertEqual(r.seconds, 754)}+ // Play links accept typed ids only and round-trip; the stub's files are plain and predictable.+ func testPlayLinkParsingAndStubFiles() throws {+ let u = PlayLink.url(for: .steam(appid: 620), token: "abc")+ XCTAssertEqual(u.absoluteString, "highball://play/steam/620?t=abc")+ XCTAssertEqual(PlayLink.parse(u), PlayLink.Request(target: .steam(appid: 620), token: "abc"))+ let pinID = UUID()+ let p = PlayLink.url(for: .pin(bottle: "Gaming", id: pinID), token: "abc")+ XCTAssertEqual(PlayLink.parse(p)?.target, .pin(bottle: "Gaming", id: pinID))+ XCTAssertEqual(PlayLink.parse(PlayLink.url(for: .epic(appName: "Duck"), token: "x"))?.target.libraryID, "epic:Duck")+ XCTAssertNil(PlayLink.parse(URL(string: "highball://play/steam/notanumber")!))+ XCTAssertNil(PlayLink.parse(URL(string: "highball://play/exe/C:/x.exe")!), "no paths, ever")+ XCTAssertNil(PlayLink.parse(URL(string: "highball://install/steam/620")!), "only play exists")+ XCTAssertNil(PlayLink.parse(URL(string: "http://play/steam/620")!))+ XCTAssertEqual(PlayLink.parse(URL(string: "highball://play/steam/620")!)?.token, nil, "no token: the app confirms")++ XCTAssertEqual(MacAppStub.appName(for: "Half-Life: Alyx"), "Half-Life Alyx")+ XCTAssertEqual(MacAppStub.appName(for: " "), "Highball game")+ XCTAssertEqual(MacAppStub.bundleID(for: "steam:620"), "app.highball.stub.steam-620")+ XCTAssertTrue(MacAppStub.launchScript(url: u).contains("/usr/bin/open \"highball://play/steam/620?t=abc\""))+ XCTAssertTrue(MacAppStub.infoPlist(appName: "Portal 2", bundleID: "x").contains("<key>LSUIElement</key><true/>"), "no Dock icon of its own, no window")+ }+func testDefaultEnginePrefersBundledManifestID() throws {func engine(_ id: String) throws -> InstalledEngine {let json = #"{"id":"\#(id)","displayName":"e","arch":"x86_64","minMacOS":"14.0","components":{}}"#