Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
feat(setup): choose Metal HUD and High Resolution for every game
raymondchins8b9abf9e4371
diff --git a/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings b/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstringsindex 794bd93..8e2345f 100644--- a/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings+++ b/app/Sources/BridgeplayApp/Resources/Localization/Localizable.xcstrings@@ -972,6 +972,22 @@}}},+ "A game's own Steam Properties › Compatibility settings win over these." : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Le impostazioni di un gioco in Proprietà di Steam › Compatibilità hanno la precedenza su queste."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "单个游戏在 Steam 属性 › 兼容性中的设置优先于这里。"+ }+ }+ }+ },"A header field" : {"localizations" : {"it" : {@@ -1948,6 +1964,22 @@}}},+ "Both start off. You can change them here later, or for one game in its Steam Properties › Compatibility." : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Entrambe partono disattivate. Puoi cambiarle qui più tardi, o per un singolo gioco in Proprietà di Steam › Compatibilità."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "两项默认关闭。之后可以在这里更改,也可以在单个游戏的 Steam 属性 › 兼容性中更改。"+ }+ }+ }+ },"Bridgeplay" : {"shouldTranslate" : false},@@ -2063,6 +2095,22 @@}}},+ "Bridgeplay could not save this setting. %@" : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Bridgeplay non è riuscito a salvare questa impostazione. %@"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Bridgeplay 无法保存此设置。%@"+ }+ }+ }+ },"Bridgeplay couldn't do this on its own." : {"localizations" : {"it" : {@@ -4066,6 +4114,38 @@}}},+ "For Every Game" : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Per tutti i giochi"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "所有游戏"+ }+ }+ }+ },+ "For every game" : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Per tutti i giochi"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "所有游戏"+ }+ }+ }+ },"Frame Generation (Experimental. Adds input lag)" : {"localizations" : {"it" : {@@ -7234,6 +7314,22 @@}}},+ "Sharper on Retina displays, but games run slower." : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Più nitido sui display Retina, ma i giochi vanno più lenti."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "在 Retina 显示屏上更清晰,但游戏会变慢。"+ }+ }+ }+ },"Show all compatibility tools" : {"localizations" : {"it" : {@@ -7314,6 +7410,22 @@}}},+ "Shows frame rate and GPU details in a corner while you play." : {+ "localizations" : {+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Mostra frame rate e dettagli della GPU in un angolo mentre giochi."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "游戏时在角落显示帧率和 GPU 信息。"+ }+ }+ }+ },"Sign in to Steam" : {"localizations" : {"it" : {diff --git a/app/Sources/BridgeplayApp/SetupAssistant.swift b/app/Sources/BridgeplayApp/SetupAssistant.swiftindex 9c6f3c6..ec20dbc 100644--- a/app/Sources/BridgeplayApp/SetupAssistant.swift+++ b/app/Sources/BridgeplayApp/SetupAssistant.swift@@ -61,6 +61,10 @@ final class SetupAssistant {var needsAppManagement = false@ObservationIgnored private var permissionWatch: Task<Void, Never>?+ // Done: settings for every game, read from and written to gamefixes/default.conf.+ var metalHUD = GameDefaults.isOn(.metalHUD)+ var highResolution = GameDefaults.isOn(.highResolution)+static let plannedTasks = [SetupTask(id: "steam", title: String(localized: "Add Bridgeplay to Steam")),SetupTask(id: "engine", title: String(localized: "Set up the WineCX engine")),@@ -80,6 +84,8 @@ final class SetupAssistant {rosettaInstalled = falsesignedIn = falsetrust = .needed+ metalHUD = false+ highResolution = false}// The preview can open on a later step; the steps before it count as passed, so a// fresh Mac shows step 4 as someone who pressed Trust in step 3 would see it.@@ -95,6 +101,20 @@ final class SetupAssistant {enum Preview { case thisMac, fresh }+ // The preview only flips the switch; it never writes the real default.conf.+ func setGameDefault(_ setting: GameDefaults.Setting, _ on: Bool) {+ switch setting {+ case .metalHUD: metalHUD = on+ case .highResolution: highResolution = on+ }+ guard !isPreview else { return }+ do {+ try GameDefaults.set(setting, to: on)+ } catch {+ message = String(localized: "Bridgeplay could not save this setting. \(error.localizedDescription)")+ }+ }+private func pretend(_ seconds: Double = 0.9) async {try? await Task.sleep(for: .seconds(seconds))}diff --git a/app/Sources/BridgeplayApp/Support/GameDefaults.swift b/app/Sources/BridgeplayApp/Support/GameDefaults.swiftnew file mode 100644index 0000000..f37b7b5--- /dev/null+++ b/app/Sources/BridgeplayApp/Support/GameDefaults.swift@@ -0,0 +1,68 @@+import Foundation++// The few settings the Setup Assistant and the Status page offer for every game. They live+// in the user's gamefixes/default.conf, the lowest layer the run script reads (launch+// options, then <appid>.conf, then the shipped per-game defaults all win over it). Only the+// lines for these keys are rewritten: every other line, comment or setting the user wrote+// stays as it is. A setting that is off is removed rather than written as 0, so the engine's+// own default applies.+enum GameDefaults {++ enum Setting: CaseIterable, Sendable {+ case metalHUD+ case highResolution++ // The first spelling is the one written; the others are read and replaced.+ var keys: [String] {+ switch self {+ case .metalHUD: ["MTL_HUD_ENABLED"]+ case .highResolution: ["RETINA", "BRIDGEPLAY_RETINA"]+ }+ }+ }++ static var file: URL { SupportPaths.gamefixes.appending(path: "default.conf") }++ static let header = "# Settings for every game. Per-game confs and Steam launch options win over these."++ // Last assignment wins, as in the run script.+ static func isOn(_ setting: Setting, in text: String) -> Bool {+ var on = false+ for line in text.split(separator: "\n", omittingEmptySubsequences: false) {+ guard let (key, value) = assignment(line), setting.keys.contains(key) else { continue }+ on = value == "1"+ }+ return on+ }++ static func setting(_ setting: Setting, to on: Bool, in text: String) -> String {+ var lines = text.isEmpty ? [] : text.components(separatedBy: "\n")+ if lines.last == "" { lines.removeLast() }+ lines.removeAll { line in assignment(Substring(line)).map { setting.keys.contains($0.0) } ?? false }+ if on {+ if lines.isEmpty { lines.append(header) }+ lines.append("\(setting.keys[0])=1")+ }+ return lines.isEmpty ? "" : lines.joined(separator: "\n") + "\n"+ }++ static func isOn(_ setting: Setting, at url: URL = file) -> Bool {+ isOn(setting, in: (try? String(contentsOf: url, encoding: .utf8)) ?? "")+ }++ static func set(_ setting: Setting, to on: Bool, at url: URL = file) throws {+ let current = (try? String(contentsOf: url, encoding: .utf8)) ?? ""+ let updated = Self.setting(setting, to: on, in: current)+ guard updated != current else { return }+ try FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true)+ try Data(updated.utf8).write(to: url, options: .atomic)+ AppLog.note("game defaults: \(setting.keys[0]) \(on ? "on" : "off")")+ }++ // KEY=VALUE with surrounding whitespace trimmed, as the run script reads it.+ private static func assignment(_ line: Substring) -> (String, String)? {+ let trimmed = line.trimmingCharacters(in: .whitespaces)+ guard let equals = trimmed.firstIndex(of: "="), !trimmed.hasPrefix("#") else { return nil }+ return (String(trimmed[..<equals]), String(trimmed[trimmed.index(after: equals)...]))+ }+}diff --git a/app/Sources/BridgeplayApp/Support/SupportPaths.swift b/app/Sources/BridgeplayApp/Support/SupportPaths.swiftindex acbfbc5..fea3e01 100644--- a/app/Sources/BridgeplayApp/Support/SupportPaths.swift+++ b/app/Sources/BridgeplayApp/Support/SupportPaths.swift@@ -57,7 +57,8 @@ enum SupportPaths {// Free WineHQ engines Bridgeplay downloaded, laid out like a CrossOver bundle.static var engines: URL { support.appending(path: "engines") }// Per-game defaults Bridgeplay ships. Replaced on every install; the user's own- // overrides live in the sibling "gamefixes" directory, which Bridgeplay never writes.+ // overrides live in the sibling "gamefixes" directory. Bridgeplay writes there only the+ // lines of default.conf that GameDefaults owns, and keeps everything else as it is.static var gamefixesDefault: URL { support.appending(path: "gamefixes-default") }static var gamefixes: URL { support.appending(path: "gamefixes") }// Where Remove Everything moves the user's own overrides, outside the folder it deletes.diff --git a/app/Sources/BridgeplayApp/Views/SetupAssistantView.swift b/app/Sources/BridgeplayApp/Views/SetupAssistantView.swiftindex 98c90e9..e53d5b8 100644--- a/app/Sources/BridgeplayApp/Views/SetupAssistantView.swift+++ b/app/Sources/BridgeplayApp/Views/SetupAssistantView.swift@@ -343,6 +343,27 @@ struct SetupAssistantView: View {tone: .info,action: StatusAction(label: String(localized: "Open Input Monitoring")) { SystemStatus.openInputMonitoring() }))}+ Text("For every game")+ .font(BP.sans(13, .semibold))+ .foregroundStyle(BP.fg)+ .padding(.horizontal, 2)+ .padding(.top, 8)+ Card {+ WizardRow(row: StatusRow(title: String(localized: "Metal HUD"),+ value: String(localized: "Shows frame rate and GPU details in a corner while you play."),+ toggle: Binding(get: { model.metalHUD }, set: { model.setGameDefault(.metalHUD, $0) })),+ symbol: "gauge.with.dots.needle.33percent")+ Hairline()+ WizardRow(row: StatusRow(title: String(localized: "High Resolution"),+ value: String(localized: "Sharper on Retina displays, but games run slower."),+ toggle: Binding(get: { model.highResolution }, set: { model.setGameDefault(.highResolution, $0) })),+ symbol: "display")+ }+ Text("Both start off. You can change them here later, or for one game in its Steam Properties › Compatibility.")+ .font(BP.sans(12))+ .foregroundStyle(BP.fg3)+ .fixedSize(horizontal: false, vertical: true)+ .padding(.horizontal, 2)}private func value(of task: SetupAssistant.SetupTask) -> String? {@@ -510,6 +531,8 @@ private struct WizardRow: View {var pending = false// A step number in place of the tone, for rows that are instructions.var number: Int?+ // A symbol in place of the tone, for rows that are settings rather than checks.+ var symbol: String?var body: some View {HStack(alignment: .center, spacing: 14) {@@ -519,6 +542,13 @@ private struct WizardRow: View {.foregroundStyle(.black).frame(width: 24, height: 24).background(BP.iridescentDiagonal, in: RoundedRectangle(cornerRadius: 7, style: .continuous))+ } else if let symbol {+ Image(systemName: symbol)+ .font(.system(size: 11, weight: .semibold))+ .foregroundStyle(BP.fg2)+ .frame(width: 24, height: 24)+ .background(BP.raise2, in: RoundedRectangle(cornerRadius: 7, style: .continuous))+ .accessibilityHidden(true)} else {ToneBadge(tone: row.tone, pending: pending)}@@ -553,6 +583,12 @@ private struct WizardRow: View {}}.frame(maxWidth: .infinity, alignment: .leading)+ if let toggle = row.toggle {+ Toggle(row.title, isOn: toggle)+ .toggleStyle(.switch)+ .labelsHidden()+ .tint(BP.blue)+ }if row.secondaryAction != nil || row.action != nil {HStack(spacing: 8) {if let secondary = row.secondaryAction { button(secondary, prominent: false) }diff --git a/app/Sources/BridgeplayApp/Views/StatusView.swift b/app/Sources/BridgeplayApp/Views/StatusView.swiftindex 35b4a31..d3c6822 100644--- a/app/Sources/BridgeplayApp/Views/StatusView.swift+++ b/app/Sources/BridgeplayApp/Views/StatusView.swift@@ -164,6 +164,10 @@ struct StatusRow: View {struct StatusView: View {@Environment(SystemStatus.self) private var status+ // gamefixes/default.conf, read when the page opens; the switches write it straight away.+ @State private var metalHUD = GameDefaults.isOn(.metalHUD)+ @State private var highResolution = GameDefaults.isOn(.highResolution)+ @State private var gameDefaultsError: String?private static let updateBlockPrompt =String(localized: "Steam client updates may break Bridgeplay. If you don't want to wait for Bridgeplay to be updated to be compatible with future Steam versions at the cost of not getting updates to the Steam client, you can stop the Steam client from updating itself.")@@ -364,6 +368,8 @@ struct StatusView: View {}}+ gameDefaultsSection+componentsSection(snapshot.payload)dangerSection@@ -436,6 +442,36 @@ struct StatusView: View {}}+ private var gameDefaultsSection: some View {+ Section {+ StatusRow(title: String(localized: "Metal HUD"),+ value: String(localized: "Shows frame rate and GPU details in a corner while you play."),+ toggle: gameDefault(.metalHUD, $metalHUD))+ StatusRow(title: String(localized: "High Resolution"),+ value: String(localized: "Sharper on Retina displays, but games run slower."),+ toggle: gameDefault(.highResolution, $highResolution))+ if let gameDefaultsError {+ StatusRow(title: String(localized: "Something went wrong"), value: gameDefaultsError, tone: .bad)+ }+ } header: {+ Text("For Every Game")+ } footer: {+ Text("A game's own Steam Properties › Compatibility settings win over these.")+ }+ }++ private func gameDefault(_ setting: GameDefaults.Setting, _ value: Binding<Bool>) -> Binding<Bool> {+ Binding(get: { value.wrappedValue }, set: { on in+ value.wrappedValue = on+ do {+ try GameDefaults.set(setting, to: on)+ gameDefaultsError = nil+ } catch {+ gameDefaultsError = String(localized: "Bridgeplay could not save this setting. \(error.localizedDescription)")+ }+ })+ }+private var dangerSection: some View {Section {StatusRow(diff --git a/app/Tests/BridgeplayAppTests/GameDefaultsTests.swift b/app/Tests/BridgeplayAppTests/GameDefaultsTests.swiftnew file mode 100644index 0000000..5bf328f--- /dev/null+++ b/app/Tests/BridgeplayAppTests/GameDefaultsTests.swift@@ -0,0 +1,37 @@+import Foundation+import Testing+@testable import BridgeplayApp++@Suite struct GameDefaultsTests {+ @Test func readsTheLastAssignmentInEitherSpelling() {+ #expect(GameDefaults.isOn(.highResolution, in: "RETINA=1\n"))+ #expect(GameDefaults.isOn(.highResolution, in: " BRIDGEPLAY_RETINA=1 \n"))+ #expect(!GameDefaults.isOn(.highResolution, in: "RETINA=1\nRETINA=0\n"))+ #expect(!GameDefaults.isOn(.metalHUD, in: "# MTL_HUD_ENABLED=1\n"))+ #expect(!GameDefaults.isOn(.metalHUD, in: ""))+ }++ @Test func keepsEveryOtherLineAndReplacesOnlyItsOwn() {+ let text = "# mine\nMTL_HUD_ENABLED=1\nRETINA=1\nBRIDGEPLAY_RETINA=1\nROSETTA_ADVERTISE_AVX=1\n"+ let off = GameDefaults.setting(.highResolution, to: false, in: text)+ #expect(off == "# mine\nMTL_HUD_ENABLED=1\nROSETTA_ADVERTISE_AVX=1\n")+ let on = GameDefaults.setting(.metalHUD, to: true, in: "# mine\nROSETTA_ADVERTISE_AVX=1")+ #expect(on == "# mine\nROSETTA_ADVERTISE_AVX=1\nMTL_HUD_ENABLED=1\n")+ }++ @Test func startsANewFileWithItsHeaderAndEmptiesItWhenAllIsOff() {+ let on = GameDefaults.setting(.metalHUD, to: true, in: "")+ #expect(on == GameDefaults.header + "\nMTL_HUD_ENABLED=1\n")+ #expect(GameDefaults.setting(.metalHUD, to: false, in: "MTL_HUD_ENABLED=1\n") == "")+ }++ @Test func writesAndReadsBackAFile() throws {+ let dir = FileManager.default.temporaryDirectory.appending(path: "gamedefaults-\(UUID().uuidString)")+ defer { try? FileManager.default.removeItem(at: dir) }+ let url = dir.appending(path: "gamefixes/default.conf")+ try GameDefaults.set(.highResolution, to: true, at: url)+ #expect(GameDefaults.isOn(.highResolution, at: url))+ try GameDefaults.set(.highResolution, to: false, at: url)+ #expect(!GameDefaults.isOn(.highResolution, at: url))+ }+}