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
Merge branch 'feat/epic-mac' into feat/mac-relaunch
Gabe63c52336922c
diff --cc Sources/HighballApp/AppState.swiftindex 9016dac,006db9f..a36013d--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@@ -3573,81 -3602,9 +3604,81 @@@ final class AppStateprivate func epicMacGameEnded(_ item: LibraryItem) { macGameProcesses[item.id] = nil }+ // MARK: Mac games opened outside Highball++ static let relaunchDefaultsKey = "openMacGamesThroughHighball"+ /// Off unless turned on in Settings: closing an app the player opened is a surprise otherwise.+ static var relaunchEnabled: Bool { UserDefaults.standard.bool(forKey: relaunchDefaultsKey) }+ @ObservationIgnored private var macLaunchObserver: NSObjectProtocol?+ @ObservationIgnored private var relaunching: Set<String> = []+ /// When Highball last started each Mac game, and last closed one to start it again: a launch+ /// near either is Highball's own (a game whose app hands over to another process) and is left+ /// alone, so the watcher can never loop.+ @ObservationIgnored private var macLaunchedAt: [String: Date] = [:]+ @ObservationIgnored private var macRelaunchedAt: [String: Date] = [:]++ /// A GOG or Epic Mac game opened from Applications, the Dock or Spotlight starts without+ /// what Highball brings (comet, which a game looks for only at startup, the save sync and its+ /// backups, Epic's sign-in). With the setting on, such a launch is closed within its first+ /// seconds and started again through Highball. Never one Highball started, and never one+ /// running for longer than a few seconds.+ private func startMacLaunchWatch() {+ guard macLaunchObserver == nil else { return }+ macLaunchObserver = NSWorkspace.shared.notificationCenter.addObserver(+ forName: NSWorkspace.didLaunchApplicationNotification, object: nil, queue: .main) { [weak self] note in+ guard let app = note.userInfo?[NSWorkspace.applicationUserInfoKey] as? NSRunningApplication else { return }+ MainActor.assumeIsolated { self?.macAppLaunched(app) }+ }+ }++ private func macAppLaunched(_ app: NSRunningApplication) {+ guard Self.relaunchEnabled, let bundle = app.bundleURL?.standardizedFileURL.path else { return }+ guard let item = libraryItems.first(where: { item in+ guard (item.source == .gog || item.source == .epic), let folder = macFolder(for: item)?.standardizedFileURL.path else { return false }+ return MacRelaunch.opens(bundle: bundle, from: folder)+ }), !relaunching.contains(item.id) else { return }+ relaunching.insert(item.id)+ // A moment for Highball's own launch to be recorded (Epic's is, once legendary answers).+ DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in+ guard let self else { return }+ defer { self.relaunching.remove(item.id) }+ guard self.relaunchShouldTakeOver(app, item: item) else { return }+ self.macRelaunchedAt[item.id] = Date()+ self.appendLog("\(item.title) was opened outside Highball; starting it again through Highball")+ app.terminate()+ Task { [weak self] in+ try? await Task.sleep(for: .seconds(1.5))+ if !app.isTerminated { app.forceTerminate() }+ try? await Task.sleep(for: .seconds(0.5))+ // A task can take the strip in these seconds, and Play then starts nothing: the+ // game was closed, so it waits for the strip, up to a minute, then says so.+ for _ in 0..<60 where self?.busy == true { try? await Task.sleep(for: .seconds(1)) }+ guard let self else { return }+ if busy { appendLog("\(item.title) was closed to start through Highball, but Highball stayed busy; press Play"); return }+ playOnMac(item)+ }+ }+ }++ /// Whether to close a game just opened outside Highball (MacRelaunch.shouldTakeOver, which+ /// the tests cover): what Highball knows of the game and the app, and whether it can start+ /// the game again right now.+ private func relaunchShouldTakeOver(_ app: NSRunningApplication, item: LibraryItem) -> Bool {+ let canStart: Bool+ switch item.source {+ case .gog: canStart = item.gogID.flatMap { gogMacInstalled[$0]?.app } != nil+ case .epic: canStart = item.epicAppName.flatMap { epicMacInstalls[$0] } != nil+ default: canStart = false+ }+ return MacRelaunch.shouldTakeOver(now: Date(), gameRunning: macGameProcesses[item.id] != nil,+ startedAt: macLaunchedAt[item.id], takenOverAt: macRelaunchedAt[item.id],+ appLaunchedAt: app.launchDate, appTerminated: app.isTerminated,+ busy: busy, canStart: canStart)+ }+/// Removes an Epic game's Mac build through legendary, so its library stays right.func epicUninstallMac(_ item: LibraryItem) {- guard let app = item.epicAppName else { return }+ guard let app = item.epicAppName, refuseWhileRunning(item) else { return }runBusy(String(format: L("Removing the Mac version of %@"), item.title), expected: nil) { [self] intry await legendaryUninstall(app)await MainActor.run { self.epicRefresh() }diff --cc Sources/HighballApp/L10n.swiftindex c9248ac,af1d2d1..b415f3a--- a/Sources/HighballApp/L10n.swift+++ b/Sources/HighballApp/L10n.swift@@@ -435,11 -435,8 +435,11 @@@ enum L10n"Switch to the Windows version…": "Passer à la version Windows…","Switch to the Windows version": "Passer à la version Windows","Switch %@ to the Windows version?": "Passer %@ à la version Windows ?",- "Epic keeps one version of a game installed at a time, so the Mac version is removed first, then the Windows version downloads into your environment.":- "Epic n’installe qu’une version d’un jeu à la fois : la version Mac est d’abord supprimée, puis la version Windows est téléchargée dans votre environnement.",+ "Epic keeps one version of a game installed at a time, so the Windows version downloads into your environment and the Mac version is removed once it is in. Stop the download, or should it fail, and the Mac version stays.":+ "Epic n’installe qu’une version d’un jeu à la fois : la version Windows est téléchargée dans votre environnement, puis la version Mac est supprimée une fois la nouvelle en place. Si vous arrêtez le téléchargement, ou s’il échoue, la version Mac reste.",+ "A Mac game opened from Applications, the Dock or Spotlight is closed within its first seconds and started again through Highball, which brings GOG's achievements and cloud saves and Epic's sign-in. Only while Highball is open, and never while it is busy with another task.":+ "Un jeu Mac ouvert depuis Applications, le Dock ou Spotlight est fermé dans ses premières secondes et relancé avec Highball, qui apporte les succès et sauvegardes en ligne de GOG et la connexion d’Epic. Seulement quand Highball est ouvert, et jamais pendant une autre tâche.",+ "Open GOG and Epic Mac games through Highball": "Ouvrir les jeux Mac GOG et Epic avec Highball","Highball could not find the Mac version of %@ to open.": "Highball ne trouve pas la version Mac de %@ à ouvrir.","The Mac version of %@ did not start: %@": "La version Mac de %@ n’a pas démarré : %@","Removing the Windows version of %@": "Suppression de la version Windows de %@",