Skip to content

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

uninstall a game from its page or its tile (#185, asked on r/macgaming): Steam and the Epic tools do their own removing so their libraries stay right, a pinned program goes through Windows' Add or Remove Programs, and a game with no route says so instead of offering a dead button; the confirmation names who removes it and how much comes back. Drop an image on a tile or a game's hero to set its cover (#175), from Finder or straight out of a browser

Gauthier Piarrette711f6931b012
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index 054ee47..7e97c8f 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -391,10 +391,39 @@ final class AppState {
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 }
+ setCover(for: item, from: url)
+ }
+
+ func setCover(for item: LibraryItem, from url: URL) {
do { try coverStore.setCover(for: item.id, from: url); coverVersion += 1 }
catch { fail(error) }
}
+ /// Takes a dropped image as a game's cover, so nobody has to walk a file browser for it
+ /// (highball#175). A file is read from disk; an image dragged out of a browser arrives as
+ /// bytes with no file, and is taken too. Returns whether anything was claimed, which is what
+ /// SwiftUI uses to decide if the drop was ours.
+ @discardableResult
+ func acceptCoverDrop(_ providers: [NSItemProvider], for item: LibraryItem) -> Bool {
+ guard let provider = providers.first else { return false }
+ if provider.canLoadObject(ofClass: URL.self) {
+ _ = provider.loadObject(ofClass: URL.self) { url, _ in
+ guard let url else { return }
+ Task { @MainActor in self.setCover(for: item, from: url) }
+ }
+ return true
+ }
+ guard let type = provider.registeredTypeIdentifiers.first(where: { UTType($0)?.conforms(to: .image) == true }) else { return false }
+ provider.loadDataRepresentation(forTypeIdentifier: type) { data, _ in
+ guard let data else { return }
+ Task { @MainActor in
+ do { try self.coverStore.setCover(for: item.id, imageData: data); self.coverVersion += 1 }
+ catch { self.fail(error) }
+ }
+ }
+ return true
+ }
+
func resetCover(for item: LibraryItem) {
coverStore.clearCover(for: item.id)
coverVersion += 1
@@ -1274,6 +1303,49 @@ final class AppState {
/// Opens Wine's Add/Remove Programs in the environment, the way to uninstall a Windows
/// program that was installed into it (issue #97). Nothing here is Highball's own data.
+ /// A game the owner asked to remove, held until they confirm (highball#185).
+ var pendingUninstall: (item: LibraryItem, route: Uninstall.Route)?
+
+ /// Offers to remove a game. Nothing happens until the confirmation is answered, and nothing
+ /// deletes files behind a store's back: Steam and the Epic tools do their own removing.
+ func askUninstall(_ item: LibraryItem) {
+ pendingUninstall = (item, Uninstall.route(for: item))
+ }
+
+ /// Carries out the route the ask offered.
+ func uninstallConfirmed() {
+ guard let (item, route) = pendingUninstall else { return }
+ pendingUninstall = nil
+ guard let bottleName = item.bottleName, let bottle = bottles.first(where: { $0.name == bottleName }) else { return }
+ switch route {
+ case let .steam(appID):
+ guard let engine = engine(for: bottle) else { return }
+ let runner = WineRunner(paths: paths, engine: engine, bottle: bottle)
+ let url = Uninstall.steamURL(appID: appID)
+ appendLog("\(item.title): asking Steam to uninstall it (\(url))")
+ Task.detached {
+ // A running client takes the URL and shows its own dialog; with none running the
+ // client starts first, which is what `start` does with a steam:// argument.
+ if (try? await runner.forwardToRunningSteam([url])) == nil {
+ _ = try? await runner.start(bottle.driveC.appending(path: "Program Files (x86)/Steam/steam.exe"), arguments: [url])
+ }
+ }
+ case let .epic(appName):
+ appendLog("\(item.title): asking the Epic tools to uninstall it")
+ let store = EpicStore(paths: paths)
+ runBusy(String(format: L("Removing %@"), item.title),
+ done: DoneState(title: String(format: L("%@ removed"), item.title), ctaTitle: nil, cta: nil),
+ stop: .cancelTask(label: L("Stop"))) { [self] in
+ _ = try store.uninstall(appName) { line in Task { @MainActor in self.appendLog(line) } }
+ await MainActor.run { self.refresh() }
+ }
+ case .windowsUninstaller:
+ openUninstaller(in: bottle)
+ case .none:
+ break
+ }
+ }
+
func openUninstaller(in bottle: Bottle) {
guard let engine = engine(for: bottle) else { return }
let runner = WineRunner(paths: paths, engine: engine, bottle: bottle)
diff --git a/Sources/HighballApp/GameDetailView.swift b/Sources/HighballApp/GameDetailView.swift
index 25d5f78..d17c5ad 100644
--- a/Sources/HighballApp/GameDetailView.swift
+++ b/Sources/HighballApp/GameDetailView.swift
@@ -7,6 +7,7 @@ struct GameDetailView: View {
@Environment(AppState.self) private var state
let passedItem: LibraryItem
@State private var showBottleSettings = false
+ @State private var coverDropTargeted = false
/// The live row: after an install, a delete or a rename, the passed-in copy goes stale.
private var item: LibraryItem { state.libraryItems.first { $0.id == passedItem.id } ?? passedItem }
@State private var showWhy = false
@@ -86,7 +87,12 @@ struct GameDetailView: View {
.padding(14)
}
.clipShape(RoundedRectangle(cornerRadius: 12))
- .overlay(RoundedRectangle(cornerRadius: 12).stroke(HB.cardStroke))
+ // Same as the tile: an image dropped on the hero becomes this game's cover (#175).
+ .onDrop(of: [.image], isTargeted: $coverDropTargeted) { providers in
+ state.acceptCoverDrop(providers, for: item)
+ }
+ .overlay(RoundedRectangle(cornerRadius: 12)
+ .stroke(coverDropTargeted ? HB.amber : HB.cardStroke, lineWidth: coverDropTargeted ? 2 : 1))
}
private var verdictColor: Color {
@@ -260,6 +266,10 @@ struct GameDetailView: View {
.help(L("Opens the game's own folder in the Finder, where mods and config files go."))
}
Button(L("Show the Windows drive")) { NSWorkspace.shared.open(bottle.driveC) }.controlSize(.small)
+ if item.installed {
+ Button(L("Uninstall…"), role: .destructive) { state.askUninstall(item) }.controlSize(.small)
+ .help(L("Steam and the Epic tools do their own uninstalling, so their libraries stay right."))
+ }
if MacAppStub.existing(for: item.title) != nil {
Button(L("Remove the shortcut")) { state.removeMacApp(title: item.title) }.controlSize(.small)
.help(L("Moves this game's shortcut app in ~/Applications/Highball to the Trash."))
diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swift
index bf8206e..1c0645c 100644
--- a/Sources/HighballApp/HighballApp.swift
+++ b/Sources/HighballApp/HighballApp.swift
@@ -203,6 +203,7 @@ struct ContentView: View {
.d3dMetalAsk(state)
.engineAsk(state)
.updateAsk(state)
+ .uninstallAsk(state)
.rendererTrialAsk(state)
.modesetTrialAsk(state)
.homeMoveAsk(state)
@@ -338,6 +339,19 @@ private extension View {
Text(GamePageCopy.updateAsk(recipe: pending.recipe, engineID: pending.engineID, canPlay: pending.play != nil))
}
}
+ @MainActor func uninstallAsk(_ state: AppState) -> some View {
+ self.alert(state.pendingUninstall.map { String(format: L("Remove %@?"), $0.item.title) } ?? "",
+ isPresented: .init(get: { state.pendingUninstall != nil }, set: { if !$0 { state.pendingUninstall = nil } }),
+ presenting: state.pendingUninstall) { pending in
+ if Uninstall.isActionable(pending.route) {
+ Button(L("Remove"), role: .destructive) { state.uninstallConfirmed() }
+ }
+ Button(L("Cancel"), role: .cancel) { state.pendingUninstall = nil }
+ } message: { pending in
+ Text(Uninstall.confirmation(title: pending.item.title, route: pending.route, sizeOnDisk: pending.item.sizeOnDisk))
+ }
+ }
+
@MainActor func rendererTrialAsk(_ state: AppState) -> some View {
self.alert(state.rendererTrial.map { String(format: L("Try %@ for %@ next time?"), GamePageCopy.plainName($0.next), $0.title) } ?? "",
isPresented: .init(get: { state.rendererTrial != nil }, set: { if !$0 { state.rendererTrial = nil } }),
diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swift
index 6787db3..a1b5451 100644
--- a/Sources/HighballApp/L10n.swift
+++ b/Sources/HighballApp/L10n.swift
@@ -471,6 +471,17 @@ enum L10n {
"Delete this environment? Its Windows drive and everything installed in it are removed, including the game saves kept in its Documents folder.": "Supprimer cet environnement ? Son disque Windows et tout ce qui y est installé seront supprimés, y compris les sauvegardes gardées dans son dossier Documents.",
"Keep game files inside this environment": "Garder les fichiers des jeux dans cet environnement",
"Show the game's folder": "Afficher le dossier du jeu",
+ "Uninstall…": "Désinstaller…",
+ "Engine installed again": "Moteur réinstallé",
+ "Installing engine %@ again": "Réinstallation du moteur %@",
+ "Scale %@ to the screen next time?": "Adapter %@ à l'écran la prochaine fois ?",
+ "Scale it to the screen": "L'adapter à l'écran",
+ "Its last run asked Windows for a fullscreen size this Mac did not switch to. That is what leaves a game small in a corner, or with the mouse landing away from what it draws. Highball can have Wine report the change as done and scale the game to the screen instead. This game only; undo it under Advanced on its page.": "Sa dernière session a demandé à Windows une résolution plein écran que ce Mac n'a pas appliquée. C'est ce qui laisse un jeu petit dans un coin, ou avec la souris qui tombe à côté de ce qui est dessiné. Highball peut faire répondre à Wine que le changement a eu lieu et adapter l'image à l'écran. Pour ce jeu seulement, annulable dans Avancé sur sa page.",
+ "Remove %@?": "Supprimer %@ ?",
+ "Remove": "Supprimer",
+ "Removing %@": "Suppression de %@",
+ "%@ removed": "%@ supprimé",
+ "Steam and the Epic tools do their own uninstalling, so their libraries stay right.": "Steam et les outils Epic font eux-mêmes la désinstallation, pour que leurs bibliothèques restent justes.",
"Opens the game's own folder in the Finder, where mods and config files go.": "Ouvre le dossier du jeu dans le Finder, là où vont les mods et les fichiers de configuration.",
"On, the Windows Documents folder lives inside this environment, so games that save there (FromSoftware, Bandai Namco, the Sims and others) no longer write into your Mac's Documents. Files already in your Mac's Documents stay there and the game starts fresh here. Off again keeps the environment's folder as “Documents (environment)”. Saves kept inside go with the environment when you delete it.": "Activé, le dossier Documents de Windows vit dans cet environnement, donc les jeux qui y sauvegardent (FromSoftware, Bandai Namco, les Sims et d'autres) n'écrivent plus dans le dossier Documents de votre Mac. Les fichiers déjà dans le Documents du Mac y restent et le jeu repart de zéro ici. Désactivé, le dossier de l'environnement est gardé sous le nom « Documents (environment) ». Les sauvegardes gardées à l'intérieur partent avec l'environnement quand vous le supprimez.",
"Deleting the %@ environment": "Suppression de l'environnement %@",
diff --git a/Sources/HighballApp/LibraryView.swift b/Sources/HighballApp/LibraryView.swift
index 6646762..7ab0964 100644
--- a/Sources/HighballApp/LibraryView.swift
+++ b/Sources/HighballApp/LibraryView.swift
@@ -200,6 +200,7 @@ struct LibraryTile: View {
let entry: GameDBEntry?
var width: CGFloat? = nil
@State private var hovering = false
+ @State private var coverDropTargeted = false
private var blocked: Bool { entry?.isBlocked == true }
private var playable: Bool { item.installed && !blocked && !state.busy }
@@ -249,8 +250,15 @@ struct LibraryTile: View {
}
.aspectRatio(2 / 3, contentMode: .fit)
.clipShape(RoundedRectangle(cornerRadius: 9))
+ // An image dropped on the tile becomes the cover, so nobody has to walk a file
+ // browser for it (highball#175). Only images are claimed here, so a dropped
+ // Windows program still reaches the window's own handler and runs.
+ .onDrop(of: [.image], isTargeted: $coverDropTargeted) { providers in
+ state.acceptCoverDrop(providers, for: item)
+ }
.overlay(RoundedRectangle(cornerRadius: 9)
- .stroke(hovering ? HB.amber.opacity(0.55) : HB.cardStroke, lineWidth: 1))
+ .stroke(coverDropTargeted ? HB.amber : (hovering ? HB.amber.opacity(0.55) : HB.cardStroke),
+ lineWidth: coverDropTargeted ? 2 : 1))
.scaleEffect(hovering ? 1.02 : 1)
.shadow(color: .black.opacity(hovering ? 0.4 : 0.2), radius: hovering ? 12 : 5, y: 3)
@@ -292,6 +300,12 @@ struct LibraryTile: View {
Divider()
Button(L("Remove from list"), role: .destructive) { state.removePin(pin, from: bottle) }
}
+ // Removing the game itself, not just the entry: asked for on r/macgaming because
+ // there was nowhere to do it (highball#185).
+ if item.installed {
+ Divider()
+ Button(L("Uninstall…"), role: .destructive) { state.askUninstall(item) }
+ }
}
.accessibilityLabel("\(item.title), \(item.source.rawValue)\(item.installed ? "" : ", " + L("Not installed"))")
}
diff --git a/Sources/HighballKit/EpicStore.swift b/Sources/HighballKit/EpicStore.swift
index 05340aa..f3d445d 100644
--- a/Sources/HighballKit/EpicStore.swift
+++ b/Sources/HighballKit/EpicStore.swift
@@ -194,6 +194,16 @@ public struct EpicStore: Sendable {
return try runStreaming(Self.installArguments(appName: appName, basePath: base.path), onLine: onLine)
}
+ static func uninstallArguments(appName: String) -> [String] { ["uninstall", appName, "-y"] }
+
+ /// Removes a game legendary installed. Legendary owns the Epic install state, so it does the
+ /// deleting and its library stays right; deleting the folder ourselves would leave it
+ /// believing the game is still there (highball#185).
+ @discardableResult
+ public func uninstall(_ appName: String, onLine: (@Sendable (String) -> Void)? = nil) throws -> Int32 {
+ try runStreaming(Self.uninstallArguments(appName: appName), onLine: onLine)
+ }
+
public struct LaunchInfo: Sendable {
public let executable: URL
public let arguments: [String]
diff --git a/Sources/HighballKit/Library.swift b/Sources/HighballKit/Library.swift
index bd2ece7..84ca893 100644
--- a/Sources/HighballKit/Library.swift
+++ b/Sources/HighballKit/Library.swift
@@ -235,6 +235,26 @@ public struct CoverStore: Sendable {
try png.write(to: dest, options: .atomic)
}
+ /// Same, from image bytes rather than a file. An image dragged out of a browser arrives as
+ /// data with no file behind it, and refusing that would make the drop look broken (#175).
+ public func setCover(for id: String, imageData: Data) throws {
+ try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
+ let png = try Self.normalized(imageData: imageData)
+ clearCover(for: id)
+ try png.write(to: dir.appending(path: Self.filename(for: id)).appendingPathExtension("png"), options: .atomic)
+ }
+
+ public static func normalized(imageData: Data) throws -> Data {
+ guard let src = CGImageSourceCreateWithData(imageData as CFData, nil),
+ let image = CGImageSourceCreateThumbnailAtIndex(src, 0, [
+ kCGImageSourceCreateThumbnailFromImageAlways: true,
+ kCGImageSourceCreateThumbnailWithTransform: true,
+ kCGImageSourceThumbnailMaxPixelSize: 4096] as CFDictionary) else {
+ throw HighballError.invalid("That is not an image Highball can read. Drop a PNG, JPEG or HEIC file.")
+ }
+ return try normalized(image)
+ }
+
/// The stored form of an image file: 2:3, capped, PNG. Refuses what ImageIO cannot read.
public static func normalized(imageAt url: URL) throws -> Data {
// A thumbnail request applies the EXIF orientation and pre-shrinks a huge photo before
diff --git a/Sources/HighballKit/Uninstall.swift b/Sources/HighballKit/Uninstall.swift
new file mode 100644
index 0000000..a80731c
--- /dev/null
+++ b/Sources/HighballKit/Uninstall.swift
@@ -0,0 +1,72 @@
+import Foundation
+
+/// What removing a game means, which is not the same thing for every game.
+///
+/// Asked on r/macgaming as "how can i uninstall the game? couldn't find the button to do it"
+/// (highball#185). Before this there was no answer on a game's page at all: Steam games came out
+/// through the Steam client, anything with its own installer through Wine's Add/Remove Programs
+/// in the environment's settings, and everything else only by deleting the whole environment.
+///
+/// The rule that shapes this: a store's library is the store's to keep. Deleting a Steam game's
+/// folder from underneath the client leaves Steam believing it is installed, and the next launch
+/// repairs or redownloads it, so a Steam game is handed to Steam's own uninstall dialog and
+/// Highball does not touch the files. The same goes for Epic through legendary.
+public enum Uninstall {
+ public enum Route: Equatable, Sendable {
+ /// Hand it to the running Steam client (`steam://uninstall/<appid>`), which asks its own
+ /// confirmation and does the removing.
+ case steam(appID: Int)
+ /// Legendary owns Epic installs, so it does the removing.
+ case epic(appName: String)
+ /// Wine's Add/Remove Programs, for a program that came with its own uninstaller.
+ case windowsUninstaller
+ /// Nothing can be run for it. The reason is shown to the person, who then decides.
+ case none(reason: String)
+ }
+
+ /// The route for one library item. Pure, so the wording and the choice are tested without a
+ /// Steam client, a prefix or a network.
+ public static func route(for item: LibraryItem) -> Route {
+ switch item.source {
+ case .steam:
+ guard let appID = item.steamAppID else {
+ return .none(reason: "Highball does not know this game's Steam id, so Steam cannot be asked to remove it.")
+ }
+ return .steam(appID: appID)
+ case .epic:
+ guard let name = item.epicAppName else {
+ return .none(reason: "Highball does not know this game's Epic id, so the Epic tools cannot be asked to remove it.")
+ }
+ return .epic(appName: name)
+ case .pin:
+ return .windowsUninstaller
+ }
+ }
+
+ /// The question asked before anything happens. It names the game, says who does the removing,
+ /// and says how much space comes back when that is known, because "are you sure" without a
+ /// figure is a question nobody can answer.
+ public static func confirmation(title: String, route: Route, sizeOnDisk: Int64) -> String {
+ let size = sizeOnDisk > 0 ? " That frees \(ByteCountFormatter.string(fromByteCount: sizeOnDisk, countStyle: .file))." : ""
+ switch route {
+ case .steam:
+ return "Remove \(title)? Steam does the uninstalling and asks you to confirm in its own window, so its library stays right.\(size)"
+ case .epic:
+ return "Remove \(title)? The Epic tools do the uninstalling, so their library stays right.\(size)"
+ case .windowsUninstaller:
+ return "Remove \(title)? Highball opens Windows' Add or Remove Programs in this environment, where you pick it from the list. A game with no uninstaller of its own will not be in that list, and then the only way to remove it is to delete the environment."
+ case let .none(reason):
+ return reason
+ }
+ }
+
+ /// True when the route can actually do something, so a view can offer the button only then
+ /// and never open a dialog whose only answer is "nothing happens".
+ public static func isActionable(_ route: Route) -> Bool {
+ if case .none = route { return false }
+ return true
+ }
+
+ /// The argument handed to the Steam client. Its own dialog does the rest.
+ public static func steamURL(appID: Int) -> String { "steam://uninstall/\(appID)" }
+}
diff --git a/Tests/HighballKitTests/CoverDropTests.swift b/Tests/HighballKitTests/CoverDropTests.swift
new file mode 100644
index 0000000..8dc396b
--- /dev/null
+++ b/Tests/HighballKitTests/CoverDropTests.swift
@@ -0,0 +1,73 @@
+import XCTest
+import CoreGraphics
+import ImageIO
+import UniformTypeIdentifiers
+@testable import HighballKit
+
+/// highball#175: dropping an image on a game should set its cover, including an image dragged out
+/// of a browser, which arrives as bytes with no file behind it. Whatever the source, what gets
+/// stored is the same normalised form a chosen file produces.
+final class CoverDropTests: XCTestCase {
+ private var home: URL!
+ private var store: CoverStore!
+
+ override func setUpWithError() throws {
+ home = FileManager.default.temporaryDirectory.appending(path: "covers-\(UUID().uuidString)")
+ try FileManager.default.createDirectory(at: home, withIntermediateDirectories: true)
+ store = CoverStore(paths: HighballPaths(home: home))
+ }
+
+ override func tearDownWithError() throws {
+ try? FileManager.default.removeItem(at: home)
+ }
+
+ private func pngData(width: Int, height: Int) throws -> Data {
+ let ctx = CGContext(data: nil, width: width, height: height, bitsPerComponent: 8, bytesPerRow: 0,
+ space: CGColorSpaceCreateDeviceRGB(),
+ bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!
+ ctx.setFillColor(CGColor(red: 0.2, green: 0.4, blue: 0.8, alpha: 1))
+ ctx.fill(CGRect(x: 0, y: 0, width: width, height: height))
+ let out = NSMutableData()
+ let dest = CGImageDestinationCreateWithData(out, UTType.png.identifier as CFString, 1, nil)!
+ CGImageDestinationAddImage(dest, ctx.makeImage()!, nil)
+ XCTAssertTrue(CGImageDestinationFinalize(dest))
+ return out as Data
+ }
+
+ func testImageBytesBecomeACoverJustLikeAFile() throws {
+ let data = try pngData(width: 800, height: 400)
+ try store.setCover(for: "steam:620", imageData: data)
+ let url = try XCTUnwrap(store.coverURL(for: "steam:620"), "no cover was stored")
+ let stored = try XCTUnwrap(CGImageSourceCreateWithURL(url as CFURL, nil).flatMap { CGImageSourceCreateImageAtIndex($0, 0, nil) })
+ XCTAssertEqual(Double(stored.width) / Double(stored.height), CoverStore.aspect, accuracy: 0.01,
+ "a dropped image is cropped to the same 2:3 as a chosen one")
+ XCTAssertLessThanOrEqual(stored.height, CoverStore.maxHeight)
+ }
+
+ func testAFileAndTheSameBytesGiveTheSameCover() throws {
+ let data = try pngData(width: 600, height: 900)
+ let file = home.appending(path: "art.png")
+ try data.write(to: file)
+ try store.setCover(for: "pin:a", from: file)
+ let fromFile = try Data(contentsOf: try XCTUnwrap(store.coverURL(for: "pin:a")))
+ try store.setCover(for: "pin:b", imageData: data)
+ let fromBytes = try Data(contentsOf: try XCTUnwrap(store.coverURL(for: "pin:b")))
+ XCTAssertEqual(fromFile, fromBytes, "the drop must not produce a different image from the file chooser")
+ }
+
+ func testRubbishBytesAreRefusedWithSomethingToDoAboutIt() {
+ XCTAssertThrowsError(try store.setCover(for: "steam:1", imageData: Data("not an image".utf8))) { error in
+ let text = "\(error)"
+ XCTAssertTrue(text.contains("PNG"), text)
+ XCTAssertNil(self.store.coverURL(for: "steam:1"), "nothing is stored when the bytes are not an image")
+ }
+ }
+
+ func testANewCoverReplacesTheOldOneRatherThanPilingUp() throws {
+ try store.setCover(for: "steam:620", imageData: try pngData(width: 400, height: 600))
+ try store.setCover(for: "steam:620", imageData: try pngData(width: 1200, height: 800))
+ let dir = home.appending(path: "covers")
+ let files = try FileManager.default.contentsOfDirectory(atPath: dir.path).filter { !$0.hasPrefix(".") }
+ XCTAssertEqual(files.count, 1, "one cover per game: \(files)")
+ }
+}
diff --git a/Tests/HighballKitTests/UninstallTests.swift b/Tests/HighballKitTests/UninstallTests.swift
new file mode 100644
index 0000000..c3dca1d
--- /dev/null
+++ b/Tests/HighballKitTests/UninstallTests.swift
@@ -0,0 +1,62 @@
+import XCTest
+@testable import HighballKit
+
+/// highball#185, asked on r/macgaming: there was no way to remove a game from its page. The rule
+/// these tests hold to is that a store's library is the store's to keep, so Highball never deletes
+/// a Steam or Epic game's files itself.
+final class UninstallTests: XCTestCase {
+ private func item(_ source: HighballKit.LibrarySource, steam: Int? = nil, epic: String? = nil, size: Int64 = 0) -> HighballKit.LibraryItem {
+ HighballKit.LibraryItem(source: source, id: "x", title: "Portal 2", bottleName: "Games", installed: true,
+ steamAppID: steam, epicAppName: epic, sizeOnDisk: size)
+ }
+
+ func testASteamGameIsHandedToSteam() {
+ XCTAssertEqual(Uninstall.route(for: item(.steam, steam: 620)), .steam(appID: 620))
+ XCTAssertEqual(Uninstall.steamURL(appID: 620), "steam://uninstall/620",
+ "the client shows its own dialog and does the removing")
+ }
+
+ func testAnEpicGameIsHandedToTheEpicTools() {
+ XCTAssertEqual(Uninstall.route(for: item(.epic, epic: "Fortnite")), .epic(appName: "Fortnite"))
+ XCTAssertEqual(EpicStore.uninstallArguments(appName: "Fortnite"), ["uninstall", "Fortnite", "-y"])
+ }
+
+ func testAPinnedProgramGoesThroughWindowsAddRemove() {
+ XCTAssertEqual(Uninstall.route(for: item(.pin)), .windowsUninstaller)
+ }
+
+ /// A store entry with no id cannot be handed anywhere, and offering a button whose only
+ /// outcome is nothing happening is worse than saying so.
+ func testAStoreEntryWithoutAnIdSaysSoInsteadOfOfferingAButton() {
+ for route in [Uninstall.route(for: item(.steam)), Uninstall.route(for: item(.epic))] {
+ guard case let .none(reason) = route else { return XCTFail("expected none, got \(route)") }
+ XCTAssertFalse(Uninstall.isActionable(route))
+ XCTAssertFalse(reason.isEmpty)
+ }
+ XCTAssertTrue(Uninstall.isActionable(.steam(appID: 1)))
+ XCTAssertTrue(Uninstall.isActionable(.windowsUninstaller))
+ }
+
+ func testTheQuestionNamesWhoRemovesItAndWhatComesBack() {
+ let steam = Uninstall.confirmation(title: "Portal 2", route: .steam(appID: 620), sizeOnDisk: 12_884_901_888)
+ XCTAssertTrue(steam.contains("Portal 2"), steam)
+ XCTAssertTrue(steam.contains("Steam does the uninstalling"), steam)
+ XCTAssertTrue(steam.contains("GB"), "a confirmation without a figure is unanswerable: \(steam)")
+ let unknownSize = Uninstall.confirmation(title: "Portal 2", route: .steam(appID: 620), sizeOnDisk: 0)
+ XCTAssertFalse(unknownSize.contains("frees"), "no invented figure when the size is unknown")
+ }
+
+ /// The Windows route can come up empty, and the question says so rather than promising.
+ func testTheWindowsRouteAdmitsItMayNotListTheGame() {
+ let text = Uninstall.confirmation(title: "Dark Omen", route: .windowsUninstaller, sizeOnDisk: 0)
+ XCTAssertTrue(text.contains("will not be in that list"), text)
+ XCTAssertTrue(text.contains("delete the environment"), text)
+ }
+
+ func testTheReasonIsWhatAnUnroutableGameShows() {
+ let route = Uninstall.route(for: item(.steam))
+ guard case let .none(reason) = route else { return XCTFail("expected none") }
+ XCTAssertEqual(Uninstall.confirmation(title: "Portal 2", route: route, sizeOnDisk: 99), reason,
+ "no size talk when nothing can be removed")
+ }
+}