Skip to content

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

Steam accounts: per environment, and the warning agrees with the Account row

Gabe7360183f58cb
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index 3f85f15..79337e4 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -312,7 +312,10 @@ final class AppState {
// MARK: Whose Steam games
/// The accounts that have signed in to each environment's Steam, newest sign-in first.
- var steamAccountsByBottle: [String: [SteamAccount]] = [:]
+ 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)) }
@@ -331,7 +334,7 @@ final class AppState {
/// 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.
+ /// 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
}
@@ -344,7 +347,20 @@ final class AppState {
private struct SteamBook: Codable {
var added: [Int: UInt64] = [:]
var chosen: [Int: Set<UInt64>] = [:]
- var seen: Set<Int> = []
+ /// 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") }
@@ -365,11 +381,14 @@ final class AppState {
private func noteNewSteamGames(_ appIDsByBottle: [String: Set<Int>], signedIn: [String: UInt64]) {
loadSteamBook()
var book = steamBook
- let firstLook = book.seen.isEmpty
var changed = false
for (bottle, appIDs) in appIDsByBottle.sorted(by: { $0.key < $1.key }) {
- changed = SteamAccounts.noteArrivals(appIDs, signedIn: signedIn[bottle], firstLook: firstLook,
- seen: &book.seen, added: &book.added) || changed
+ 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
@@ -377,15 +396,21 @@ final class AppState {
}
/// Whose a Steam game is, as far as this Mac can tell (SteamAccounts.owners), among the
- /// 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.
+ /// 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 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
- return SteamAccounts.owners(appID: appID, installedBy: installer, added: steamAddedBy,
- chosen: steamBook.chosen, present: steamAccountIDs)
+ 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.
diff --git a/Sources/HighballApp/GameDetailView.swift b/Sources/HighballApp/GameDetailView.swift
index aab3653..0110263 100644
--- a/Sources/HighballApp/GameDetailView.swift
+++ b/Sources/HighballApp/GameDetailView.swift
@@ -76,16 +76,14 @@ struct GameDetailView: View {
}
/// Who installed this Steam game, and whether Steam is signed in, or signed in last, to an
- /// account that may not have it: "is signed in" only while that Steam runs, and an account the
- /// player said has the game is never warned about.
- private var accountNote: SteamAccounts.GameNote? {
- guard item.source == .steam, let appID = item.steamAppID, let name = item.bottleName,
- let read = activeUserRead, read.bottle == name else { return nil }
- let owners = state.steamOwners(for: item)
- return SteamAccounts.note(installedBy: state.gamesByBottle[name]?.first { $0.appid == appID }?.lastOwner,
+ /// account that may not have it: "is signed in" only while that Steam runs, and an account
+ /// the Account row counts as having the game is never warned about.
+ private func accountNote(_ owners: SteamAccounts.Owners?) -> SteamAccounts.GameNote? {
+ guard item.source == .steam, let name = item.bottleName, let read = activeUserRead, read.bottle == name else { return nil }
+ return SteamAccounts.note(installedBy: state.steamInstaller(for: item),
accounts: state.steamAccountsByBottle[name] ?? [], activeUser: read.user,
steamRunning: state.steamClients.contains(name),
- chosen: owners?.reason == .chosen ? owners?.accounts : nil)
+ owners: owners?.reason == .unknown ? nil : owners?.accounts)
}
var body: some View {
@@ -244,8 +242,9 @@ struct GameDetailView: View {
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"))
- if item.source == .steam, let owners = state.steamOwners(for: item) { steamAccountRow(owners) }
- if let note = accountNote {
+ 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 {
@@ -774,9 +773,11 @@ struct GameDetailView: View {
}
/// Whose Steam game this is, by profile name, and why Highball thinks so; the menu sets it.
- /// Shown with more than one account, also when Highball has no sign of whose it is
+ /// Shown with more than one account on its Steam, 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 {
+ // The accounts of this game's own Steam: another environment's are no answer here.
+ let accounts = state.steamAccountsByBottle[item.bottleName ?? ""] ?? []
let names = owners.reason == .unknown ? [L("Any account")]
: owners.accounts.compactMap { state.steamAccountName($0) }.sorted()
let why: String = switch owners.reason {
@@ -786,12 +787,12 @@ struct GameDetailView: View {
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)
+ Text(L("Account")).font(.caption).foregroundStyle(.secondary).frame(width: Self.rowLabelWidth, alignment: .leading)
Menu {
- ForEach(state.steamAccounts, id: \.id) { account in
+ ForEach(accounts, id: \.id) { account in
Button(account.displayName) { state.setSteamOwners([account.id], for: item) }
}
- Button(L("Every account here")) { state.setSteamOwners(Set(state.steamAccounts.map(\.id)), for: item) }
+ Button(L("Every account here")) { state.setSteamOwners(Set(accounts.map(\.id)), for: item) }
Divider()
Button(L("Let Highball guess")) { state.setSteamOwners(nil, for: item) }
} label: {
diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swift
index 16b71ac..a1d6a19 100644
--- a/Sources/HighballApp/L10n.swift
+++ b/Sources/HighballApp/L10n.swift
@@ -398,8 +398,8 @@ 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. 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.",
+ "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é",
diff --git a/Sources/HighballApp/LibraryView.swift b/Sources/HighballApp/LibraryView.swift
index 1923a52..416b89b 100644
--- a/Sources/HighballApp/LibraryView.swift
+++ b/Sources/HighballApp/LibraryView.swift
@@ -45,11 +45,9 @@ struct LibraryView: View {
return shown.filter { item in
if 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)?.accounts
- if !(owners?.contains(account) ?? false) { return false }
- }
+ // A game with no sign of whose it is is every account's (`.unknown`), so it stays, as
+ // does one Highball cannot place (Steam for Mac's, or before the accounts are read).
+ if let account, let owners = state.steamOwners(for: item), !owners.accounts.contains(account) { return false }
if verifiedOnly {
guard state.gameDB.entry(for: item)?.status == "verified-local" else { return false }
}
@@ -280,7 +278,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. A game with no sign of whose it is shows under every account."))
+ .help(L("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."))
}
}
diff --git a/Sources/HighballKit/SteamAccounts.swift b/Sources/HighballKit/SteamAccounts.swift
index e2174be..19914e4 100644
--- a/Sources/HighballKit/SteamAccounts.swift
+++ b/Sources/HighballKit/SteamAccounts.swift
@@ -73,14 +73,14 @@ public enum SteamAccounts {
/// `activeUser` is the registry's (signedIn(bottleURL:)), `steamRunning` whether this Steam
/// runs now: ActiveUser can outlive Steam, so only then is it who is signed in. Without it,
/// the account signed in last is loginusers.vdf's newest. The accounts that have the game are
- /// the player's choice when there is one (`chosen`, Every account included), else the
+ /// `owners`, as the Account row shows them (the player's choice, else every sign), else the
/// installer; the warning names the current account only when it is not among them.
public static func note(installedBy owner: UInt64?, accounts: [SteamAccount], activeUser: UInt64?,
- steamRunning: Bool, chosen: Set<UInt64>? = nil) -> GameNote? {
+ steamRunning: Bool, owners: Set<UInt64>? = nil) -> GameNote? {
guard accounts.count > 1, let owner, let installer = accounts.first(where: { $0.id == owner }) else { return nil }
let active = activeUser.flatMap { id in accounts.first { $0.id == id } }
let current = active ?? (activeUser == nil ? accounts.first : nil)
- let haveIt: Set<UInt64> = chosen.flatMap { $0.isEmpty ? nil : $0 } ?? [owner]
+ let haveIt: Set<UInt64> = owners.flatMap { $0.isEmpty ? nil : $0 } ?? [owner]
return GameNote(installedBy: installer, otherAccount: current.flatMap { haveIt.contains($0.id) ? nil : $0 },
signedInNow: steamRunning && active != nil)
}
diff --git a/Tests/HighballKitTests/SteamAccountsTests.swift b/Tests/HighballKitTests/SteamAccountsTests.swift
index 55c329d..ab89c99 100644
--- a/Tests/HighballKitTests/SteamAccountsTests.swift
+++ b/Tests/HighballKitTests/SteamAccountsTests.swift
@@ -105,14 +105,14 @@ final class SteamAccountsTests: XCTestCase {
let accounts = SteamAccounts.parse(loginUsers: loginUsers)
let alder: UInt64 = 76561198000000001, birch: UInt64 = 76561198000000002
XCTAssertNil(SteamAccounts.note(installedBy: alder, accounts: accounts, activeUser: birch, steamRunning: true,
- chosen: [birch])?.otherAccount, "the player says the signed-in account has it")
+ owners: [birch])?.otherAccount, "the player says the signed-in account has it")
XCTAssertNil(SteamAccounts.note(installedBy: alder, accounts: accounts, activeUser: birch, steamRunning: true,
- chosen: [alder, birch])?.otherAccount, "Every account here")
+ owners: [alder, birch])?.otherAccount, "Every account here")
XCTAssertEqual(SteamAccounts.note(installedBy: alder, accounts: accounts, activeUser: alder, steamRunning: true,
- chosen: [birch])?.otherAccount?.displayName, "Alder",
+ owners: [birch])?.otherAccount?.displayName, "Alder",
"the player says only the other account has it")
XCTAssertEqual(SteamAccounts.note(installedBy: alder, accounts: accounts, activeUser: birch, steamRunning: true,
- chosen: [])?.otherAccount?.displayName, "Birch", "an empty choice is no choice")
+ owners: [])?.otherAccount?.displayName, "Birch", "an empty choice is no choice")
}
/// The player's choice wins; otherwise every account with a sign, the strongest named.