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
Open steam:// URLs with Steam for Mac itself
Kevindb0911b96e04
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex 3a3d328..e87ead8 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -250,24 +250,34 @@ final class AppState {/// What Steam for Mac has installed (MacSteam), refreshed with the bottles' own installs.var macSteamGames: [SteamGame] = []- /// Steam for Mac is there to take steam:// URLs.- var steamForMacInstalled: Bool {- NSWorkspace.shared.urlForApplication(toOpen: URL(string: "steam://run/0")!) != nil+ /// Steam for Mac, when it is one of the apps registered for steam:// (MacSteam.app).+ var steamForMacApp: URL? {+ MacSteam.app(among: NSWorkspace.shared.urlsForApplications(toOpen: URL(string: "steam://run/0")!))+ }++ var steamForMacInstalled: Bool { steamForMacApp != nil }++ /// Opens a steam:// URL with Steam for Mac itself, never the scheme's default handler.+ private func openInSteamForMac(_ url: URL) -> Bool {+ guard let app = steamForMacApp else { return false }+ NSWorkspace.shared.open([url], withApplicationAt: app, configuration: NSWorkspace.OpenConfiguration())+ return true}/// Starts the native build through Steam for Mac.func playOnMac(_ item: LibraryItem) {guard let appid = item.steamAppID else { return }recordPlay(item)- NSWorkspace.shared.open(URL(string: "steam://run/\(appid)")!)+ _ = openInSteamForMac(URL(string: "steam://run/\(appid)")!)}/// Hands the game to Steam for Mac, whose own dialog asks where to put it; without it, the/// download page for Steam for Mac.func installOnMac(_ item: LibraryItem) {guard let appid = item.steamAppID else { return }- NSWorkspace.shared.open(steamForMacInstalled ? URL(string: "steam://install/\(appid)")!- : URL(string: "https://store.steampowered.com/about/")!)+ if !openInSteamForMac(URL(string: "steam://install/\(appid)")!) {+ NSWorkspace.shared.open(URL(string: "https://store.steampowered.com/about/")!)+ }}/// Store `platforms.mac` per appid (MacFlagStore), for Steam games whose appinfo lists macOS.diff --git a/Sources/HighballKit/MacSteam.swift b/Sources/HighballKit/MacSteam.swiftindex 5bea79f..0875f33 100644--- a/Sources/HighballKit/MacSteam.swift+++ b/Sources/HighballKit/MacSteam.swift@@ -5,9 +5,19 @@ import Foundation/// `libraryfolders.vdf` (an external drive, say). Read only.////// A game installed there is played through Steam for Mac with `steam://run/<appid>`, and one-/// that isn't is handed to it with `steam://install/<appid>`: bottles run with winemenubuilder-/// disabled, so Wine's Steam registers no macOS URL handler and steam:// reaches the Mac app.+/// that isn't is handed to it with `steam://install/<appid>`, both opened with the Steam for Mac+/// app itself rather than whatever handles the scheme.public enum MacSteam {+ public static let bundleID = "com.valvesoftware.steam"++ /// Steam for Mac among the apps that open steam:// URLs, or nil when only something else+ /// does: environments made before winemenubuilder was switched off can still have a+ /// Wine-made Steam wrapper in ~/Applications/Wine registered for the scheme.+ public static func app(among handlers: [URL],+ bundleID: (URL) -> String? = { Bundle(url: $0)?.bundleIdentifier }) -> URL? {+ handlers.first { bundleID($0) == Self.bundleID }+ }+public static var root: URL {FileManager.default.homeDirectoryForCurrentUser.appending(path: "Library/Application Support/Steam")}diff --git a/Tests/HighballKitTests/MacSteamBuildTests.swift b/Tests/HighballKitTests/MacSteamBuildTests.swiftindex b3676b7..2188d3c 100644--- a/Tests/HighballKitTests/MacSteamBuildTests.swift+++ b/Tests/HighballKitTests/MacSteamBuildTests.swift@@ -64,6 +64,17 @@ final class MacSteamBuildTests: XCTestCase {XCTAssertEqual(MacSteam.installedGames(root: nowhere), [])}+ func testOnlyValvesAppCountsAsSteamForMac() {+ let wrapper = URL(fileURLWithPath: "/Users/me/Applications/Wine/Steam.app")+ let steam = URL(fileURLWithPath: "/Applications/Steam.app")+ let ids = [wrapper: "com.wine.wine.steam", steam: "com.valvesoftware.steam"]+ XCTAssertEqual(MacSteam.app(among: [wrapper, steam], bundleID: { ids[$0] }), steam,+ "a Wine wrapper ahead of it doesn't hide Steam for Mac")+ XCTAssertNil(MacSteam.app(among: [wrapper], bundleID: { ids[$0] }),+ "a Wine wrapper alone isn't Steam for Mac")+ XCTAssertNil(MacSteam.app(among: []))+ }+func testRowCanRetireAPortTheStoreStillLists() throws {let retired = try entry(#"{"id":"x","title":"X","steam_appid":1,"status":"community","nativeMac":{"available":false,"note":"32-bit, stopped running with Catalina"}}"#)XCTAssertNil(MacSteamBuild.resolve(entry: retired, storeMac: true))