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
Mac relaunch: an outside launch is taken over only when Highball adds something
Gabe000f91566eea
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex a36013d..0588f80 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -3661,8 +3661,8 @@ final class AppState {}/// 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.+ /// the tests cover): what Highball knows of the game and the app, whether it can start the+ /// game again right now, and whether its start adds anything.private func relaunchShouldTakeOver(_ app: NSRunningApplication, item: LibraryItem) -> Bool {let canStart: Boolswitch item.source {@@ -3673,7 +3673,19 @@ final class AppState {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)+ busy: busy, canStart: canStart, highballAdds: highballAddsToMacLaunch(item))+ }++ /// What Highball's start brings that a launch from outside lacks: comet or the save sync for+ /// a GOG game, when signed in and not turned off for it; Epic's sign-in for an Epic one.+ private func highballAddsToMacLaunch(_ item: LibraryItem) -> Bool {+ switch item.source {+ case .gog:+ guard gogSignedIn, let id = item.gogID else { return false }+ return gogSettings.cometOff[id] == nil || !gogSettings.cloudSavesOff.contains(id)+ case .epic: return epicSignedIn+ default: return false+ }}/// Removes an Epic game's Mac build through legendary, so its library stays right.diff --git a/Sources/HighballKit/MacRelaunch.swift b/Sources/HighballKit/MacRelaunch.swiftindex 572e47b..b18c8c2 100644--- a/Sources/HighballKit/MacRelaunch.swift+++ b/Sources/HighballKit/MacRelaunch.swift@@ -17,13 +17,17 @@ public enum MacRelaunch {/// within `takenOverWindow` of closing it already. Only an app that is still running and/// opened within `freshLaunchWindow`, and only when Highball can start the game again right/// now: a busy Highball (a download holding the strip) would close it and start nothing.+ /// And only when Highball's start adds something the outside launch lacks (`highballAdds`:+ /// comet or the save sync for a GOG game, Epic's sign-in for an Epic one): without it,+ /// closing the game would only cost the player a restart.public static func shouldTakeOver(now: Date, gameRunning: Bool, startedAt: Date?, takenOverAt: Date?,- appLaunchedAt: Date?, appTerminated: Bool, busy: Bool, canStart: Bool) -> Bool {+ appLaunchedAt: Date?, appTerminated: Bool, busy: Bool, canStart: Bool,+ highballAdds: Bool) -> Bool {if gameRunning { return false }if let startedAt, now.timeIntervalSince(startedAt) < ownLaunchWindow { return false }if let takenOverAt, now.timeIntervalSince(takenOverAt) < takenOverWindow { return false }guard !appTerminated, let appLaunchedAt, now.timeIntervalSince(appLaunchedAt) < freshLaunchWindow, !busy else { return false }- return canStart+ return canStart && highballAdds}/// Whether an app at `bundle` is from a game's `folder`: the folder itself (a GOG build'sdiff --git a/Tests/HighballKitTests/MacRelaunchTests.swift b/Tests/HighballKitTests/MacRelaunchTests.swiftindex 659a524..db18318 100644--- a/Tests/HighballKitTests/MacRelaunchTests.swift+++ b/Tests/HighballKitTests/MacRelaunchTests.swift@@ -7,12 +7,12 @@ final class MacRelaunchTests: XCTestCase {private func takesOver(gameRunning: Bool = false, startedAgo: TimeInterval? = nil, takenOverAgo: TimeInterval? = nil,appLaunchedAgo: TimeInterval? = 2, appTerminated: Bool = false, busy: Bool = false,- canStart: Bool = true) -> Bool {+ canStart: Bool = true, highballAdds: Bool = true) -> Bool {MacRelaunch.shouldTakeOver(now: now, gameRunning: gameRunning,startedAt: startedAgo.map { now.addingTimeInterval(-$0) },takenOverAt: takenOverAgo.map { now.addingTimeInterval(-$0) },appLaunchedAt: appLaunchedAgo.map { now.addingTimeInterval(-$0) },- appTerminated: appTerminated, busy: busy, canStart: canStart)+ appTerminated: appTerminated, busy: busy, canStart: canStart, highballAdds: highballAdds)}func testAFreshOutsideLaunchHighballCanStartIsTakenOver() {@@ -51,6 +51,13 @@ final class MacRelaunchTests: XCTestCase {XCTAssertFalse(takesOver(canStart: false))}+ /// Signed out, or comet and the save sync both off for the game: Highball's start adds+ /// nothing, so the game is left as the player opened it.+ func testAGameHighballAddsNothingToIsLeftAlone() {+ XCTAssertFalse(takesOver(highballAdds: false))+ XCTAssertFalse(takesOver(startedAgo: 600, takenOverAgo: 600, highballAdds: false))+ }+func testAnAppIsFromAGamesFolderOnlyWhenItIsTheFolderOrInsideIt() {XCTAssertTrue(MacRelaunch.opens(bundle: "/Applications/Foo.app", from: "/Applications/Foo.app"))XCTAssertTrue(MacRelaunch.opens(bundle: "/Games/Garlic/Garlic.app", from: "/Games/Garlic"))