Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Move the language and the strings out of BuildModel into a Localizer store (#387)

v0lumehif3fb1607c865
diff --git a/frontend/ARCHITECTURE.md b/frontend/ARCHITECTURE.md
index 87e2615d..41863c48 100644
--- a/frontend/ARCHITECTURE.md
+++ b/frontend/ARCHITECTURE.md
@@ -13,11 +13,11 @@ The plan and the steps are in [LNPANDY/NX2Apple#387](https://github.com/LNPANDY/
## Where it stands
-Step 1 of #387 made the targets and moved the files that already fit. The rest still lives in the app target and moves with the later steps.
+Step 1 of #387 made the targets and moved the files that already fit. Step 2 moved the language out of `BuildModel` into the `Localizer` store. The rest still lives in the app target and moves with the later steps.
-- `BuildModel` and `ContentView.swift` are unchanged. `BuildModel` is the model of the whole launcher and reaches into every layer, so the files that use it cannot leave the app target yet.
+- `BuildModel` is the model of the whole launcher and reaches into every layer, so the files that use it cannot leave the app target yet. It no longer owns the language: it holds the `Localizer` it was given and forwards `lang` and `t()` to it, for the text it writes itself (alerts, status, failures).
- `NXCore` holds the value types and static functions that need only Foundation: app and engine update parsing, `Localization.swift`, the release notes, the device and signing tools, the cloud folder and saves migration, the bundled tools, input staging, the build target and the pipe reader.
-- `NXModel` is empty. No store exists yet, and every file that was looked at reaches into `BuildModel`, AppKit or SwiftUI types. `NXModel.swift` keeps the target alive.
+- `NXModel` holds `Localizer`: `lang` and `t()`. The app creates one with each `BuildModel`, and `ContentView` hands it to every view as an environment object. A view that shows text declares `@EnvironmentObject var loc: Localizer` and calls `loc.t(...)`. A language change redraws these views and nothing else. No other store exists yet.
- `NXLauncher` holds the views and styles that do not need `BuildModel`: `LauncherPalette`, `Typography`, `LauncherStyles`, `LauncherDropdown`, `PadFocus` and `EmbeddedFonts`.
- `NX2Apple` holds everything else, including `BuildModel`.
diff --git a/frontend/Sources/NX2Apple/BuildFailureView.swift b/frontend/Sources/NX2Apple/BuildFailureView.swift
index ba0deba3..2ba30486 100644
--- a/frontend/Sources/NX2Apple/BuildFailureView.swift
+++ b/frontend/Sources/NX2Apple/BuildFailureView.swift
@@ -1,11 +1,13 @@
import SwiftUI
import NXCore
+import NXModel
import NXLauncher
/// Under the build button after a stop the script's early checks explain: what happened in plain words, the next step, and the
/// button that does it (a dependency's own install command, or "Build anyway" for the three stops that have an override).
struct BuildFailureCard: View {
@ObservedObject var m: BuildModel
+ @EnvironmentObject var loc: Localizer
/// The failure to show: the build's (`m.failure`) unless the caller passes another one, such as the engine sync's.
var failure: BuildFailure?
@@ -17,13 +19,13 @@ struct BuildFailureCard: View {
var body: some View {
if let f = failure ?? m.failure {
VStack(alignment: .leading, spacing: 10) {
- Text(m.t("fail.section")).font(.manrope(15, .semibold)).foregroundStyle(.secondary).padding(.leading, 2)
+ Text(loc.t("fail.section")).font(.manrope(15, .semibold)).foregroundStyle(.secondary).padding(.leading, 2)
VStack(alignment: .leading, spacing: 8) {
HStack(alignment: .firstTextBaseline, spacing: 10) {
Circle().fill(LauncherPalette.building).frame(width: 7, height: 7)
Text(m.failureWhat(f)).font(.manrope(14, .semibold)).fixedSize(horizontal: false, vertical: true)
}
- Text(m.t(f.kind.nextKey)).font(.manrope(13)).foregroundStyle(.secondary)
+ Text(loc.t(f.kind.nextKey)).font(.manrope(13)).foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true).padding(.leading, 17)
buttons(f.kind).padding(.leading, 17).padding(.top, 2)
}
@@ -32,11 +34,11 @@ struct BuildFailureCard: View {
.background(LauncherPalette.surface.opacity(0.75), in: RoundedRectangle(cornerRadius: 14))
.overlay(RoundedRectangle(cornerRadius: 14).strokeBorder(Color.white.opacity(0.06)))
}
- .alert(m.t("fail.confirm.title"), isPresented: Binding(get: { m.confirmingOverride != nil }, set: { if !$0 { m.cancelBuildAnyway() } })) {
- Button(m.t("fail.confirm.go")) { m.confirmBuildAnyway() }
- Button(m.t("fail.confirm.cancel"), role: .cancel) { m.cancelBuildAnyway() }
+ .alert(loc.t("fail.confirm.title"), isPresented: Binding(get: { m.confirmingOverride != nil }, set: { if !$0 { m.cancelBuildAnyway() } })) {
+ Button(loc.t("fail.confirm.go")) { m.confirmBuildAnyway() }
+ Button(loc.t("fail.confirm.cancel"), role: .cancel) { m.cancelBuildAnyway() }
} message: {
- Text(m.confirmingOverride.map { m.t("fail.\($0.rawValue).risk") } ?? "")
+ Text(m.confirmingOverride.map { loc.t("fail.\($0.rawValue).risk") } ?? "")
}
}
}
@@ -65,11 +67,11 @@ struct BuildFailureCard: View {
case .shellDataIncomplete:
fix(kind, "shell.retry")
case .engineOffline, .engineSync:
- Button(m.t("fail.retry")) { m.retryEngineSync() }.disabled(m.engineSyncing)
+ Button(loc.t("fail.retry")) { m.retryEngineSync() }.disabled(m.engineSyncing)
default: EmptyView()
}
if kind.overrideFlag != nil {
- Button(m.t("fail.buildAnyway")) { m.requestBuildAnyway() }.disabled(m.running)
+ Button(loc.t("fail.buildAnyway")) { m.requestBuildAnyway() }.disabled(m.running)
}
}
.buttonStyle(LauncherSecondaryButtonStyle())
@@ -78,9 +80,9 @@ struct BuildFailureCard: View {
private func fix(_ kind: BuildFailureKind, _ key: String) -> some View {
Group {
if m.fixBusy(kind) {
- HStack(spacing: 8) { ProgressView().controlSize(.small); Text(m.t("dep.installing")).font(.manrope(12)).foregroundStyle(LauncherPalette.building) }
+ HStack(spacing: 8) { ProgressView().controlSize(.small); Text(loc.t("dep.installing")).font(.manrope(12)).foregroundStyle(LauncherPalette.building) }
} else {
- Button(m.t(key)) { m.fixBuildFailure(kind) }.disabled(m.running)
+ Button(loc.t(key)) { m.fixBuildFailure(kind) }.disabled(m.running)
}
}
}
@@ -90,12 +92,13 @@ struct BuildFailureCard: View {
/// updates), and its failure row when that stops: what happened, what to do, and Try again.
struct EngineSyncBanner: View {
@ObservedObject var m: BuildModel
+ @EnvironmentObject var loc: Localizer
var body: some View {
if m.engineSyncing {
HStack(spacing: 10) {
ProgressView().controlSize(.small)
- Text(m.t("engine.syncing")).font(.manrope(13)).foregroundStyle(LauncherPalette.building)
+ Text(loc.t("engine.syncing")).font(.manrope(13)).foregroundStyle(LauncherPalette.building)
.fixedSize(horizontal: false, vertical: true)
Spacer(minLength: 0)
}
diff --git a/frontend/Sources/NX2Apple/BuildModelStrings.swift b/frontend/Sources/NX2Apple/BuildModelStrings.swift
new file mode 100644
index 00000000..51496acf
--- /dev/null
+++ b/frontend/Sources/NX2Apple/BuildModelStrings.swift
@@ -0,0 +1,9 @@
+import NXCore
+import NXModel
+
+// The language and the strings of `BuildModel` are the `Localizer`'s (LNPANDY/NX2Apple#387). `BuildModel` is not observed for them:
+// a language change reaches the views through the environment. These two forward to it for the text the model writes itself.
+extension BuildModel {
+ var lang: Lang { get { localizer.lang } set { localizer.lang = newValue } }
+ func t(_ key: String) -> String { localizer.t(key) }
+}
diff --git a/frontend/Sources/NX2Apple/CheatsView.swift b/frontend/Sources/NX2Apple/CheatsView.swift
index 902d20ce..a31967ab 100644
--- a/frontend/Sources/NX2Apple/CheatsView.swift
+++ b/frontend/Sources/NX2Apple/CheatsView.swift
@@ -1,6 +1,7 @@
import AppKit
import SwiftUI
import NXCore
+import NXModel
import NXLauncher
/// The Cheats sheet (#97): a game's cheat files, an on / off switch per cheat, an import by drop or pick, and a copy to the
@@ -9,6 +10,7 @@ import NXLauncher
/// starts (or on its own Reload cheats).
struct CheatsView: View {
@ObservedObject var m: BuildModel
+ @EnvironmentObject var loc: Localizer
@ObservedObject var library: GameLibrary
let gameID: UUID
var devicectl: DeviceControl? = nil // tests and the visual QA hand in a stand-in
@@ -42,7 +44,7 @@ struct CheatsView: View {
var body: some View {
VStack(alignment: .leading, spacing: 0) {
VStack(alignment: .leading, spacing: 4) {
- Text(m.t("cheats.title")).font(.manrope(26, .heavy)).tracking(-0.6)
+ Text(loc.t("cheats.title")).font(.manrope(26, .heavy)).tracking(-0.6)
if let game { Text(game.name).font(.manrope(14)).foregroundStyle(.secondary) }
}
.padding(.horizontal, 30).padding(.top, 28).padding(.bottom, 16)
@@ -54,7 +56,7 @@ struct CheatsView: View {
if busy {
HStack(spacing: 10) {
ProgressView().controlSize(.small)
- Text(m.t("cheats.copying")).font(.manrope(13)).foregroundStyle(.secondary)
+ Text(loc.t("cheats.copying")).font(.manrope(13)).foregroundStyle(.secondary)
}
} else if let result {
Label(result.text, systemImage: result.ok ? "checkmark.circle.fill" : "exclamationmark.triangle.fill")
@@ -66,11 +68,11 @@ struct CheatsView: View {
Spacer(minLength: 0)
Divider().opacity(0.3)
HStack(spacing: 14) {
- Text(m.t("cheats.note") + ((game?.onDevice ?? false) ? " " + String(format: m.t("cheats.noteDevice"), deviceName) : "")).font(.manrope(12)).foregroundStyle(.secondary)
+ Text(loc.t("cheats.note") + ((game?.onDevice ?? false) ? " " + String(format: loc.t("cheats.noteDevice"), deviceName) : "")).font(.manrope(12)).foregroundStyle(.secondary)
.lineLimit(3).fixedSize(horizontal: false, vertical: true)
Spacer(minLength: 8)
Button { dismiss() } label: {
- Text(m.t("launch.done")).font(.manrope(13.5, .bold)).foregroundStyle(.black)
+ Text(loc.t("launch.done")).font(.manrope(13.5, .bold)).foregroundStyle(.black)
.padding(.horizontal, 22).padding(.vertical, 9)
.background(LauncherPalette.cream, in: Capsule())
}
@@ -85,7 +87,7 @@ struct CheatsView: View {
.font(.manrope(13))
.preferredColorScheme(.dark)
.tint(LauncherPalette.cream)
- .modifier(GameFilesDrop(enabled: !busy, label: m.t("cheats.dropHint"), targeted: dropped) { importPaths($0) })
+ .modifier(GameFilesDrop(enabled: !busy, label: loc.t("cheats.dropHint"), targeted: dropped) { importPaths($0) })
.onAppear(perform: refresh)
}
@@ -103,8 +105,8 @@ struct CheatsView: View {
HStack(spacing: 14) {
Image(systemName: "number").font(.system(size: 16, weight: .light)).foregroundStyle(.secondary).frame(width: 26)
VStack(alignment: .leading, spacing: 3) {
- Text(m.t("cheats.buildLabel")).font(.manrope(14, .medium))
- Text(buildID ?? m.t("cheats.buildUnknown")).font(buildID == nil ? .manrope(12) : .system(size: 12.5, design: .monospaced))
+ Text(loc.t("cheats.buildLabel")).font(.manrope(14, .medium))
+ Text(buildID ?? loc.t("cheats.buildUnknown")).font(buildID == nil ? .manrope(12) : .system(size: 12.5, design: .monospaced))
.foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
}
Spacer(minLength: 12)
@@ -114,14 +116,14 @@ struct CheatsView: View {
HStack(spacing: 14) {
Image(systemName: "power").font(.system(size: 16, weight: .light)).foregroundStyle(.secondary).frame(width: 26)
VStack(alignment: .leading, spacing: 3) {
- Text(m.t("cheats.master")).font(.manrope(14, .medium))
+ Text(loc.t("cheats.master")).font(.manrope(14, .medium))
if safeMode {
- Text(m.t("cheats.safeMode")).font(.manrope(12)).foregroundStyle(LauncherPalette.building).fixedSize(horizontal: false, vertical: true)
+ Text(loc.t("cheats.safeMode")).font(.manrope(12)).foregroundStyle(LauncherPalette.building).fixedSize(horizontal: false, vertical: true)
}
}
Spacer(minLength: 12)
Toggle("", isOn: Binding(get: { master }, set: { setMaster($0) })).toggleStyle(CheatSwitchStyle()).labelsHidden()
- .accessibilityLabel(m.t("cheats.master"))
+ .accessibilityLabel(loc.t("cheats.master"))
.padTarget("cheats.master", scope: "cheats") { setMaster(!master) }
}
.padding(.horizontal, 18).padding(.vertical, 11)
@@ -132,7 +134,7 @@ struct CheatsView: View {
private var iosNoteCard: some View {
HStack(alignment: .top, spacing: 14) {
Image(systemName: "info.circle").font(.system(size: 16, weight: .light)).foregroundStyle(.secondary).frame(width: 26)
- Text(m.t("cheats.iosNote")).font(.manrope(12.5)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
+ Text(loc.t("cheats.iosNote")).font(.manrope(12.5)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
Spacer(minLength: 0)
}
.padding(.horizontal, 18).padding(.vertical, 11)
@@ -144,7 +146,7 @@ struct CheatsView: View {
card {
VStack(spacing: 10) {
Image(systemName: "square.and.arrow.down").font(.system(size: 26, weight: .light)).foregroundStyle(.secondary)
- Text(m.t("cheats.empty")).font(.manrope(13)).foregroundStyle(.secondary).multilineTextAlignment(.center)
+ Text(loc.t("cheats.empty")).font(.manrope(13)).foregroundStyle(.secondary).multilineTextAlignment(.center)
.fixedSize(horizontal: false, vertical: true)
}
.frame(maxWidth: .infinity, minHeight: 150).padding(18)
@@ -159,7 +161,7 @@ struct CheatsView: View {
Divider().opacity(0.25).padding(.leading, 18)
}
if current == nil {
- Text(buildID == nil ? m.t("cheats.noBuildFile") : String(format: m.t("cheats.noFileForBuild"), buildID ?? ""))
+ Text(buildID == nil ? loc.t("cheats.noBuildFile") : String(format: loc.t("cheats.noFileForBuild"), buildID ?? ""))
.font(.manrope(12.5)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
.padding(.horizontal, 18).padding(.vertical, 14).frame(maxWidth: .infinity, alignment: .leading)
} else {
@@ -178,14 +180,14 @@ struct CheatsView: View {
Image(systemName: "doc.text").font(.system(size: 15, weight: .light)).foregroundStyle(.secondary).frame(width: 26)
Text(file.buildID + ".txt").font(.system(size: 12.5, design: .monospaced))
Spacer(minLength: 8)
- Text((isCurrent ? m.t("cheats.thisBuild") : m.t("cheats.otherBuild")).uppercased()).font(.manrope(10.5, .bold)).tracking(1.1)
+ Text((isCurrent ? loc.t("cheats.thisBuild") : loc.t("cheats.otherBuild")).uppercased()).font(.manrope(10.5, .bold)).tracking(1.1)
.foregroundStyle(isCurrent ? .black : .secondary)
.padding(.horizontal, 10).padding(.vertical, 4)
.background(isCurrent ? AnyShapeStyle(LauncherPalette.cream) : AnyShapeStyle(Color.white.opacity(0.08)), in: Capsule())
}
.padding(.horizontal, 18).padding(.vertical, 9)
.opacity(isCurrent ? 1 : 0.6)
- .help(isCurrent ? "" : m.t("cheats.otherHint"))
+ .help(isCurrent ? "" : loc.t("cheats.otherHint"))
}
@ViewBuilder private func cheatRow(_ cheat: CheatFiles.Cheat, index: Int) -> some View {
@@ -203,15 +205,15 @@ struct CheatsView: View {
HStack(spacing: 10) {
Text(cheat.name).font(.manrope(13))
Spacer(minLength: 8)
- Text(m.t("cheats.alwaysOn")).font(.manrope(11.5)).foregroundStyle(.secondary)
+ Text(loc.t("cheats.alwaysOn")).font(.manrope(11.5)).foregroundStyle(.secondary)
}
.padding(.horizontal, 18).padding(.vertical, 6)
case .cheat:
HStack(spacing: 10) {
VStack(alignment: .leading, spacing: 1) {
Text(cheat.name).font(.manrope(13)).lineLimit(2)
- if cheat.broken { Text(m.t("cheats.broken")).font(.manrope(11.5)).foregroundStyle(LauncherPalette.building) }
- else if cheat.once { Text(m.t("cheats.once")).font(.manrope(11.5)).foregroundStyle(.secondary) }
+ if cheat.broken { Text(loc.t("cheats.broken")).font(.manrope(11.5)).foregroundStyle(LauncherPalette.building) }
+ else if cheat.once { Text(loc.t("cheats.once")).font(.manrope(11.5)).foregroundStyle(.secondary) }
}
Spacer(minLength: 8)
if cheat.switchable {
@@ -227,13 +229,13 @@ struct CheatsView: View {
/// Import, the folder, and the copy to the device.
private var actions: some View {
HStack(spacing: 10) {
- Button(m.t("cheats.import")) { pick() }.disabled(busy)
+ Button(loc.t("cheats.import")) { pick() }.disabled(busy)
.padTarget("cheats.import", scope: "cheats") { if !busy { pick() } }
- Button(m.t("cheats.showFolder")) { showFolder() }
+ Button(loc.t("cheats.showFolder")) { showFolder() }
.padTarget("cheats.folder", scope: "cheats") { showFolder() }
Spacer(minLength: 8)
if game?.onDevice ?? false {
- Button(String(format: m.t("cheats.toDevice"), deviceName)) { copyToDevice() }.disabled(!canCopy)
+ Button(String(format: loc.t("cheats.toDevice"), deviceName)) { copyToDevice() }.disabled(!canCopy)
.padTarget("cheats.toDevice", scope: "cheats") { if canCopy { copyToDevice() } }
}
}
@@ -257,13 +259,13 @@ struct CheatsView: View {
do {
try cheatFiles.writeEnabled(file.buildID, cheats: cheats, on: next)
on = next
- result = game.flatMap { CheatsView.running(game: $0) ? (String(format: m.t("cheats.running"), $0.name), false) : nil }
- } catch { result = (String(format: m.t("cheats.writeFailed"), error.localizedDescription), false) }
+ result = game.flatMap { CheatsView.running(game: $0) ? (String(format: loc.t("cheats.running"), $0.name), false) : nil }
+ } catch { result = (String(format: loc.t("cheats.writeFailed"), error.localizedDescription), false) }
}
private func setMaster(_ value: Bool) {
guard let cheatFiles else { return }
- do { try cheatFiles.setMaster(value); master = value } catch { result = (String(format: m.t("cheats.writeFailed"), error.localizedDescription), false) }
+ do { try cheatFiles.setMaster(value); master = value } catch { result = (String(format: loc.t("cheats.writeFailed"), error.localizedDescription), false) }
}
private func pick() {
@@ -271,7 +273,7 @@ struct CheatsView: View {
panel.canChooseDirectories = true
panel.canChooseFiles = true
panel.allowsMultipleSelection = true
- panel.message = m.t("cheats.pickMessage")
+ panel.message = loc.t("cheats.pickMessage")
if panel.runModal() == .OK { importPaths(panel.urls.map(\.path)) }
}
@@ -280,16 +282,16 @@ struct CheatsView: View {
do {
let outcome = try cheatFiles.importFiles(from: paths.map { URL(fileURLWithPath: $0) })
refresh()
- result = Self.importMessage(outcome, m: m)
- } catch { result = (String(format: m.t("cheats.writeFailed"), error.localizedDescription), false) }
+ result = Self.importMessage(outcome, loc: loc)
+ } catch { result = (String(format: loc.t("cheats.writeFailed"), error.localizedDescription), false) }
}
/// What an import says: how many files came in, and the ones without a build ID in their name.
- static func importMessage(_ r: CheatFiles.ImportResult, m: BuildModel) -> (String, Bool) {
+ static func importMessage(_ r: CheatFiles.ImportResult, loc: Localizer) -> (String, Bool) {
var parts: [String] = []
- if !r.imported.isEmpty { parts.append(String(format: m.t("cheats.imported"), r.imported.count)) }
- if !r.skipped.isEmpty { parts.append(String(format: m.t("cheats.notNamed"), r.skipped.prefix(3).joined(separator: ", "))) }
- if parts.isEmpty { return (m.t("cheats.nothingFound"), false) }
+ if !r.imported.isEmpty { parts.append(String(format: loc.t("cheats.imported"), r.imported.count)) }
+ if !r.skipped.isEmpty { parts.append(String(format: loc.t("cheats.notNamed"), r.skipped.prefix(3).joined(separator: ", "))) }
+ if parts.isEmpty { return (loc.t("cheats.nothingFound"), false) }
return (parts.joined(separator: " "), !r.imported.isEmpty)
}
@@ -305,10 +307,10 @@ struct CheatsView: View {
busy = true; result = nil
DispatchQueue.global(qos: .userInitiated).async {
let outcome: (String, Bool)
- do { try transfer.toDevice(); outcome = (String(format: m.t("cheats.copied"), deviceName), true) }
- catch CheatTransfer.Failure.noFiles { outcome = (m.t("cheats.empty"), false) }
- catch CheatTransfer.Failure.device(let line) { outcome = (String(format: m.t("cheats.copyFailed"), line), false) }
- catch { outcome = (String(format: m.t("cheats.copyFailed"), error.localizedDescription), false) }
+ do { try transfer.toDevice(); outcome = (String(format: loc.t("cheats.copied"), deviceName), true) }
+ catch CheatTransfer.Failure.noFiles { outcome = (loc.t("cheats.empty"), false) }
+ catch CheatTransfer.Failure.device(let line) { outcome = (String(format: loc.t("cheats.copyFailed"), line), false) }
+ catch { outcome = (String(format: loc.t("cheats.copyFailed"), error.localizedDescription), false) }
DispatchQueue.main.async { busy = false; result = outcome; focus.focused = "cheats.done" }
}
}
diff --git a/frontend/Sources/NX2Apple/ContentView.swift b/frontend/Sources/NX2Apple/ContentView.swift
index c52ab444..7726b355 100644
--- a/frontend/Sources/NX2Apple/ContentView.swift
+++ b/frontend/Sources/NX2Apple/ContentView.swift
@@ -1,6 +1,7 @@
import SwiftUI
import NXCore
import NXLauncher
+import NXModel
// NS Port Builder: a macOS front end that walks a user through building a playable
// IPA from their own Switch game files. Not part of the host runtime; drives the
@@ -220,9 +221,9 @@ final class BuildModel: ObservableObject {
@Published var pythonPath = ""
@Published var dotnetPath = ""
- /// Interface language: the system's, read at every launch.
- @Published var lang: Lang = Lang.initial()
- func t(_ key: String) -> String { L10n.string(key, lang) }
+ /// The language and the strings: views take them from the environment, this model only for the text it writes itself.
+ let localizer: Localizer
+ init(localizer: Localizer = Localizer()) { self.localizer = localizer }
private var proc: Process?
private var lineBuf = ""
@@ -3044,6 +3045,7 @@ final class BuildModel: ObservableObject {
struct BuilderView: View {
@ObservedObject var m: BuildModel
+ @EnvironmentObject var loc: Localizer
@ObservedObject var library: GameLibrary
var settings = false
var onViewGame: () -> Void = {}
@@ -3075,7 +3077,7 @@ struct BuilderView: View {
.onChange(of: padFocus.focused) { id in // a controller's focus on this page scrolls into view
if let id, id.hasPrefix("set.") { withAnimation(.easeInOut(duration: 0.2)) { proxy.scrollTo(id, anchor: .center) } }
}
- .modifier(GameFilesDrop(enabled: !settings && !m.running, label: m.t("drop.hint")) { m.take(dropped: $0) }) // DropFiles.swift
+ .modifier(GameFilesDrop(enabled: !settings && !m.running, label: loc.t("drop.hint")) { m.take(dropped: $0) }) // DropFiles.swift
}
.buttonStyle(LauncherSecondaryButtonStyle())
}
@@ -3160,11 +3162,11 @@ struct BuilderView: View {
// ---- Build game ----
@ViewBuilder private var buildPage: some View {
- pageHeading(m.t("build.heading"), note: m.t("build.intro"))
+ pageHeading(loc.t("build.heading"), note: loc.t("build.intro"))
if !m.repoOK || !m.allDepsPresent {
- group(m.t("section.setup")) {
- row(m.t("library.setupHint"), dot: LauncherPalette.building) {
- Button(m.t("build.setup"), action: onOpenSettings)
+ group(loc.t("section.setup")) {
+ row(loc.t("library.setupHint"), dot: LauncherPalette.building) {
+ Button(loc.t("build.setup"), action: onOpenSettings)
}
}
}
@@ -3181,24 +3183,24 @@ struct BuilderView: View {
/// Where an iPhone build goes: exported as an IPA (as before), or signed and installed on a paired device.
private var install: some View {
- let devices = [(value: "", label: m.t("dev.none"))] + m.devices.map { d in
- (value: d.id, label: d.name + (d.reachable ? "" : " (" + m.t("dev.notConnected") + ")"))
+ let devices = [(value: "", label: loc.t("dev.none"))] + m.devices.map { d in
+ (value: d.id, label: d.name + (d.reachable ? "" : " (" + loc.t("dev.notConnected") + ")"))
}
- let teams = m.teams.map { (value: $0.id, label: $0.label(personalTeam: m.t("dev.personalTeam"))) }
+ let teams = m.teams.map { (value: $0.id, label: $0.label(personalTeam: loc.t("dev.personalTeam"))) }
let needsCertificate = m.teams.first { $0.id == m.signingTeam }.map { !$0.hasCertificate } ?? false
- return group(m.t("dev.section"), footnote: m.installDevice.isEmpty ? "" : (needsCertificate ? m.t("dev.teamNoCert") + " " : "") + m.t("dev.note")) {
- row(m.t("dev.target"), detail: m.devicesChecked && m.devices.isEmpty ? m.t("dev.noDevices") : "") {
+ return group(loc.t("dev.section"), footnote: m.installDevice.isEmpty ? "" : (needsCertificate ? loc.t("dev.teamNoCert") + " " : "") + loc.t("dev.note")) {
+ row(loc.t("dev.target"), detail: m.devicesChecked && m.devices.isEmpty ? loc.t("dev.noDevices") : "") {
if !m.devicesChecked { ProgressView().controlSize(.small) }
- Button(m.t("dev.refresh")) { m.refreshDevices() }.buttonStyle(.plain).font(.manrope(13)).foregroundStyle(.secondary)
- LauncherDropdown(options: devices, selection: m.installDevice, label: m.t("dev.target")) { m.installDevice = $0 }
+ Button(loc.t("dev.refresh")) { m.refreshDevices() }.buttonStyle(.plain).font(.manrope(13)).foregroundStyle(.secondary)
+ LauncherDropdown(options: devices, selection: m.installDevice, label: loc.t("dev.target")) { m.installDevice = $0 }
}
if !m.installDevice.isEmpty {
divider
if teams.isEmpty {
- row(m.t("dev.team"), detail: m.t("dev.noTeam"), dot: LauncherPalette.building) { EmptyView() }
+ row(loc.t("dev.team"), detail: loc.t("dev.noTeam"), dot: LauncherPalette.building) { EmptyView() }
} else {
- row(m.t("dev.team")) {
- LauncherDropdown(options: teams, selection: m.signingTeam, label: m.t("dev.team")) { m.signingTeam = $0 }
+ row(loc.t("dev.team")) {
+ LauncherDropdown(options: teams, selection: m.signingTeam, label: loc.t("dev.team")) { m.signingTeam = $0 }
}
}
}
@@ -3209,11 +3211,11 @@ struct BuilderView: View {
private var files: some View {
// The report's own mistake, and a reasonable one: the output folder silently decides where
// the build cache lives, so changing it threw away a finished build. Say it under Save to, all the time.
- group(m.t("section.files"), footnote: m.t("msg.workdirHint")) {
+ group(loc.t("section.files"), footnote: loc.t("msg.workdirHint")) {
Button(action: pickFolder) {
- row(m.t(m.gameDir.isEmpty ? "build.folderCTA" : "build.folderSelected"),
- detail: m.gameDir.isEmpty ? m.t("build.folderNote") : m.shortPath(m.gameDir), help: m.gameDir) {
- Text(m.t(m.gameDir.isEmpty ? "data.choose" : "data.change"))
+ row(loc.t(m.gameDir.isEmpty ? "build.folderCTA" : "build.folderSelected"),
+ detail: m.gameDir.isEmpty ? loc.t("build.folderNote") : m.shortPath(m.gameDir), help: m.gameDir) {
+ Text(loc.t(m.gameDir.isEmpty ? "data.choose" : "data.change"))
.font(.manrope(13, .semibold)).foregroundStyle(.black)
.launcherRowControlFrame()
.background(LauncherPalette.cream, in: Capsule())
@@ -3223,16 +3225,16 @@ struct BuilderView: View {
.buttonStyle(.plain)
ForEach(m.slots.filter { !$0.optional }, id: \.id) { s in
divider; slotRow(s)
- if s.id == "keys", let keyCheck { KeyCheckLine(outcome: keyCheck, t: m.t) }
+ if s.id == "keys", let keyCheck { KeyCheckLine(outcome: keyCheck, t: loc.t) }
}
divider
- disclosure(m.t("build.options"), isOpen: extrasOpen) { extrasOpen.toggle() }
+ disclosure(loc.t("build.options"), isOpen: extrasOpen) { extrasOpen.toggle() }
if extrasOpen {
ForEach(m.slots.filter(\.optional), id: \.id) { s in divider; slotRow(s) }
}
divider
- row(m.t("build.saveTo"), detail: m.outDir.isEmpty ? m.t("build.saveDefault") : m.shortPath(m.outDir), help: m.outDir) {
- Button(m.t("data.change")) { m.chooseBuildFolder() }
+ row(loc.t("build.saveTo"), detail: m.outDir.isEmpty ? loc.t("build.saveDefault") : m.shortPath(m.outDir), help: m.outDir) {
+ Button(loc.t("data.change")) { m.chooseBuildFolder() }
}
}
.task(id: KeyCheck.Inputs(keys: m.keysPath, files: [m.basePath, m.updatePath] + m.dlcPaths)) {
@@ -3242,13 +3244,13 @@ struct BuilderView: View {
private func slotRow(_ s: Slot) -> some View {
// An empty prod.keys row says where the file comes from.
- row(m.t(s.title), detail: s.id == "keys" && s.paths.isEmpty ? m.t("build.keyHint") : s.summary(m.t), dot: s.ok ? LauncherPalette.ready : LauncherPalette.unbuilt,
+ row(loc.t(s.title), detail: s.id == "keys" && s.paths.isEmpty ? loc.t("build.keyHint") : s.summary(loc.t), dot: s.ok ? LauncherPalette.ready : LauncherPalette.unbuilt,
help: s.paths.joined(separator: "\n")) {
if !s.paths.isEmpty {
- Button(m.t("data.clear")) { m.clear(s.id) }.buttonStyle(.plain)
+ Button(loc.t("data.clear")) { m.clear(s.id) }.buttonStyle(.plain)
.font(.manrope(13)).foregroundStyle(.secondary)
}
- Button(s.paths.isEmpty ? m.t("data.choose") : m.t("data.change")) { m.pickFiles(kind: s.kind) }
+ Button(s.paths.isEmpty ? loc.t("data.choose") : loc.t("data.change")) { m.pickFiles(kind: s.kind) }
}
}
@@ -3260,7 +3262,7 @@ struct BuilderView: View {
private var target: some View {
VStack(alignment: .leading, spacing: 10) {
- Text(m.t("section.target")).font(.manrope(15, .semibold)).foregroundStyle(.secondary)
+ Text(loc.t("section.target")).font(.manrope(15, .semibold)).foregroundStyle(.secondary)
.padding(.leading, 2)
HStack(spacing: 14) {
targetCard(BuildTarget.mac, symbol: "desktopcomputer", title: "build.mac", note: "build.macNote")
@@ -3271,8 +3273,8 @@ struct BuilderView: View {
VStack(spacing: 0) {
HStack(alignment: .center, spacing: 12) {
VStack(alignment: .leading, spacing: 3) {
- Text(m.t("opt.bc")).font(.manrope(14))
- Text(m.t("opt.bc.note")).font(.manrope(12.5)).foregroundStyle(.secondary)
+ Text(loc.t("opt.bc")).font(.manrope(14))
+ Text(loc.t("opt.bc.note")).font(.manrope(12.5)).foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
}
Spacer(minLength: 12)
@@ -3299,8 +3301,8 @@ struct BuilderView: View {
.frame(width: 18, height: 18)
}
VStack(alignment: .leading, spacing: 4) {
- Text(m.t(title)).font(.manrope(16, .semibold))
- Text(m.t(note)).font(.manrope(12.5)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
+ Text(loc.t(title)).font(.manrope(16, .semibold))
+ Text(loc.t(note)).font(.manrope(12.5)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
}
}
.padding(20).frame(maxWidth: .infinity, alignment: .leading)
@@ -3314,17 +3316,17 @@ struct BuilderView: View {
@ViewBuilder private var outcome: some View {
if m.done && m.target == BuildTarget.mac {
- group(m.t("section.done")) {
- row(m.t("library.ready"), detail: m.shortPath(m.macAppPath), dot: LauncherPalette.ready, help: m.macAppPath) {
- Button(m.t("install.reveal")) { reveal(m.macAppPath) }
- Button(m.t("build.showLibrary"), action: onViewGame)
+ group(loc.t("section.done")) {
+ row(loc.t("library.ready"), detail: m.shortPath(m.macAppPath), dot: LauncherPalette.ready, help: m.macAppPath) {
+ Button(loc.t("install.reveal")) { reveal(m.macAppPath) }
+ Button(loc.t("build.showLibrary"), action: onViewGame)
}
}
}
if m.done && !m.installedOn.isEmpty {
- group(String(format: m.t("dev.installed"), m.deviceName(m.installedOn))) {
- row(m.t("dev.installedNote"), dot: LauncherPalette.ready) {
- Button(String(format: m.t("dev.open"), m.deviceName(m.installedOn))) {
+ group(String(format: loc.t("dev.installed"), m.deviceName(m.installedOn))) {
+ row(loc.t("dev.installedNote"), dot: LauncherPalette.ready) {
+ Button(String(format: loc.t("dev.open"), m.deviceName(m.installedOn))) {
m.openOnDevice(udid: m.installedOn, app: m.installedAppPath) { error in if let error { m.doneNote = error } }
}
}
@@ -3332,8 +3334,8 @@ struct BuilderView: View {
// fast external drive handed to the device is quicker than USB): show where they are.
if !m.archivePath.isEmpty {
divider
- row(m.t("dev.gameData"), detail: m.shortPath(m.archivePath), dot: LauncherPalette.ready, help: m.archivePath) {
- Button(m.t("install.reveal")) { reveal(m.archivePath) }
+ row(loc.t("dev.gameData"), detail: m.shortPath(m.archivePath), dot: LauncherPalette.ready, help: m.archivePath) {
+ Button(loc.t("install.reveal")) { reveal(m.archivePath) }
}
}
}
@@ -3343,7 +3345,7 @@ struct BuilderView: View {
/// The script's own stages once a build has run, and its log behind a disclosure.
@ViewBuilder private var progress: some View {
if m.running || !m.stages.isEmpty {
- group(m.t("section.progress")) {
+ group(loc.t("section.progress")) {
ForEach(Array(m.stages.enumerated()), id: \.element.id) { index, s in
if index > 0 { divider }
HStack(spacing: 12) {
@@ -3353,7 +3355,7 @@ struct BuilderView: View {
Spacer(minLength: 12)
if s.state == .running {
TimelineView(.periodic(from: Date(), by: 1)) { context in
- Text([s.detail, s.clock(at: context.date, left: m.t("prog.eta"))].filter { !$0.isEmpty }.joined(separator: " · "))
+ Text([s.detail, s.clock(at: context.date, left: loc.t("prog.eta"))].filter { !$0.isEmpty }.joined(separator: " · "))
.font(.manrope(12)).monospacedDigit().foregroundStyle(.secondary).lineLimit(1)
}
} else if !s.detail.isEmpty { Text(s.detail).font(.manrope(12)).foregroundStyle(.secondary).lineLimit(1) }
@@ -3366,7 +3368,7 @@ struct BuilderView: View {
.padding(.horizontal, 18).padding(.vertical, 12)
}
if m.stages.isEmpty && m.running {
- row(m.t("library.preparing")) { ProgressView().controlSize(.small) }
+ row(loc.t("library.preparing")) { ProgressView().controlSize(.small) }
}
}
}
@@ -3376,14 +3378,14 @@ struct BuilderView: View {
/// It used to sit at the bottom of the progress card, which is where a failed build's message
/// pointed ("see the log below") while the log itself was out of view on a short window (#52).
@ViewBuilder private var logPanel: some View {
- group(m.t("section.log")) {
+ group(loc.t("section.log")) {
if m.shellCopy != nil || m.shellWaiting {
// The log below is the build's own output; the data transfer is driven by the app, so
// its questions and errors (a locked device, a failed listing) answer here, not in it.
- Text(m.t("log.transferNote")).font(.manrope(12.5)).foregroundStyle(.secondary)
+ Text(loc.t("log.transferNote")).font(.manrope(12.5)).foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true).padding(.horizontal, 14).padding(.top, 2)
}
- disclosure(m.t("build.log"), isOpen: logOpen) { logOpen.toggle() }
+ disclosure(loc.t("build.log"), isOpen: logOpen) { logOpen.toggle() }
if logOpen { logView.padding(.horizontal, 14).padding(.bottom, 14) }
}
.onReceive(BuildNotifier.shared.$showLog) { show in // a clicked notification of a failed build
@@ -3394,7 +3396,7 @@ struct BuilderView: View {
private var logView: some View {
ScrollViewReader { sp in
ScrollView {
- Text(m.logTail.isEmpty ? m.t("log.placeholder") : m.logTail)
+ Text(m.logTail.isEmpty ? loc.t("log.placeholder") : m.logTail)
.font(.mono(11))
.textSelection(.enabled)
.frame(maxWidth: .infinity, alignment: .leading)
@@ -3417,7 +3419,7 @@ struct BuilderView: View {
Button {
m.running ? m.stop() : m.startBuild()
} label: {
- Label(m.running ? m.t(m.stopping ? "library.stopping" : "btn.stop") : (m.done ? m.t("btn.rebuild") : m.t("build.startGame")),
+ Label(m.running ? loc.t(m.stopping ? "library.stopping" : "btn.stop") : (m.done ? loc.t("btn.rebuild") : loc.t("build.startGame")),
systemImage: m.running ? "stop.fill" : "hammer.fill")
.font(.manrope(15, .semibold)).padding(.horizontal, 24).padding(.vertical, 13)
.foregroundStyle(.black).background(m.running ? LauncherPalette.building : LauncherPalette.cream, in: Capsule())
@@ -3436,15 +3438,15 @@ struct BuilderView: View {
Text(m.doneNote).font(.manrope(13))
.foregroundStyle(m.done ? LauncherPalette.ready : LauncherPalette.building).lineLimit(2)
} else if !m.depsChecked {
- Text(m.t("status.checkingDeps")).font(.manrope(13)).foregroundStyle(.secondary)
+ Text(loc.t("status.checkingDeps")).font(.manrope(13)).foregroundStyle(.secondary)
} else if !m.allDepsPresent {
- Text(m.t("status.installFirst")).font(.manrope(13)).foregroundStyle(LauncherPalette.building)
+ Text(loc.t("status.installFirst")).font(.manrope(13)).foregroundStyle(LauncherPalette.building)
} else if !m.repoOK {
- Text(m.t("status.chooseRepo")).font(.manrope(13)).foregroundStyle(LauncherPalette.building)
+ Text(loc.t("status.chooseRepo")).font(.manrope(13)).foregroundStyle(LauncherPalette.building)
} else if !m.slot("base").ok || !m.slot("keys").ok {
- Text(m.t("status.needInputs")).font(.manrope(13)).foregroundStyle(.secondary)
+ Text(loc.t("status.needInputs")).font(.manrope(13)).foregroundStyle(.secondary)
} else {
- Text(String(format: m.t("status.output"), m.shortPath(m.outDir.isEmpty ? (m.basePath as NSString).deletingLastPathComponent : m.outDir)))
+ Text(String(format: loc.t("status.output"), m.shortPath(m.outDir.isEmpty ? (m.basePath as NSString).deletingLastPathComponent : m.outDir)))
.font(.manrope(13)).foregroundStyle(.secondary).lineLimit(1).truncationMode(.head)
}
}
@@ -3452,93 +3454,92 @@ struct BuilderView: View {
// ---- Settings ----
@ViewBuilder private var settingsPage: some View {
- pageHeading(m.t("settings.heading"), note: m.t("settings.note"))
+ pageHeading(loc.t("settings.heading"), note: loc.t("settings.note"))
settingsCards
}
@ViewBuilder private var settingsCards: some View {
- group(m.t("section.library"), footnote: m.t("library.folderHint")) {
- row(m.t("library.folderTitle"), detail: library.folder.isEmpty ? m.t("library.folderUnset") : m.shortPath(library.folder),
+ group(loc.t("section.library"), footnote: loc.t("library.folderHint")) {
+ row(loc.t("library.folderTitle"), detail: library.folder.isEmpty ? loc.t("library.folderUnset") : m.shortPath(library.folder),
dot: library.folder.isEmpty ? LauncherPalette.unbuilt : LauncherPalette.ready, help: library.folder) {
if library.scanning { ProgressView().controlSize(.small) }
if !library.folder.isEmpty {
- Button(m.t("library.rescan")) { library.discover() }.disabled(library.scanning)
+ Button(loc.t("library.rescan")) { library.discover() }.disabled(library.scanning)
.padTarget("set.rescan", scope: "main") { if !library.scanning { library.discover() } }
}
- Button(m.t("library.chooseFolder"), action: onChooseLibraryFolder)
+ Button(loc.t("library.chooseFolder"), action: onChooseLibraryFolder)
.padTarget("set.folder", scope: "main") { onChooseLibraryFolder() }
}
}
- group(m.t("section.controls"), footnote: m.t("controls.settingsHint")) {
- row(m.t("controls.row"), detail: controlChanges == 0 ? m.t("controls.defaultLayout") : String(format: m.t("controls.changes"), controlChanges)) {
- Button(m.t("controls.customize"), action: onOpenControls)
+ group(loc.t("section.controls"), footnote: loc.t("controls.settingsHint")) {
+ row(loc.t("controls.row"), detail: controlChanges == 0 ? loc.t("controls.defaultLayout") : String(format: loc.t("controls.changes"), controlChanges)) {
+ Button(loc.t("controls.customize"), action: onOpenControls)
.padTarget("set.controls", scope: "main") { onOpenControls() }
}
divider
- row(m.t("console.mergeAll"), detail: m.t("console.mergeNote")) {
+ row(loc.t("console.mergeAll"), detail: loc.t("console.mergeNote")) {
Toggle("", isOn: padMerge).labelsHidden().toggleStyle(LauncherSwitchStyle())
.padTarget("set.padMerge", scope: "main") { padMerge.wrappedValue.toggle() }
}
divider
- row(m.t("console.controllers"), detail: m.t("console.controllersRowNote")) {
- Button(m.t("console.controllersOpen"), action: onOpenControllers)
+ row(loc.t("console.controllers"), detail: loc.t("console.controllersRowNote")) {
+ Button(loc.t("console.controllersOpen"), action: onOpenControllers)
.padTarget("set.controllers", scope: "main") { onOpenControllers() }
}
divider
- row(m.t("console.promptSetting"), detail: m.t("console.promptSettingNote")) {
+ row(loc.t("console.promptSetting"), detail: loc.t("console.promptSettingNote")) {
Toggle("", isOn: $consolePromptOn).labelsHidden().toggleStyle(LauncherSwitchStyle())
.padTarget("set.consolePrompt", scope: "main") { consolePromptOn.toggle() }
}
}
tools
- group(m.t("section.app"), footnote: m.appStatus) {
+ group(loc.t("section.app"), footnote: m.appStatus) {
// The interface language: the device default unless someone picks one here. Stored as
// "" (follow), "zh", "en", "sv", "de" or "fr" so a later system-language change still applies.
- row(m.t("settings.language"),
- detail: Lang.saved.map { m.t("settings.language.\($0.rawValue)") }
- ?? m.t("settings.language.system"), dot: LauncherPalette.ready, help: "") {
+ row(loc.t("settings.language"),
+ detail: Lang.saved.map { loc.t("settings.language.\($0.rawValue)") }
+ ?? loc.t("settings.language.system"), dot: LauncherPalette.ready, help: "") {
// The launcher's own list, drawn like the buttons beside it and as wide as they are.
// The language names are in their own language (see "settings.language.*"), only "system" follows the UI.
- LauncherDropdown(options: Self.languageCodes.map { (value: $0, label: m.t("settings.language." + ($0.isEmpty ? "system" : $0))) },
- selection: Lang.saved.map { $0.rawValue } ?? "", label: m.t("settings.language"),
+ LauncherDropdown(options: Self.languageCodes.map { (value: $0, label: loc.t("settings.language." + ($0.isEmpty ? "system" : $0))) },
+ selection: Lang.saved.map { $0.rawValue } ?? "", label: loc.t("settings.language"),
style: .button) { v in
- Lang.saved = v.isEmpty ? nil : Lang(rawValue: v)
- m.lang = Lang.initial()
+ loc.choose(v)
}
.padTarget("set.language", scope: "main", activate: { cycleLanguage(1) }, adjust: { cycleLanguage($0) })
}
divider
// Build notifications (BuildNotifications.swift): none without an app bundle, e.g. under swift run
- row(m.t("settings.notify"), detail: m.t(BuildNotice.hasBundleID ? "settings.notifyNote" : "settings.notifyUnbundled")) {
+ row(loc.t("settings.notify"), detail: loc.t(BuildNotice.hasBundleID ? "settings.notifyNote" : "settings.notifyUnbundled")) {
Toggle("", isOn: $notifyBuilds).toggleStyle(LauncherSwitchStyle()).labelsHidden().disabled(!BuildNotice.hasBundleID)
.padTarget("set.notify", scope: "main") { notifyBuilds.toggle() }
}
divider
if let onRunSetup {
- row(m.t("settings.setup"), detail: m.t("settings.setupNote")) {
- Button(m.t("settings.setupBtn"), action: onRunSetup)
+ row(loc.t("settings.setup"), detail: loc.t("settings.setupNote")) {
+ Button(loc.t("settings.setupBtn"), action: onRunSetup)
.padTarget("set.setup", scope: "main") { onRunSetup() }
}
divider
}
// The launcher back in front when a game it started quits (ReturnAfterPlay.swift)
- row(m.t("settings.returnAfterPlay"), detail: m.t("settings.returnAfterPlayNote")) {
+ row(loc.t("settings.returnAfterPlay"), detail: loc.t("settings.returnAfterPlayNote")) {
Toggle("", isOn: $returnAfterPlay).toggleStyle(LauncherSwitchStyle()).labelsHidden()
.padTarget("set.returnAfterPlay", scope: "main") { returnAfterPlay.toggle() }
}
divider
- row("NX2Apple", detail: String(format: m.t("app.version"), BuildModel.appVersion),
+ row("NX2Apple", detail: String(format: loc.t("app.version"), BuildModel.appVersion),
dot: m.appStaged != nil ? LauncherPalette.ready : nil) {
if m.appBusy { ProgressView().controlSize(.small) }
if m.appStaged != nil {
// Downloaded and verified: it goes in when the app quits; this restarts into it now (not during a build)
- Button(m.t("app.restartNow")) { m.restartToUpdate() }.disabled(m.running)
+ Button(loc.t("app.restartNow")) { m.restartToUpdate() }.disabled(m.running)
.padTarget("set.appRestart", scope: "main") { if !m.running { m.restartToUpdate() } }
} else if let u = m.appUpdate, m.appInstallability == .ok {
- Button(String(format: m.t("app.updateBtn"), u.tag)) { m.performAppUpdate() }.disabled(m.appBusy || m.running)
+ Button(String(format: loc.t("app.updateBtn"), u.tag)) { m.performAppUpdate() }.disabled(m.appBusy || m.running)
.padTarget("set.appUpdate", scope: "main") { if !(m.appBusy || m.running) { m.performAppUpdate() } }
} else {
- Button(m.t("repo.check")) { m.checkAppUpdate() }.disabled(m.appBusy)
+ Button(loc.t("repo.check")) { m.checkAppUpdate() }.disabled(m.appBusy)
.padTarget("set.appCheck", scope: "main") { if !m.appBusy { m.checkAppUpdate() } }
}
}
@@ -3546,15 +3547,15 @@ struct BuilderView: View {
if m.appInstallability == .ok {
// The uninstaller (Uninstall.swift): state folders and the launcher's own checkout go; the
// games folder and prod.keys stay; the app itself goes to the Trash.
- row(m.t("uninstall.title"), detail: m.t("uninstall.note")) {
- Button(m.t("uninstall.button")) { m.uninstallPlan = uninstallPlan() }
+ row(loc.t("uninstall.title"), detail: loc.t("uninstall.note")) {
+ Button(loc.t("uninstall.button")) { m.uninstallPlan = uninstallPlan() }
.disabled(m.running)
.padTarget("set.uninstall", scope: "main") { if !m.running { m.uninstallPlan = uninstallPlan() } }
}
divider
}
// A launcher built from the repository never replaces itself (AppUpdate.installability): the switch says so and stays off
- row(m.t("app.auto"), detail: m.t(m.appInstallability == .ok ? "app.autoNote" : m.appInstallability == .developer ? "app.autoDev" : "app.autoReadOnly")) {
+ row(loc.t("app.auto"), detail: loc.t(m.appInstallability == .ok ? "app.autoNote" : m.appInstallability == .developer ? "app.autoDev" : "app.autoReadOnly")) {
Toggle("", isOn: Binding(get: { m.autoUpdateApp && m.appInstallability == .ok }, set: { m.autoUpdateApp = $0 }))
.labelsHidden().toggleStyle(LauncherSwitchStyle()).disabled(m.appInstallability != .ok)
.padTarget("set.appAuto", scope: "main") { if m.appInstallability == .ok { m.autoUpdateApp.toggle() } }
@@ -3571,8 +3572,7 @@ struct BuilderView: View {
let values = Self.languageCodes
let at = values.firstIndex(of: Lang.saved.map { $0.rawValue } ?? "") ?? 0
let v = values[(at + by + values.count) % values.count]
- Lang.saved = v.isEmpty ? nil : Lang(rawValue: v)
- m.lang = Lang.initial()
+ loc.choose(v)
}
private func uninstallPlan() -> Uninstall.Plan {
@@ -3581,72 +3581,72 @@ struct BuilderView: View {
}
private var tools: some View {
- group(m.t("section.tools"), footnote: m.usesEngineStore ? m.engineStatus
- : (m.repoStatus.isEmpty ? (m.repoOK ? "" : m.t("repo.firstHint")) : m.repoStatus)) {
+ group(loc.t("section.tools"), footnote: m.usesEngineStore ? m.engineStatus
+ : (m.repoStatus.isEmpty ? (m.repoOK ? "" : loc.t("repo.firstHint")) : m.repoStatus)) {
if m.usesEngineStore {
engineRows
} else {
- row(m.t("repo.title"),
+ row(loc.t("repo.title"),
detail: m.repoOK ? m.shortPath(m.repoPath)
- : (m.repoPath.isEmpty ? m.t("repo.notFound") : String(format: m.t("repo.notRepo"), m.shortPath(m.repoPath))),
+ : (m.repoPath.isEmpty ? loc.t("repo.notFound") : String(format: loc.t("repo.notRepo"), m.shortPath(m.repoPath))),
dot: m.repoOK ? LauncherPalette.ready : LauncherPalette.building, help: m.repoPath) {
if m.repoBusy { ProgressView().controlSize(.small) }
if m.repoOK {
if m.repoIsGit {
if let n = m.repoBehind, n > 0 {
- Button(m.t("repo.pull")) { m.pullRepo() }.disabled(m.repoBusy || m.running)
+ Button(loc.t("repo.pull")) { m.pullRepo() }.disabled(m.repoBusy || m.running)
.padTarget("set.repoPull", scope: "main") { if !(m.repoBusy || m.running) { m.pullRepo() } }
}
- Button(m.t("repo.check")) { m.checkRepoUpdates() }.disabled(m.repoBusy || m.running)
+ Button(loc.t("repo.check")) { m.checkRepoUpdates() }.disabled(m.repoBusy || m.running)
.padTarget("set.repoCheck", scope: "main") { if !(m.repoBusy || m.running) { m.checkRepoUpdates() } }
} else {
- Button(m.t("repo.adopt")) { m.adoptRepoAsGit() }.disabled(m.repoBusy || m.running)
+ Button(loc.t("repo.adopt")) { m.adoptRepoAsGit() }.disabled(m.repoBusy || m.running)
.padTarget("set.repoAdopt", scope: "main") { if !(m.repoBusy || m.running) { m.adoptRepoAsGit() } }
}
}
// Always offered, including when a repository is already configured: a saved path from
// an earlier session (an upstream clone, a moved folder) is exactly the state a user
// cannot fix without this button — the report had no way to leave the wrong repository.
- Button(m.t("repo.choose")) { pickRepo() }
+ Button(loc.t("repo.choose")) { pickRepo() }
if !m.repoOK {
- Button(m.t("repo.download")) { m.cloneRepo() }.disabled(m.repoBusy || m.running)
+ Button(loc.t("repo.download")) { m.cloneRepo() }.disabled(m.repoBusy || m.running)
}
}
if !m.repoOK {
// GitHub does not load everywhere: the manual route (Code → Download ZIP → unzip →
// Choose repository) needs no git at all, and the note says which folder to pick.
HStack(spacing: 4) {
- Text(m.t("repo.manualHint")).foregroundStyle(.secondary)
+ Text(loc.t("repo.manualHint")).foregroundStyle(.secondary)
Link("github.com/LNPANDY/NX2Apple", destination: URL(string: BuildModel.repoURL.replacingOccurrences(of: ".git", with: ""))!)
- Text(m.t("repo.manualHint2")).foregroundStyle(.secondary)
+ Text(loc.t("repo.manualHint2")).foregroundStyle(.secondary)
}
.font(.manrope(12)).padding(.horizontal, 18).padding(.bottom, 12)
}
if m.repoOK, !m.repoIsGit {
- Text(m.t(m.autoUpdateRepo ? "repo.noGit" : "repo.zipNoAuto")).font(.manrope(12)).foregroundStyle(.secondary)
+ Text(loc.t(m.autoUpdateRepo ? "repo.noGit" : "repo.zipNoAuto")).font(.manrope(12)).foregroundStyle(.secondary)
.padding(.horizontal, 18).padding(.bottom, 12)
}
if m.repoOK, !BuildModel.missingTools(in: m.repoPath).isEmpty {
- Text(String(format: m.t("repo.toolsOld"), BuildModel.missingTools(in: m.repoPath).joined(separator: ", ")))
+ Text(String(format: loc.t("repo.toolsOld"), BuildModel.missingTools(in: m.repoPath).joined(separator: ", ")))
.font(.manrope(12)).foregroundStyle(LauncherPalette.building)
.padding(.horizontal, 18).padding(.bottom, 12)
}
if m.repoOK { // a ZIP copy too: its adoption at launch follows this switch
divider
- row(m.t("repo.auto"), detail: m.t("repo.autoNote")) {
+ row(loc.t("repo.auto"), detail: loc.t("repo.autoNote")) {
Toggle("", isOn: $m.autoUpdateRepo).labelsHidden().toggleStyle(LauncherSwitchStyle())
}
}
}
divider
Button(action: { withAnimation(.easeInOut(duration: 0.18)) { m.toggleDeps() } }) {
- row(m.t("dep.title"),
- detail: !m.depsChecked ? m.t("dep.checking")
- : (m.allDepsPresent ? m.t("dep.allReady") : String(format: m.t("dep.missing"), m.deps.filter { !$0.present }.count)),
+ row(loc.t("dep.title"),
+ detail: !m.depsChecked ? loc.t("dep.checking")
+ : (m.allDepsPresent ? loc.t("dep.allReady") : String(format: loc.t("dep.missing"), m.deps.filter { !$0.present }.count)),
dot: !m.depsChecked ? LauncherPalette.unbuilt : (m.allDepsPresent ? LauncherPalette.ready : LauncherPalette.building),
open: m.depsOpen) {
if !m.depsChecked { ProgressView().controlSize(.small) }
- Button(m.t("dep.recheck")) { m.checkDeps() }
+ Button(loc.t("dep.recheck")) { m.checkDeps() }
.padTarget("set.deps", scope: "main") { m.checkDeps() }
}
.contentShape(Rectangle())
@@ -3656,13 +3656,13 @@ struct BuilderView: View {
ForEach(m.deps, id: \.id) { d in
divider
VStack(alignment: .leading, spacing: 0) {
- row(m.t(d.name), detail: m.shortPath(m.depDetail(d)), dot: d.present && !d.warning ? LauncherPalette.ready : LauncherPalette.building,
- help: m.t(d.hint)) {
+ row(loc.t(d.name), detail: m.shortPath(m.depDetail(d)), dot: d.present && !d.warning ? LauncherPalette.ready : LauncherPalette.building,
+ help: loc.t(d.hint)) {
if d.installing {
ProgressView().controlSize(.small)
- Text(m.t("dep.installing")).font(.manrope(12)).foregroundStyle(LauncherPalette.building)
+ Text(loc.t("dep.installing")).font(.manrope(12)).foregroundStyle(LauncherPalette.building)
} else if !d.present {
- Button(d.actionLabel.isEmpty ? (d.installCmd.isEmpty ? m.t("dep.openAppStore") : m.t("dep.install")) : m.t(d.actionLabel)) { m.installDep(d) }
+ Button(d.actionLabel.isEmpty ? (d.installCmd.isEmpty ? loc.t("dep.openAppStore") : loc.t("dep.install")) : loc.t(d.actionLabel)) { m.installDep(d) }
}
}
// Why the last install failed, and what to do about it: the tool's own
@@ -3672,7 +3672,7 @@ struct BuilderView: View {
Text(d.lastError).font(.mono(11)).foregroundStyle(LauncherPalette.building)
.lineLimit(3).help(d.lastError)
if !d.fixHint.isEmpty {
- Text(m.t(d.fixHint)).font(.manrope(11.5)).foregroundStyle(.secondary)
+ Text(loc.t(d.fixHint)).font(.manrope(11.5)).foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
}
}
@@ -3683,27 +3683,27 @@ struct BuilderView: View {
}
}
divider
- row(m.t("diag.title"), detail: m.t("diag.note")) { DiagnosticsButton(m: m, game: library.selected) }
+ row(loc.t("diag.title"), detail: loc.t("diag.note")) { DiagnosticsButton(m: m, game: library.selected) }
}
}
/// The release app's engine (EngineUpdateModel.swift): which one the build uses, its channel, and the automatic update.
@ViewBuilder private var engineRows: some View {
let idle = !(m.engineBusy || m.running)
- row(m.t("engine.title"), detail: m.engineDetail,
+ row(loc.t("engine.title"), detail: m.engineDetail,
dot: m.engineSelection.engineID.isEmpty ? LauncherPalette.building : LauncherPalette.ready, help: m.repoPath) {
if m.engineBusy { ProgressView().controlSize(.small) }
if let next = m.engineAvailable {
- Button(String(format: m.t("engine.install"), next.version)) { m.installAvailableEngine() }.disabled(!idle)
+ Button(String(format: loc.t("engine.install"), next.version)) { m.installAvailableEngine() }.disabled(!idle)
.padTarget("set.engineInstall", scope: "main") { if idle { m.installAvailableEngine() } }
}
- Button(m.t("repo.check")) { m.checkEngineUpdate() }.disabled(!idle)
+ Button(loc.t("repo.check")) { m.checkEngineUpdate() }.disabled(!idle)
.padTarget("set.engineCheck", scope: "main") { if idle { m.checkEngineUpdate() } }
}
divider
// A different channel is asked about first (the alert below): the switch can recompile every game's shaders
- row(m.t("engine.update"), detail: m.t("engine.channelNote"), dot: LauncherPalette.ready) {
- LauncherDropdown(options: EngineChannel.allCases.map { (value: $0.rawValue, label: m.t($0.labelKey)) },
+ row(loc.t("engine.update"), detail: loc.t("engine.channelNote"), dot: LauncherPalette.ready) {
+ LauncherDropdown(options: EngineChannel.allCases.map { (value: $0.rawValue, label: loc.t($0.labelKey)) },
selection: m.engineSelection.channel.rawValue) { v in
if let channel = EngineChannel(rawValue: v) { m.requestEngineChannel(channel) }
}
@@ -3712,22 +3712,22 @@ struct BuilderView: View {
if idle { m.requestEngineChannel(m.engineSelection.channel == .stable ? .experimental : .stable) }
}
}
- .alert(m.t("engine.switch.title"), isPresented: Binding(get: { m.confirmingChannel != nil },
+ .alert(loc.t("engine.switch.title"), isPresented: Binding(get: { m.confirmingChannel != nil },
set: { if !$0 { m.cancelEngineChannel() } })) {
if let channel = m.confirmingChannel {
- Button(String(format: m.t("engine.switch.go"), m.t(channel.labelKey))) { m.confirmEngineChannel(channel) }
+ Button(String(format: loc.t("engine.switch.go"), loc.t(channel.labelKey))) { m.confirmEngineChannel(channel) }
}
- Button(m.t("engine.switch.cancel"), role: .cancel) { m.cancelEngineChannel() }
+ Button(loc.t("engine.switch.cancel"), role: .cancel) { m.cancelEngineChannel() }
} message: {
- Text(m.confirmingChannel.flatMap { m.engineSelection.channel.switchWarningKey(to: $0) }.map { m.t($0) } ?? "")
+ Text(m.confirmingChannel.flatMap { m.engineSelection.channel.switchWarningKey(to: $0) }.map { loc.t($0) } ?? "")
}
divider
- row(m.t("shellCache.row"), detail: m.t("shellCache.note"), detail2: m.shellCachePath) {
- Button(m.t("shellCache.open")) { m.revealFolder(URL(fileURLWithPath: m.shellCachePath)) }
+ row(loc.t("shellCache.row"), detail: loc.t("shellCache.note"), detail2: m.shellCachePath) {
+ Button(loc.t("shellCache.open")) { m.revealFolder(URL(fileURLWithPath: m.shellCachePath)) }
.buttonStyle(LauncherSecondaryButtonStyle())
}
divider
- row(m.t("repo.auto"), detail: m.t("engine.autoNote")) {
+ row(loc.t("repo.auto"), detail: loc.t("engine.autoNote")) {
Toggle("", isOn: $m.autoUpdateRepo).labelsHidden().toggleStyle(LauncherSwitchStyle())
}
}
@@ -3735,7 +3735,7 @@ struct BuilderView: View {
private func pickRepo() {
let d = NSOpenPanel()
d.canChooseDirectories = true; d.canChooseFiles = false
- d.message = m.t("repo.pickMessage")
+ d.message = loc.t("repo.pickMessage")
if d.runModal() == .OK, let u = d.url { m.repoPath = u.path }
}
}
diff --git a/frontend/Sources/NX2Apple/ControlPresets.swift b/frontend/Sources/NX2Apple/ControlPresets.swift
index 57f0a0f6..2351e2f1 100644
--- a/frontend/Sources/NX2Apple/ControlPresets.swift
+++ b/frontend/Sources/NX2Apple/ControlPresets.swift
@@ -1,6 +1,7 @@
import GameController
import SwiftUI
import NXCore
+import NXModel
import NXLauncher
/// The controller layouts of the Controls page (#70). Each produces only a DM_PAD_MAP value (dm/host/input_map.h), so the
@@ -49,21 +50,21 @@ extension ControlLayout {
/// The Controls page's layout choice: a picker, which controller is connected and what Auto picks for it, and a note
/// on the layout chosen.
struct PadModeSection: View {
- @ObservedObject var m: BuildModel
+ @EnvironmentObject var loc: Localizer
@ObservedObject var layout: ControlLayout
@State private var category: String?
var body: some View {
VStack(alignment: .leading, spacing: 10) {
- Text(m.t("controls.mode")).font(.manrope(15, .semibold)).foregroundStyle(.secondary).padding(.leading, 2)
+ Text(loc.t("controls.mode")).font(.manrope(15, .semibold)).foregroundStyle(.secondary).padding(.leading, 2)
HStack(spacing: 16) {
VStack(alignment: .leading, spacing: 3) {
- Text(m.t("controls.modeRow")).font(.manrope(14, .medium))
+ Text(loc.t("controls.modeRow")).font(.manrope(14, .medium))
Text(connected).font(.manrope(12)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
}
Spacer(minLength: 12)
LauncherDropdown(options: PadMode.allCases.map { (value: $0.rawValue, label: label($0)) },
- selection: layout.padMode.rawValue, label: m.t("controls.modeRow"), fill: true) { v in PadMode(rawValue: v).map(layout.setPadMode) }
+ selection: layout.padMode.rawValue, label: loc.t("controls.modeRow"), fill: true) { v in PadMode(rawValue: v).map(layout.setPadMode) }
.frame(width: 168) // as wide as the button rows' choices below it
.frame(width: LaunchControl.width, alignment: .trailing)
}
@@ -72,7 +73,7 @@ struct PadModeSection: View {
.padTarget("pad.mode", scope: "controls", radius: 10, activate: { step(1) }, adjust: step)
.background(LauncherPalette.surface.opacity(0.75), in: RoundedRectangle(cornerRadius: 14))
.overlay(RoundedRectangle(cornerRadius: 14).strokeBorder(Color.white.opacity(0.06)))
- Text(m.t("controls.modeNote." + layout.padMode.rawValue)).font(.manrope(12)).foregroundStyle(.secondary)
+ Text(loc.t("controls.modeNote." + layout.padMode.rawValue)).font(.manrope(12)).foregroundStyle(.secondary)
.padding(.leading, 2).fixedSize(horizontal: false, vertical: true)
}
.onAppear { category = layout.controllerCategory() }
@@ -82,11 +83,11 @@ struct PadModeSection: View {
}
}
- private func label(_ mode: PadMode) -> String { m.t("controls.mode." + mode.rawValue) }
+ private func label(_ mode: PadMode) -> String { loc.t("controls.mode." + mode.rawValue) }
private var connected: String {
let pick = label(ControlLayout.autoMode(category: category))
- return category.map { String(format: m.t("controls.connected"), $0, pick) } ?? String(format: m.t("controls.noController"), pick)
+ return category.map { String(format: loc.t("controls.connected"), $0, pick) } ?? String(format: loc.t("controls.noController"), pick)
}
/// A controller's left / right through the layouts.
diff --git a/frontend/Sources/NX2Apple/Controls.swift b/frontend/Sources/NX2Apple/Controls.swift
index 29f095ae..780b28ca 100644
--- a/frontend/Sources/NX2Apple/Controls.swift
+++ b/frontend/Sources/NX2Apple/Controls.swift
@@ -1,6 +1,7 @@
import AppKit
import SwiftUI
import NXCore
+import NXModel
import NXLauncher
/// The player's keyboard and controller layout for every game, passed at Play as the host's DM_KEYMAP and DM_PAD_MAP
@@ -137,7 +138,7 @@ final class ControlLayout: ObservableObject {
/// The Controls sheet: the keyboard's key for each function (click, then press a key) and what each controller button sends.
struct ControlsView: View {
- @ObservedObject var m: BuildModel
+ @EnvironmentObject var loc: Localizer
@ObservedObject var layout: ControlLayout
@Environment(\.dismiss) private var dismiss
@State private var listening: String?
@@ -147,17 +148,17 @@ struct ControlsView: View {
var body: some View {
VStack(alignment: .leading, spacing: 0) {
VStack(alignment: .leading, spacing: 4) {
- Text(m.t("controls.title")).font(.manrope(26, .heavy)).tracking(-0.6)
- Text(m.t("controls.note")).font(.manrope(14)).foregroundStyle(.secondary)
+ Text(loc.t("controls.title")).font(.manrope(26, .heavy)).tracking(-0.6)
+ Text(loc.t("controls.note")).font(.manrope(14)).foregroundStyle(.secondary)
}
.padding(.horizontal, 30).padding(.top, 28).padding(.bottom, 20)
ScrollViewReader { proxy in
ScrollView {
VStack(alignment: .leading, spacing: 24) {
- section(m.t("controls.sticks"), ControlLayout.functions.filter(\.isDirection)) { keyRow($0) }
- section(m.t("controls.keyButtons"), ControlLayout.functions.filter { !$0.isDirection }) { keyRow($0) }
- PadModeSection(m: m, layout: layout)
- section(m.t("controls.pad"), ControlLayout.buttons, note: m.t("controls.padNote")) { padRow($0) }
+ section(loc.t("controls.sticks"), ControlLayout.functions.filter(\.isDirection)) { keyRow($0) }
+ section(loc.t("controls.keyButtons"), ControlLayout.functions.filter { !$0.isDirection }) { keyRow($0) }
+ PadModeSection(layout: layout)
+ section(loc.t("controls.pad"), ControlLayout.buttons, note: loc.t("controls.padNote")) { padRow($0) }
}
.padding(.horizontal, 30).padding(.bottom, 24)
}
@@ -165,15 +166,15 @@ struct ControlsView: View {
}
Divider().opacity(0.3)
HStack(spacing: 14) {
- Text(m.t("controls.applied")).font(.manrope(12)).foregroundStyle(.secondary).lineLimit(2)
+ Text(loc.t("controls.applied")).font(.manrope(12)).foregroundStyle(.secondary).lineLimit(2)
Spacer(minLength: 8)
if !layout.isDefault {
- Button(m.t("controls.reset")) { stopListening(); layout.resetKeyboard(); layout.resetController() }
+ Button(loc.t("controls.reset")) { stopListening(); layout.resetKeyboard(); layout.resetController() }
.buttonStyle(LauncherSecondaryButtonStyle())
.padTarget("controls.reset", scope: "controls") { stopListening(); layout.resetKeyboard(); layout.resetController() }
}
Button { stopListening(); dismiss() } label: {
- Text(m.t("launch.done")).font(.manrope(13.5, .bold)).foregroundStyle(.black)
+ Text(loc.t("launch.done")).font(.manrope(13.5, .bold)).foregroundStyle(.black)
.padding(.horizontal, 22).padding(.vertical, 9)
.background(LauncherPalette.cream, in: Capsule())
}
@@ -223,17 +224,17 @@ struct ControlsView: View {
private func keyRow(_ f: ControlLayout.Function) -> some View {
let on = listening == f.id
let key = layout.key(f)
- return line(m.t("controls.fn." + f.id), target: "key." + f.id, activate: { on ? stopListening() : listen(f) }) {
+ return line(loc.t("controls.fn." + f.id), target: "key." + f.id, activate: { on ? stopListening() : listen(f) }) {
HStack(spacing: 6) {
if key != nil && !on {
Button { layout.assign(f, key: nil) } label: {
Image(systemName: "xmark").font(.system(size: 9, weight: .bold)).foregroundStyle(.secondary)
.frame(width: 22, height: 22).contentShape(Circle())
}
- .buttonStyle(.plain).help(m.t("controls.clear"))
+ .buttonStyle(.plain).help(loc.t("controls.clear"))
}
Button { on ? stopListening() : listen(f) } label: {
- Text(on ? m.t("controls.press") : ControlLayout.keyName(key, m.t) ?? m.t("controls.none"))
+ Text(on ? loc.t("controls.press") : ControlLayout.keyName(key, loc.t) ?? loc.t("controls.none"))
.font(.manrope(12.5, on ? .bold : .semibold))
.foregroundStyle(on ? Color.black : key == nil ? Color.white.opacity(0.45) : Color.white.opacity(0.92))
.frame(maxWidth: .infinity).padding(.vertical, 6)
@@ -249,13 +250,13 @@ struct ControlsView: View {
private func padRow(_ button: String) -> some View {
let choices = ControlLayout.buttons + ["none"]
- return line(m.t("controls.fn." + button), target: "pad." + button,
+ return line(loc.t("controls.fn." + button), target: "pad." + button,
adjust: { by in
let at = choices.firstIndex(of: layout.sends(button)) ?? 0
layout.setSends(button, choices[(at + by + choices.count) % choices.count])
}) {
- LauncherDropdown(options: ControlLayout.buttons.map { (value: $0, label: m.t("controls.fn." + $0)) } + [(value: "none", label: m.t("controls.none"))],
- selection: layout.sends(button), label: m.t("controls.fn." + button), fill: true) { layout.setSends(button, $0) }
+ LauncherDropdown(options: ControlLayout.buttons.map { (value: $0, label: loc.t("controls.fn." + $0)) } + [(value: "none", label: loc.t("controls.none"))],
+ selection: layout.sends(button), label: loc.t("controls.fn." + button), fill: true) { layout.setSends(button, $0) }
.frame(width: 168) // the keyboard rows' width (× and key field), and "Right stick press" fits
}
}
diff --git a/frontend/Sources/NX2Apple/Diagnostics.swift b/frontend/Sources/NX2Apple/Diagnostics.swift
index 22ffbd39..d1e0d0da 100644
--- a/frontend/Sources/NX2Apple/Diagnostics.swift
+++ b/frontend/Sources/NX2Apple/Diagnostics.swift
@@ -1,6 +1,7 @@
import AppKit
import SwiftUI
import NXCore
+import NXModel
import NXLauncher
/// Copy diagnostics (#69): a short Markdown report for a bug report — the app, the Mac, the checkout and how far behind it
@@ -333,6 +334,7 @@ extension BuildModel {
/// Settings' Copy diagnostics: the report goes to the clipboard and the button says Copied for a moment.
struct DiagnosticsButton: View {
@ObservedObject var m: BuildModel
+ @EnvironmentObject var loc: Localizer
var game: LibraryGame? // the library's selected game: its log goes in the report
var showCopied = false // the visual QA's confirmation
@State private var busy = false
@@ -340,7 +342,7 @@ struct DiagnosticsButton: View {
var body: some View {
Button(action: copy) {
- if copied || showCopied { Label(m.t("diag.copied"), systemImage: "checkmark") } else { Text(m.t("diag.copy")) }
+ if copied || showCopied { Label(loc.t("diag.copied"), systemImage: "checkmark") } else { Text(loc.t("diag.copy")) }
}
.buttonStyle(LauncherSecondaryButtonStyle(accent: copied || showCopied ? LauncherPalette.ready : nil))
.disabled(busy)
diff --git a/frontend/Sources/NX2Apple/FreeSpace.swift b/frontend/Sources/NX2Apple/FreeSpace.swift
index 930f6ebe..4b408b02 100644
--- a/frontend/Sources/NX2Apple/FreeSpace.swift
+++ b/frontend/Sources/NX2Apple/FreeSpace.swift
@@ -1,6 +1,7 @@
import AppKit
import SwiftUI
import NXCore
+import NXModel
import NXLauncher
/// The parts of a game's build folder (<output folder>/<title ID>_build) that the next build makes again
@@ -214,6 +215,7 @@ enum BuildFolder {
/// picks parts and confirms.
struct FreeSpaceView: View {
@ObservedObject var m: BuildModel
+ @EnvironmentObject var loc: Localizer
let game: LibraryGame
@Environment(\.dismiss) private var dismiss
@EnvironmentObject private var focus: PadFocus
@@ -237,18 +239,18 @@ struct FreeSpaceView: View {
var body: some View {
VStack(alignment: .leading, spacing: 0) {
VStack(alignment: .leading, spacing: 4) {
- Text(m.t("free.title")).font(.manrope(26, .heavy)).tracking(-0.6)
+ Text(loc.t("free.title")).font(.manrope(26, .heavy)).tracking(-0.6)
Text(game.name).font(.manrope(14)).foregroundStyle(.secondary)
}
.padding(.horizontal, 30).padding(.top, 28).padding(.bottom, 14)
- Text(m.t("free.note")).font(.manrope(13)).foregroundStyle(.secondary)
+ Text(loc.t("free.note")).font(.manrope(13)).foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
.padding(.horizontal, 30).padding(.bottom, 18)
ScrollView {
VStack(alignment: .leading, spacing: 14) {
if let survey {
if survey.parts.isEmpty {
- Text(m.t("free.empty")).font(.manrope(14)).foregroundStyle(.secondary)
+ Text(loc.t("free.empty")).font(.manrope(14)).foregroundStyle(.secondary)
} else {
card {
ForEach(survey.parts) { part in
@@ -257,8 +259,8 @@ struct FreeSpaceView: View {
}
HStack(spacing: 16) {
VStack(alignment: .leading, spacing: 3) {
- Text(m.t("free.kept")).font(.manrope(14, .medium)).foregroundStyle(.secondary)
- Text(m.t("free.keptNote")).font(.manrope(12)).foregroundStyle(.secondary)
+ Text(loc.t("free.kept")).font(.manrope(14, .medium)).foregroundStyle(.secondary)
+ Text(loc.t("free.keptNote")).font(.manrope(12)).foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
}
Spacer(minLength: 12)
@@ -268,28 +270,28 @@ struct FreeSpaceView: View {
}
}
if game.isReady { // pack_app.py clones the game files and shaders into the app on the same APFS volume
- Text(m.t("free.clones")).font(.manrope(12)).foregroundStyle(.secondary)
+ Text(loc.t("free.clones")).font(.manrope(12)).foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true).padding(.horizontal, 2)
}
Text(survey.folder).font(.system(size: 11, design: .monospaced)).foregroundStyle(.tertiary)
.lineLimit(1).truncationMode(.middle).textSelection(.enabled).padding(.horizontal, 2)
} else {
- HStack(spacing: 10) { ProgressView().controlSize(.small); Text(m.t("free.measuring")).foregroundStyle(.secondary) }
+ HStack(spacing: 10) { ProgressView().controlSize(.small); Text(loc.t("free.measuring")).foregroundStyle(.secondary) }
}
}
.padding(.horizontal, 30).padding(.bottom, 20)
}
Divider().opacity(0.3)
HStack(spacing: 14) {
- Text(outcome ?? (m.running ? m.t("free.running") : String(format: m.t("free.selected"), Self.bytes(chosenBytes))))
+ Text(outcome ?? (m.running ? loc.t("free.running") : String(format: loc.t("free.selected"), Self.bytes(chosenBytes))))
.font(.manrope(12)).foregroundStyle(.secondary).lineLimit(2)
Spacer(minLength: 8)
- Button(m.t("free.remove")) { confirming = true }
+ Button(loc.t("free.remove")) { confirming = true }
.buttonStyle(LauncherSecondaryButtonStyle(accent: LauncherPalette.building))
.disabled(chosen.isEmpty || m.running || working)
.padTarget("free.remove", scope: "free") { if !chosen.isEmpty && !m.running && !working { confirming = true } }
Button { dismiss() } label: {
- Text(m.t("free.done")).font(.manrope(13.5, .bold)).foregroundStyle(.black)
+ Text(loc.t("free.done")).font(.manrope(13.5, .bold)).foregroundStyle(.black)
.padding(.horizontal, 22).padding(.vertical, 9)
.background(LauncherPalette.cream, in: Capsule())
}
@@ -305,10 +307,10 @@ struct FreeSpaceView: View {
.preferredColorScheme(.dark)
.tint(LauncherPalette.cream)
.onAppear { if survey == nil { measure() } }
- .confirmationDialog(String(format: m.t("free.confirm"), Self.bytes(chosenBytes)), isPresented: $confirming, titleVisibility: .visible) {
- Button(m.t("free.confirmButton"), role: .destructive) { removeChosen() }
+ .confirmationDialog(String(format: loc.t("free.confirm"), Self.bytes(chosenBytes)), isPresented: $confirming, titleVisibility: .visible) {
+ Button(loc.t("free.confirmButton"), role: .destructive) { removeChosen() }
} message: {
- Text(([m.t("free.confirmNote")] + BuildFolderPart.allCases.filter { chosen.contains($0) && !($0 == .oldShaders && chosen.contains(.shaders)) }.map { m.t("free.cost." + $0.rawValue) }).joined(separator: "\n"))
+ Text(([loc.t("free.confirmNote")] + BuildFolderPart.allCases.filter { chosen.contains($0) && !($0 == .oldShaders && chosen.contains(.shaders)) }.map { loc.t("free.cost." + $0.rawValue) }).joined(separator: "\n"))
}
}
@@ -316,8 +318,8 @@ struct FreeSpaceView: View {
let on = Binding(get: { chosen.contains(part) }, set: { if $0 { chosen.insert(part) } else { chosen.remove(part) } })
return HStack(spacing: 16) {
VStack(alignment: .leading, spacing: 3) {
- Text(m.t("free.part." + part.rawValue)).font(.manrope(14, .medium))
- Text(m.t("free.cost." + part.rawValue)).font(.manrope(12)).foregroundStyle(.secondary)
+ Text(loc.t("free.part." + part.rawValue)).font(.manrope(14, .medium))
+ Text(loc.t("free.cost." + part.rawValue)).font(.manrope(12)).foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
if part == .oldShaders, let versions = survey?.oldShaders { // which versions, each with its size
Text(versions.map { "\($0.name) \(Self.bytes($0.bytes))" }.joined(separator: "\n"))
@@ -367,9 +369,9 @@ struct FreeSpaceView: View {
survey = after
chosen = []
switch result {
- case .success(let freed): outcome = String(format: m.t("free.freed"), Self.bytes(freed))
- case .failure(FreeSpaceError.buildRunning): outcome = m.t("free.running")
- case .failure(let error): outcome = String(format: m.t("free.failed"), error.localizedDescription)
+ case .success(let freed): outcome = String(format: loc.t("free.freed"), Self.bytes(freed))
+ case .failure(FreeSpaceError.buildRunning): outcome = loc.t("free.running")
+ case .failure(let error): outcome = String(format: loc.t("free.failed"), error.localizedDescription)
}
}
}
diff --git a/frontend/Sources/NX2Apple/LaunchOptionsView.swift b/frontend/Sources/NX2Apple/LaunchOptionsView.swift
index 0314339a..9d717561 100644
--- a/frontend/Sources/NX2Apple/LaunchOptionsView.swift
+++ b/frontend/Sources/NX2Apple/LaunchOptionsView.swift
@@ -1,6 +1,7 @@
import AppKit
import SwiftUI
import NXCore
+import NXModel
import NXLauncher
/// A game's launch options: the settings its Mac app was packed with (dm/launcher.json), drawn as the
@@ -9,6 +10,7 @@ import NXLauncher
/// app reads at every start; Play passes only the launch overrides (what the list has no row for, the mods) as its environment.
struct LaunchOptionsView: View {
@ObservedObject var m: BuildModel
+ @EnvironmentObject var loc: Localizer
@ObservedObject var library: GameLibrary
let gameID: UUID
@Environment(\.dismiss) private var dismiss
@@ -20,7 +22,7 @@ struct LaunchOptionsView: View {
private var game: LibraryGame? { library.games.first { $0.id == gameID } }
private var settings: [LaunchSetting]? {
- game.flatMap { LaunchSetting.forMac(app: $0.appPath, titleID: $0.titleID, repo: m.repoPath, labels: m.t) }
+ game.flatMap { LaunchSetting.forMac(app: $0.appPath, titleID: $0.titleID, repo: m.repoPath, labels: loc.t) }
}
private var store: SavedChoices? { game.map { SavedChoices(app: $0.appPath, titleID: $0.titleID) } }
/// A saved choice for a row of the list, else the tested default; what only this launcher has comes from the library.
@@ -40,7 +42,7 @@ struct LaunchOptionsView: View {
VStack(alignment: .leading, spacing: 0) {
HStack(alignment: .firstTextBaseline) {
VStack(alignment: .leading, spacing: 4) {
- Text(m.t("launch.title")).font(.manrope(26, .heavy)).tracking(-0.6)
+ Text(loc.t("launch.title")).font(.manrope(26, .heavy)).tracking(-0.6)
if let game { Text(game.name).font(.manrope(14)).foregroundStyle(.secondary) }
}
Spacer()
@@ -58,11 +60,11 @@ struct LaunchOptionsView: View {
card {
Button { withAnimation(.easeInOut(duration: 0.18)) { advancedOpen.toggle() } } label: {
HStack(spacing: 8) {
- Text(m.t("launch.advanced")).font(.manrope(14, .medium))
+ Text(loc.t("launch.advanced")).font(.manrope(14, .medium))
Image(systemName: "chevron.right").font(.system(size: 10, weight: .bold)).foregroundStyle(.secondary)
.rotationEffect(.degrees(advancedOpen ? 90 : 0))
Spacer()
- Text(String(format: m.t("launch.advancedCount"), advanced.count)).font(.manrope(12)).foregroundStyle(.secondary)
+ Text(String(format: loc.t("launch.advancedCount"), advanced.count)).font(.manrope(12)).foregroundStyle(.secondary)
}
.padding(.horizontal, 18).frame(minHeight: 52).contentShape(Rectangle())
}
@@ -77,23 +79,23 @@ struct LaunchOptionsView: View {
.onChange(of: focus.focused) { id in if let id { withAnimation(.easeInOut(duration: 0.2)) { proxy.scrollTo(id, anchor: .center) } } }
}
} else {
- Text(m.t("launch.none")).font(.manrope(14)).foregroundStyle(.secondary)
+ Text(loc.t("launch.none")).font(.manrope(14)).foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
.padding(30).frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
}
Divider().opacity(0.3)
HStack(spacing: 14) {
- Text(m.t("launch.applied")).font(.manrope(12)).foregroundStyle(.secondary).lineLimit(2)
+ Text(loc.t("launch.applied")).font(.manrope(12)).foregroundStyle(.secondary).lineLimit(2)
Spacer(minLength: 8)
// One LauncherControl wide, as the buttons of a setting row: its label fits on one line in every language
if let game, let settings, !game.launchOptions.isEmpty || (store?.hasChoices(settings) ?? false) {
- Button(m.t("launch.reset")) { reset(settings) }
+ Button(loc.t("launch.reset")) { reset(settings) }
.buttonStyle(LauncherSecondaryButtonStyle())
.launcherRowControls()
.padTarget("opt.reset", scope: "launch") { reset(settings) }
}
Button { dismiss() } label: {
- Text(m.t("launch.done")).font(.manrope(13.5, .bold)).foregroundStyle(.black)
+ Text(loc.t("launch.done")).font(.manrope(13.5, .bold)).foregroundStyle(.black)
.padding(.horizontal, 22).padding(.vertical, 9)
.background(LauncherPalette.cream, in: Capsule())
}
@@ -145,14 +147,14 @@ struct LaunchOptionsView: View {
/// The translated heading of a section this launcher knows; a section it does not know is drawn under its own name.
private func sectionName(_ section: String) -> String {
let key = "launch.section." + section
- let name = m.t(key)
+ let name = loc.t(key)
return name == key ? section : name
}
/// A setting's text in the launcher's language when this launcher has it (a game's launcher.json is in English), else the list's own.
private func text(_ key: String, _ fallback: String) -> String {
- guard m.lang != .en else { return fallback }
- let translated = m.t(key)
+ guard loc.lang != .en else { return fallback }
+ let translated = loc.t(key)
return translated == key ? fallback : translated
}
private func label(_ s: LaunchSetting) -> String { text("launch.set." + s.env, s.label) }
@@ -183,7 +185,7 @@ struct LaunchOptionsView: View {
Text(label(s)).font(.manrope(14, .medium))
if let full = s.kind == "range" ? s.pixels(scale: 1, docked: isDocked) : nil {
// The render scale in pixels: the share of the game's own size in the console mode chosen
- Text(String(format: m.t(isDocked ? "launch.scaleOfDocked" : "launch.scaleOfHandheld"), Int(((Double(value) ?? 1) * 100).rounded()), full))
+ Text(String(format: loc.t(isDocked ? "launch.scaleOfDocked" : "launch.scaleOfHandheld"), Int(((Double(value) ?? 1) * 100).rounded()), full))
.font(.manrope(12)).foregroundStyle(.secondary)
} else if !note(s).isEmpty {
Text(note(s)).font(.manrope(12)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
@@ -242,8 +244,8 @@ struct LaunchOptionsView: View {
.foregroundStyle(.secondary).contentShape(Rectangle())
}
.buttonStyle(.plain)
- .help(m.t("launch.rowReset"))
- .accessibilityLabel(m.t("launch.rowReset"))
+ .help(loc.t("launch.rowReset"))
+ .accessibilityLabel(loc.t("launch.rowReset"))
}
}
.frame(width: 16)
@@ -262,13 +264,13 @@ struct LaunchOptionsView: View {
@ViewBuilder private func modsSection(_ game: LibraryGame) -> some View {
let list = mods
VStack(alignment: .leading, spacing: 10) {
- heading(m.t("launch.mods"))
+ heading(loc.t("launch.mods"))
card {
if list.isEmpty {
HStack(spacing: 16) {
VStack(alignment: .leading, spacing: 3) {
- Text(m.t("launch.modsNone")).font(.manrope(14, .medium))
- Text(m.t("launch.modsHow")).font(.manrope(12)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
+ Text(loc.t("launch.modsNone")).font(.manrope(14, .medium))
+ Text(loc.t("launch.modsHow")).font(.manrope(12)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
}
Spacer()
}
@@ -279,7 +281,7 @@ struct LaunchOptionsView: View {
VStack(alignment: .leading, spacing: 3) {
Text(mod.name).font(.manrope(14, .medium)).lineLimit(1)
if !mod.usable {
- Text(m.t("launch.modCode")).font(.manrope(12)).foregroundStyle(.secondary)
+ Text(loc.t("launch.modCode")).font(.manrope(12)).foregroundStyle(.secondary)
}
}
Spacer(minLength: 12)
@@ -297,17 +299,17 @@ struct LaunchOptionsView: View {
if list.isEmpty { divider }
HStack(spacing: 10) {
Spacer()
- Button(m.t("launch.modsRefresh")) { modsRevision += 1 }
+ Button(loc.t("launch.modsRefresh")) { modsRevision += 1 }
.padTarget("mods.refresh", scope: "launch") { modsRevision += 1 }
- Button(m.t("launch.modsOpen")) { openModsFolder() }
+ Button(loc.t("launch.modsOpen")) { openModsFolder() }
.padTarget("mods.open", scope: "launch") { openModsFolder() }
- Button(m.t("launch.savesShow")) { showSaves(game) }
+ Button(loc.t("launch.savesShow")) { showSaves(game) }
.padTarget("mods.saves", scope: "launch") { showSaves(game) }
}
.buttonStyle(LauncherSecondaryButtonStyle())
.padding(.horizontal, 18).padding(.vertical, 12)
}
- Text(m.t(list.count > 1 ? "launch.modsNoteOrder" : "launch.modsNote")).font(.manrope(12)).foregroundStyle(.secondary)
+ Text(loc.t(list.count > 1 ? "launch.modsNoteOrder" : "launch.modsNote")).font(.manrope(12)).foregroundStyle(.secondary)
.padding(.leading, 2).fixedSize(horizontal: false, vertical: true)
}
}
@@ -322,10 +324,10 @@ struct LaunchOptionsView: View {
let on = Binding(get: { _ = frameTimesRevision; return FrameTimes.enabled(titleID: game.titleID) },
set: { FrameTimes.setEnabled($0, titleID: game.titleID); frameTimesRevision += 1 })
VStack(alignment: .leading, spacing: 10) {
- heading(m.t("launch.frameTimes"))
+ heading(loc.t("launch.frameTimes"))
card {
HStack(spacing: 16) {
- Text(m.t("launch.frameTimesRecord")).font(.manrope(14, .medium))
+ Text(loc.t("launch.frameTimesRecord")).font(.manrope(14, .medium))
Spacer(minLength: 12)
Toggle("", isOn: on).labelsHidden().toggleStyle(LauncherSwitchStyle())
}
@@ -334,25 +336,25 @@ struct LaunchOptionsView: View {
activate: { on.wrappedValue.toggle() }, adjust: { _ in on.wrappedValue.toggle() })
divider
if recent.isEmpty {
- Text(m.t("launch.frameTimesNone")).font(.manrope(13)).foregroundStyle(.secondary)
+ Text(loc.t("launch.frameTimesNone")).font(.manrope(13)).foregroundStyle(.secondary)
.padding(.horizontal, 18).padding(.vertical, 12)
divider
}
ForEach(recent, id: \.self) { file in
- FrameTimesRecordingView(file: file, t: m.t)
+ FrameTimesRecordingView(file: file, t: loc.t)
divider
}
HStack(spacing: 10) {
Spacer()
- Button(m.t("launch.modsRefresh")) { frameTimesRevision += 1 }
+ Button(loc.t("launch.modsRefresh")) { frameTimesRevision += 1 }
.padTarget("frameTimes.refresh", scope: "launch") { frameTimesRevision += 1 }
- Button(m.t("launch.frameTimesOpen")) { openFolder(folder) }
+ Button(loc.t("launch.frameTimesOpen")) { openFolder(folder) }
.padTarget("frameTimes.open", scope: "launch") { openFolder(folder) }
}
.buttonStyle(LauncherSecondaryButtonStyle())
.padding(.horizontal, 18).padding(.vertical, 12)
}
- Text(m.t("launch.frameTimesNote")).font(.manrope(12)).foregroundStyle(.secondary)
+ Text(loc.t("launch.frameTimesNote")).font(.manrope(12)).foregroundStyle(.secondary)
.padding(.leading, 2).fixedSize(horizontal: false, vertical: true)
}
}
diff --git a/frontend/Sources/NX2Apple/LauncherView.swift b/frontend/Sources/NX2Apple/LauncherView.swift
index 77048ea6..0604614d 100644
--- a/frontend/Sources/NX2Apple/LauncherView.swift
+++ b/frontend/Sources/NX2Apple/LauncherView.swift
@@ -1,6 +1,7 @@
import SwiftUI
import UniformTypeIdentifiers
import NXCore
+import NXModel
import NXLauncher
enum LauncherPage: String, CaseIterable {
@@ -41,6 +42,7 @@ enum LibraryFilter: String, CaseIterable, Identifiable {
struct ContentView: View {
@StateObject private var m: BuildModel
+ @ObservedObject private var loc: Localizer // the strings: handed on to every view below through the environment
@StateObject private var library: GameLibrary
@State private var page: LauncherPage = .library
@State private var search = ""
@@ -91,7 +93,9 @@ struct ContentView: View {
if let search { _search = State(initialValue: search); _searching = State(initialValue: true) } // visual QA: the bar with its field open
_toolsAge = StateObject(wrappedValue: ToolsAge(older: olderTools)) // visual QA: games marked without a checkout to compare
_gamepad = StateObject(wrappedValue: gamepad ?? LauncherGamepad()) // LauncherPerformanceTests presses its buttons
- _m = StateObject(wrappedValue: model ?? BuildModel())
+ let model = model ?? BuildModel()
+ _m = StateObject(wrappedValue: model)
+ _loc = ObservedObject(wrappedValue: model.localizer)
_library = StateObject(wrappedValue: library ?? GameLibrary())
_page = State(initialValue: initialPage)
_activeBuildID = State(initialValue: activeBuildID)
@@ -132,7 +136,7 @@ struct ContentView: View {
if !controllerSheet, let toast = consoleDriver.state.toast { ConsoleToastView(toast: toast) }
}
.sheet(isPresented: $controllerSheet) {
- ConsoleControllersSheet(driver: consoleDriver, lang: m.lang, close: { controllerSheet = false; consoleDriver.back() })
+ ConsoleControllersSheet(driver: consoleDriver, lang: loc.lang, close: { controllerSheet = false; consoleDriver.back() })
.environmentObject(padFocus)
}
.onChange(of: controllerSheet) { open in
@@ -142,7 +146,7 @@ struct ContentView: View {
}
.overlay {
if consolePrompt, let enterConsole {
- ConsoleConnectionPrompt(lang: m.lang, enterConsole: { consolePrompt = false; enterConsole() }, dismissPrompt: { consolePrompt = false })
+ ConsoleConnectionPrompt(lang: loc.lang, enterConsole: { consolePrompt = false; enterConsole() }, dismissPrompt: { consolePrompt = false })
}
}
.onChange(of: gamepad.connected) { connected in
@@ -157,6 +161,7 @@ struct ContentView: View {
if open { padFocus.focused = "console.entry.enter" }
}
.environmentObject(padFocus)
+ .environmentObject(loc)
}
private var launcherBody: some View {
@@ -178,7 +183,7 @@ struct ContentView: View {
.padScope("main", padFocus)
.environmentObject(padFocus)
.manageMenuOverlay(items: manageOpenFor.flatMap { id in library.games.first { $0.id == id } }.map(manageItems),
- label: m.t("library.manage"), pad: padFocus) { manageOpenFor = nil }
+ label: loc.t("library.manage"), pad: padFocus) { manageOpenFor = nil }
.launcherDropdownHost()
.onChange(of: manageOpenFor) { id in
padFocus.scope = id != nil ? "manage" : currentPadScope
@@ -256,44 +261,44 @@ struct ContentView: View {
.onChange(of: scenePhase) { phase in
if phase == .active { library.objectWillChange.send() }
}
- .alert(m.t("library.error"), isPresented: Binding(
+ .alert(loc.t("library.error"), isPresented: Binding(
get: { launchError != nil || library.error != nil },
set: { if !$0 { launchError = nil; library.error = nil } }
)) {
- Button(m.t("library.ok")) { launchError = nil; library.error = nil }
+ Button(loc.t("library.ok")) { launchError = nil; library.error = nil }
} message: { Text(launchError ?? library.error ?? "") }
- .confirmationDialog(m.t("library.removeQuestion"), isPresented: Binding(
+ .confirmationDialog(loc.t("library.removeQuestion"), isPresented: Binding(
get: { removing != nil }, set: { if !$0 { removing = nil } }
), titleVisibility: .visible) {
- Button(m.t("library.remove"), role: .destructive) {
+ Button(loc.t("library.remove"), role: .destructive) {
if let game = removing { library.remove(game.id) }
removing = nil
}
- } message: { Text(m.t("library.removeNote")) }
+ } message: { Text(loc.t("library.removeNote")) }
.sheet(isPresented: Binding(get: { optionsFor != nil }, set: { if !$0 { optionsFor = nil } })) {
if let id = optionsFor { LaunchOptionsView(m: m, library: library, gameID: id).environmentObject(padFocus).launcherDropdownHost() }
}
- .sheet(isPresented: $controlsOpen) { ControlsView(m: m, layout: controls).environmentObject(padFocus).launcherDropdownHost() }
+ .sheet(isPresented: $controlsOpen) { ControlsView(layout: controls).environmentObject(padFocus).launcherDropdownHost() }
.sheet(isPresented: Binding(get: { freeSpaceFor != nil }, set: { if !$0 { freeSpaceFor = nil } })) {
if let game = library.games.first(where: { $0.id == freeSpaceFor }) { FreeSpaceView(m: m, game: game).environmentObject(padFocus) }
}
.onChange(of: freeSpaceFor) { id in padFocus.scope = id != nil ? "free" : currentPadScope }
.sheet(isPresented: $m.showUpdateSheet) { UpdateSheet(m: m) }
- .confirmationDialog(m.t("uninstall.title"), isPresented: Binding(
+ .confirmationDialog(loc.t("uninstall.title"), isPresented: Binding(
get: { m.uninstallPlan != nil }, set: { if !$0 { m.uninstallPlan = nil } }
), titleVisibility: .visible) {
- Button(m.t("uninstall.confirmButton"), role: .destructive) {
+ Button(loc.t("uninstall.confirmButton"), role: .destructive) {
if let plan = m.uninstallPlan {
let result = Uninstall.run(plan)
m.uninstallPlan = nil
if result.failures.isEmpty {
- m.appStatus = String(format: m.t("uninstall.done"), result.removed.count)
+ m.appStatus = String(format: loc.t("uninstall.done"), result.removed.count)
} else {
- m.appStatus = m.t("uninstall.failed") + "\n" + result.failures.joined(separator: "\n")
+ m.appStatus = loc.t("uninstall.failed") + "\n" + result.failures.joined(separator: "\n")
}
}
}
- } message: { Text(m.t("uninstall.confirm")) }
+ } message: { Text(loc.t("uninstall.confirm")) }
.sheet(isPresented: Binding(get: { savesFor != nil }, set: { if !$0 { savesFor = nil } })) {
if let id = savesFor { SavesView(m: m, library: library, gameID: id).environmentObject(padFocus).launcherDropdownHost() }
}
@@ -308,8 +313,8 @@ struct ContentView: View {
}
@ViewBuilder private func navLabel(_ destination: LauncherPage, compact: Bool) -> some View {
- if compact { Image(systemName: destination.symbol).accessibilityLabel(m.t("nav." + destination.rawValue)) }
- else { Label(m.t("nav." + destination.rawValue), systemImage: destination.symbol) }
+ if compact { Image(systemName: destination.symbol).accessibilityLabel(loc.t("nav." + destination.rawValue)) }
+ else { Label(loc.t("nav." + destination.rawValue), systemImage: destination.symbol) }
}
private var topBar: some View {
@@ -338,7 +343,7 @@ struct ContentView: View {
in: RoundedRectangle(cornerRadius: 9))
.contentShape(RoundedRectangle(cornerRadius: 9)) // the whole pill takes the click, not only its text
}
- .buttonStyle(.plain).help(m.t("nav." + destination.rawValue))
+ .buttonStyle(.plain).help(loc.t("nav." + destination.rawValue))
.accessibilityAddTraits(page == destination ? .isSelected : [])
.padTarget("tab." + destination.rawValue, scope: "main") { page = destination }
}
@@ -346,15 +351,15 @@ struct ContentView: View {
searchField
Button { newBuild() } label: {
Group {
- if compact { Image(systemName: "plus").accessibilityLabel(m.t("library.newBuild")) }
- else { Label(m.t("library.newBuild"), systemImage: "plus") }
+ if compact { Image(systemName: "plus").accessibilityLabel(loc.t("library.newBuild")) }
+ else { Label(loc.t("library.newBuild"), systemImage: "plus") }
}
.padding(.horizontal, 12).padding(.vertical, 8)
.background(Color.white.opacity(0.07), in: RoundedRectangle(cornerRadius: 8))
.overlay(RoundedRectangle(cornerRadius: 8).strokeBorder(Color.white.opacity(0.1)))
.contentShape(RoundedRectangle(cornerRadius: 8))
}
- .buttonStyle(.plain).disabled(m.running).help(m.t("library.newBuild")).accessibilityLabel(m.t("library.newBuild"))
+ .buttonStyle(.plain).disabled(m.running).help(loc.t("library.newBuild")).accessibilityLabel(loc.t("library.newBuild"))
.padTarget("top.build", scope: "main", radius: 8) { if !m.running { newBuild() } }
.padding(.leading, 12)
// A newer release is out: a small icon, last in the bar, opens the update sheet. Without one the bar
@@ -370,8 +375,8 @@ struct ContentView: View {
.buttonStyle(.plain)
.padTarget("top.update", scope: "main", radius: 17) { m.showUpdateSheet = true }
.padding(.leading, 16.5).padding(.trailing, -7.5)
- .help(String(format: m.t("update.pill"), update.tag) + "\n" + m.t(readOnly ? "update.readOnlyHint" : "update.pillHelp"))
- .accessibilityLabel(String(format: m.t("update.pill"), update.tag))
+ .help(String(format: loc.t("update.pill"), update.tag) + "\n" + loc.t(readOnly ? "update.readOnlyHint" : "update.pillHelp"))
+ .accessibilityLabel(String(format: loc.t("update.pill"), update.tag))
}
}
.padding(.leading, 90).padding(.trailing, 24)
@@ -394,9 +399,9 @@ struct ContentView: View {
.foregroundStyle(searching ? Color.secondary : Color.primary)
.frame(width: searching ? 16 : 40, height: searching ? 16 : 40).contentShape(Rectangle())
}
- .buttonStyle(.plain).help(m.t("library.search")).accessibilityLabel(m.t("library.search"))
+ .buttonStyle(.plain).help(loc.t("library.search")).accessibilityLabel(loc.t("library.search"))
if searching {
- TextField(m.t("library.search"), text: $search)
+ TextField(loc.t("library.search"), text: $search)
.textFieldStyle(.plain).font(.manrope(14))
.focused($searchFocused)
.onSubmit { if search.isEmpty { closeSearch() } }
@@ -406,7 +411,7 @@ struct ContentView: View {
Button { closeSearch() } label: {
Image(systemName: "xmark.circle.fill").font(.system(size: 13)).foregroundStyle(.secondary)
}
- .buttonStyle(.plain).help(m.t("library.clearSearch")).accessibilityLabel(m.t("library.clearSearch"))
+ .buttonStyle(.plain).help(loc.t("library.clearSearch")).accessibilityLabel(loc.t("library.clearSearch"))
}
}
.padding(.horizontal, searching ? 12 : 0)
@@ -453,22 +458,22 @@ struct ContentView: View {
Spacer()
Image(systemName: "gamecontroller").font(.system(size: 44, weight: .light))
.foregroundStyle(LauncherPalette.cream)
- Text(m.t("library.welcome")).font(.manrope(54, .bold)).tracking(-1.8)
- Text(m.t("library.welcomeNote")).font(.manrope(17)).foregroundStyle(.secondary)
+ Text(loc.t("library.welcome")).font(.manrope(54, .bold)).tracking(-1.8)
+ Text(loc.t("library.welcomeNote")).font(.manrope(17)).foregroundStyle(.secondary)
.frame(maxWidth: 490, alignment: .leading).fixedSize(horizontal: false, vertical: true)
Button { newBuild() } label: {
- Label(m.t("library.firstBuild"), systemImage: "plus")
+ Label(loc.t("library.firstBuild"), systemImage: "plus")
.font(.manrope(16, .semibold))
.padding(.horizontal, 24).padding(.vertical, 15)
.foregroundStyle(.black).background(LauncherPalette.cream, in: Capsule())
}
.buttonStyle(.plain).padding(.top, 8)
Button(action: chooseLibraryFolder) {
- Label(m.t("library.chooseFolder"), systemImage: "folder")
+ Label(loc.t("library.chooseFolder"), systemImage: "folder")
.font(.manrope(14)).foregroundStyle(.secondary)
}.buttonStyle(.plain)
Spacer()
- Text(m.t("library.localNote")).font(.manrope(12)).foregroundStyle(.secondary)
+ Text(loc.t("library.localNote")).font(.manrope(12)).foregroundStyle(.secondary)
}
.padding(48).frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
}
@@ -494,14 +499,14 @@ struct ContentView: View {
status(game, prominent: true)
if toolsAge.older.contains(game.id) && !(m.running && activeBuildID == game.id) {
Button { configureBuild(game) } label: {
- Label(m.t("library.rebuildShort"), systemImage: "arrow.clockwise")
+ Label(loc.t("library.rebuildShort"), systemImage: "arrow.clockwise")
.font(.manrope(12, .semibold)).foregroundStyle(LauncherPalette.cream)
.padding(.horizontal, 10).padding(.vertical, 4)
.overlay(Capsule().strokeBorder(LauncherPalette.cream.opacity(0.35)))
.contentShape(Capsule())
}
.buttonStyle(.plain).disabled(m.running || game.inputs["base", default: []].isEmpty)
- .help(m.t("library.olderToolsHelp"))
+ .help(loc.t("library.olderToolsHelp"))
.padTarget("hero.rebuild", scope: "main", radius: 12) { if !m.running { configureBuild(game) } }
}
}
@@ -510,9 +515,9 @@ struct ContentView: View {
HStack(spacing: 18) {
Button { primaryAction(game) } label: {
LauncherHeroActionLabel(
- title: game.primary == .play ? m.t("library.play")
- : (game.primary == .openOnDevice ? String(format: m.t("dev.open"), m.deviceName(game.installedDevice))
- : m.t("library.newBuild")),
+ title: game.primary == .play ? loc.t("library.play")
+ : (game.primary == .openOnDevice ? String(format: loc.t("dev.open"), m.deviceName(game.installedDevice))
+ : loc.t("library.newBuild")),
symbol: game.primary == .play ? "play.fill" : (game.primary == .openOnDevice ? "iphone" : "hammer.fill"))
}
.buttonStyle(.plain).disabled(launching || (m.running && !game.isReady))
@@ -525,11 +530,11 @@ struct ContentView: View {
.background(Color.white.opacity(0.10), in: Circle())
.overlay(Circle().strokeBorder(Color.white.opacity(0.14)))
}
- .buttonStyle(.plain).help(m.t("launch.title")).accessibilityLabel(m.t("launch.title"))
+ .buttonStyle(.plain).help(loc.t("launch.title")).accessibilityLabel(loc.t("launch.title"))
.padTarget("hero.options", scope: "main", radius: 24) { optionsFor = game.id }
}
- Button { manageOpenFor = manageOpenFor == nil ? game.id : nil } label: { ManageButtonLabel(title: m.t("library.manage")) }
- .buttonStyle(.plain).accessibilityLabel(m.t("library.manage"))
+ Button { manageOpenFor = manageOpenFor == nil ? game.id : nil } label: { ManageButtonLabel(title: loc.t("library.manage")) }
+ .buttonStyle(.plain).accessibilityLabel(loc.t("library.manage"))
.anchorPreference(key: ManageAnchorKey.self, value: .bounds) { $0 }
.padTarget("hero.manage", scope: "main", radius: 12) { manageOpenFor = game.id }
}
@@ -539,19 +544,19 @@ struct ContentView: View {
HStack(spacing: 10) {
Image(systemName: "checkmark.seal").font(.system(size: 12))
.foregroundStyle(LauncherPalette.cream.opacity(0.7))
- Text(signatureExpiry[game.id].map { AppSignature.describe($0, m.t) } ?? m.t("dev.expiryUnknown"))
+ Text(signatureExpiry[game.id].map { AppSignature.describe($0, loc.t) } ?? loc.t("dev.expiryUnknown"))
.font(.manrope(12.5))
.foregroundStyle(signatureExpiry[game.id].map { AppSignature.isUrgent($0) } == true
? LauncherPalette.building : .secondary)
Button { resign(game) } label: {
- Text(m.t("dev.resign")).font(.manrope(12, .semibold))
+ Text(loc.t("dev.resign")).font(.manrope(12, .semibold))
.foregroundStyle(LauncherPalette.cream)
.padding(.horizontal, 10).padding(.vertical, 4)
.overlay(Capsule().strokeBorder(LauncherPalette.cream.opacity(0.35)))
.contentShape(Capsule())
}
.buttonStyle(.plain).disabled(m.running)
- .help(m.t("dev.resignHelp"))
+ .help(loc.t("dev.resignHelp"))
.padTarget("hero.resign", scope: "main", radius: 12) { if !m.running { resign(game) } }
}
}
@@ -572,19 +577,19 @@ struct ContentView: View {
let heroID = heroGame?.id
return VStack(alignment: .leading, spacing: 18) {
HStack(spacing: 16) {
- Text(m.t("library.collection")).font(.manrope(28, .bold)).tracking(-0.6)
+ Text(loc.t("library.collection")).font(.manrope(28, .bold)).tracking(-0.6)
Spacer()
- LauncherSegmented(options: LibraryFilter.allCases.map { ($0.rawValue, m.t($0.labelKey)) },
+ LauncherSegmented(options: LibraryFilter.allCases.map { ($0.rawValue, loc.t($0.labelKey)) },
selection: libraryFilter.rawValue) { setLibraryFilter(LibraryFilter(rawValue: $0) ?? .owned) }
.frame(width: LauncherControl.width)
.padTarget("library.filter", scope: "main", radius: 17,
activate: { setLibraryFilter(libraryFilter == .owned ? .built : .owned) },
adjust: { setLibraryFilter($0 > 0 ? .built : .owned) })
- Text(String(format: m.t("library.gameCount"), libraryFilter == .owned ? library.games.count : library.games.filter(libraryFilter.includes).count))
+ Text(String(format: loc.t("library.gameCount"), libraryFilter == .owned ? library.games.count : library.games.filter(libraryFilter.includes).count))
.font(.manrope(12)).foregroundStyle(.secondary)
}
if games.isEmpty {
- Text(m.t("library.noResults")).foregroundStyle(.secondary).padding(.vertical, 28)
+ Text(loc.t("library.noResults")).foregroundStyle(.secondary).padding(.vertical, 28)
} else {
ScrollViewReader { proxy in
ScrollView(.horizontal, showsIndicators: false) {
@@ -655,7 +660,7 @@ struct ContentView: View {
}
.buttonStyle(.plain)
.frame(height: height)
- .accessibilityLabel(m.t(symbol == "chevron.left" ? "library.scrollBack" : "library.scrollForward"))
+ .accessibilityLabel(loc.t(symbol == "chevron.left" ? "library.scrollBack" : "library.scrollForward"))
.transition(.opacity)
}
@@ -665,14 +670,14 @@ struct ContentView: View {
let key = building ? "library.building" : (game.isReady ? "library.ready" : (game.hasIOSBuild ? (game.isOlderIOSBuild ? "library.olderIOS" : "library.readyIOS") : "library.notBuilt"))
return HStack(spacing: 7) {
Circle().fill(color).frame(width: prominent ? 9 : 7, height: prominent ? 9 : 7)
- Text(prominent ? m.t(key).uppercased() : m.t(key))
+ Text(prominent ? loc.t(key).uppercased() : loc.t(key))
.font(prominent ? .manrope(12, .bold) : .manrope(13, .medium))
.tracking(prominent ? 1.3 : 0) // the eyebrow: the same face, in tracked capitals
.foregroundStyle(color)
if !building && toolsAge.older.contains(game.id) { // a quiet note beside the status, not a warning
- Text("· " + m.t(prominent ? "library.olderTools" : "library.olderToolsShort"))
+ Text("· " + loc.t(prominent ? "library.olderTools" : "library.olderToolsShort"))
.font(.manrope(prominent ? 13 : 12)).foregroundStyle(.secondary).lineLimit(1)
- .help(m.t("library.olderToolsHelp"))
+ .help(loc.t("library.olderToolsHelp"))
}
}
.accessibilityElement(children: .combine)
@@ -685,12 +690,12 @@ struct ContentView: View {
if m.running {
Image(systemName: "wrench.and.screwdriver").font(.system(size: 22, weight: .light)).foregroundStyle(.secondary)
VStack(alignment: .leading, spacing: 4) {
- Text(m.t(m.shellCopy != nil || m.shellWaiting || m.stages.contains { $0.id == 1003 && $0.state == .running }
+ Text(loc.t(m.shellCopy != nil || m.shellWaiting || m.stages.contains { $0.id == 1003 && $0.state == .running }
? "activity.transfer" : (m.target == BuildTarget.mac ? "activity.mac" : "activity.ios"))).font(.manrope(15, .bold))
TimelineView(.periodic(from: Date(), by: 1)) { context in // the clock ticks while a count may stand still
Text(m.stages.last(where: { $0.state == .running })
- .map { [$0.name, $0.detail, $0.clock(at: context.date, left: m.t("prog.eta"))].filter { !$0.isEmpty }.joined(separator: " · ") }
- ?? m.t("library.preparing"))
+ .map { [$0.name, $0.detail, $0.clock(at: context.date, left: loc.t("prog.eta"))].filter { !$0.isEmpty }.joined(separator: " · ") }
+ ?? loc.t("library.preparing"))
.font(.manrope(13)).monospacedDigit().foregroundStyle(.secondary).lineLimit(1).truncationMode(.middle)
}
}
@@ -699,21 +704,21 @@ struct ContentView: View {
Text(buildProgress.map { "\(Int($0 * 100))%" } ?? "")
.font(.manrope(14, .semibold)).monospacedDigit().foregroundStyle(.secondary).frame(width: 46, alignment: .leading)
Spacer(minLength: 8)
- Button(m.t("library.viewBuild")) { page = .builds }.buttonStyle(LauncherSecondaryButtonStyle())
- Button(m.t(m.stopping ? "library.stopping" : "btn.stop")) { m.stop() }
+ Button(loc.t("library.viewBuild")) { page = .builds }.buttonStyle(LauncherSecondaryButtonStyle())
+ Button(loc.t(m.stopping ? "library.stopping" : "btn.stop")) { m.stop() }
.buttonStyle(LauncherSecondaryButtonStyle(accent: LauncherPalette.building)).disabled(m.stopping)
} else {
Image(systemName: "desktopcomputer").foregroundStyle(.secondary)
- Text(m.t("library.localNote")).font(.manrope(13)).foregroundStyle(.secondary)
+ Text(loc.t("library.localNote")).font(.manrope(13)).foregroundStyle(.secondary)
if let n = m.autoPulled, n > 0 {
// The automatic update when the app opened (BuildModel.autoPull): the build tools are the current ones
Circle().fill(LauncherPalette.ready).frame(width: 6, height: 6).padding(.leading, 10)
- Text(String(format: m.t("library.toolsUpdated"), n)).font(.manrope(13)).foregroundStyle(.secondary)
+ Text(String(format: loc.t("library.toolsUpdated"), n)).font(.manrope(13)).foregroundStyle(.secondary)
}
if m.autoAdopted {
// A ZIP copy connected to git and updated when the app opened (BuildModel.adoptAtLaunch)
Circle().fill(LauncherPalette.ready).frame(width: 6, height: 6).padding(.leading, 10)
- Text(m.t("library.toolsAdopted")).font(.manrope(13)).foregroundStyle(.secondary)
+ Text(loc.t("library.toolsAdopted")).font(.manrope(13)).foregroundStyle(.secondary)
}
Spacer()
if let staged = m.appStaged {
@@ -721,16 +726,16 @@ struct ContentView: View {
// This branch only shows with no build running, and restartToUpdate checks again.
HStack(spacing: 10) {
Circle().fill(LauncherPalette.ready).frame(width: 6, height: 6)
- Text(String(format: m.t("library.appReady"), staged.release.tag)).font(.manrope(13)).foregroundStyle(.secondary)
+ Text(String(format: loc.t("library.appReady"), staged.release.tag)).font(.manrope(13)).foregroundStyle(.secondary)
}
- Button(m.t("app.restartNow")) { m.restartToUpdate() }.buttonStyle(LauncherSecondaryButtonStyle())
+ Button(loc.t("app.restartNow")) { m.restartToUpdate() }.buttonStyle(LauncherSecondaryButtonStyle())
}
if gamepad.connected {
// The buttons a controller has here, named as the game names them (A on the right)
HStack(spacing: 18) {
- padHint(.activate, m.t("pad.play")); padHint(.launchOptions, m.t("pad.options")); padHint(.back, m.t("pad.back"))
- padHint(.manage, m.t("pad.manage"))
- if enterConsole != nil { padHint(.select, m.t("console.entry")) }
+ padHint(.activate, loc.t("pad.play")); padHint(.launchOptions, loc.t("pad.options")); padHint(.back, loc.t("pad.back"))
+ padHint(.manage, loc.t("pad.manage"))
+ if enterConsole != nil { padHint(.select, loc.t("console.entry")) }
}
}
}
@@ -845,7 +850,7 @@ struct ContentView: View {
/// The Manage menu's rows for a game, wired to the launcher's sheets and actions (ManageItem.list).
private func manageItems(_ game: LibraryGame) -> [ManageItem] {
- ManageItem.list(game: game, labels: m.t, running: m.running, olderTools: toolsAge.older.contains(game.id), activeBuildID: activeBuildID,
+ ManageItem.list(game: game, labels: loc.t, running: m.running, olderTools: toolsAge.older.contains(game.id), activeBuildID: activeBuildID,
hasBuildFolder: BuildFolder.location(for: game) != nil,
hasLog: GameLog.latest(titleID: game.titleID, appPath: game.appPath) != nil,
actions: ManageActions(
@@ -883,7 +888,7 @@ struct ContentView: View {
// The launch options; the app's launcher (dm/mac/launcher.c) keeps a variable that is already set.
// The keyboard and controller layout (Settings → Controls) goes to every game; a build whose host does not read it plays with the default keys.
// They stay launch overrides (the environment) for now: DM_KEYMAP and DM_PAD_MAP become saved choices only when seedds/nxnative#386 merges.
- let environment = GameStart.environment(for: game, library: library, controls: controls, repo: m.repoPath, labels: m.t) // GameStart.swift: the console mode starts games with the same
+ let environment = GameStart.environment(for: game, library: library, controls: controls, repo: m.repoPath, labels: loc.t) // GameStart.swift: the console mode starts games with the same
let withRecording = environment.merging(FrameTimes.recordingEnvironment(for: game, library: library.folder)) { $1 } // FrameTimes.swift, as console mode does
if !withRecording.isEmpty { configuration.environment = withRecording }
NSWorkspace.shared.openApplication(at: URL(fileURLWithPath: game.appPath), configuration: configuration) { app, error in
@@ -948,7 +953,7 @@ struct ContentView: View {
private func chooseArtwork(_ game: LibraryGame) {
let panel = NSOpenPanel()
panel.allowedContentTypes = [.png, .jpeg, .tiff, .heic]
- panel.message = m.t("library.artworkHint")
+ panel.message = loc.t("library.artworkHint")
if panel.runModal() == .OK, let url = panel.url, NSImage(contentsOf: url) != nil {
library.setArtwork(url.path, for: game.id)
}
@@ -958,7 +963,7 @@ struct ContentView: View {
let panel = NSOpenPanel()
panel.canChooseDirectories = true
panel.canChooseFiles = false
- panel.message = m.t("library.folderHint")
+ panel.message = loc.t("library.folderHint")
if !library.folder.isEmpty { panel.directoryURL = URL(fileURLWithPath: library.folder) }
if panel.runModal() == .OK, let url = panel.url {
library.setFolder(url)
@@ -966,75 +971,3 @@ struct ContentView: View {
}
}
}
-
-/// The collection row's scroll state, read from its NSScrollView: SwiftUI's horizontal ScrollView does not
-/// report its offset on macOS 13, so the pager chevrons follow the clip view's bounds instead.
-final class RowScroller: ObservableObject {
- @Published private(set) var canBack = false
- @Published private(set) var canForward = false
- private weak var scrollView: NSScrollView?
- private var observers: [NSObjectProtocol] = []
-
- func attach(_ view: NSScrollView) {
- guard view !== scrollView else { return update() }
- observers.forEach(NotificationCenter.default.removeObserver)
- scrollView = view
- let clip = view.contentView
- clip.postsBoundsChangedNotifications = true
- clip.postsFrameChangedNotifications = true
- view.documentView?.postsFrameChangedNotifications = true
- observers = [(NSView.boundsDidChangeNotification, clip), (NSView.frameDidChangeNotification, clip),
- (NSView.frameDidChangeNotification, view.documentView as Any)].map { name, object in
- NotificationCenter.default.addObserver(forName: name, object: object, queue: .main) { [weak self] _ in self?.update() }
- }
- update()
- }
-
- deinit { observers.forEach(NotificationCenter.default.removeObserver) }
-
- private func update() {
- guard let view = scrollView, let document = view.documentView else { return }
- let x = view.contentView.bounds.minX, end = document.frame.width - view.contentView.bounds.width
- if canBack != (x > 1) { canBack = x > 1 }
- if canForward != (x < end - 1) { canForward = x < end - 1 }
- }
-
- /// Scroll by the whole cards that fit in the row.
- func page(_ direction: CGFloat, step: CGFloat) {
- guard let view = scrollView, let document = view.documentView else { return }
- let clip = view.contentView
- let distance = max(step, (clip.bounds.width / step).rounded(.down) * step)
- let target = min(max(0, clip.bounds.minX + direction * distance), max(0, document.frame.width - clip.bounds.width))
- NSAnimationContext.runAnimationGroup { context in
- context.duration = 0.35
- context.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
- clip.animator().setBoundsOrigin(NSPoint(x: target, y: clip.bounds.minY))
- }
- view.reflectScrolledClipView(clip)
- }
-}
-
-/// Hands the NSScrollView around this background view to the row's scroller once it is in a window.
-private struct EnclosingScrollView: NSViewRepresentable {
- let row: RowScroller
- final class Probe: NSView {
- var row: RowScroller?
- override func viewDidMoveToWindow() {
- super.viewDidMoveToWindow()
- DispatchQueue.main.async { [weak self] in
- if let view = self?.enclosingScrollView { self?.row?.attach(view) }
- }
- }
- }
- func makeNSView(context: Context) -> Probe { let probe = Probe(); probe.row = row; return probe }
- func updateNSView(_ probe: Probe, context: Context) {
- probe.row = row
- DispatchQueue.main.async { if let view = probe.enclosingScrollView { row.attach(view) } }
- }
-}
-
-/// The library's collection row reports its height, so the hero above it fills exactly what is left.
-private struct CollectionHeightKey: PreferenceKey {
- static var defaultValue: CGFloat = 0
- static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { value = max(value, nextValue()) }
-}
diff --git a/frontend/Sources/NX2Apple/RowScroller.swift b/frontend/Sources/NX2Apple/RowScroller.swift
new file mode 100644
index 00000000..446aed07
--- /dev/null
+++ b/frontend/Sources/NX2Apple/RowScroller.swift
@@ -0,0 +1,73 @@
+import SwiftUI
+
+/// The collection row's scroll state, read from its NSScrollView: SwiftUI's horizontal ScrollView does not
+/// report its offset on macOS 13, so the pager chevrons follow the clip view's bounds instead.
+final class RowScroller: ObservableObject {
+ @Published private(set) var canBack = false
+ @Published private(set) var canForward = false
+ private weak var scrollView: NSScrollView?
+ private var observers: [NSObjectProtocol] = []
+
+ func attach(_ view: NSScrollView) {
+ guard view !== scrollView else { return update() }
+ observers.forEach(NotificationCenter.default.removeObserver)
+ scrollView = view
+ let clip = view.contentView
+ clip.postsBoundsChangedNotifications = true
+ clip.postsFrameChangedNotifications = true
+ view.documentView?.postsFrameChangedNotifications = true
+ observers = [(NSView.boundsDidChangeNotification, clip), (NSView.frameDidChangeNotification, clip),
+ (NSView.frameDidChangeNotification, view.documentView as Any)].map { name, object in
+ NotificationCenter.default.addObserver(forName: name, object: object, queue: .main) { [weak self] _ in self?.update() }
+ }
+ update()
+ }
+
+ deinit { observers.forEach(NotificationCenter.default.removeObserver) }
+
+ private func update() {
+ guard let view = scrollView, let document = view.documentView else { return }
+ let x = view.contentView.bounds.minX, end = document.frame.width - view.contentView.bounds.width
+ if canBack != (x > 1) { canBack = x > 1 }
+ if canForward != (x < end - 1) { canForward = x < end - 1 }
+ }
+
+ /// Scroll by the whole cards that fit in the row.
+ func page(_ direction: CGFloat, step: CGFloat) {
+ guard let view = scrollView, let document = view.documentView else { return }
+ let clip = view.contentView
+ let distance = max(step, (clip.bounds.width / step).rounded(.down) * step)
+ let target = min(max(0, clip.bounds.minX + direction * distance), max(0, document.frame.width - clip.bounds.width))
+ NSAnimationContext.runAnimationGroup { context in
+ context.duration = 0.35
+ context.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
+ clip.animator().setBoundsOrigin(NSPoint(x: target, y: clip.bounds.minY))
+ }
+ view.reflectScrolledClipView(clip)
+ }
+}
+
+/// Hands the NSScrollView around this background view to the row's scroller once it is in a window.
+struct EnclosingScrollView: NSViewRepresentable {
+ let row: RowScroller
+ final class Probe: NSView {
+ var row: RowScroller?
+ override func viewDidMoveToWindow() {
+ super.viewDidMoveToWindow()
+ DispatchQueue.main.async { [weak self] in
+ if let view = self?.enclosingScrollView { self?.row?.attach(view) }
+ }
+ }
+ }
+ func makeNSView(context: Context) -> Probe { let probe = Probe(); probe.row = row; return probe }
+ func updateNSView(_ probe: Probe, context: Context) {
+ probe.row = row
+ DispatchQueue.main.async { if let view = probe.enclosingScrollView { row.attach(view) } }
+ }
+}
+
+/// The library's collection row reports its height, so the hero above it fills exactly what is left.
+struct CollectionHeightKey: PreferenceKey {
+ static var defaultValue: CGFloat = 0
+ static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { value = max(value, nextValue()) }
+}
diff --git a/frontend/Sources/NX2Apple/SaveTransfer.swift b/frontend/Sources/NX2Apple/SaveTransfer.swift
index 0fcb692e..c00a09ca 100644
--- a/frontend/Sources/NX2Apple/SaveTransfer.swift
+++ b/frontend/Sources/NX2Apple/SaveTransfer.swift
@@ -2,6 +2,7 @@ import AppKit
import Darwin
import SwiftUI
import NXCore
+import NXModel
import NXLauncher
/// `xcrun devicectl` for the save transfer, as one function: the tests hand in a stand-in, so no test ever reaches a device.
@@ -384,6 +385,7 @@ struct SaveTransfer {
/// A copy asks first, in the sheet itself (a controller reaches it), and says where the save it replaced went.
struct SavesView: View {
@ObservedObject var m: BuildModel
+ @EnvironmentObject var loc: Localizer
@ObservedObject var library: GameLibrary
let gameID: UUID
var support: URL? = nil // the Application Support folder; tests use a temporary one
@@ -424,9 +426,9 @@ struct SavesView: View {
private var macLocationText: String {
func shown(_ url: URL) -> String { (url.path as NSString).abbreviatingWithTildeInPath }
switch model.macLocation {
- case .library(let url): return String(format: m.t("saves.macLibrary"), shown(url))
- case .standard(let url): return String(format: m.t("saves.macStandard"), shown(url))
- case .pending(let url): return String(format: m.t("saves.macPending"), shown(url))
+ case .library(let url): return String(format: loc.t("saves.macLibrary"), shown(url))
+ case .standard(let url): return String(format: loc.t("saves.macStandard"), shown(url))
+ case .pending(let url): return String(format: loc.t("saves.macPending"), shown(url))
}
}
/// The device the sheet asks: its name, or what the launcher recorded when the list has not come yet.
@@ -436,16 +438,16 @@ struct SavesView: View {
var body: some View {
VStack(alignment: .leading, spacing: 0) {
VStack(alignment: .leading, spacing: 4) {
- Text(m.t("saves.title")).font(.manrope(26, .heavy)).tracking(-0.6)
+ Text(loc.t("saves.title")).font(.manrope(26, .heavy)).tracking(-0.6)
if let game { Text(game.name).font(.manrope(14)).foregroundStyle(.secondary) }
}
.padding(.horizontal, 30).padding(.top, 28).padding(.bottom, model.showsSelector ? 12 : 20)
if model.showsSelector {
HStack(spacing: 12) {
- Text(m.t("saves.device")).font(.manrope(13)).foregroundStyle(.secondary)
+ Text(loc.t("saves.device")).font(.manrope(13)).foregroundStyle(.secondary)
LauncherDropdown(options: model.devices.map { d in
- (value: d.id, label: d.name + (d.reachable ? "" : " (" + m.t("dev.notConnected") + ")"))
- }, selection: model.selected, label: m.t("saves.device")) { model.select($0) }
+ (value: d.id, label: d.name + (d.reachable ? "" : " (" + loc.t("dev.notConnected") + ")"))
+ }, selection: model.selected, label: loc.t("saves.device")) { model.select($0) }
.padTarget("saves.device", scope: "saves") {}
}
.padding(.horizontal, 30).padding(.bottom, 16)
@@ -460,7 +462,7 @@ struct SavesView: View {
if busy {
HStack(spacing: 10) {
ProgressView().controlSize(.small)
- Text(m.t("saves.copying")).font(.manrope(13)).foregroundStyle(.secondary)
+ Text(loc.t("saves.copying")).font(.manrope(13)).foregroundStyle(.secondary)
}
} else if let result {
Label(result.text, systemImage: result.ok ? "checkmark.circle.fill" : "exclamationmark.triangle.fill")
@@ -472,11 +474,11 @@ struct SavesView: View {
.padding(.horizontal, 30)
Divider().opacity(0.3)
HStack(spacing: 14) {
- Text(String(format: m.t("saves.note"), deviceName)).font(.manrope(12)).foregroundStyle(.secondary)
+ Text(String(format: loc.t("saves.note"), deviceName)).font(.manrope(12)).foregroundStyle(.secondary)
.lineLimit(3).fixedSize(horizontal: false, vertical: true)
Spacer(minLength: 8)
Button { dismiss() } label: {
- Text(m.t("launch.done")).font(.manrope(13.5, .bold)).foregroundStyle(.black)
+ Text(loc.t("launch.done")).font(.manrope(13.5, .bold)).foregroundStyle(.black)
.padding(.horizontal, 22).padding(.vertical, 9)
.background(LauncherPalette.cream, in: Capsule())
}
@@ -504,23 +506,23 @@ struct SavesView: View {
let newer = SaveTransfer.newer(mac: macSave.newest, device: deviceSave?.newest)
let detail: String
switch side {
- case .mac: detail = macSave.newest.map { String(format: m.t("saves.saved"), dateText($0)) } ?? m.t("saves.none")
+ case .mac: detail = macSave.newest.map { String(format: loc.t("saves.saved"), dateText($0)) } ?? loc.t("saves.none")
case .device:
switch model.deviceState {
- case .noDevices: detail = m.t("saves.noDevices")
- case .notConnected: detail = String(format: m.t("saves.notConnected"), deviceName)
- case .notInstalled: detail = String(format: m.t("saves.notInstalled"), deviceName)
- case .reading: detail = String(format: m.t("saves.reading"), deviceName)
- case .failed(let why): detail = String(format: m.t("saves.unreachable"), why)
- case .timedOut: detail = String(format: m.t("saves.timeout"), deviceName)
- case .ready(let c): detail = c.newest.map { String(format: m.t("saves.saved"), dateText($0)) } ?? m.t("saves.none")
+ case .noDevices: detail = loc.t("saves.noDevices")
+ case .notConnected: detail = String(format: loc.t("saves.notConnected"), deviceName)
+ case .notInstalled: detail = String(format: loc.t("saves.notInstalled"), deviceName)
+ case .reading: detail = String(format: loc.t("saves.reading"), deviceName)
+ case .failed(let why): detail = String(format: loc.t("saves.unreachable"), why)
+ case .timedOut: detail = String(format: loc.t("saves.timeout"), deviceName)
+ case .ready(let c): detail = c.newest.map { String(format: loc.t("saves.saved"), dateText($0)) } ?? loc.t("saves.none")
}
}
return HStack(spacing: 14) {
Image(systemName: side == .mac ? "desktopcomputer" : (model.selectedDevice?.model.lowercased().contains("ipad") == true ? "ipad" : "iphone")).font(.system(size: 18, weight: .light))
.foregroundStyle(.secondary).frame(width: 26)
VStack(alignment: .leading, spacing: 3) {
- Text(side == .mac ? m.t("saves.mac") : deviceName).font(.manrope(14, .medium))
+ Text(side == .mac ? loc.t("saves.mac") : deviceName).font(.manrope(14, .medium))
Text(detail).font(.manrope(12)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
if side == .mac {
Text(macLocationText).font(.manrope(11)).foregroundStyle(.tertiary).lineLimit(2).truncationMode(.middle)
@@ -529,7 +531,7 @@ struct SavesView: View {
}
Spacer(minLength: 12)
if newer == side && (side == .mac || deviceSave != nil) {
- Text(m.t("saves.newer").uppercased()).font(.manrope(10.5, .bold)).tracking(1.1).foregroundStyle(.black)
+ Text(loc.t("saves.newer").uppercased()).font(.manrope(10.5, .bold)).tracking(1.1).foregroundStyle(.black)
.padding(.horizontal, 10).padding(.vertical, 4)
.background(LauncherPalette.cream, in: Capsule())
}
@@ -543,15 +545,15 @@ struct SavesView: View {
let toDevice = !busy && deviceSave != nil && !macSave.folders.isEmpty
let toMac = !busy && !(deviceSave?.folders.isEmpty ?? true)
return HStack(spacing: 10) {
- Button(String(format: m.t("saves.toDevice"), deviceName)) { ask(.device) }.disabled(!toDevice)
+ Button(String(format: loc.t("saves.toDevice"), deviceName)) { ask(.device) }.disabled(!toDevice)
.padTarget("saves.toDevice", scope: "saves") { if toDevice { ask(.device) } }
- Button(String(format: m.t("saves.toMac"), deviceName)) { ask(.mac) }.disabled(!toMac)
+ Button(String(format: loc.t("saves.toMac"), deviceName)) { ask(.mac) }.disabled(!toMac)
.padTarget("saves.toMac", scope: "saves") { if toMac { ask(.mac) } }
Spacer(minLength: 8)
- Button(m.t("dev.refresh")) { model.refresh() }.disabled(busy || !model.canRefresh)
+ Button(loc.t("dev.refresh")) { model.refresh() }.disabled(busy || !model.canRefresh)
.padTarget("saves.refresh", scope: "saves") { if !busy { model.refresh() } }
if FileManager.default.fileExists(atPath: transfer.backups.path) {
- Button(m.t("saves.backups")) { NSWorkspace.shared.open(transfer.backups) }
+ Button(loc.t("saves.backups")) { NSWorkspace.shared.open(transfer.backups) }
.padTarget("saves.backups", scope: "saves") { NSWorkspace.shared.open(transfer.backups) }
}
}
@@ -561,16 +563,16 @@ struct SavesView: View {
/// Asking before a copy replaces a save: which one, where its backup goes, and that the game must be closed on the device.
private func confirmation(_ replacing: SaveTransfer.Side) -> some View {
VStack(alignment: .leading, spacing: 12) {
- Text(replacing == .device ? String(format: m.t("saves.askToDevice"), deviceName) : String(format: m.t("saves.askToMac"), deviceName))
+ Text(replacing == .device ? String(format: loc.t("saves.askToDevice"), deviceName) : String(format: loc.t("saves.askToMac"), deviceName))
.font(.manrope(15, .semibold)).fixedSize(horizontal: false, vertical: true)
- Text(String(format: m.t("saves.askNote"), deviceName, m.shortPath(transfer.backups.path)))
+ Text(String(format: loc.t("saves.askNote"), deviceName, m.shortPath(transfer.backups.path)))
.font(.manrope(12.5)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
HStack(spacing: 10) {
Spacer()
- Button(m.t("saves.cancel")) { asking = nil }.buttonStyle(LauncherSecondaryButtonStyle())
+ Button(loc.t("saves.cancel")) { asking = nil }.buttonStyle(LauncherSecondaryButtonStyle())
.padTarget("saves.cancel", scope: "saves") { asking = nil }
Button { copy(replacing) } label: {
- Text(m.t("saves.replace")).font(.manrope(13, .bold)).foregroundStyle(.black)
+ Text(loc.t("saves.replace")).font(.manrope(13, .bold)).foregroundStyle(.black)
.padding(.horizontal, 18).padding(.vertical, 9)
.background(LauncherPalette.cream, in: RoundedRectangle(cornerRadius: 9))
}
@@ -585,7 +587,7 @@ struct SavesView: View {
private func dateText(_ date: Date) -> String {
let f = DateFormatter()
- f.locale = m.lang == .zh ? Locale(identifier: "zh_Hans") : (Locale.current.identifier.hasPrefix("zh") ? Locale(identifier: "en_US") : .current)
+ f.locale = loc.lang == .zh ? Locale(identifier: "zh_Hans") : (Locale.current.identifier.hasPrefix("zh") ? Locale(identifier: "en_US") : .current)
f.dateStyle = .medium; f.timeStyle = .short
return f.string(from: date)
}
@@ -593,7 +595,7 @@ struct SavesView: View {
private func ask(_ replacing: SaveTransfer.Side) {
result = nil
guard let game, !SaveTransfer.runningOnMac(titleID: game.titleID) else {
- result = (String(format: m.t("saves.running"), game?.name ?? ""), false)
+ result = (String(format: loc.t("saves.running"), game?.name ?? ""), false)
return
}
asking = replacing
@@ -604,7 +606,7 @@ struct SavesView: View {
asking = nil
guard let game, let transfer = model.found else { return }
if SaveTransfer.runningOnMac(titleID: game.titleID) { // started while the question was open
- result = (String(format: m.t("saves.running"), game.name), false)
+ result = (String(format: loc.t("saves.running"), game.name), false)
return
}
busy = true
@@ -612,8 +614,8 @@ struct SavesView: View {
let outcome: (String, Bool)
do {
let backup = try replacing == .device ? transfer.macToDevice() : transfer.deviceToMac()
- outcome = (backup.map { String(format: m.t("saves.copiedBackup"), m.shortPath($0.path)) } ?? m.t("saves.copied"), true)
- } catch { outcome = (String(format: m.t("saves.failed"), message(error)), false) }
+ outcome = (backup.map { String(format: loc.t("saves.copiedBackup"), m.shortPath($0.path)) } ?? loc.t("saves.copied"), true)
+ } catch { outcome = (String(format: loc.t("saves.failed"), message(error)), false) }
DispatchQueue.main.async {
busy = false
result = outcome
@@ -625,10 +627,10 @@ struct SavesView: View {
private func message(_ error: Error) -> String {
switch error as? SaveTransfer.Failure {
- case .noMacSave: return m.t("saves.noMacSave")
- case .noDeviceSave: return String(format: m.t("saves.noDeviceSave"), deviceName)
+ case .noMacSave: return loc.t("saves.noMacSave")
+ case .noDeviceSave: return String(format: loc.t("saves.noDeviceSave"), deviceName)
case .device(let line): return line
- case .timeout: return String(format: m.t("saves.timeout"), deviceName)
+ case .timeout: return String(format: loc.t("saves.timeout"), deviceName)
case nil: return error.localizedDescription
}
}
diff --git a/frontend/Sources/NX2Apple/ShellCopyView.swift b/frontend/Sources/NX2Apple/ShellCopyView.swift
index 099fc205..ad273e92 100644
--- a/frontend/Sources/NX2Apple/ShellCopyView.swift
+++ b/frontend/Sources/NX2Apple/ShellCopyView.swift
@@ -1,5 +1,6 @@
import SwiftUI
import NXCore
+import NXModel
import NXLauncher
/// Before the shared app's game data goes over USB or Wi-Fi: how much, over which connection, and what to do about it. A cable
@@ -7,19 +8,20 @@ import NXLauncher
/// device shows up wired). While it waits, the card says so and offers to stop.
struct ShellCopyCard: View {
@ObservedObject var m: BuildModel
+ @EnvironmentObject var loc: Localizer
var body: some View {
if let plan = m.shellCopy {
card {
- Text(m.t("shell.copyTitle")).font(.manrope(14, .semibold))
+ Text(loc.t("shell.copyTitle")).font(.manrope(14, .semibold))
Text(plan.sizeText).font(.manrope(13)).foregroundStyle(.secondary)
Text(plan.connectionText).font(.manrope(13)).fixedSize(horizontal: false, vertical: true)
- Text(m.t("shell.copyExternalNote")).font(.manrope(12.5)).foregroundStyle(.secondary)
+ Text(loc.t("shell.copyExternalNote")).font(.manrope(12.5)).foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true).padding(.top, 1)
HStack(spacing: 10) {
- Button(m.t("shell.copyStart")) { m.answerShellCopy(.copy) }
- if plan.canWaitForCable { Button(m.t("shell.copyWaitCable")) { m.answerShellCopy(.waitForCable) } }
- Button(m.t("shell.copySkip")) { m.answerShellCopy(.skip) }
+ Button(loc.t("shell.copyStart")) { m.answerShellCopy(.copy) }
+ if plan.canWaitForCable { Button(loc.t("shell.copyWaitCable")) { m.answerShellCopy(.waitForCable) } }
+ Button(loc.t("shell.copySkip")) { m.answerShellCopy(.skip) }
}
.buttonStyle(LauncherSecondaryButtonStyle()).padding(.top, 2)
}
@@ -27,9 +29,9 @@ struct ShellCopyCard: View {
card {
HStack(spacing: 8) {
ProgressView().controlSize(.small)
- Text(String(format: m.t("shell.copyWaiting"), m.deviceName(m.installDevice))).font(.manrope(13))
+ Text(String(format: loc.t("shell.copyWaiting"), m.deviceName(m.installDevice))).font(.manrope(13))
}
- Button(m.t("shell.copyStopWaiting")) { m.cancelShellWait() }
+ Button(loc.t("shell.copyStopWaiting")) { m.cancelShellWait() }
.buttonStyle(LauncherSecondaryButtonStyle()).padding(.top, 2)
}
}
diff --git a/frontend/Sources/NX2Apple/StaleFrameworksPrompt.swift b/frontend/Sources/NX2Apple/StaleFrameworksPrompt.swift
index c2dff10d..0e9148f9 100644
--- a/frontend/Sources/NX2Apple/StaleFrameworksPrompt.swift
+++ b/frontend/Sources/NX2Apple/StaleFrameworksPrompt.swift
@@ -1,5 +1,6 @@
import SwiftUI
import NXCore
+import NXModel
// LNPANDY/NX2Apple#449: a build for the iPhone or iPad asks before the long steps when the shell folder holds frameworks of
// another shader chain than the engine this build uses. Stop leaves every file as it is. Continue deletes the stale frameworks
@@ -52,14 +53,15 @@ extension BuildModel {
private struct StaleFrameworksPrompt: ViewModifier {
@ObservedObject var m: BuildModel
+ @EnvironmentObject var loc: Localizer
func body(content: Content) -> some View {
- content.alert(m.t("stale.title"), isPresented: Binding(get: { !m.staleFrameworks.isEmpty },
+ content.alert(loc.t("stale.title"), isPresented: Binding(get: { !m.staleFrameworks.isEmpty },
set: { if !$0 { m.stopForStaleFrameworks() } })) {
- Button(m.t("stale.go")) { m.continueWithStaleFrameworks() }
- Button(m.t("stale.stop"), role: .cancel) { m.stopForStaleFrameworks() }
+ Button(loc.t("stale.go")) { m.continueWithStaleFrameworks() }
+ Button(loc.t("stale.stop"), role: .cancel) { m.stopForStaleFrameworks() }
} message: {
- Text(String(format: m.t("stale.message"), StaleFrameworks.list(m.staleFrameworks)))
+ Text(String(format: loc.t("stale.message"), StaleFrameworks.list(m.staleFrameworks)))
}
}
}
diff --git a/frontend/Sources/NX2Apple/UpdateSheet.swift b/frontend/Sources/NX2Apple/UpdateSheet.swift
index d372637d..906cf416 100644
--- a/frontend/Sources/NX2Apple/UpdateSheet.swift
+++ b/frontend/Sources/NX2Apple/UpdateSheet.swift
@@ -1,5 +1,6 @@
import SwiftUI
import NXCore
+import NXModel
import NXLauncher
/// "A new version is out", with what it changes, shown when the app opens or Check for updates finds
@@ -13,6 +14,7 @@ import NXLauncher
/// ReleaseNotes turns them into blocks with links, and this file only styles those.
struct UpdateSheet: View {
@ObservedObject var m: BuildModel
+ @EnvironmentObject var loc: Localizer
@Environment(\.dismiss) private var dismiss
private var update: AppUpdate.Release? { m.appUpdate }
@@ -20,9 +22,9 @@ struct UpdateSheet: View {
var body: some View {
VStack(alignment: .leading, spacing: 0) {
VStack(alignment: .leading, spacing: 6) {
- Text(m.t("update.title"))
+ Text(loc.t("update.title"))
.font(.manrope(24, .heavy)).tracking(-0.5)
- Text(String(format: m.t("update.fromTo"), BuildModel.appVersion, update?.tag ?? ""))
+ Text(String(format: loc.t("update.fromTo"), BuildModel.appVersion, update?.tag ?? ""))
.font(.manrope(13)).foregroundStyle(.secondary)
}
.padding(.horizontal, 28).padding(.top, 26).padding(.bottom, 18)
@@ -30,12 +32,12 @@ struct UpdateSheet: View {
ScrollView {
VStack(alignment: .leading, spacing: 6) {
if let notes = update?.notes, !notes.isEmpty {
- let blocks = ReleaseNotes.blocks(from: ReleaseNotes.markdown(notes, for: m.lang))
+ let blocks = ReleaseNotes.blocks(from: ReleaseNotes.markdown(notes, for: loc.lang))
ForEach(Array(blocks.enumerated()), id: \.offset) { index, block in
blockView(block, first: index == 0)
}
} else {
- Text(m.t("update.noNotes")).font(.manrope(13)).foregroundStyle(.secondary)
+ Text(loc.t("update.noNotes")).font(.manrope(13)).foregroundStyle(.secondary)
}
}
.padding(.horizontal, 28).padding(.bottom, 20)
@@ -50,11 +52,11 @@ struct UpdateSheet: View {
Divider().opacity(0.3)
HStack(spacing: 12) {
if let u = update {
- Link(m.t("update.openPage"), destination: URL(string: "https://github.com/LNPANDY/NX2Apple/releases/tag/\(u.tag)")!)
+ Link(loc.t("update.openPage"), destination: URL(string: "https://github.com/LNPANDY/NX2Apple/releases/tag/\(u.tag)")!)
.font(.manrope(12.5))
}
Spacer(minLength: 8)
- Button(m.t("update.later")) { dismiss() }
+ Button(loc.t("update.later")) { dismiss() }
.buttonStyle(LauncherSecondaryButtonStyle())
.keyboardShortcut(.cancelAction)
Button {
@@ -63,7 +65,7 @@ struct UpdateSheet: View {
// The sheet stays up while it downloads, so a refusal (a macOS too old for the release) is seen here.
if m.appStaged != nil { m.installStagedUpdate(relaunch: true); dismiss() } else { m.performAppUpdate() }
} label: {
- Text(m.t(m.appStaged != nil ? "app.restartNow" : "update.now"))
+ Text(loc.t(m.appStaged != nil ? "app.restartNow" : "update.now"))
.font(.manrope(13.5, .bold)).foregroundStyle(.black)
.padding(.horizontal, 20).padding(.vertical, 9)
.background(LauncherPalette.cream, in: Capsule())
diff --git a/frontend/Sources/NXModel/Localizer.swift b/frontend/Sources/NXModel/Localizer.swift
new file mode 100644
index 00000000..83336329
--- /dev/null
+++ b/frontend/Sources/NXModel/Localizer.swift
@@ -0,0 +1,47 @@
+import Foundation
+import Combine
+import NXCore
+
+/// The interface language and the strings for it (LNPANDY/NX2Apple#387). Views take it from the environment, so a language change
+/// redraws the views that show text and nothing else. `BuildModel` gets it through its init for the strings it writes itself.
+///
+/// The language choice is stored by `Lang.saved` (UserDefaults key `appLanguage`): "" follows the system. `choose()` writes it.
+///
+/// `lang` and `t()` are not tied to the main actor, because `BuildModel` writes status text from background queues. The value is
+/// behind a lock, and a change sends `objectWillChange` for the views.
+@MainActor package final class Localizer: ObservableObject {
+ /// Holds the language where any thread may read it.
+ private final class Box: @unchecked Sendable {
+ private let lock = NSLock()
+ private var stored: Lang
+ init(_ lang: Lang) { stored = lang }
+ var value: Lang {
+ get { lock.lock(); defer { lock.unlock() }; return stored }
+ set { lock.lock(); stored = newValue; lock.unlock() }
+ }
+ }
+
+ private let box: Box
+ nonisolated package let objectWillChange = ObservableObjectPublisher()
+
+ nonisolated package init(_ lang: Lang = Lang.initial()) { box = Box(lang) }
+
+ /// The interface language: the one picked in Settings, else the system's.
+ nonisolated package var lang: Lang {
+ get { box.value }
+ set {
+ guard newValue != box.value else { return }
+ objectWillChange.send()
+ box.value = newValue
+ }
+ }
+
+ /// The string for `key` in the current language. An unknown key comes back as itself, so it shows up in the UI.
+ nonisolated package func t(_ key: String) -> String { L10n.string(key, lang) }
+
+ /// Settings' choice: "" follows the system, else a `Lang` raw value. It is stored, and the language changes now.
+ package func choose(_ code: String) {
+ Lang.saved = Lang(rawValue: code)
+ lang = Lang.initial()
+ }
+}
diff --git a/frontend/Sources/NXModel/NXModel.swift b/frontend/Sources/NXModel/NXModel.swift
deleted file mode 100644
index 27a8d793..00000000
--- a/frontend/Sources/NXModel/NXModel.swift
+++ /dev/null
@@ -1,4 +0,0 @@
-// The stores: `ObservableObject`s that own their @Published state (see frontend/ARCHITECTURE.md).
-// May import NXCore, Foundation and Combine, never SwiftUI or AppKit.
-// Empty until the stores of LNPANDY/NX2Apple#387 move here. Every file that was checked for step 1
-// reaches into BuildModel, AppKit or SwiftUI types and so stays in NX2Apple.
diff --git a/frontend/Tests/NX2AppleTests/BuildFailureTests.swift b/frontend/Tests/NX2AppleTests/BuildFailureTests.swift
index 886f1a0e..68b2e48c 100644
--- a/frontend/Tests/NX2AppleTests/BuildFailureTests.swift
+++ b/frontend/Tests/NX2AppleTests/BuildFailureTests.swift
@@ -289,7 +289,7 @@ final class BuildFailureTests: XCTestCase {
m.doneNote = m.failureWhat(m.failure!)
try capture(name, width: 760, height: kind == .noTitleID ? 380 : 250, ZStack(alignment: .top) {
LauncherPalette.background
- BuildFailureCard(m: m).padding(24)
+ BuildFailureCard(m: m).environmentObject(m.localizer).padding(24)
})
}
let m = BuildModel()
diff --git a/frontend/Tests/NX2AppleTests/CheatFilesTests.swift b/frontend/Tests/NX2AppleTests/CheatFilesTests.swift
index 207253b6..351158ba 100644
--- a/frontend/Tests/NX2AppleTests/CheatFilesTests.swift
+++ b/frontend/Tests/NX2AppleTests/CheatFilesTests.swift
@@ -262,10 +262,10 @@ final class CheatFilesTests: XCTestCase {
func testTheImportMessageSaysWhatCameInAndWhatDidNot() {
let m = BuildModel(); m.lang = .en
- XCTAssertEqual(CheatsView.importMessage(.init(imported: ["A", "B"]), m: m).0, "Files imported: 2.")
- XCTAssertTrue(CheatsView.importMessage(.init(imported: ["A"], skipped: ["x.txt"]), m: m).0.contains("x.txt"))
- XCTAssertFalse(CheatsView.importMessage(.init(), m: m).1)
- XCTAssertTrue(CheatsView.importMessage(.init(imported: ["A"]), m: m).1)
+ XCTAssertEqual(CheatsView.importMessage(.init(imported: ["A", "B"]), loc: m.localizer).0, "Files imported: 2.")
+ XCTAssertTrue(CheatsView.importMessage(.init(imported: ["A"], skipped: ["x.txt"]), loc: m.localizer).0.contains("x.txt"))
+ XCTAssertFalse(CheatsView.importMessage(.init(), loc: m.localizer).1)
+ XCTAssertTrue(CheatsView.importMessage(.init(imported: ["A"]), loc: m.localizer).1)
}
// ---- the copy to the device ----
@@ -417,16 +417,16 @@ final class CheatFilesTests: XCTestCase {
try XCTUnwrap(rep.representation(using: .png, properties: [:])).write(to: output.appendingPathComponent(name + ".png"))
window.orderOut(nil)
}
- try shot("cheats", CheatsView(m: model, library: library, gameID: id, devicectl: DeviceControl { _ in (true, "") }, support: support))
- try shot("cheats-drop", CheatsView(m: model, library: library, gameID: id, support: support, dropped: true))
+ try shot("cheats", CheatsView(m: model, library: library, gameID: id, devicectl: DeviceControl { _ in (true, "") }, support: support).environmentObject(model.localizer))
+ try shot("cheats-drop", CheatsView(m: model, library: library, gameID: id, support: support, dropped: true).environmentObject(model.localizer))
model.lang = .de
- try shot("cheats-de", CheatsView(m: model, library: library, gameID: id, support: support))
+ try shot("cheats-de", CheatsView(m: model, library: library, gameID: id, support: support).environmentObject(model.localizer))
model.lang = .zh
- try shot("cheats-zh", CheatsView(m: model, library: library, gameID: id, support: support))
+ try shot("cheats-zh", CheatsView(m: model, library: library, gameID: id, support: support).environmentObject(model.localizer))
model.lang = .en
try fm.removeItem(at: folder)
try write("x", ".cheats-running-\(game)", under: folder)
- try shot("cheats-empty", CheatsView(m: model, library: library, gameID: id, support: support))
+ try shot("cheats-empty", CheatsView(m: model, library: library, gameID: id, support: support).environmentObject(model.localizer))
}
}
diff --git a/frontend/Tests/NX2AppleTests/DropFilesTests.swift b/frontend/Tests/NX2AppleTests/DropFilesTests.swift
index 621d5b4b..7497131d 100644
--- a/frontend/Tests/NX2AppleTests/DropFilesTests.swift
+++ b/frontend/Tests/NX2AppleTests/DropFilesTests.swift
@@ -216,7 +216,7 @@ final class DropFilesTests: XCTestCase {
model.deps = [BuildModel.Dep(id: "test", name: "Xcode", hint: "", present: true, installCmd: [])]
let library = GameLibrary(file: temporary.appendingPathComponent("preview.json"))
// the page as a drag shows it: the highlight drawn over the Builds page
- let page = BuilderView(m: model, library: library).environmentObject(PadFocus())
+ let page = BuilderView(m: model, library: library).environmentObject(PadFocus()).environmentObject(model.localizer)
.modifier(GameFilesDrop(enabled: true, label: model.t("drop.hint"), targeted: true) { _ in })
.frame(width: 1100, height: 760).background(LauncherPalette.background).environment(\.colorScheme, .dark)
let host = NSHostingView(rootView: page)
diff --git a/frontend/Tests/NX2AppleTests/FrameTimesTests.swift b/frontend/Tests/NX2AppleTests/FrameTimesTests.swift
index f65261b6..cca294e3 100644
--- a/frontend/Tests/NX2AppleTests/FrameTimesTests.swift
+++ b/frontend/Tests/NX2AppleTests/FrameTimesTests.swift
@@ -178,7 +178,7 @@ final class FrameTimesTests: XCTestCase {
FrameTimes.setEnabled(true, titleID: titleID)
let model = BuildModel()
model.lang = .en
- let host = NSHostingView(rootView: LaunchOptionsView(m: model, library: library, gameID: library.games[0].id).environmentObject(PadFocus()))
+ let host = NSHostingView(rootView: LaunchOptionsView(m: model, library: library, gameID: library.games[0].id).environmentObject(PadFocus()).environmentObject(model.localizer))
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 900, height: 1300), styleMask: [.titled, .closable, .resizable], backing: .buffered, defer: false)
window.contentView = host
window.orderFront(nil)
diff --git a/frontend/Tests/NX2AppleTests/LauncherControlWidthTests.swift b/frontend/Tests/NX2AppleTests/LauncherControlWidthTests.swift
index 5572c0ad..a5cef2ce 100644
--- a/frontend/Tests/NX2AppleTests/LauncherControlWidthTests.swift
+++ b/frontend/Tests/NX2AppleTests/LauncherControlWidthTests.swift
@@ -273,7 +273,7 @@ final class LauncherControlWidthTests: XCTestCase {
for lang in Lang.allCases {
model.lang = lang
let samples = Samples()
- let view = LaunchOptionsView(m: model, library: library, gameID: game.id).environmentObject(PadFocus())
+ let view = LaunchOptionsView(m: model, library: library, gameID: game.id).environmentObject(PadFocus()).environmentObject(model.localizer)
.environment(\.measuresLauncherControls, true)
.onPreferenceChange(LauncherControlSamples.self) { samples.all = $0 }
let host = NSHostingView(rootView: view)
diff --git a/frontend/Tests/NX2AppleTests/LibraryTests.swift b/frontend/Tests/NX2AppleTests/LibraryTests.swift
index c4966c26..64a00c84 100644
--- a/frontend/Tests/NX2AppleTests/LibraryTests.swift
+++ b/frontend/Tests/NX2AppleTests/LibraryTests.swift
@@ -739,7 +739,7 @@ final class LibraryTests: XCTestCase {
if let upscale = LaunchSetting.read(app: library.games.first { $0.id == botwID }!.appPath)?.first(where: { $0.env == "DM_PRESENT_UPSCALE" }) {
SavedChoices(app: library.games.first { $0.id == botwID }!.appPath, titleID: "01007EF00011E000").set(upscale, "metalfx")
}
- try shot("launch-options", LaunchOptionsView(m: model, library: library, gameID: botwID), size: NSSize(width: 600, height: 700), trafficLights: false) // a sheet: no window controls of its own
+ try shot("launch-options", LaunchOptionsView(m: model, library: library, gameID: botwID).environmentObject(model.localizer), size: NSSize(width: 600, height: 700), trafficLights: false) // a sheet: no window controls of its own
}
/// Opt-in native rendering for visual QA; it never touches the user's saved library.
@@ -881,7 +881,7 @@ final class LibraryTests: XCTestCase {
for (name, running) in [("free-space", false), ("free-space-running", true)] {
model.running = running
let sheet = NSHostingView(rootView: FreeSpaceView(m: model, game: library.games[0], survey: measured, chosen: [.extracted, .oldShaders])
- .environmentObject(PadFocus()))
+ .environmentObject(PadFocus()).environmentObject(model.localizer))
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 560, height: 690), styleMask: [.titled], backing: .buffered, defer: false)
window.contentView = sheet
window.orderFront(nil)
@@ -898,7 +898,7 @@ final class LibraryTests: XCTestCase {
try FileManager.default.createDirectory(at: dm, withIntermediateDirectories: true)
try FileManager.default.copyItem(at: URL(fileURLWithPath: json), to: dm.appendingPathComponent("launcher.json"))
if let fps = LaunchSetting.read(app: first.appPath)?.first(where: { $0.env == "DM_FPS_TARGET" }) { SavedChoices(app: first.appPath, titleID: first.titleID).set(fps, "60") }
- let host = NSHostingView(rootView: LaunchOptionsView(m: model, library: library, gameID: first.id).environmentObject(PadFocus()))
+ let host = NSHostingView(rootView: LaunchOptionsView(m: model, library: library, gameID: first.id).environmentObject(PadFocus()).environmentObject(model.localizer))
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 600, height: 700), styleMask: [.titled], backing: .buffered, defer: false)
window.contentView = host
window.orderFront(nil)
@@ -909,7 +909,7 @@ final class LibraryTests: XCTestCase {
window.orderOut(nil)
// The same sheet with a controller's focus on the console mode row
let focus = PadFocus()
- let focused = NSHostingView(rootView: LaunchOptionsView(m: model, library: library, gameID: first.id).environmentObject(focus))
+ let focused = NSHostingView(rootView: LaunchOptionsView(m: model, library: library, gameID: first.id).environmentObject(focus).environmentObject(model.localizer))
window.contentView = focused
window.orderFront(nil)
RunLoop.main.run(until: Date().addingTimeInterval(0.4))
@@ -929,7 +929,7 @@ final class LibraryTests: XCTestCase {
let layout = ControlLayout(defaults: defaults)
if let up = ControlLayout.functions.first(where: { $0.id == "RUp" }) { layout.assign(up, key: 34) }
layout.setSends("A", "B"); layout.setSends("B", "A")
- let host = NSHostingView(rootView: ControlsView(m: model, layout: layout).environmentObject(PadFocus()))
+ let host = NSHostingView(rootView: ControlsView(layout: layout).environmentObject(PadFocus()).environmentObject(model.localizer))
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 600, height: 700), styleMask: [.titled], backing: .buffered, defer: false)
window.contentView = host
window.orderFront(nil)
@@ -995,7 +995,7 @@ final class LibraryTests: XCTestCase {
layout.controllerCategory = { category }
layout.setPadMode(mode)
let focus = PadFocus()
- let host = NSHostingView(rootView: ControlsView(m: model, layout: layout).environmentObject(focus))
+ let host = NSHostingView(rootView: ControlsView(layout: layout).environmentObject(focus).environmentObject(model.localizer))
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 600, height: 700), styleMask: [.titled], backing: .buffered, defer: false)
window.contentView = host
window.orderFront(nil)
@@ -1015,7 +1015,7 @@ final class LibraryTests: XCTestCase {
let buttons = NSHostingView(rootView: HStack(spacing: 14) {
DiagnosticsButton(m: model)
DiagnosticsButton(m: model, showCopied: true)
- }.launcherRowControls().padding(24).background(LauncherPalette.background).environmentObject(PadFocus()))
+ }.launcherRowControls().padding(24).background(LauncherPalette.background).environmentObject(PadFocus()).environmentObject(model.localizer))
buttons.frame = NSRect(x: 0, y: 0, width: 420, height: 90)
let window = NSWindow(contentRect: buttons.frame, styleMask: [.titled], backing: .buffered, defer: false)
window.contentView = buttons
@@ -1053,7 +1053,7 @@ final class LibraryTests: XCTestCase {
let host = NSHostingView(rootView: SavesView(m: model, library: library, gameID: game.id, devicectl: device, support: support, listDevices: {
[AppleDevice(id: "00008150-AAAA", name: "Zijad\u{2019}s iPhone", model: "iPhone 17", os: "27.0", reachable: true),
AppleDevice(id: "00008150-BBBB", name: "Zijad\u{2019}s iPad", model: "iPad Pro", os: "27.0", reachable: true)]
- }).environmentObject(focus))
+ }).environmentObject(focus).environmentObject(model.localizer))
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 600, height: 520), styleMask: [.titled], backing: .buffered, defer: false)
window.contentView = host
window.orderFront(nil)
diff --git a/frontend/Tests/NX2AppleTests/LocalizerTests.swift b/frontend/Tests/NX2AppleTests/LocalizerTests.swift
new file mode 100644
index 00000000..1467893f
--- /dev/null
+++ b/frontend/Tests/NX2AppleTests/LocalizerTests.swift
@@ -0,0 +1,71 @@
+import Combine
+import XCTest
+@testable import NXCore
+@testable import NXModel
+
+/// LNPANDY/NX2Apple#387, step 2: the language and the strings live in `Localizer`, which needs no SwiftUI. The choice is stored under the
+/// UserDefaults key `appLanguage`, as before, so the tests put the player's own value back.
+@MainActor final class LocalizerTests: XCTestCase {
+ private var stored: String?
+
+ override func setUp() {
+ stored = UserDefaults.standard.string(forKey: "appLanguage")
+ }
+
+ override func tearDown() {
+ if let stored { UserDefaults.standard.set(stored, forKey: "appLanguage") } else { UserDefaults.standard.removeObject(forKey: "appLanguage") }
+ }
+
+ func testTheLanguageSwitchChangesTheStrings() {
+ let loc = Localizer(.en)
+ XCTAssertEqual(loc.t("onboarding.start"), "Start")
+ loc.lang = .de
+ XCTAssertEqual(loc.t("onboarding.start"), L10n.string("onboarding.start", .de))
+ loc.lang = .zh
+ XCTAssertEqual(loc.t("onboarding.start"), "\u{5f00}\u{59cb}")
+ }
+
+ func testAnUnknownKeyComesBackAsItself() {
+ XCTAssertEqual(Localizer(.en).t("no.such.key"), "no.such.key")
+ XCTAssertEqual(Localizer(.fr).t("no.such.key"), "no.such.key")
+ }
+
+ func testAChangeAnnouncesItselfOnce() {
+ let loc = Localizer(.en)
+ var sent = 0
+ let watch = loc.objectWillChange.sink { sent += 1 }
+ loc.lang = .de
+ loc.lang = .de // the same language: no redraw
+ loc.lang = .fr
+ XCTAssertEqual(sent, 2)
+ watch.cancel()
+ }
+
+ func testChooseStoresTheLanguageAndChangesIt() {
+ let loc = Localizer(.en)
+ loc.choose("sv")
+ XCTAssertEqual(loc.lang, .sv)
+ XCTAssertEqual(UserDefaults.standard.string(forKey: "appLanguage"), "sv")
+ XCTAssertEqual(Lang.saved, .sv)
+ XCTAssertEqual(Localizer().lang, .sv, "a new launch reads the stored choice")
+ }
+
+ func testChoosingTheSystemClearsTheChoice() {
+ let loc = Localizer(.en)
+ loc.choose("zh")
+ loc.choose("")
+ XCTAssertEqual(UserDefaults.standard.string(forKey: "appLanguage"), "")
+ XCTAssertNil(Lang.saved)
+ XCTAssertEqual(loc.lang, Lang.device())
+ }
+
+ func testAnyThreadCanReadTheStrings() {
+ let loc = Localizer(.en)
+ let done = expectation(description: "read in the background")
+ DispatchQueue.global().async {
+ XCTAssertEqual(loc.t("onboarding.start"), "Start")
+ done.fulfill()
+ }
+ wait(for: [done], timeout: 5)
+ }
+}
diff --git a/frontend/Tests/NX2AppleTests/ReleaseNotesTests.swift b/frontend/Tests/NX2AppleTests/ReleaseNotesTests.swift
index 43a11ac9..111c25df 100644
--- a/frontend/Tests/NX2AppleTests/ReleaseNotesTests.swift
+++ b/frontend/Tests/NX2AppleTests/ReleaseNotesTests.swift
@@ -206,7 +206,7 @@ final class ReleaseNotesTests: XCTestCase {
m.lang = lang
m.appUpdate = AppUpdate.Release(tag: tag, url: "", digest: nil, notes: notes)
let width: CGFloat = 560, height: CGFloat = 640
- let host = NSHostingView(rootView: UpdateSheet(m: m).frame(width: width, height: height))
+ let host = NSHostingView(rootView: UpdateSheet(m: m).environmentObject(m.localizer).frame(width: width, height: height))
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: width, height: height), styleMask: [.titled], backing: .buffered, defer: false)
window.contentView = host
window.appearance = NSAppearance(named: .darkAqua)
diff --git a/frontend/Tests/NX2AppleTests/SourceSizeTests.swift b/frontend/Tests/NX2AppleTests/SourceSizeTests.swift
index 311dda04..bab1296e 100644
--- a/frontend/Tests/NX2AppleTests/SourceSizeTests.swift
+++ b/frontend/Tests/NX2AppleTests/SourceSizeTests.swift
@@ -8,7 +8,7 @@ final class SourceSizeTests: XCTestCase {
/// Path under frontend/Sources → its line count when the limit came in. Lower the number when the file shrinks.
private static let aboveTheLimit: [String: Int] = [
"NX2Apple/ContentView.swift": 3749,
- "NX2Apple/LauncherView.swift": 1040,
+ "NX2Apple/LauncherView.swift": 973,
"NXCore/Localization.swift": 4237,
]