Skip to content

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

feat: Epic Games in the app (#14, #8)

Gauthier Piarrette9dda82531f77
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index c15cf85..e841562 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -35,6 +35,14 @@ final class AppState {
var errorMessage: String?
+ // Epic (via Legendary; see EpicStore)
+ var epicSignedIn = false
+ var epicOwned: [EpicStore.Game] = []
+ var epicInstalled: Set<String> = []
+ var epicLoading = false
+ private var epicFetchInFlight = false
+ var showEpicSignIn = false
+
/// A Windows program awaiting the run/pin choice (from drag-drop, the File menu, or the button).
var pendingRun: URL?
@@ -58,6 +66,7 @@ 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 })
+ epicRefresh()
if gameDB.byAppID.isEmpty {
var dirs: [URL] = []
if let res = Bundle.main.resourceURL { dirs.append(res.appending(path: "db-games")) }
@@ -304,6 +313,74 @@ final class AppState {
}
}
+ // MARK: Epic
+
+ var epicStore: EpicStore { EpicStore(paths: paths) }
+
+ func epicRefresh() {
+ epicSignedIn = epicStore.isAuthenticated
+ guard epicSignedIn else { epicOwned = []; epicInstalled = []; return }
+ guard !epicFetchInFlight else { return }
+ epicFetchInFlight = true
+ epicLoading = epicOwned.isEmpty
+ Task.detached { [store = epicStore] in
+ let owned = (try? store.ownedGames()) ?? []
+ let installed = (try? store.installedAppNames()) ?? []
+ await MainActor.run { [weak self] in
+ self?.epicOwned = owned.sorted { $0.app_title < $1.app_title }
+ self?.epicInstalled = installed
+ self?.epicLoading = false
+ self?.epicFetchInFlight = false
+ }
+ }
+ }
+
+ func epicSignIn(code: String) {
+ runBusy("Connecting your Epic account", showLogSheet: false) { [self] in
+ let store = epicStore
+ _ = try await store.ensureInstalled()
+ try await Task.detached { try store.authenticate(code: code) }.value
+ await MainActor.run { self.epicRefresh() }
+ }
+ }
+
+ func epicInstall(_ game: EpicStore.Game, in bottle: Bottle) {
+ runBusy("Installing \(game.app_title)") { [self] in
+ let store = epicStore
+ let status = try await Task.detached {
+ try store.install(game.app_name, into: bottle) { line in
+ Task { @MainActor in self.appendLog(line) }
+ }
+ }.value
+ guard status == 0 else {
+ throw HighballError.processFailed(command: "epic install", status: status, output: "see the log above")
+ }
+ await MainActor.run { self.epicRefresh() }
+ }
+ }
+
+ func epicPlay(_ game: EpicStore.Game, in bottle: Bottle, renderer: Renderer? = .dxvk) {
+ guard let engine = engine(for: bottle) else { return }
+ runBusy("Running \(game.app_title)", showLogSheet: false) { [self] in
+ let store = epicStore
+ // Fresh single-use token, fetched off the main thread right before launch.
+ let info = try await Task.detached { try store.launchInfo(game.app_name) }.value
+ let runner = WineRunner(paths: paths, engine: engine, bottle: bottle)
+ let result = try await runner.start(info.executable, arguments: info.arguments,
+ renderer: renderer, extraEnvironment: info.environment,
+ workingDirectory: info.workingDirectory) { line in
+ Task { @MainActor in self.appendLog(line) }
+ }
+ if result.crashedEarly {
+ await MainActor.run {
+ self.crashSuggestion = CrashSuggestion(program: game.app_title,
+ renderer: renderer == .dxvk ? .d3dmetal : .dxvk,
+ logPath: result.log.path)
+ }
+ }
+ }
+ }
+
func setRetina(_ on: Bool, in bottle: Bottle) {
guard let engine = engine(for: bottle) else { return }
var copy = bottle
diff --git a/Sources/HighballApp/BottleView.swift b/Sources/HighballApp/BottleView.swift
index 529d699..87e9635 100644
--- a/Sources/HighballApp/BottleView.swift
+++ b/Sources/HighballApp/BottleView.swift
@@ -68,6 +68,7 @@ struct BottleView: View {
gamesSection
launchersSection
if !customPins.isEmpty { programsSection }
+ epicSection
HStack(spacing: 6) {
Button { state.chooseProgramToRun() } label: {
Label(L("Run a Windows program…"), systemImage: "folder")
@@ -119,6 +120,64 @@ struct BottleView: View {
}
}
+ // MARK: Epic
+
+ @ViewBuilder private var epicSection: some View {
+ VStack(alignment: .leading, spacing: 12) {
+ HStack(alignment: .firstTextBaseline, spacing: 8) {
+ HB.eyebrow(L("Epic Games"))
+ if state.epicSignedIn {
+ Text("\(state.epicOwned.count)").font(.caption.monospaced()).foregroundStyle(.tertiary)
+ }
+ }
+ if !state.epicSignedIn {
+ HStack(spacing: 10) {
+ Button(L("Connect Epic account…")) { state.showEpicSignIn = true }
+ Text(L("Installs go through the open source Legendary client, so the Epic launcher's broken install flow is never involved."))
+ .font(.caption).foregroundStyle(.secondary)
+ }
+ } else if state.epicLoading {
+ HStack(spacing: 8) { ProgressView().controlSize(.small); Text(L("Loading your Epic library…")).font(.callout).foregroundStyle(.secondary) }
+ } else if state.epicOwned.isEmpty {
+ Text(L("No games on this Epic account yet. Claimed games appear here."))
+ .font(.callout).foregroundStyle(.secondary)
+ } else {
+ LazyVGrid(columns: [GridItem(.adaptive(minimum: 150, maximum: 210), spacing: 12)], spacing: 12) {
+ ForEach(state.epicOwned, id: \.app_name) { g in
+ let installed = state.epicInstalled.contains(g.app_name)
+ VStack(alignment: .leading, spacing: 6) {
+ Text(g.app_title).font(.callout.weight(.semibold)).lineLimit(2)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ HStack {
+ if installed {
+ Button(L("Play")) { state.epicPlay(g, in: bottle) }
+ .buttonStyle(.borderedProminent).controlSize(.small).disabled(state.busy)
+ } else {
+ Button(L("Install")) { state.epicInstall(g, in: bottle) }
+ .controlSize(.small).disabled(state.busy)
+ }
+ Spacer()
+ }
+ }
+ .padding(12)
+ .background(RoundedRectangle(cornerRadius: 10).fill(HB.card))
+ .contextMenu {
+ if installed {
+ Button(L("Play with D3DMetal")) { state.epicPlay(g, in: bottle, renderer: .d3dmetal) }
+ Button(L("Play with DXMT")) { state.epicPlay(g, in: bottle, renderer: .dxmt) }
+ }
+ }
+ }
+ }
+ Text(L("Epic games launch with DXVK, the renderer that works for most of them. Right-click a game to try another."))
+ .font(.caption).foregroundStyle(.secondary)
+ }
+ }
+ .sheet(isPresented: Binding(get: { state.showEpicSignIn }, set: { state.showEpicSignIn = $0 })) {
+ EpicSignInSheet()
+ }
+ }
+
// MARK: Games
@ViewBuilder private var gamesSection: some View {
@@ -639,3 +698,33 @@ struct GPTKLicenseSheet: View {
.padding(16)
}
}
+
+
+struct EpicSignInSheet: View {
+ @Environment(AppState.self) private var state
+ @Environment(\.dismiss) private var dismiss
+ @State private var code = ""
+
+ var body: some View {
+ VStack(alignment: .leading, spacing: 14) {
+ Text(L("Connect your Epic account")).font(.title2.bold())
+ Text(L("1. Open Epic's sign-in page and log in.\n2. The page ends by showing an authorizationCode.\n3. Paste that code here."))
+ .font(.callout).foregroundStyle(.secondary)
+ Button(L("Open Epic sign-in page")) { NSWorkspace.shared.open(EpicStore.loginURL) }
+ TextField(L("authorizationCode"), text: $code).textFieldStyle(.roundedBorder).frame(width: 340)
+ Text(L("Your password never touches Highball. The code is single use and connects through Legendary, the open source Epic client the Heroic launcher uses."))
+ .font(.caption).foregroundStyle(.secondary).frame(maxWidth: 360, alignment: .leading)
+ HStack {
+ Spacer()
+ Button(L("Cancel")) { dismiss() }
+ Button(L("Connect")) {
+ dismiss()
+ state.epicSignIn(code: code.trimmingCharacters(in: .whitespacesAndNewlines))
+ }
+ .keyboardShortcut(.defaultAction)
+ .disabled(code.trimmingCharacters(in: .whitespaces).count < 8)
+ }
+ }
+ .padding(24)
+ }
+}
diff --git a/Sources/HighballApp/L10n.swift b/Sources/HighballApp/L10n.swift
index 22d8636..b9202d9 100644
--- a/Sources/HighballApp/L10n.swift
+++ b/Sources/HighballApp/L10n.swift
@@ -50,6 +50,25 @@ enum L10n {
"'%@' isn't a Windows program. You can drop .exe, .msi or .bat files here.":
"« %@ » n'est pas un programme Windows. Vous pouvez déposer des fichiers .exe, .msi ou .bat ici.",
"Installed": "Installée",
+ "Epic Games": "Epic Games",
+ "Connect Epic account…": "Connecter un compte Epic…",
+ "Installs go through the open source Legendary client, so the Epic launcher's broken install flow is never involved.":
+ "Les installations passent par le client libre Legendary, le mécanisme défaillant du launcher Epic n'est jamais utilisé.",
+ "No games on this Epic account yet. Claimed games appear here.":
+ "Aucun jeu sur ce compte Epic pour l'instant. Les jeux récupérés apparaîtront ici.",
+ "Play with D3DMetal": "Jouer avec D3DMetal",
+ "Play with DXMT": "Jouer avec DXMT",
+ "Epic games launch with DXVK, the renderer that works for most of them. Right-click a game to try another.":
+ "Les jeux Epic se lancent avec DXVK, le moteur qui fonctionne pour la plupart. Clic droit sur un jeu pour en essayer un autre.",
+ "Connect your Epic account": "Connecter votre compte Epic",
+ "1. Open Epic's sign-in page and log in.\n2. The page ends by showing an authorizationCode.\n3. Paste that code here.":
+ "1. Ouvrez la page de connexion Epic et identifiez-vous.\n2. La page affiche à la fin un authorizationCode.\n3. Collez ce code ici.",
+ "Open Epic sign-in page": "Ouvrir la page de connexion Epic",
+ "Your password never touches Highball. The code is single use and connects through Legendary, the open source Epic client the Heroic launcher uses.":
+ "Votre mot de passe ne passe jamais par Highball. Le code est à usage unique et la connexion utilise Legendary, le client Epic libre qu'utilise Heroic.",
+ "Connect": "Connecter",
+ "Connecting your Epic account": "Connexion de votre compte Epic",
+ "Loading your Epic library…": "Chargement de votre bibliothèque Epic…",
"Windows runtimes some games need. Install them when a game complains about a missing runtime or refuses to start.":
"Des composants Windows dont certains jeux ont besoin. Installez-les quand un jeu se plaint d'un composant manquant ou refuse de démarrer.",
"Steam crashed at a known spot — relaunching to resume the update":
diff --git a/Sources/HighballKit/EpicStore.swift b/Sources/HighballKit/EpicStore.swift
index 8cfb696..21b36bb 100644
--- a/Sources/HighballKit/EpicStore.swift
+++ b/Sources/HighballKit/EpicStore.swift
@@ -108,9 +108,11 @@ public struct EpicStore: Sendable {
return try JSONDecoder().decode([Game].self, from: Data(out.utf8))
}
- public func installedGames() throws -> [Game] {
+ struct InstalledGame: Codable { let app_name: String }
+ /// App names of installed games (this endpoint uses `title`, not `app_title`, so it gets its own type).
+ public func installedAppNames() throws -> Set<String> {
let out = try capture(["list-installed", "--json"])
- return try JSONDecoder().decode([Game].self, from: Data(out.utf8))
+ return Set(try JSONDecoder().decode([InstalledGame].self, from: Data(out.utf8)).map(\.app_name))
}
/// Installs a game's Windows build into the bottle at drive_c/Games/<folder>.
diff --git a/Sources/highball/main.swift b/Sources/highball/main.swift
index 3061a7b..76f0566 100644
--- a/Sources/highball/main.swift
+++ b/Sources/highball/main.swift
@@ -430,7 +430,7 @@ struct Epic: AsyncParsableCommand {
let store = EpicStore()
_ = try await store.ensureInstalled()
guard store.isAuthenticated else { fail("not signed in — run 'highball epic login' first") }
- let installed = Set((try? store.installedGames())?.map(\.app_name) ?? [])
+ let installed = (try? store.installedAppNames()) ?? []
for g in try store.ownedGames().sorted(by: { $0.app_title < $1.app_title }) {
print("\(installed.contains(g.app_name) ? "[installed] " : "")\(g.app_name)\t\(g.app_title)")
}