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
Opt-in install statistics: local funnel log, aggregate shown before sending
Gauthier Piarrette994192d3f7f1
diff --git a/Sources/HighballApp/ActivityStrip.swift b/Sources/HighballApp/ActivityStrip.swiftindex d1fe944..074c6d0 100644--- a/Sources/HighballApp/ActivityStrip.swift+++ b/Sources/HighballApp/ActivityStrip.swift@@ -9,7 +9,7 @@ struct ActivityStrip: View {@Environment(AppState.self) private var statevar body: some View {- if state.busy || state.doneState != nil || state.postPlay != nil || !state.runningSessions.isEmpty || !steamBottles.isEmpty {+ if state.busy || state.doneState != nil || state.postPlay != nil || state.funnelOffer || !state.runningSessions.isEmpty || !steamBottles.isEmpty {VStack(spacing: 0) {Divider()VStack(spacing: 0) {@@ -19,6 +19,7 @@ struct ActivityStrip: View {doneRow(done)}if let record = state.postPlay { postPlayRow(record) }+ if state.funnelOffer, state.postPlay == nil { funnelRow }ForEach(state.runningSessions) { session insessionRow(session)}@@ -140,6 +141,22 @@ struct ActivityStrip: View {.padding(.horizontal, 14).padding(.vertical, 8)}+ /// Opt-in install statistics (UX plan 0.7): asked once, after the first game, and the text+ /// is shown before anything leaves the Mac. Aggregate counts, no game names.+ private var funnelRow: some View {+ HStack(spacing: 10) {+ Image(systemName: "chart.bar").foregroundStyle(.secondary)+ VStack(alignment: .leading, spacing: 1) {+ Text(L("Help count how often installs and first launches succeed?")).font(.callout.weight(.medium))+ Text(L("A few counts from this Mac, no game names; you read the text before it is sent.")).font(.caption).foregroundStyle(.secondary)+ }+ Spacer(minLength: 12)+ Button(L("Show me")) { state.sendFunnel() }.controlSize(.small)+ Button(L("No thanks")) { state.declineFunnel() }.controlSize(.small).buttonStyle(.link)+ }+ .padding(.horizontal, 14).padding(.vertical, 8)+ }+private func sessionRow(_ session: GameSession) -> some View {HStack(spacing: 10) {Circle().fill(HB.good).frame(width: 8, height: 8).padding(.horizontal, 4)diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swiftindex a90fb9d..80e6614 100644--- a/Sources/HighballApp/AppState.swift+++ b/Sources/HighballApp/AppState.swift@@ -203,6 +203,7 @@ final class AppState {private func launch(_ item: LibraryItem, in bottle: Bottle) {recordPlay(item)+ if !FunnelLog.records(in: paths.logs).contains(where: { $0.event == .firstLaunch }) { funnel(.firstLaunch) }switch item.source {case .steam:guard let game = (gamesByBottle[bottle.name] ?? []).first(where: { $0.appid == item.steamAppID }) else { return }@@ -508,6 +509,12 @@ final class AppState {doneState = d.silent ? nil : d} catch {showLog = false+ if title == L("Setting up Highball"), !stopRequested {+ let bytes = busyProgress.map { " at \($0.received / 1_048_576) MB" } ?? ""+ if let u = error as? URLError { funnel(.downloadFailed, detail: "URLError \(u.code.rawValue)\(bytes)") }+ else if case HighballError.checksumMismatch = error { funnel(.downloadFailed, detail: "checksum mismatch") }+ else if busyProgress == nil, engines.isEmpty { funnel(.extractFailed, detail: String(describing: type(of: error))) }+ }if stopRequested || error is CancellationError || (error as? URLError)?.code == .cancelled {// The user stopped it: a result, not a failure, and no alert.doneState = DoneState(title: stop?.stoppedTitle ?? L("Stopped."), ctaTitle: nil, cta: nil)@@ -576,6 +583,7 @@ final class AppState {guard let manifestURL = Self.bundledManifest else {errorMessage = "No engine manifest found. Reinstall Highball."; return}+ funnel(.installStarted)runBusy(L("Setting up Highball"),expected: L("usually 5–15 minutes"),done: DoneState(title: L("Highball is ready"), ctaTitle: nil, cta: nil),@@ -590,12 +598,12 @@ final class AppState {_ = try await engineStore.install(manifest, accepted: []) { name, received, total inTask { @MainActor in self.reportDownload(name, received: received, total: total) }}- await MainActor.run { self.appendLog("engine installed"); self.refresh() }+ await MainActor.run { self.appendLog("engine installed"); self.funnel(.installCompleted); self.refresh() }}if bottles.isEmpty, let engine = defaultEngine {await MainActor.run { self.stage = L("Preparing your Windows environment"); self.busyExpected = L("about 90 seconds") }_ = try await bottleStore.create(name: Self.defaultEnvironmentName, engine: engine)- await MainActor.run { self.appendLog("environment ready"); self.selectedBottle = Self.defaultEnvironmentName; self.pane = .library }+ await MainActor.run { self.appendLog("environment ready"); self.funnel(.environmentCreated); self.selectedBottle = Self.defaultEnvironmentName; self.pane = .library }}}}@@ -725,6 +733,27 @@ final class AppState {} catch { fail(error) }}+ // MARK: Install funnel (UX plan 0.7)++ /// Local only. Nothing leaves the Mac unless the person reads the aggregate and sends it.+ func funnel(_ event: FunnelLog.Event, detail: String? = nil) {+ FunnelLog.append(.init(event: event, detail: detail), to: paths.logs)+ }+ /// The strip's one-time offer after the first game session of a minute or more.+ var funnelOffer = false+ private var funnelAsked: Bool {+ get { UserDefaults.standard.bool(forKey: "funnelAsked") }+ set { UserDefaults.standard.set(newValue, forKey: "funnelAsked") }+ }+ func declineFunnel() { funnelAsked = true; funnelOffer = false }+ /// Shows the aggregate as an issue draft in the browser; the person reads it there first.+ func sendFunnel() {+ funnelAsked = true; funnelOffer = false+ let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "dev"+ let text = FunnelLog.aggregate(FunnelLog.records(in: paths.logs), appVersion: version, macos: Machine.macOSVersion(), chip: machineChip)+ NSWorkspace.shared.open(FunnelLog.url(aggregate: text))+ }+// MARK: Steam clients (UX plan §3.3, issue #33)/// Bottles with a Steam client running right now. A client left behind by a game launch is@@ -782,6 +811,7 @@ final class AppState {private func beginSession(_ session: GameSession) {runningSessions.append(session)appendLog("\(session.title) is running")+ if !FunnelLog.records(in: paths.logs).contains(where: { $0.event == .firstGameProcess }) { funnel(.firstGameProcess) }sessionWatchers[session.id] = Task.detached { [weak self] in// A game that is gone for two consecutive checks has ended; one miss can be a// process table read racing a restart (some games relaunch themselves once).@@ -806,7 +836,13 @@ final class AppState {started: session.started, ended: Date(), reason: reason, renderer: session.renderer)SessionWatch.append(record, to: paths.logs)lastEndedSession = record- if record.seconds >= 60 { postPlay = record }+ let firstSession = !FunnelLog.records(in: paths.logs).contains { $0.event == .sessionEnded }+ funnel(.sessionEnded, detail: "\(record.seconds) s, \(reason)")+ if record.seconds >= 60 {+ postPlay = record+ // The consent question comes after the first successful game, never before (0.7).+ if !funnelAsked, firstSession { funnelOffer = true }+ }appendLog("\(session.title) \(reason) after \(record.seconds / 60) min")}diff --git a/Sources/HighballKit/FunnelLog.swift b/Sources/HighballKit/FunnelLog.swiftnew file mode 100644index 0000000..7d539f8--- /dev/null+++ b/Sources/HighballKit/FunnelLog.swift@@ -0,0 +1,72 @@+import Foundation++/// The install funnel, recorded locally and never sent on its own (UX plan 0.7). Each event is+/// one line in `logs/funnel.jsonl`. Sending is a separate, explicit act: the app builds an+/// aggregate the person reads first, and it travels as a public issue, the way reports do.+public enum FunnelLog {+ public enum Event: String, Codable, CaseIterable, Sendable {+ case installStarted = "install-started"+ case downloadFailed = "download-failed"+ case extractFailed = "extract-failed"+ case installCompleted = "install-completed"+ case environmentCreated = "environment-created"+ case firstLaunch = "first-launch"+ case firstGameProcess = "first-game-process"+ case sessionEnded = "session-ended"+ }++ public struct Record: Codable, Sendable, Equatable {+ public var event: Event+ public var at: Date+ /// A detail with no personal data: a URLError code, a byte offset, a duration in seconds.+ public var detail: String?+ public init(event: Event, at: Date = Date(), detail: String? = nil) { self.event = event; self.at = at; self.detail = detail }+ }++ public static func file(in logs: URL) -> URL { logs.appending(path: "funnel.jsonl") }++ public static func append(_ record: Record, to logs: URL) {+ guard let data = try? JSONEncoder().encode(record) else { return }+ let url = file(in: logs)+ try? FileManager.default.createDirectory(at: logs, withIntermediateDirectories: true)+ if let handle = try? FileHandle(forWritingTo: url) {+ defer { try? handle.close() }+ try? handle.seekToEnd(); handle.write(data); handle.write(Data("\n".utf8))+ } else {+ try? (data + Data("\n".utf8)).write(to: url)+ }+ }++ public static func records(in logs: URL) -> [Record] {+ guard let text = try? String(contentsOf: file(in: logs), encoding: .utf8) else { return [] }+ let dec = JSONDecoder()+ return text.split(separator: "\n").compactMap { try? dec.decode(Record.self, from: Data($0.utf8)) }+ }++ /// Counts per event plus the failure details, in words a person can check before sending.+ /// Pure: the same records always give the same text.+ public static func aggregate(_ records: [Record], appVersion: String, macos: String, chip: String) -> String {+ var lines = ["Highball \(appVersion), macOS \(macos), \(chip)", ""]+ for event in Event.allCases {+ let matching = records.filter { $0.event == event }+ guard !matching.isEmpty else { continue }+ var line = "\(event.rawValue): \(matching.count)"+ let details = matching.compactMap(\.detail)+ if !details.isEmpty, event == .downloadFailed || event == .extractFailed {+ line += " (" + details.joined(separator: "; ") + ")"+ }+ lines.append(line)+ }+ if lines.count == 2 { lines.append("no events yet") }+ return lines.joined(separator: "\n")+ }++ /// The issue that carries the aggregate: the person sees the text before the browser opens.+ public static func url(aggregate: String) -> URL {+ var comps = URLComponents(string: "https://github.com/gauthierpiarrette/highball/issues/new")!+ comps.queryItems = [URLQueryItem(name: "title", value: "Install statistics"),+ URLQueryItem(name: "labels", value: "funnel"),+ URLQueryItem(name: "body", value: aggregate)]+ return comps.url!+ }+}diff --git a/Tests/HighballKitTests/FunnelLogTests.swift b/Tests/HighballKitTests/FunnelLogTests.swiftnew file mode 100644index 0000000..0cba526--- /dev/null+++ b/Tests/HighballKitTests/FunnelLogTests.swift@@ -0,0 +1,38 @@+import XCTest+@testable import HighballKit++final class FunnelLogTests: XCTestCase {+ func testAppendAndReadBack() throws {+ let dir = FileManager.default.temporaryDirectory.appending(path: "funnel-\(UUID().uuidString)")+ defer { try? FileManager.default.removeItem(at: dir) }+ FunnelLog.append(.init(event: .installStarted), to: dir)+ FunnelLog.append(.init(event: .downloadFailed, detail: "URLError -1005 at 164 MB"), to: dir)+ let records = FunnelLog.records(in: dir)+ XCTAssertEqual(records.map(\.event), [.installStarted, .downloadFailed])+ XCTAssertEqual(records[1].detail, "URLError -1005 at 164 MB")+ }++ func testAggregateIsCountsInWords() {+ let r: [FunnelLog.Record] = [+ .init(event: .installStarted), .init(event: .downloadFailed, detail: "URLError -1005 at 164 MB"),+ .init(event: .installStarted), .init(event: .installCompleted), .init(event: .sessionEnded, detail: "187 s"),+ ]+ let text = FunnelLog.aggregate(r, appVersion: "0.7.23", macos: "26.6.2", chip: "Apple M1 Pro")+ XCTAssertEqual(text, """+ Highball 0.7.23, macOS 26.6.2, Apple M1 Pro++ install-started: 2+ download-failed: 1 (URLError -1005 at 164 MB)+ install-completed: 1+ session-ended: 1+ """)+ XCTAssertTrue(FunnelLog.aggregate([], appVersion: "x", macos: "y", chip: "z").hasSuffix("no events yet"))+ }++ func testIssueURLCarriesTheAggregate() throws {+ let url = FunnelLog.url(aggregate: "install-started: 2")+ let q = Dictionary(uniqueKeysWithValues: (URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems ?? []).map { ($0.name, $0.value ?? "") })+ XCTAssertEqual(q["title"], "Install statistics")+ XCTAssertEqual(q["body"], "install-started: 2")+ }+}