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
Library Phase 2, sessions 2-3a: the One Library surface
Gauthier Piarrettef08f8d71079b
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex c020de4..f1052b1 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -48,6 +48,59 @@ final class AppState {var errorMessage: String?+ // MARK: One Library (Phase 2)++ /// Which primary surface the detail column shows. `selectedBottle` keeps backing every+ /// bottle action and the File-menu commands; it just stopped being the router.+ enum Pane: Hashable { case library, bottles }+ var pane: Pane = .library+ var libraryItems: [LibraryItem] = []+ var libraryPlays: [String: LibraryStore.PlayRecord] = [:]+ var libraryStore: LibraryStore { LibraryStore(paths: paths) }++ func rebuildLibrary() {+ libraryItems = LibraryIndex.build(bottles: bottles, steamByBottle: gamesByBottle,+ epicOwned: epicOwned, epicInstalls: epicInstalls,+ plays: libraryPlays)+ }++ /// The "never pick a bottle first" guarantee: every Play in the library resolves the+ /// item's own bottle and dispatches by source.+ func play(_ item: LibraryItem) {+ guard let bottleName = item.bottleName,+ let bottle = bottles.first(where: { $0.name == bottleName }) else { return }+ recordPlay(item)+ switch item.source {+ case .steam:+ guard let game = (gamesByBottle[bottleName] ?? []).first(where: { $0.appid == item.steamAppID }) else { return }+ launchGame(game, in: bottle)+ case .epic:+ guard let game = epicOwned.first(where: { $0.app_name == item.epicAppName }) else { return }+ epicPlay(game, in: bottle)+ case .pin:+ guard let pin = bottle.settings.pins.first(where: { $0.id == item.pinID }) else { return }+ launch(pin: pin, in: bottle)+ }+ }++ /// Epic-only today: installs into the item's resolved bottle, else the selected one,+ /// else the first — a menu in the detail view refines it, never a modal prerequisite.+ func install(_ item: LibraryItem) {+ guard item.source == .epic,+ let game = epicOwned.first(where: { $0.app_name == item.epicAppName }) else { return }+ let target = item.bottleName.flatMap { name in bottles.first { $0.name == name } }+ ?? selectedBottle.flatMap { name in bottles.first { $0.name == name } }+ ?? bottles.first+ guard let target else { return }+ epicInstall(game, in: target)+ }++ private func recordPlay(_ item: LibraryItem) {+ libraryStore.recordPlay(id: item.id, bottle: item.bottleName)+ libraryPlays[item.id] = LibraryStore.PlayRecord(lastPlayedAt: Date(), bottle: item.bottleName)+ rebuildLibrary()+ }+// Epic (via Legendary; see EpicStore)var epicSignedIn = falsevar epicOwned: [EpicStore.Game] = []@@ -82,6 +135,8 @@ final class AppState {if selectedBottle == nil { selectedBottle = bottles.first?.name }// Never trap on duplicate names (a Finder-duplicated bottle crashed the app at launch — issue #13).gamesByBottle = Dictionary(bottles.map { ($0.name, SteamLibrary.games(in: $0)) }, uniquingKeysWith: { a, _ in a })+ libraryPlays = libraryStore.load()+ rebuildLibrary()epicRefresh()if gameDB.byAppID.isEmpty {var dirs: [URL] = []@@ -172,7 +227,7 @@ final class AppState {let notes = try await runner.apply(recipe) { line in Task { @MainActor in self.appendLog(line) } }for n in notes { await MainActor.run { self.appendLog("note: \(n)") } }}- await MainActor.run { self.selectedBottle = name }+ await MainActor.run { self.selectedBottle = name; self.pane = .bottles }}}@@ -374,6 +429,7 @@ final class AppState {installed.compactMap { g in g.install_path.map { (g.app_name, $0) } })self?.epicLoading = falseself?.epicFetchInFlight = false+ self?.rebuildLibrary() // Epic results arrive after refresh(); fold them in}}}diff --git a/Sources/HighballApp/BottleView.swift b/Sources/HighballApp/BottleView.swiftindex d530304..ac3fefb 100644--- a/Sources/HighballApp/BottleView.swift+++ b/Sources/HighballApp/BottleView.swift@@ -170,9 +170,8 @@ struct BottleView: View {}}}- .sheet(isPresented: Binding(get: { state.showEpicSignIn }, set: { state.showEpicSignIn = $0 })) {- EpicSignInSheet()- }+ // EpicSignInSheet is presented at ContentView level so the Library surface can+ // trigger it too — a store account is a library-level concept, not a bottle one.}// MARK: Gamesdiff --git a/Sources/HighballApp/GameDetailView.swift b/Sources/HighballApp/GameDetailView.swiftnew file mode 100644index 0000000..580ff6e--- /dev/null+++ b/Sources/HighballApp/GameDetailView.swift@@ -0,0 +1,142 @@+import SwiftUI+import HighballKit++/// A game's page: wide hero art, verdict chips, then the properties — with the bottle as a+/// property row carrying quick actions, never a prerequisite for Play.+struct GameDetailView: View {+ @Environment(AppState.self) private var state+ let item: LibraryItem+ @State private var showBottleSettings = false++ private var entry: GameDBEntry? { item.steamAppID.flatMap { state.gameDB[$0] } }+ private var bottle: Bottle? { item.bottleName.flatMap { name in state.bottles.first { $0.name == name } } }+ private var blocked: Bool { entry?.isBlocked == true }++ var body: some View {+ ScrollView {+ VStack(alignment: .leading, spacing: 20) {+ hero+ HStack(spacing: 8) {+ if let (label, color) = verdictLabel(entry?.status) {+ Text(label)+ .font(.system(size: 10.5, weight: .semibold).monospaced())+ .padding(.horizontal, 8).padding(.vertical, 3)+ .background(Capsule().fill(color.opacity(0.22)))+ .overlay(Capsule().stroke(color.opacity(0.8), lineWidth: 1))+ .foregroundStyle(color)+ }+ if let r = entry?.renderer {+ Text(r.rawValue.uppercased())+ .font(.system(size: 10.5, weight: .medium).monospaced())+ .foregroundStyle(.secondary)+ }+ if blocked {+ Text(entry?.anticheat?.names.first ?? "anti-cheat")+ .font(.system(size: 10.5).monospaced())+ .foregroundStyle(HB.bad)+ }+ SourceBadge(source: item.source)+ }+ if let notes = entry?.notes {+ Text(notes).font(.callout).foregroundStyle(.secondary)+ .frame(maxWidth: 620, alignment: .leading)+ }+ properties+ Spacer(minLength: 0)+ }+ .padding(.horizontal, 28).padding(.vertical, 20)+ .frame(maxWidth: .infinity, alignment: .leading)+ }+ .background(BottleBackdrop())+ .navigationTitle(item.title)+ .sheet(isPresented: $showBottleSettings) {+ if let bottle { BottleSettingsSheet(bottle: bottle) }+ }+ }++ private var hero: some View {+ ZStack(alignment: .bottomLeading) {+ Color.clear+ .aspectRatio(460 / 215, contentMode: .fit)+ .frame(maxWidth: 640)+ .overlay(+ AsyncImage(url: item.artworkWide ?? item.artworkTall) { phase in+ if case .success(let image) = phase {+ image.resizable().scaledToFill()+ } else {+ ZStack {+ LinearGradient(colors: [HB.card, HB.ground], startPoint: .top, endPoint: .bottom)+ Image(systemName: "gamecontroller").font(.largeTitle).foregroundStyle(.quaternary)+ }+ }+ }+ )+ .clipped()+ LinearGradient(colors: [.black.opacity(0.8), .clear], startPoint: .bottom, endPoint: .center)+ .frame(maxWidth: 640)+ Text(item.title)+ .font(.system(size: 24, weight: .bold, design: .rounded))+ .foregroundStyle(.white).shadow(radius: 4)+ .padding(14)+ }+ .clipShape(RoundedRectangle(cornerRadius: 12))+ .overlay(RoundedRectangle(cornerRadius: 12).stroke(HB.cardStroke))+ }++ private var properties: some View {+ VStack(alignment: .leading, spacing: 1) {+ // Bottle row: the runtime as a property with quick actions.+ HStack(spacing: 10) {+ Image(systemName: "cylinder.split.1x2").foregroundStyle(.secondary)+ VStack(alignment: .leading, spacing: 1) {+ Text(item.bottleName ?? L("Not installed in any bottle")).font(.callout.weight(.semibold))+ if let bottle {+ Text("\(bottle.settings.renderer.rawValue.uppercased()) · \(bottle.settings.engineID)")+ .font(.caption).foregroundStyle(.secondary)+ }+ if !item.otherBottles.isEmpty {+ Text(String(format: L("Also installed in %@"), item.otherBottles.joined(separator: ", ")))+ .font(.caption).foregroundStyle(.tertiary)+ }+ }+ Spacer()+ if item.installed {+ Button(L("Play")) { state.play(item) }+ .buttonStyle(.borderedProminent).disabled(state.busy || blocked)+ if bottle != nil {+ Button { showBottleSettings = true } label: { Image(systemName: "gearshape") }+ Button { if let b = bottle { NSWorkspace.shared.open(b.driveC) } } label: {+ Image(systemName: "folder")+ }+ }+ } else if item.source == .epic {+ Button(L("Install")) { state.install(item) }.disabled(state.busy)+ }+ }+ .padding(12)+ .background(RoundedRectangle(cornerRadius: 10).fill(HB.card))++ Group {+ row(L("Source"), item.source == .steam+ ? "Steam · \(item.steamAppID.map(String.init) ?? "")"+ : item.source == .epic ? "Epic · \(item.epicAppName ?? "")" : L("Windows program"))+ if item.sizeOnDisk > 0 {+ row(L("Size on disk"), ByteCountFormatter.string(fromByteCount: item.sizeOnDisk, countStyle: .file))+ }+ if let played = item.lastPlayed {+ row(L("Last played"), played.formatted(date: .abbreviated, time: .shortened))+ }+ }+ }+ .frame(maxWidth: 640)+ }++ private func row(_ label: String, _ value: String) -> some View {+ HStack {+ Text(label).font(.caption).foregroundStyle(.secondary).frame(width: 110, alignment: .leading)+ Text(value).font(.caption)+ Spacer()+ }+ .padding(.horizontal, 12).padding(.vertical, 7)+ }+}diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swiftindex d3e7cd7..67ea7ab 100644--- a/Sources/HighballApp/HighballApp.swift+++ b/Sources/HighballApp/HighballApp.swift@@ -125,11 +125,37 @@ struct ContentView: View {}.padding(.vertical, 2)}+ // One Library (Phase 2): the primary surface, above the bottles.+ Section {+ let onLibrary = state.pane == .library+ Button {+ state.pane = .library+ } label: {+ HStack(spacing: 8) {+ Image(systemName: onLibrary ? "square.grid.2x2.fill" : "square.grid.2x2")+ .foregroundStyle(onLibrary ? HB.amber : Color.secondary)+ .frame(width: 18)+ Text(L("Library")).fontWeight(onLibrary ? .semibold : .regular)+ Spacer()+ Text("\(state.libraryItems.count)")+ .font(.caption2.monospaced()).foregroundStyle(.tertiary)+ }+ .contentShape(Rectangle())+ }+ .buttonStyle(.plain)+ .padding(.vertical, 5).padding(.horizontal, 7)+ .background(RoundedRectangle(cornerRadius: 7)+ .fill(onLibrary ? HB.amber.opacity(0.16) : .clear))+ .overlay(RoundedRectangle(cornerRadius: 7)+ .stroke(onLibrary ? HB.amber.opacity(0.35) : .clear))+ .listRowInsets(EdgeInsets(top: 1, leading: 6, bottom: 1, trailing: 6))+ }Section(L("Bottles")) {ForEach(state.bottles, id: \.name) { bottle in- let selected = state.selectedBottle == bottle.name+ let selected = state.selectedBottle == bottle.name && state.pane == .bottlesButton {state.selectedBottle = bottle.name+ state.pane = .bottles} label: {HStack(spacing: 8) {Image(systemName: "wineglass\(selected ? ".fill" : "")")@@ -173,12 +199,17 @@ struct ContentView: View {Button { showCreate = true } label: { Label(L("New Bottle"), systemImage: "plus") }}} detail: {- if let name = state.selectedBottle,- let bottle = state.bottles.first(where: { $0.name == name }) {- BottleView(bottle: bottle)- } else {- ContentUnavailableView(L("No bottle selected"), systemImage: "wineglass",- description: Text(L("Create a bottle to install Steam and play.")))+ switch state.pane {+ case .library:+ NavigationStack { LibraryView() }+ case .bottles:+ if let name = state.selectedBottle,+ let bottle = state.bottles.first(where: { $0.name == name }) {+ BottleView(bottle: bottle)+ } else {+ ContentUnavailableView(L("No bottle selected"), systemImage: "wineglass",+ description: Text(L("Create a bottle to install Steam and play.")))+ }}}}@@ -195,6 +226,7 @@ struct ContentView: View {}.sheet(isPresented: $state.showLog) { LogSheet() }.sheet(isPresented: $state.showGPTKLicense) { GPTKLicenseSheet() }+ .sheet(isPresented: $state.showEpicSignIn) { EpicSignInSheet() }.alert(L("Something went wrong"), isPresented: .init(get: { state.errorMessage != nil },set: { if !$0 { state.errorMessage = nil } })) {diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swiftindex 6fc2cd0..8b32771 100644--- a/Sources/HighballApp/L10n.swift+++ b/Sources/HighballApp/L10n.swift@@ -136,6 +136,22 @@ enum L10n {// Unified game cards (library Phase 1)"Not installed": "Non installé","Play with %@": "Jouer avec %@",+ // One Library (Phase 2)+ "Library": "Bibliothèque",+ "Continue playing": "Reprendre",+ "Search your games": "Rechercher vos jeux",+ "All": "Tous",+ "No bottles yet. A bottle is a private Windows environment for your games.":+ "Pas encore de bouteille. Une bouteille est un environnement Windows privé pour vos jeux.",+ "No games yet. Install Steam in a bottle, or connect your Epic account.":+ "Pas encore de jeux. Installez Steam dans une bouteille, ou connectez votre compte Epic.",+ "Nothing matches these filters.": "Rien ne correspond à ces filtres.",+ "Not installed in any bottle": "Installé dans aucune bouteille",+ "Also installed in %@": "Aussi installé dans %@",+ "Source": "Source",+ "Size on disk": "Taille sur le disque",+ "Last played": "Dernière partie",+ "Windows program": "Programme Windows","Hide": "Masquer","Close": "Fermer","Details": "Détails",diff --git a/Sources/HighballApp/LibraryView.swift b/Sources/HighballApp/LibraryView.swiftnew file mode 100644index 0000000..7f505a2--- /dev/null+++ b/Sources/HighballApp/LibraryView.swift@@ -0,0 +1,288 @@+import SwiftUI+import HighballKit++/// SwiftUI re-exports DeveloperToolsSupport.LibraryItem; this pins the name to ours+/// for the whole app target.+typealias LibraryItem = HighballKit.LibraryItem++// One Library (Phase 2): the app's primary surface. One uniform cover grid across all+// bottles and sources — store is a corner badge and a filter chip, never a section; the+// bottle is a per-game property on the detail page, never the navigation.++struct LibraryView: View {+ @Environment(AppState.self) private var state+ @State private var search = ""+ @State private var sourceFilter: LibrarySource?+ @State private var installedOnly = false+ @State private var verifiedOnly = false++ private var filtered: [LibraryItem] {+ state.libraryItems.filter { item in+ if let sourceFilter, item.source != sourceFilter { return false }+ if installedOnly && !item.installed { return false }+ if verifiedOnly {+ guard let appid = item.steamAppID,+ state.gameDB[appid]?.status == "verified-local" else { return false }+ }+ if !search.isEmpty && !item.title.localizedCaseInsensitiveContains(search) { return false }+ return true+ }+ }++ private var continueItems: [LibraryItem] {+ state.libraryItems+ .filter { $0.lastPlayed != nil && $0.installed }+ .sorted { ($0.lastPlayed ?? .distantPast) > ($1.lastPlayed ?? .distantPast) }+ .prefix(10).map { $0 }+ }++ var body: some View {+ ScrollView {+ VStack(alignment: .leading, spacing: 26) {+ if state.busy && !state.stage.isEmpty && !state.showLog {+ Label(state.stage, systemImage: "clock")+ .font(.callout).foregroundStyle(.secondary)+ }+ filterBar+ if !continueItems.isEmpty && search.isEmpty && sourceFilter == nil {+ VStack(alignment: .leading, spacing: 12) {+ HB.eyebrow(L("Continue playing"))+ ScrollView(.horizontal, showsIndicators: false) {+ LazyHStack(spacing: 14) {+ ForEach(continueItems) { item in+ LibraryTile(item: item, entry: entry(for: item), width: 128)+ }+ }+ }+ }+ }+ VStack(alignment: .leading, spacing: 12) {+ HStack(alignment: .firstTextBaseline, spacing: 8) {+ HB.eyebrow(L("Library"))+ Text("\(filtered.count)").font(.caption.monospaced()).foregroundStyle(.tertiary)+ }+ if filtered.isEmpty {+ emptyState+ } else {+ LazyVGrid(columns: [GridItem(.adaptive(minimum: 140, maximum: 190), spacing: 14)],+ spacing: 18) {+ ForEach(filtered) { item in+ LibraryTile(item: item, entry: entry(for: item))+ }+ }+ }+ }+ }+ .padding(.horizontal, 28).padding(.top, 18).padding(.bottom, 40)+ .frame(maxWidth: .infinity, alignment: .leading)+ }+ .background(BottleBackdrop())+ .searchable(text: $search, prompt: L("Search your games"))+ .navigationDestination(for: LibraryItem.self) { GameDetailView(item: $0) }+ }++ private func entry(for item: LibraryItem) -> GameDBEntry? {+ item.steamAppID.flatMap { state.gameDB[$0] }+ }++ private var filterBar: some View {+ HStack(spacing: 8) {+ FilterChip(label: L("All"), on: sourceFilter == nil) { sourceFilter = nil }+ FilterChip(label: "Steam", on: sourceFilter == .steam) { sourceFilter = .steam }+ FilterChip(label: "Epic", on: sourceFilter == .epic) { sourceFilter = .epic }+ FilterChip(label: L("Programs"), on: sourceFilter == .pin) { sourceFilter = .pin }+ Divider().frame(height: 16)+ FilterChip(label: L("Installed"), on: installedOnly) { installedOnly.toggle() }+ FilterChip(label: L("Verified"), on: verifiedOnly) { verifiedOnly.toggle() }+ Spacer()+ }+ }++ @ViewBuilder private var emptyState: some View {+ VStack(alignment: .leading, spacing: 10) {+ if state.bottles.isEmpty {+ Text(L("No bottles yet. A bottle is a private Windows environment for your games."))+ .foregroundStyle(.secondary)+ Button(L("Create your first bottle")) { state.requestCreateBottle = true }+ .buttonStyle(.borderedProminent)+ } else if state.libraryItems.isEmpty {+ Text(L("No games yet. Install Steam in a bottle, or connect your Epic account."))+ .foregroundStyle(.secondary)+ HStack(spacing: 10) {+ if let bottle = state.bottles.first(where: { $0.name == state.selectedBottle }) ?? state.bottles.first {+ Button(L("Install Steam")) { state.applyRecipe("steam", to: bottle) }+ }+ Button(L("Connect Epic account…")) { state.showEpicSignIn = true }+ }+ } else {+ Text(L("Nothing matches these filters.")).foregroundStyle(.secondary)+ }+ }+ .padding(.vertical, 24)+ }+}++struct FilterChip: View {+ let label: String+ let on: Bool+ let action: () -> Void+ var body: some View {+ Button(action: action) {+ Text(label)+ .font(.system(size: 12.5, weight: .semibold))+ .padding(.horizontal, 12).padding(.vertical, 4)+ .background(Capsule().fill(on ? HB.amber : HB.card))+ .overlay(Capsule().stroke(on ? HB.amber : HB.cardStroke))+ .foregroundStyle(on ? Color(red: 0.13, green: 0.08, blue: 0.01) : .secondary)+ }+ .buttonStyle(.plain)+ }+}++/// The 2:3 portrait cover tile. Not GameCard: portrait geometry, title below the art,+/// click = detail, hover-play = launch.+struct LibraryTile: View {+ @Environment(AppState.self) private var state+ let item: LibraryItem+ let entry: GameDBEntry?+ var width: CGFloat? = nil+ @State private var hovering = false++ private var blocked: Bool { entry?.isBlocked == true }+ private var playable: Bool { item.installed && !blocked && !state.busy }++ var body: some View {+ NavigationLink(value: item) {+ VStack(alignment: .leading, spacing: 6) {+ ZStack {+ CoverArt(item: item)+ .saturation(blocked ? 0.15 : (item.installed ? 1 : 0.45))+ .brightness(item.installed ? 0 : -0.08)+ if hovering && playable {+ ZStack {+ Color.black.opacity(0.25)+ Button { state.play(item) } label: {+ ZStack {+ Circle().fill(HB.amber).frame(width: 44, height: 44)+ .shadow(color: .black.opacity(0.45), radius: 9, y: 3)+ Image(systemName: "play.fill")+ .font(.system(size: 17, weight: .bold))+ .foregroundStyle(Color(red: 0.13, green: 0.08, blue: 0.01))+ .offset(x: 1)+ }+ }+ .buttonStyle(.plain)+ }+ .transition(.opacity)+ }+ SourceBadge(source: item.source)+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)+ .padding(6)+ if !item.installed {+ Image(systemName: "arrow.down.circle.fill")+ .foregroundStyle(.white.opacity(0.85))+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topTrailing)+ .padding(6)+ }+ }+ .aspectRatio(2 / 3, contentMode: .fit)+ .clipShape(RoundedRectangle(cornerRadius: 9))+ .overlay(RoundedRectangle(cornerRadius: 9)+ .stroke(hovering ? HB.amber.opacity(0.55) : HB.cardStroke, lineWidth: 1))+ .scaleEffect(hovering ? 1.02 : 1)+ .shadow(color: .black.opacity(hovering ? 0.4 : 0.2), radius: hovering ? 12 : 5, y: 3)++ Text(item.title)+ .font(.system(size: 12, weight: .semibold))+ .lineLimit(1)+ .foregroundStyle(.primary)+ if let (label, color) = verdict {+ Text(label)+ .font(.system(size: 9, weight: .semibold).monospaced())+ .foregroundStyle(color)+ }+ }+ .frame(width: width)+ }+ .buttonStyle(.plain)+ .animation(.spring(duration: 0.2), value: hovering)+ .onHover { hovering = $0 }+ .help(entry?.notes ?? item.title)+ .accessibilityLabel("\(item.title), \(item.source.rawValue)\(item.installed ? "" : ", " + L("Not installed"))")+ }++ private var verdict: (String, Color)? { verdictLabel(entry?.status) }+}++/// Shared verdict mapping (was embedded in GameCard).+func verdictLabel(_ status: String?) -> (String, Color)? {+ switch status {+ case "verified-local": return (L("Verified"), HB.good)+ case "reported-upstream": return (L("Reported"), Color(red: 0.55, green: 0.70, blue: 0.90))+ case "community": return (L("Community"), HB.warn)+ case "blocked-anticheat": return (L("Blocked"), HB.bad)+ default: return nil+ }+}++struct SourceBadge: View {+ let source: LibrarySource+ private var label: String {+ switch source { case .steam: "STEAM"; case .epic: "EPIC"; case .pin: "EXE" }+ }+ var body: some View {+ Text(label)+ .font(.system(size: 8.5, weight: .medium).monospaced())+ .kerning(0.4)+ .padding(.horizontal, 5).padding(.vertical, 2)+ .background(RoundedRectangle(cornerRadius: 4).fill(.black.opacity(0.55)))+ .overlay(RoundedRectangle(cornerRadius: 4).stroke(.white.opacity(0.18), lineWidth: 0.5))+ .foregroundStyle(.white.opacity(0.92))+ }+}++/// Portrait cover with a fallback chain: tall art → wide art scaled to fill → placeholder.+/// AsyncImage can't chain URLs itself, so the state walks the chain on failure. Steam's+/// library_600x900 404s for some older appids — the fallback is not optional polish.+struct CoverArt: View {+ let item: LibraryItem+ @State private var stage = 0++ private var url: URL? {+ switch stage {+ case 0: item.artworkTall ?? item.artworkWide+ case 1: item.artworkTall != nil ? item.artworkWide : nil+ default: nil+ }+ }++ var body: some View {+ GeometryReader { geo in+ if let url {+ AsyncImage(url: url) { phase in+ switch phase {+ case .success(let image):+ image.resizable().scaledToFill()+ case .failure:+ placeholder.onAppear { stage += 1 }+ default:+ Rectangle().fill(HB.card)+ }+ }+ .frame(width: geo.size.width, height: geo.size.height)+ .clipped()+ } else {+ placeholder.frame(width: geo.size.width, height: geo.size.height)+ }+ }+ }++ private var placeholder: some View {+ ZStack {+ LinearGradient(colors: [HB.card, HB.ground], startPoint: .top, endPoint: .bottom)+ Text(String(item.title.prefix(1)))+ .font(.system(size: 34, weight: .bold, design: .rounded))+ .foregroundStyle(.quaternary)+ }+ }+}