Skip to content

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

Library Phase 3: user-chosen cover art

Gauthier Piarrette324c12e79614
diff --git a/GameDetailView.swiftdeps~ b/GameDetailView.swiftdeps~
new file mode 100644
index 0000000..2e02c37
Binary files /dev/null and b/GameDetailView.swiftdeps~ differ
diff --git a/LibraryView.swiftdeps~ b/LibraryView.swiftdeps~
new file mode 100644
index 0000000..2a53dbe
Binary files /dev/null and b/LibraryView.swiftdeps~ differ
diff --git a/ProgressParser.swiftdeps~ b/ProgressParser.swiftdeps~
new file mode 100644
index 0000000..f3915fe
Binary files /dev/null and b/ProgressParser.swiftdeps~ differ
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index f1052b1..f435dff 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -101,6 +101,25 @@ final class AppState {
rebuildLibrary()
}
+ // Custom covers (Phase 3): local images only, chosen by the user.
+ var coverStore: CoverStore { CoverStore(paths: paths) }
+ /// Bumped when a cover changes so tiles reload their local image.
+ var coverVersion = 0
+
+ func chooseCover(for item: LibraryItem) {
+ let panel = NSOpenPanel()
+ panel.allowedContentTypes = [.image]
+ panel.message = String(format: L("Choose a cover image for %@"), item.title)
+ guard panel.runModal() == .OK, let url = panel.url else { return }
+ do { try coverStore.setCover(for: item.id, from: url); coverVersion += 1 }
+ catch { errorMessage = "\(error)" }
+ }
+
+ func resetCover(for item: LibraryItem) {
+ coverStore.clearCover(for: item.id)
+ coverVersion += 1
+ }
+
// Epic (via Legendary; see EpicStore)
var epicSignedIn = false
var epicOwned: [EpicStore.Game] = []
diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swift
index 8b32771..5186df4 100644
--- a/Sources/HighballApp/L10n.swift
+++ b/Sources/HighballApp/L10n.swift
@@ -152,6 +152,9 @@ enum L10n {
"Size on disk": "Taille sur le disque",
"Last played": "Dernière partie",
"Windows program": "Programme Windows",
+ "Choose cover image…": "Choisir une image de couverture…",
+ "Reset cover": "Réinitialiser la couverture",
+ "Choose a cover image for %@": "Choisir une image de couverture pour %@",
"Hide": "Masquer",
"Close": "Fermer",
"Details": "Détails",
diff --git a/Sources/HighballApp/LibraryView.swift b/Sources/HighballApp/LibraryView.swift
index 7f505a2..94f41b2 100644
--- a/Sources/HighballApp/LibraryView.swift
+++ b/Sources/HighballApp/LibraryView.swift
@@ -208,6 +208,13 @@ struct LibraryTile: View {
.animation(.spring(duration: 0.2), value: hovering)
.onHover { hovering = $0 }
.help(entry?.notes ?? item.title)
+ .contextMenu {
+ if playable { Button(L("Play")) { state.play(item) } }
+ Button(L("Choose cover image…")) { state.chooseCover(for: item) }
+ if state.coverStore.coverURL(for: item.id) != nil {
+ Button(L("Reset cover")) { state.resetCover(for: item) }
+ }
+ }
.accessibilityLabel("\(item.title), \(item.source.rawValue)\(item.installed ? "" : ", " + L("Not installed"))")
}
@@ -245,6 +252,7 @@ struct SourceBadge: View {
/// 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 {
+ @Environment(AppState.self) private var state
let item: LibraryItem
@State private var stage = 0
@@ -258,7 +266,14 @@ struct CoverArt: View {
var body: some View {
GeometryReader { geo in
- if let url {
+ // A user-chosen cover always wins (coverVersion invalidates after changes).
+ if let custom = state.coverStore.coverURL(for: item.id),
+ let image = NSImage(contentsOf: custom) {
+ Image(nsImage: image).resizable().scaledToFill()
+ .frame(width: geo.size.width, height: geo.size.height)
+ .clipped()
+ .id(state.coverVersion)
+ } else if let url {
AsyncImage(url: url) { phase in
switch phase {
case .success(let image):
diff --git a/Sources/HighballKit/Library.swift b/Sources/HighballKit/Library.swift
index ce46c1f..f28ef28 100644
--- a/Sources/HighballKit/Library.swift
+++ b/Sources/HighballKit/Library.swift
@@ -166,3 +166,43 @@ public struct LibraryStore: Sendable {
}
}
}
+
+/// User-chosen cover art (Phase 3): a local image per library item, overriding the store's
+/// artwork. Pure files under covers/ at the Highball home — no API, no keys; the automatic
+/// pipeline (SteamGridDB) stays a deliberate non-feature until its ToS/key story is decided.
+public struct CoverStore: Sendable {
+ public let paths: HighballPaths
+ public init(paths: HighballPaths = HighballPaths()) { self.paths = paths }
+
+ var dir: URL { paths.home.appending(path: "covers", directoryHint: .isDirectory) }
+
+ /// Item ids contain ':'; filenames must not. Deterministic and collision-safe for our
+ /// id shapes (bottle names already reject path characters — issue #12).
+ static func filename(for id: String) -> String {
+ id.replacingOccurrences(of: ":", with: "_").replacingOccurrences(of: "/", with: "_")
+ }
+
+ /// The stored override for an item, if any.
+ public func coverURL(for id: String) -> URL? {
+ let base = dir.appending(path: Self.filename(for: id))
+ for ext in ["png", "jpg", "jpeg", "heic", "webp"] {
+ let url = base.appendingPathExtension(ext)
+ if FileManager.default.fileExists(atPath: url.path) { return url }
+ }
+ return nil
+ }
+
+ /// Copies the chosen image in (replacing any previous override).
+ public func setCover(for id: String, from source: URL) throws {
+ try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
+ clearCover(for: id)
+ let ext = source.pathExtension.isEmpty ? "png" : source.pathExtension.lowercased()
+ let dest = dir.appending(path: Self.filename(for: id)).appendingPathExtension(ext)
+ try FileManager.default.copyItem(at: source, to: dest)
+ }
+
+ public func clearCover(for id: String) {
+ guard let existing = coverURL(for: id) else { return }
+ try? FileManager.default.removeItem(at: existing)
+ }
+}
diff --git a/Tests/HighballKitTests/LibraryTests.swift b/Tests/HighballKitTests/LibraryTests.swift
index fd0d457..934f6bd 100644
--- a/Tests/HighballKitTests/LibraryTests.swift
+++ b/Tests/HighballKitTests/LibraryTests.swift
@@ -82,6 +82,26 @@ final class LibraryTests: XCTestCase {
XCTAssertEqual(store.load(), [:])
}
+ func testCoverStoreRoundTrip() throws {
+ let tmp = FileManager.default.temporaryDirectory.appending(path: "hb-cover-\(UUID().uuidString)")
+ defer { try? FileManager.default.removeItem(at: tmp) }
+ let store = CoverStore(paths: HighballPaths(home: tmp))
+ XCTAssertNil(store.coverURL(for: "steam:620"))
+ let src = tmp.appending(path: "src.png")
+ try FileManager.default.createDirectory(at: tmp, withIntermediateDirectories: true)
+ try Data([0x89, 0x50, 0x4E, 0x47]).write(to: src)
+ try store.setCover(for: "steam:620", from: src)
+ let stored = store.coverURL(for: "steam:620")
+ XCTAssertEqual(stored?.lastPathComponent, "steam_620.png", "id colon sanitized, extension kept")
+ // Replacing with a different extension removes the old file.
+ let jpg = tmp.appending(path: "src2.jpg")
+ try Data([0xFF, 0xD8]).write(to: jpg)
+ try store.setCover(for: "steam:620", from: jpg)
+ XCTAssertEqual(store.coverURL(for: "steam:620")?.pathExtension, "jpg")
+ store.clearCover(for: "steam:620")
+ XCTAssertNil(store.coverURL(for: "steam:620"))
+ }
+
func testACFLastPlayedSeedsShelf() {
let acf = """
"AppState" { "appid" "620" "name" "Portal 2" "StateFlags" "4" "LastPlayed" "1756300000" }