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
Steam accounts: a game with no sign of whose it is stays under every account and can still be set
Gabe3bdede3365ed
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex 15bf8d2..3f85f15 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -320,13 +320,26 @@ final class AppState {@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] = [:]+ 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.- private var steamBook = SteamBook()+ 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] = [:]@@ -364,18 +377,15 @@ final class AppState {}/// Whose a Steam game is, as far as this Mac can tell (SteamAccounts.owners), among the- /// accounts known here; nil with one account, or no sign of a known one.+ /// accounts known here; every one of them when there is no sign (`.unknown`). nil only with+ /// one account, or for a game that is not Steam's.func steamOwners(for item: LibraryItem) -> SteamAccounts.Owners? {guard item.source == .steam, steamAccountIDs.count > 1, let appID = item.steamAppID else { return nil }// The game's own environment first: a second copy elsewhere may have another installer.let installer = item.bottleName.flatMap { steamInstallers[$0]?[appID] }?? steamInstallers.values.lazy.compactMap { $0[appID] }.first- // What Highball saw arrive wins over what the first sign-ins imply.- let added = steamBook.added.merging(steamEarlyArrivals) { seen, _ in seen }- guard let owners = SteamAccounts.owners(appID: appID, installedBy: installer, added: added,- chosen: steamBook.chosen) else { return nil }- let present = owners.accounts.intersection(steamAccountIDs)- return present.isEmpty ? nil : SteamAccounts.Owners(accounts: present, reason: owners.reason)+ return SteamAccounts.owners(appID: appID, installedBy: installer, added: steamAddedBy,+ chosen: steamBook.chosen, present: steamAccountIDs)}/// The player's own answer to whose a game is; nil goes back to Highball's guess.diff --git a/Sources/HighballApp/GameDetailView.swift b/Sources/HighballApp/GameDetailView.swiftindex aa73edb..cd1d692 100644--- a/Sources/HighballApp/GameDetailView.swift+++ b/Sources/HighballApp/GameDetailView.swift@@ -740,13 +740,16 @@ struct GameDetailView: View {}/// Whose Steam game this is, by profile name, and why Highball thinks so; the menu sets it.- /// Shown only when Highball knows (SteamAccounts.Owners).+ /// Shown with more than one account, also when Highball has no sign of whose it is+ /// (SteamAccounts.Owners), so the player can say.private func steamAccountRow(_ owners: SteamAccounts.Owners) -> some View {- let names = owners.accounts.compactMap { state.steamAccountName($0) }.sorted()+ let names = owners.reason == .unknown ? [L("Any account")]+ : owners.accounts.compactMap { state.steamAccountName($0) }.sorted()let why: String = switch owners.reason {case .chosen: L("set by you")case .installed: L("installed it")case .added: L("signed in when it was added")+ case .unknown: L("no sign of whose it is")}return HStack(alignment: .firstTextBaseline, spacing: 12) {Text(L("Account")).font(.caption).foregroundStyle(.secondary).frame(width: 110, alignment: .leading)diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swiftindex cfd8be1..16b71ac 100644--- a/Sources/HighballApp/L10n.swift+++ b/Sources/HighballApp/L10n.swift@@ -398,12 +398,14 @@ enum L10n {"Size on disk": "Taille sur le disque","Installed by": "Installé par","All Steam accounts": "Tous les comptes Steam",- "Steam games of one account on this Mac: the one that installed or played them, or was signed in when they appeared.":- "Les jeux Steam d’un seul compte sur ce Mac : celui qui les a installés ou y a joué, ou qui était connecté quand ils sont apparus.",+ "Steam games of one account on this Mac: the one that installed or played 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 y a joué, 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",diff --git a/Sources/HighballApp/LibraryView.swift b/Sources/HighballApp/LibraryView.swiftindex b2d7684..1923a52 100644--- a/Sources/HighballApp/LibraryView.swift+++ b/Sources/HighballApp/LibraryView.swift@@ -45,6 +45,7 @@ struct LibraryView: View {return shown.filter { item inif let sourceFilter, item.source != sourceFilter { return false }if installedOnly && !item.installedAnywhere { return false }+ // A game with no sign of whose it is is every account's (`.unknown`), so it stays.if let account {let owners = state.steamOwners(for: item)?.accountsif !(owners?.contains(account) ?? false) { return false }@@ -279,7 +280,7 @@ extension LibraryView {.foregroundStyle(activeSteamAccount == nil ? .secondary : Color(red: 0.13, green: 0.08, blue: 0.01))}.menuStyle(.button).buttonStyle(.plain).menuIndicator(.hidden).fixedSize()- .help(L("Steam games of one account on this Mac: the one that installed or played them, or was signed in when they appeared."))+ .help(L("Steam games of one account on this Mac: the one that installed or played them, or was signed in when they appeared. A game with no sign of whose it is shows under every account."))}}diff --git a/Sources/HighballKit/SteamAccounts.swift b/Sources/HighballKit/SteamAccounts.swiftindex 26f066a..a4aa0dc 100644--- a/Sources/HighballKit/SteamAccounts.swift+++ b/Sources/HighballKit/SteamAccounts.swift@@ -100,9 +100,12 @@ extension SteamAccounts {/// Whose a Steam game is, as far as this Mac can tell, and why: what the player chose, else/// every account with a sign of it (installed it, or was the one signed in when it first- /// appeared in the library). Ownership itself is not readable (the license list is encrypted).+ /// appeared in the library), else, with no sign, any account here. Ownership itself is not+ /// readable (the license list is encrypted).public struct Owners: Sendable, Equatable {- public enum Reason: Sendable, Equatable { case chosen, installed, added }+ /// `unknown`: no sign of any account here, so `accounts` is every one of them: the game+ /// stays under each account's filter until the player says whose it is.+ public enum Reason: Sendable, Equatable { case chosen, installed, added, unknown }public let accounts: Set<UInt64>/// The strongest sign among them.public let reason: Reason@@ -123,14 +126,18 @@ extension SteamAccounts {return true}+ /// Whose a game is among `present`, the accounts in loginusers.vdf now. An account that has+ /// left it counts for nothing: a choice of only such accounts gives way to the signs, and a+ /// game with no sign of a present account is `unknown`, so it never drops out of every+ /// account's filter, and its page still offers to set it.public static func owners(appID: Int, installedBy: UInt64?, added: [Int: UInt64],- chosen: [Int: Set<UInt64>]) -> Owners? {- if let picked = chosen[appID], !picked.isEmpty { return Owners(accounts: picked, reason: .chosen) }+ chosen: [Int: Set<UInt64>], present: Set<UInt64>) -> Owners {+ if let picked = chosen[appID]?.intersection(present), !picked.isEmpty { return Owners(accounts: picked, reason: .chosen) }var accounts = Set<UInt64>()var reason: Owners.Reason?- if let installedBy { accounts.insert(installedBy); reason = .installed }- if let adder = added[appID] { accounts.insert(adder); reason = reason ?? .added }- return reason.map { Owners(accounts: accounts, reason: $0) }+ if let installedBy, present.contains(installedBy) { accounts.insert(installedBy); reason = .installed }+ if let adder = added[appID], present.contains(adder) { accounts.insert(adder); reason = reason ?? .added }+ return reason.map { Owners(accounts: accounts, reason: $0) } ?? Owners(accounts: present, reason: .unknown)}}diff --git a/Tests/HighballKitTests/SteamAccountsTests.swift b/Tests/HighballKitTests/SteamAccountsTests.swiftindex 6e18a2b..5be7b78 100644--- a/Tests/HighballKitTests/SteamAccountsTests.swift+++ b/Tests/HighballKitTests/SteamAccountsTests.swift@@ -91,13 +91,40 @@ final class SteamAccountsTests: XCTestCase {/// The player's choice wins; otherwise every account with a sign, the strongest named.func testOwnersComeFromTheChoiceElseEverySign() {let alder: UInt64 = 76561198000000001, birch: UInt64 = 76561198000000002- XCTAssertEqual(SteamAccounts.owners(appID: 7, installedBy: alder, added: [7: birch], chosen: [:]),+ let both: Set<UInt64> = [alder, birch]+ XCTAssertEqual(SteamAccounts.owners(appID: 7, installedBy: alder, added: [7: birch], chosen: [:], present: both),SteamAccounts.Owners(accounts: [alder, birch], reason: .installed))- XCTAssertEqual(SteamAccounts.owners(appID: 9, installedBy: nil, added: [9: alder], chosen: [:]),+ XCTAssertEqual(SteamAccounts.owners(appID: 9, installedBy: nil, added: [9: alder], chosen: [:], present: both),SteamAccounts.Owners(accounts: [alder], reason: .added))- XCTAssertEqual(SteamAccounts.owners(appID: 7, installedBy: alder, added: [:], chosen: [7: [birch]]),+ XCTAssertEqual(SteamAccounts.owners(appID: 7, installedBy: alder, added: [:], chosen: [7: [birch]], present: both),SteamAccounts.Owners(accounts: [birch], reason: .chosen))- XCTAssertNil(SteamAccounts.owners(appID: 10, installedBy: nil, added: [:], chosen: [:]))+ }++ /// No sign of whose a game is (it arrived before Highball first looked, or its install record+ /// says LastOwner 0): every account's, so no account's filter drops it and its page can set it.+ func testAGameWithNoSignIsAnyAccounts() {+ let alder: UInt64 = 76561198000000001, birch: UInt64 = 76561198000000002+ XCTAssertEqual(SteamAccounts.owners(appID: 10, installedBy: nil, added: [:], chosen: [:], present: [alder, birch]),+ SteamAccounts.Owners(accounts: [alder, birch], reason: .unknown))+ XCTAssertEqual(SteamAccounts.owners(appID: 10, installedBy: nil, added: [11: alder], chosen: [11: [birch]], present: [alder, birch]),+ SteamAccounts.Owners(accounts: [alder, birch], reason: .unknown), "another game's signs are not this one's")+ }++ /// An account that has left loginusers.vdf counts for nothing: a choice of it gives way to the+ /// signs, a sign of it to the others, and a game left with none is any account's.+ func testAnAccountThatLeftTrapsNoGame() {+ let alder: UInt64 = 76561198000000001, birch: UInt64 = 76561198000000002, gone: UInt64 = 76561198000000009+ let present: Set<UInt64> = [alder, birch]+ XCTAssertEqual(SteamAccounts.owners(appID: 7, installedBy: alder, added: [:], chosen: [7: [gone]], present: present),+ SteamAccounts.Owners(accounts: [alder], reason: .installed), "the choice gives way to the signs")+ XCTAssertEqual(SteamAccounts.owners(appID: 7, installedBy: nil, added: [:], chosen: [7: [gone, birch]], present: present),+ SteamAccounts.Owners(accounts: [birch], reason: .chosen), "what is left of the choice stands")+ XCTAssertEqual(SteamAccounts.owners(appID: 7, installedBy: gone, added: [7: birch], chosen: [:], present: present),+ SteamAccounts.Owners(accounts: [birch], reason: .added), "the reason is a present account's")+ XCTAssertEqual(SteamAccounts.owners(appID: 7, installedBy: gone, added: [7: gone], chosen: [7: [gone]], present: present),+ SteamAccounts.Owners(accounts: present, reason: .unknown))+ XCTAssertEqual(SteamAccounts.owners(appID: 7, installedBy: alder, added: [:], chosen: [7: []], present: present),+ SteamAccounts.Owners(accounts: [alder], reason: .installed), "an empty choice is no choice")}/// Games that appeared while only the first account had ever signed in are its; later ones