Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

Merge main into feat/game-sizes

Gabedb63307d1978
diff --cc Sources/HighballApp/AppState.swift
index a881cf8,9bb8e5f..20948f5
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@@ -304,9 -307,122 +307,123 @@@ final class AppState
sortLibraryByDisplayTitle()
if let deferred = deferredPlayLink { resolvePlayLink(deferred.request) }
refreshMacFlags()
+ if sizePrefetch == nil, libraryItems.contains(where: { $0.source == .gog || $0.source == .epic }) { prefetchDownloadSizes() }
}
+ // MARK: Whose Steam games
+
+ /// The accounts that have signed in to each environment's Steam, newest sign-in first.
+ var steamAccountsByBottle: [String: [SteamAccount]] = [:] {
+ didSet { steamAccountIDsByBottle = steamAccountsByBottle.mapValues { Set($0.map(\.id)) } }
+ }
+ @ObservationIgnored private var steamAccountIDsByBottle: [String: Set<UInt64>] = [:]
+ /// Every account across them, once each, sorted by display name.
+ private(set) var steamAccounts: [SteamAccount] = [] {
+ didSet { steamAccountIDs = Set(steamAccounts.map(\.id)) }
+ }
+ @ObservationIgnored private var steamAccountIDs: Set<UInt64> = []
+ /// Games that appeared while only one account had signed in to their Steam: that account's
+ /// (SteamAccounts.earlyArrivals).
+ var steamEarlyArrivals: [Int: UInt64] = [:] {
+ didSet { mergeSteamArrivals() }
+ }
+ /// Which account each game is put down to arriving with: what Highball saw arrive, else what
+ /// the first sign-ins imply. Merged when either changes, not for every tile the account
+ /// filter looks at.
+ private var steamAddedBy: [Int: UInt64] = [:]
+ /// Who installed each Steam game, per environment, from the install records' LastOwner:
+ /// built with the library, so the account filter looks it up rather than scanning.
+ @ObservationIgnored private var steamInstallers: [String: [Int: UInt64]] = [:]
+ /// Kept on disk (steam-accounts.json): which account was signed in when a game first
+ /// appeared, the owners the player chose, and the games already seen in each environment.
+ private var steamBook = SteamBook() {
+ didSet { mergeSteamArrivals() } // rare: loaded, a game noted, a choice set
+ }
+
+ private func mergeSteamArrivals() {
+ // What Highball saw arrive wins over what the first sign-ins imply.
+ steamAddedBy = steamBook.added.merging(steamEarlyArrivals) { seen, _ in seen }
+ }
+
+ private struct SteamBook: Codable {
+ var added: [Int: UInt64] = [:]
+ var chosen: [Int: Set<UInt64>] = [:]
+ /// Per environment, so one added later gets its own first look instead of its whole
+ /// library being put down to whoever is signed in.
+ var seen: [String: Set<Int>] = [:]
+
+ init() {}
+
+ // Each field optional on read: an earlier file kept `seen` for every environment at once,
+ // and dropping it only means one more first look, which marks and puts down nothing.
+ init(from decoder: Decoder) throws {
+ let c = try decoder.container(keyedBy: CodingKeys.self)
+ added = (try? c.decodeIfPresent([Int: UInt64].self, forKey: .added)) ?? [:]
+ chosen = (try? c.decodeIfPresent([Int: Set<UInt64>].self, forKey: .chosen)) ?? [:]
+ seen = (try? c.decodeIfPresent([String: Set<Int>].self, forKey: .seen)) ?? [:]
+ }
+ }
+
+ private var steamBookFile: URL { paths.home.appending(path: "steam-accounts.json") }
+ @ObservationIgnored private var steamBookLoaded = false
+
+ private func loadSteamBook() {
+ guard !steamBookLoaded else { return }
+ steamBookLoaded = true
+ steamBook = (try? JSONDecoder().decode(SteamBook.self, from: Data(contentsOf: steamBookFile))) ?? SteamBook()
+ }
+
+ private func saveSteamBook() {
+ try? JSONEncoder().encode(steamBook).write(to: steamBookFile, options: .atomic)
+ }
+
+ /// Games appearing for the first time are put down to the account signed in to the Steam
+ /// they appeared in (SteamAccounts.noteArrivals).
+ private func noteNewSteamGames(_ appIDsByBottle: [String: Set<Int>], signedIn: [String: UInt64]) {
+ loadSteamBook()
+ var book = steamBook
+ var changed = false
+ for (bottle, appIDs) in appIDsByBottle.sorted(by: { $0.key < $1.key }) {
+ var seen = book.seen[bottle] ?? []
+ if SteamAccounts.noteArrivals(appIDs, signedIn: signedIn[bottle], firstLook: book.seen[bottle] == nil,
+ seen: &seen, added: &book.added) || book.seen[bottle] == nil {
+ book.seen[bottle] = seen
+ changed = true
+ }
+ }
+ guard changed else { return }
+ steamBook = book
+ saveSteamBook()
+ }
+
+ /// Whose a Steam game is, as far as this Mac can tell (SteamAccounts.owners), among the
+ /// accounts of its environment's Steam; every one of them when there is no sign (`.unknown`).
+ /// nil with fewer than two accounts across this Mac, for a game outside an environment
+ /// (Steam for Mac's) and for one that is not Steam's.
+ func steamOwners(for item: LibraryItem) -> SteamAccounts.Owners? {
+ guard item.source == .steam, steamAccountIDs.count > 1, let appID = item.steamAppID,
+ let present = item.bottleName.flatMap({ steamAccountIDsByBottle[$0] }), !present.isEmpty else { return nil }
+ return SteamAccounts.owners(appID: appID, installedBy: steamInstaller(for: item), added: steamAddedBy,
+ chosen: steamBook.chosen, present: present)
+ }
+
+ /// Who installed a Steam game: its own environment's record first (a second copy elsewhere
+ /// may have another installer), else any environment's.
+ func steamInstaller(for item: LibraryItem) -> UInt64? {
+ guard let appID = item.steamAppID else { return nil }
+ return item.bottleName.flatMap { steamInstallers[$0]?[appID] } ?? steamInstallers.values.lazy.compactMap { $0[appID] }.first
+ }
+
+ /// The player's own answer to whose a game is; nil goes back to Highball's guess.
+ func setSteamOwners(_ accounts: Set<UInt64>?, for item: LibraryItem) {
+ guard let appID = item.steamAppID else { return }
+ loadSteamBook()
+ steamBook.chosen[appID] = accounts
+ saveSteamBook()
+ }
+
+ func steamAccountName(_ id: UInt64) -> String? { steamAccounts.first { $0.id == id }?.displayName }
+
// MARK: Games kept out of the library (highball#445)
/// Library ids the player hid (LibraryStore). The library leaves them out unless its Hidden
@@@ -717,10 -868,30 +869,31 @@@
let bottles = self.bottles
Task.detached { [weak self] in
let owned = Dictionary(bottles.map { ($0.name, SteamOwnedLibrary.games(in: $0)) }, uniquingKeysWith: { a, _ in a })
- await MainActor.run {
- guard let self, owned != self.steamOwnedByBottle else { return }
+ // Whose games, per environment's Steam: its accounts (newest sign-in first), the games
+ // that appeared while only one of them had signed in, and who is signed in now, else
+ // who signed in last.
+ var accountsByBottle: [String: [SteamAccount]] = [:], early: [Int: UInt64] = [:], signedIn: [String: UInt64] = [:]
+ for bottle in bottles {
+ guard let root = SteamLibrary.steamRoot(of: bottle) else { continue }
+ let known = SteamAccounts.known(steamRoot: root)
+ accountsByBottle[bottle.name] = known
+ let appeared = Dictionary((owned[bottle.name] ?? []).compactMap { g in g.cachedAt.map { (g.appid, $0) } }, uniquingKeysWith: min)
+ early.merge(SteamAccounts.earlyArrivals(appeared, firstSignIns: SteamAccounts.firstSignIns(steamRoot: root))) { a, _ in a }
+ signedIn[bottle.name] = SteamAccounts.signedIn(bottleURL: bottle.url) ?? known.first?.id
+ }
+ await MainActor.run { [accountsByBottle, early, signedIn] in
+ guard let self else { return }
+ if accountsByBottle != self.steamAccountsByBottle {
+ self.steamAccountsByBottle = accountsByBottle
+ var seen = Set<UInt64>()
+ self.steamAccounts = accountsByBottle.values.joined().filter { seen.insert($0.id).inserted }
+ .sorted { $0.displayName.localizedCaseInsensitiveCompare($1.displayName) == .orderedAscending }
+ }
+ if early != self.steamEarlyArrivals { self.steamEarlyArrivals = early }
+ self.noteNewSteamGames(owned.mapValues { Set($0.map(\.appid)) }, signedIn: signedIn)
+ guard owned != self.steamOwnedByBottle else { return }
self.steamOwnedByBottle = owned
+ self.steamCloudAppIDs = Set(owned.values.joined().filter(\.steamCloud).map(\.appid))
self.macAppInfoByAppID = Dictionary(owned.values.joined().map { ($0.appid, $0.macBuild) },
uniquingKeysWith: { a, _ in a })
self.rebuildLibrary()
diff --cc Sources/HighballApp/GameDetailView.swift
index 2ff9f0d,3b79cfd..ca20592
--- a/Sources/HighballApp/GameDetailView.swift
+++ b/Sources/HighballApp/GameDetailView.swift
@@@ -7,15 -7,8 +7,17 @@@ struct GameDetailView: View
let passedItem: LibraryItem
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@State private var storeDetails: SteamGameDetails?
+ /// The registry's ActiveUser for the game's environment, as last read (accountNote).
+ @State private var activeUserRead: ActiveUserRead?
+ @State private var sizes: AppState.InstalledSizes?
+ @State private var windowsEstimate: DownloadEstimate?
+ @State private var macEstimate: DownloadEstimate?
+ /// The estimates have been asked for and answered (or not): "Checking…" until then, "Unknown" after.
+ @State private var estimatesDone = false
+ /// How this GOG game's saves sync, per version; asked when the page opens.
+ @State private var cloudSetup: GOGSaves.CloudSetup?
+ @State private var cloudSetupAsked = false
+ @State private var showCloudHelp = false
@State private var loadingDetails = true
@State private var expandedDescription = false
@State private var selectedGalleryURL: URL?
@@@ -106,41 -137,22 +146,57 @@@
storeDetails = details
loadingDetails = false
}
+ .task(id: "\(item.id)|\(item.installed)|\(item.installedOnMac)|cloud") {
+ cloudSetup = nil; cloudSetupAsked = false
+ guard item.source == .gog, item.installedAnywhere else { return }
+ cloudSetup = await state.gogCloudSetup(for: item)
+ cloudSetupAsked = true
+ }
+ // How much room it takes: the store's estimate before an install, the folders after.
+ // All three at once, each shown as it comes: a store's answer takes seconds.
+ .task(id: "\(item.id)|\(item.installed)|\(item.installedOnMac)") {
+ sizes = nil; windowsEstimate = nil; macEstimate = nil; estimatesDone = false
+ let item = item
+ let wantsWindows = !item.installed && [.gog, .epic, .steam].contains(item.source)
+ let wantsMac = hasMacVersion && !item.installedOnMac
+ // A size saved earlier shows at once; one older than a day is checked again quietly.
+ if wantsWindows { windowsEstimate = state.savedEstimate(for: item, mac: false) }
+ if wantsMac { macEstimate = state.savedEstimate(for: item, mac: true) }
+ await withTaskGroup(of: Void.self) { group in
+ if item.installedAnywhere {
+ group.addTask { @MainActor in sizes = await state.installedSizes(for: item) }
+ }
+ if wantsWindows, windowsEstimate == nil || state.estimateIsStale(for: item, mac: false) {
+ let refresh = windowsEstimate != nil
+ group.addTask { @MainActor in
+ if let fresh = await state.downloadEstimate(for: item, mac: false, refresh: refresh) { windowsEstimate = fresh }
+ }
+ }
+ if wantsMac, macEstimate == nil || state.estimateIsStale(for: item, mac: true) {
+ let refresh = macEstimate != nil
+ group.addTask { @MainActor in
+ if let fresh = await state.downloadEstimate(for: item, mac: true, refresh: refresh) { macEstimate = fresh }
+ }
+ }
+ }
+ estimatesDone = true
+ }
+ // Which account Steam is signed in to, for accountNote. Only that is read here: the install
+ // records and accounts are already in the app's state. Read with more than one account
+ // only, again every few seconds while Steam runs (switching accounts happens in Steam),
+ // and once more when it starts or quits.
+ .task(id: accountWatch) {
+ let watch = accountWatch
+ guard let name = watch.bottle, watch.severalAccounts,
+ let bottle = state.bottles.first(where: { $0.name == name }) else { return }
+ while !Task.isCancelled {
+ let user = await Task.detached { SteamAccounts.signedIn(bottleURL: bottle.url) }.value
+ let read = ActiveUserRead(bottle: name, user: user)
+ if read != activeUserRead { activeUserRead = read }
+ guard watch.running else { return }
+ try? await Task.sleep(for: .seconds(5))
+ }
+ }
}
private func overview(scroll: ScrollViewProxy) -> some View {
@@@ -238,16 -250,25 +294,33 @@@
VStack(alignment: .leading, spacing: 12) {
row(L("Source"), item.source == .steam ? "Steam" : item.source == .epic ? "Epic Games"
: item.source == .gog ? "GOG" : item.source == .battlenet ? "Battle.net" : L("Windows program"))
+ let owners = state.steamOwners(for: item)
+ if let owners, (state.steamAccountsByBottle[item.bottleName ?? ""]?.count ?? 0) > 1 { steamAccountRow(owners) }
+ if let note = accountNote(owners) {
+ VStack(alignment: .leading, spacing: 6) {
+ row(L("Installed by"), note.installedBy.displayName)
+ if let other = note.otherAccount {
+ Label(String(format: note.signedInNow
+ ? L("Steam is signed in as %@. That account may not have access to this game.")
+ : L("Steam last signed in as %@. That account may not have access to this game."),
+ other.displayName),
+ systemImage: "exclamationmark.triangle.fill")
+ .font(.caption).foregroundStyle(HB.amber)
+ .fixedSize(horizontal: false, vertical: true)
+ .padding(.leading, Self.rowLabelWidth + 12) // under the row's value
+ }
+ }
+ }
- if item.sizeOnDisk > 0 {
- row(L("Size on disk"), ByteCountFormatter.string(fromByteCount: item.sizeOnDisk, countStyle: .file))
+ // Every game says how much room it takes: what an install needs before, what is on disk after.
+ if item.source != .pin || item.installed {
+ row(hasMacVersion ? L("Size (Windows)") : L("Size"), windowsSize)
+ }
+ if hasMacVersion {
+ row(L("Size (Mac)"), macSize)
+ }
+ if item.source == .steam || item.source == .epic || (item.source == .gog && item.installedAnywhere) { cloudSavesRow }
+ if let saves = sizes?.saves {
+ row(item.source == .steam ? L("Steam Cloud saves") : L("Saves"), Self.bytes(saves))
}
if let played = item.lastPlayed {
row(L("Last played"), played.formatted(date: .abbreviated, time: .shortened))
diff --cc Sources/HighballApp/L10n.swift
index 33fef2c,34adaf5..39b75e6
--- a/Sources/HighballApp/L10n.swift
+++ b/Sources/HighballApp/L10n.swift
@@@ -395,41 -395,25 +395,59 @@@ enum L10n
"Not installed in any bottle": "Installé dans aucune bouteille",
"Also installed in %@": "Aussi installé dans %@",
"Source": "Source",
- "Size on disk": "Taille sur le disque",
+ "How this game's saves sync": "Comment se synchronisent les sauvegardes de ce jeu",
+ "Highball could not reach GOG to see how this game saves.": "Highball n’a pas pu joindre GOG pour voir comment ce jeu sauvegarde.",
+ "Kept on this Mac: Sync saves with GOG, under Game settings, syncs them.": "Gardées sur ce Mac : Synchroniser avec GOG, dans les réglages du jeu, les synchronise.",
+ "The Windows version's saves sync with GOG's cloud before and after you play.": "Les sauvegardes de la version Windows se synchronisent avec le cloud GOG avant et après chaque partie.",
+ "The game handles the Windows version's saves; some games sync them with GOG's cloud themselves while comet runs.":
+ "Le jeu gère les sauvegardes de la version Windows ; certains jeux les synchronisent eux-mêmes avec le cloud GOG quand comet tourne.",
+ "How saves sync with GOG": "Comment les sauvegardes se synchronisent avec GOG",
+ "GOG syncs saves in one of two ways, chosen per game and per version.": "GOG synchronise les sauvegardes de deux façons, selon le jeu et la version.",
+ "Folder sync: GOG names the folders a game saves in, and Highball copies them to and from GOG's cloud before and after you play, as GOG Galaxy does. When both copies changed, Highball asks which one to keep.":
+ "Synchronisation des dossiers : GOG indique les dossiers où un jeu sauvegarde, et Highball les copie vers et depuis le cloud GOG avant et après chaque partie, comme GOG Galaxy. Si les deux copies ont changé, Highball demande laquelle garder.",
+ "The game's own sync: some games send their saves to GOG's cloud themselves, through GOG's game kit. With Highball that works while comet runs beside the game, and the game says so when it syncs, as Cyberpunk 2077 does.":
+ "La synchronisation du jeu : certains jeux envoient eux-mêmes leurs sauvegardes au cloud GOG, par le kit de GOG. Avec Highball, cela fonctionne quand comet tourne à côté du jeu, et le jeu l’indique quand il synchronise, comme Cyberpunk 2077.",
+ "Folders this game syncs": "Dossiers synchronisés par ce jeu",
+ "Steam syncs this game's saves with Steam Cloud, for whichever account plays it.": "Steam synchronise les sauvegardes de ce jeu avec Steam Cloud, pour le compte qui y joue.",
+ "This game keeps its saves on this Mac.": "Ce jeu garde ses sauvegardes sur ce Mac.",
+ "Epic's cloud keeps this game's saves when Epic's own launcher plays it. Played from Highball, they stay on this Mac.":
+ "Le cloud d’Epic garde les sauvegardes de ce jeu quand le lanceur d’Epic y joue. Lancées depuis Highball, elles restent sur ce Mac.",
+ "How Steam Cloud works": "Comment fonctionne Steam Cloud",
+ "Steam syncs a game's saves with Steam Cloud itself, before and after you play, for the account signed in to Steam. Highball starts the game through Steam, so nothing changes. The Steam Cloud saves row is Steam's copy on this Mac.":
+ "Steam synchronise lui-même les sauvegardes d’un jeu avec Steam Cloud, avant et après chaque partie, pour le compte connecté à Steam. Highball lance le jeu par Steam, rien ne change donc. La ligne Sauvegardes Steam Cloud montre la copie de Steam sur ce Mac.",
+ "How Epic's cloud saves work": "Comment fonctionnent les sauvegardes en ligne d’Epic",
+ "Epic's launcher syncs a game's saves with Epic's cloud when the game sets a cloud save folder. Highball plays Epic games through legendary, and their saves stay on this Mac.":
+ "Le lanceur d’Epic synchronise les sauvegardes d’un jeu avec le cloud d’Epic quand le jeu définit un dossier de sauvegarde en ligne. Highball lance les jeux Epic par legendary, et leurs sauvegardes restent sur ce Mac.",
+ "Size (Windows)": "Taille (Windows)",
+ "Size (Mac)": "Taille (Mac)",
+ "Size": "Taille",
+ "Measuring…": "Mesure…",
+ "Checking…": "Vérification…",
+ "Unknown": "Inconnue",
+ "Takes %@ of space (%@ to download)": "Occupe %@ (%@ à télécharger)",
+ "Takes %@ of space": "Occupe %@",
+ "%@ to download": "%@ à télécharger",
+ "Uses %@ of space": "Occupe %@",
+ "Saves": "Sauvegardes",
+ "Steam Cloud saves": "Sauvegardes Steam Cloud",
+ "Installed by": "Installé par",
+ "All Steam accounts": "Tous les comptes Steam",
+ "Steam games of one account on this Mac: the one that installed them, or was signed in when they appeared. A game with no sign of whose it is shows under every account.":
+ "Les jeux Steam d’un seul compte sur ce Mac : celui qui les a installés, ou qui était connecté quand ils sont apparus. Un jeu sans indice du compte apparaît sous chaque compte.",
+ "Account": "Compte",
+ "set by you": "choisi par vous",
+ "installed it": "l’a installé",
+ "signed in when it was added": "connecté quand il a été ajouté",
+ "Any account": "N’importe quel compte",
+ "no sign of whose it is": "aucun indice du compte",
+ "Whose Steam game this is. Highball goes by who installed it and who was signed in when it appeared; pick one to set it.":
+ "À qui est ce jeu Steam. Highball se fie à qui l’a installé et à qui était connecté quand il est apparu ; choisissez un compte pour le fixer.",
+ "Every account here": "Tous les comptes de ce Mac",
+ "Let Highball guess": "Laisser Highball deviner",
+ "Steam is signed in as %@. That account may not have access to this game.":
+ "Steam est connecté au compte %@. Ce compte n’a peut-être pas accès à ce jeu.",
+ "Steam last signed in as %@. That account may not have access to this game.":
+ "Steam s’est connecté en dernier au compte %@. Ce compte n’a peut-être pas accès à ce jeu.",
"Last played": "Dernière partie",
"Windows program": "Programme Windows",
"Choose cover image…": "Choisir une image de couverture…",
diff --cc Sources/HighballKit/SteamOwnedLibrary.swift
index 5e02203,aa46335..cc3ecc0
--- a/Sources/HighballKit/SteamOwnedLibrary.swift
+++ b/Sources/HighballKit/SteamOwnedLibrary.swift
@@@ -12,13 -12,14 +12,16 @@@ public struct OwnedSteamGame: Sendable
public var listsMac = false
/// What appinfo says about the Mac build: 64-bit, 32-bit only, or none (MacAppInfoBuild).
public var macBuild: MacAppInfoBuild = .absent
+ /// When the game first appeared in this Steam's library: when the client made its
+ /// librarycache folder (SteamAccounts.earlyArrivals).
+ public var cachedAt: Date? = nil
+ /// appinfo's `ufs` gives the game room in Steam Cloud, which Steam syncs per account.
+ public var steamCloud = false
public init(appid: Int, name: String, localCapsule: URL? = nil, localHeader: URL? = nil, listsMac: Bool = false,
- macBuild: MacAppInfoBuild = .absent, steamCloud: Bool = false) {
- macBuild: MacAppInfoBuild = .absent, cachedAt: Date? = nil) {
++ macBuild: MacAppInfoBuild = .absent, steamCloud: Bool = false, cachedAt: Date? = nil) {
self.appid = appid; self.name = name; self.localCapsule = localCapsule; self.localHeader = localHeader
- self.listsMac = listsMac; self.macBuild = macBuild; self.steamCloud = steamCloud
- self.listsMac = listsMac; self.macBuild = macBuild; self.cachedAt = cachedAt
++ self.listsMac = listsMac; self.macBuild = macBuild; self.steamCloud = steamCloud; self.cachedAt = cachedAt
}
/// Local art first: newer apps keep theirs at hashed store paths, so the fixed CDN name
@@@ -63,7 -65,8 +67,8 @@@ public enum SteamOwnedLibrary
return OwnedSteamGame(appid: appid, name: name, localCapsule: art["library_600x900.jpg"],
localHeader: art["library_header.jpg"] ?? art["header.jpg"],
listsMac: app.oslist?.lowercased().contains("macos") ?? false,
- macBuild: app.macBuild, steamCloud: app.steamCloudQuota > 0)
- macBuild: app.macBuild,
++ macBuild: app.macBuild, steamCloud: app.steamCloudQuota > 0,
+ cachedAt: try? folder.resourceValues(forKeys: [.creationDateKey]).creationDate)
}
.sorted { $0.name.localizedCaseInsensitiveCompare($1.name) == .orderedAscending }
}