Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
Launcher: the release app builds from its engine store, not git
v0lumehie1f3d14dbe22
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swiftindex dbd473bd..2c7ff9c8 100644--- a/frontend/Sources/NSPortBuilder/ContentView.swift+++ b/frontend/Sources/NSPortBuilder/ContentView.swift@@ -375,6 +375,24 @@ final class BuildModel: ObservableObject {/// A copy without .git was connected to git and brought to the current version when the app opened (adoptAtLaunch).@Published var autoAdopted = false+ // ---- The release app's engine (EngineUpdater.swift, EngineUpdateModel.swift) ----++ /// The engine tree inside the app bundle. nil for a launcher built from the repository, which keeps its checkout and git.+ /// A release app builds from the engine store instead, and never clones or pulls.+ var engineBundle: URL? = EngineBundle.tree(in: Bundle.main.resourceURL)+ var engineStore = EngineStore()+ var engineTransport: EngineTransport = URLSessionEngineTransport()+ @Published var engineSelection = EngineSelection.load()+ @Published var engineBusy = false+ @Published var engineStatus = ""+ /// A newer engine the launch check found while automatic updates are off: Settings offers it.+ @Published var engineAvailable: EngineUpdate.Engine?+ /// The channel the player picked and is asked to confirm (the switch can change the shader chain).+ @Published var confirmingChannel: EngineChannel?+ /// An installed engine that waits for the running build to end before the build tools switch to it.+ var pendingEngine: (engine: EngineUpdate.Engine, channel: EngineChannel)?+ var usesEngineStore: Bool { engineBundle != nil }+nonisolated static func gitBinary() -> String? {for c in ["/usr/bin/git", "/opt/homebrew/bin/git", "/usr/local/bin/git"]where FileManager.default.isExecutableFile(atPath: c) { return c }@@ -406,7 +424,7 @@ final class BuildModel: ObservableObject {/// First-time flow: clone the project to ~/nxnative (the discovery seeds cover it) and select it.func cloneRepo() {- guard !running, !repoBusy else { return }+ guard !running, !repoBusy, !usesEngineStore else { return }guard let git = Self.gitBinary() else { repoStatus = t("repo.gitMissing"); return }let dest = NSHomeDirectory() + "/NX2Apple"if FileManager.default.fileExists(atPath: dest) {@@ -438,7 +456,7 @@ final class BuildModel: ObservableObject {/// Compare the checkout with origin/main. `silent` is the launch-time check: no status text, no/// error noise when offline — it only fills repoBehind when it can.func checkRepoUpdates(silent: Bool = false) {- guard repoOK, repoIsGit else { return }+ guard repoOK, repoIsGit, !usesEngineStore else { return } // a release app updates its engine by version insteadguard !running, !repoBusy, let git = Self.gitBinary() else {if !silent, Self.gitBinary() == nil { repoStatus = t("repo.gitMissing") }return@@ -477,7 +495,7 @@ final class BuildModel: ObservableObject {}func pullRepo() {- guard !running, !repoBusy, repoOK, repoIsGit, let git = Self.gitBinary() else { return }+ guard !running, !repoBusy, !usesEngineStore, repoOK, repoIsGit, let git = Self.gitBinary() else { return }repoBusy = true; repoStatus = t("repo.pulling")let dir = repoPathDispatchQueue.global().async {@@ -499,7 +517,7 @@ final class BuildModel: ObservableObject {/// to its tracked files and no build running, so a checkout someone works in is never touched. Settings says what/// happened (or why not), and the library's activity line names the new commits.func autoPull(_ behind: Int) {- guard !running, !repoBusy, repoOK, repoIsGit, let git = Self.gitBinary() else { return }+ guard !running, !repoBusy, !usesEngineStore, repoOK, repoIsGit, let git = Self.gitBinary() else { return }repoBusy = truelet dir = repoPathDispatchQueue.global().async {@@ -549,6 +567,7 @@ final class BuildModel: ObservableObject {/// The launch-time step for a ZIP copy; a git checkout is left to checkRepoUpdates. Settings and the library's/// activity line say what happened.func adoptAtLaunch(remote: String = BuildModel.repoURL) {+ guard !usesEngineStore else { return }switch Self.zipAdoption(isRepo: repoOK, isGit: repoIsGit, buildRunning: running, repoBusy: repoBusy, autoUpdate: autoUpdateRepo) {case .notNeeded: breakcase .waitsForBuild: repoStatus = t("repo.zipWaits")@@ -568,7 +587,7 @@ final class BuildModel: ObservableObject {/// outside the repository./// `automatic`: the launch-time adoption (adoptAtLaunch); `remote` is GitHub unless a test points it at a local repository.func adoptRepoAsGit(automatic: Bool = false, remote: String = BuildModel.repoURL) {- guard !running, !repoBusy, repoOK, !repoIsGit, let git = Self.gitBinary() else { return }+ guard !running, !repoBusy, !usesEngineStore, repoOK, !repoIsGit, let git = Self.gitBinary() else { return }repoBusy = true; repoStatus = t("repo.adopting")let dir = repoPathDispatchQueue.global().async {@@ -3511,7 +3530,11 @@ struct BuilderView: View {}private var tools: some View {- group(m.t("section.tools"), footnote: m.repoStatus.isEmpty ? (m.repoOK ? "" : m.t("repo.firstHint")) : m.repoStatus) {+ group(m.t("section.tools"), footnote: m.usesEngineStore ? m.engineStatus+ : (m.repoStatus.isEmpty ? (m.repoOK ? "" : m.t("repo.firstHint")) : m.repoStatus)) {+ if m.usesEngineStore {+ engineRows+ } else {row(m.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))),@@ -3563,6 +3586,7 @@ struct BuilderView: View {Toggle("", isOn: $m.autoUpdateRepo).labelsHidden().toggleStyle(LauncherSwitchStyle())}}+ }dividerButton(action: { withAnimation(.easeInOut(duration: 0.18)) { m.toggleDeps() } }) {row(m.t("dep.title"),@@ -3612,6 +3636,47 @@ struct BuilderView: View {}}+ /// 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,+ 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)+ .padTarget("set.engineInstall", scope: "main") { if idle { m.installAvailableEngine() } }+ }+ Button(m.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) {+ LauncherMenuPicker(options: EngineChannel.allCases.map { (value: $0.rawValue, label: m.t($0.labelKey)) },+ selection: m.engineSelection.channel.rawValue, fill: true, buttonLike: true) { v in+ if let channel = EngineChannel(rawValue: v) { m.requestEngineChannel(channel) }+ }+ .frame(width: Self.settingsButtonWidth)+ .disabled(!idle)+ .padTarget("set.engineChannel", scope: "main") {+ if idle { m.requestEngineChannel(m.engineSelection.channel == .stable ? .experimental : .stable) }+ }+ }+ .alert(m.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(m.t("engine.switch.cancel"), role: .cancel) { m.cancelEngineChannel() }+ } message: {+ Text(m.confirmingChannel.flatMap { m.engineSelection.channel.switchWarningKey(to: $0) }.map { m.t($0) } ?? "")+ }+ divider+ row(m.t("repo.auto"), detail: m.t("engine.autoNote")) {+ Toggle("", isOn: $m.autoUpdateRepo).labelsHidden().toggleStyle(LauncherSwitchStyle())+ }+ }+private func pickRepo() {let d = NSOpenPanel()d.canChooseDirectories = true; d.canChooseFiles = falsediff --git a/frontend/Sources/NSPortBuilder/Diagnostics.swift b/frontend/Sources/NSPortBuilder/Diagnostics.swiftindex d4927395..c446d45c 100644--- a/frontend/Sources/NSPortBuilder/Diagnostics.swift+++ b/frontend/Sources/NSPortBuilder/Diagnostics.swift@@ -20,6 +20,7 @@ struct Diagnostics {var branch: String?var behind: [(ref: String, count: Int)] = [] // upstream/main, origin/main: the ones this checkout hasvar lastFetch: Date?+ var engine: String? // the release app's engine: "<channel> <version> (<engine_id>)"var python: Stringvar pythonVersion: String?var pythonIsVenv = false // the launcher's own venv (BuildModel.venvDir)@@ -70,6 +71,8 @@ struct Diagnostics {if let fetched = i.lastFetch { line += " as of the last fetch, " + stamp(fetched) }}out.append(line)+ } else if let engine = i.engine {+ out.append("- Engine: \(engine)")} else if !i.repoPath.isEmpty {out.append("- Commit: not a git checkout")}@@ -293,6 +296,8 @@ extension BuildModel {let repo = repoOK ? repoPath : "", python = pythonPath.isEmpty ? Self.findPython().path : pythonPath, dotnet = dotnetPathlet rows = depsChecked ? deps.map(Diagnostics.dependency) : [], checked = depsCheckedlet command = lastBuildCommand, log = logTail, xcrun = xcrunPath+ let sel = engineSelection+ let engine = usesEngineStore && !sel.engineID.isEmpty ? "\(sel.channel.rawValue) \(sel.version) (\(sel.engineID))" : nilDispatchQueue.global(qos: .userInitiated).async {let git = Diagnostics.git(repo)let env = ["HOME": NSHomeDirectory(), "PATH": "/usr/bin:/bin", "TMPDIR": NSTemporaryDirectory()]@@ -305,6 +310,7 @@ extension BuildModel {macOS: ProcessInfo.processInfo.operatingSystemVersionString,chip: Diagnostics.chip(),repoPath: repo, commit: git.commit, branch: git.branch, behind: git.behind, lastFetch: git.lastFetch,+ engine: engine,python: python,pythonVersion: Diagnostics.version(python, ["-c", "import sys; print(sys.version.split()[0])"], env: env),pythonIsVenv: python == Self.venvPython(),diff --git a/frontend/Sources/NSPortBuilder/EngineUpdateModel.swift b/frontend/Sources/NSPortBuilder/EngineUpdateModel.swiftnew file mode 100644index 00000000..aa7f9a0b--- /dev/null+++ b/frontend/Sources/NSPortBuilder/EngineUpdateModel.swift@@ -0,0 +1,148 @@+import Foundation++// The release app's engine in the model: which tree the build reads, the launch check, the channel switch and what+// Settings says. The rules (what is verified, where a tree comes from) are in EngineUpdater.swift. A launcher built+// from the repository has no engine in its bundle (`engineBundle` is nil), and everything here leaves it alone.+extension BuildModel {+ /// At launch: build from the selected engine in the store, copy the app's own engine there on the first start,+ /// then ask the selected channel for a newer one. On the stable channel a new app brings its own engine, which+ /// then replaces the one an older app left selected, without the network.+ func prepareEngine() {+ guard let bundled = engineBundle, !engineBusy, let id = EngineStore.identity(of: bundled) else { return }+ let selected = engineSelection.engineID+ let appMovedOn = engineSelection.channel == .stable && selected != id && engineSelection.version != BuildModel.appVersion+ if !appMovedOn, engineStore.isUsable(selected), let dir = engineStore.directory(for: selected) {+ repoPath = dir.path+ checkEngineUpdate(automatic: true)+ return+ }+ engineBusy = true+ engineStatus = t("engine.preparing")+ let store = engineStore+ DispatchQueue.global(qos: .userInitiated).async {+ let result = Result { try EngineInstaller.seed(from: bundled, engineID: id, store: store) }+ DispatchQueue.main.async {+ self.engineBusy = false+ switch result {+ case .success:+ // The app's engine is the stable one of this release. A player on experimental gets theirs from the check.+ let engine = EngineUpdate.Engine(id: id, version: BuildModel.appVersion)+ if self.running { // a build started from the old folder while the copy ran+ self.pendingEngine = (engine, self.engineSelection.channel)+ self.engineStatus = ""+ } else {+ self.switchEngine(to: engine, channel: self.engineSelection.channel, announce: false)+ self.checkEngineUpdate(automatic: true)+ }+ case .failure:+ self.engineStatus = self.t("engine.seedFail")+ }+ }+ }+ }++ /// Ask the selected channel for its engine. `automatic` is the launch check: it installs only with automatic+ /// updates on, and it says nothing when the engine is current or the network is down.+ func checkEngineUpdate(automatic: Bool = false) {+ runEngineUpdate(channel: engineSelection.channel, install: automatic ? autoUpdateRepo : true, quiet: automatic)+ }++ /// Install the engine the launch check found (automatic updates off).+ func installAvailableEngine() {+ runEngineUpdate(channel: engineSelection.channel, install: true, quiet: false)+ }++ /// The channel picker: a different channel is confirmed first, because the switch can change the shader chain.+ func requestEngineChannel(_ channel: EngineChannel) {+ guard engineSelection.channel.switchWarningKey(to: channel) != nil, !engineBusy, !running else { return }+ confirmingChannel = channel+ }++ /// The alert's button passes the channel it showed, so the order of the alert's own dismissal does not matter.+ func confirmEngineChannel(_ channel: EngineChannel) {+ confirmingChannel = nil+ runEngineUpdate(channel: channel, install: true, quiet: false)+ }++ func cancelEngineChannel() { confirmingChannel = nil }++ /// The selected channel is only changed once its engine is in place, so Settings never names a channel whose+ /// engine the build does not use.+ private func runEngineUpdate(channel: EngineChannel, install: Bool, quiet: Bool) {+ guard usesEngineStore, !engineBusy else { return }+ guard !running else {+ if !quiet { engineStatus = t("engine.waitForBuild") }+ return+ }+ engineBusy = true+ if !quiet { engineStatus = t(channel == engineSelection.channel ? "engine.checking" : "engine.switching") }+ let store = engineStore, bundled = engineBundle, current = engineSelection.engineID, transport = engineTransport+ DispatchQueue.global(qos: .userInitiated).async {+ let outcome = EngineUpdate.run(channel: channel, appVersion: BuildModel.appVersion, current: current, store: store,+ bundled: bundled, install: install, transport: transport)+ DispatchQueue.main.async {+ self.engineBusy = false+ self.applyEngineOutcome(outcome, channel: channel, quiet: quiet)+ }+ }+ }++ func applyEngineOutcome(_ outcome: EngineUpdate.Outcome, channel: EngineChannel, quiet: Bool) {+ switch outcome {+ case .current(let engine):+ engineAvailable = nil+ if engineSelection.channel != channel || engineSelection.version != engine.version {+ engineSelection.channel = channel+ engineSelection.version = engine.version+ engineSelection.save()+ }+ if !quiet { engineStatus = String(format: t("engine.upToDate"), engine.version) }+ case .available(let engine):+ engineAvailable = engine+ engineStatus = String(format: t("engine.available"), engine.version)+ case .installed(let engine, _):+ engineAvailable = nil+ if running {+ pendingEngine = (engine, channel)+ engineStatus = String(format: t("engine.waitsForBuild"), engine.version)+ } else {+ switchEngine(to: engine, channel: channel)+ }+ case .failed(let failure):+ if quiet, failure == .network || failure == .noManifest { return }+ let key = EngineUpdate.key(failure)+ engineStatus = failure == .noManifest ? String(format: t(key), t(channel.labelKey)) : t(key)+ }+ }++ /// Point the build at an installed tree, keep the one before it, and say whether the shader chain changed.+ /// `announce` off (the app's own engine at launch): only a changed shader chain is worth a line.+ func switchEngine(to engine: EngineUpdate.Engine, channel: EngineChannel, announce: Bool = true) {+ guard let dir = engineStore.directory(for: engine.id) else { return }+ let old = repoPath+ engineSelection.channel = channel+ engineSelection.switched(to: engine.id, version: engine.version)+ engineSelection.save()+ repoPath = dir.path+ engineStore.prune(keeping: engineSelection.kept)+ if let change = EngineUpdate.chainChange(from: old, to: dir.path) {+ engineStatus = String(format: t("engine.chainChanged"), engine.version, change.old, change.new)+ } else {+ engineStatus = announce ? String(format: t("engine.installed"), engine.version) : ""+ }+ }++ /// The build that held an installed engine back has ended (LauncherView watches `running`).+ func applyPendingEngine() {+ guard !running, let pending = pendingEngine else { return }+ pendingEngine = nil+ switchEngine(to: pending.engine, channel: pending.channel)+ }++ /// What Settings shows for the engine: its version and the pin it was built from.+ var engineDetail: String {+ let s = engineSelection+ guard !s.engineID.isEmpty else { return t("engine.none") }+ return String(format: t("engine.detail"), s.version.isEmpty ? "?" : s.version, String(s.engineID.prefix(8)))+ }+}diff --git a/frontend/Sources/NSPortBuilder/LauncherView.swift b/frontend/Sources/NSPortBuilder/LauncherView.swiftindex 1cda1815..626b5355 100644--- a/frontend/Sources/NSPortBuilder/LauncherView.swift+++ b/frontend/Sources/NSPortBuilder/LauncherView.swift@@ -166,7 +166,8 @@ struct ContentView: View {if performStartupChecks { library.discover(); fetchArtwork(); m.refreshDevices(); checkTools() }if performStartupChecks {m.checkDeps()- if m.repoOK && m.repoIsGit { m.checkRepoUpdates(silent: true) } else { m.adoptAtLaunch() }+ if m.usesEngineStore { m.prepareEngine() } // the release app: its engine store, never git (EngineUpdateModel.swift)+ else if m.repoOK && m.repoIsGit { m.checkRepoUpdates(silent: true) } else { m.adoptAtLaunch() }m.checkAppUpdate(silent: true)BuildNotifier.shared.watch(m, library: library) // BuildNotifications.swift}@@ -200,6 +201,7 @@ struct ContentView: View {DispatchQueue.main.async {if m.done { recordBuild() }activeBuildID = nil+ m.applyPendingEngine() // an engine installed during the build takes over once it is recorded}}}diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swiftindex d2fa2248..fc7e34e0 100644--- a/frontend/Sources/NSPortBuilder/Localization.swift+++ b/frontend/Sources/NSPortBuilder/Localization.swift@@ -1053,6 +1053,37 @@ enum L10n {"pad.options": ("启动选项", "Options"),"pad.back": ("返回", "Back"),"msg.archiveLog": ("归档:%@ → %@", "Archive: %@ → %@"),+ "engine.title": ("构建引擎", "Build engine"),+ "engine.detail": ("%@ · 上游 %@", "%@ · upstream %@"),+ "engine.none": ("尚未准备好", "Not set up yet"),+ "engine.install": ("安装 %@", "Install %@"),+ "engine.update": ("引擎更新", "Engine update"),+ "engine.channelNote": ("稳定版是与本版本应用一起测试过的引擎。实验版跟随最新的上游,通过自动检查后发布。", "Stable is the engine tested with this app version. Experimental follows the newest upstream and is published once it passes the automated checks."),+ "engine.channel.stable": ("稳定版", "Stable"),+ "engine.channel.experimental": ("实验版", "Experimental"),+ "engine.autoNote": ("打开应用时安装所选通道的新引擎", "Installs a newer engine of the selected channel when the app opens"),+ "engine.preparing": ("正在准备引擎…", "Preparing the engine…"),+ "engine.seedFail": ("无法把应用内的引擎复制到 Application Support。请检查可用空间后重新打开应用。", "Could not copy the engine from the app into Application Support. Check the free space and open the app again."),+ "engine.waitForBuild": ("正在构建。请在构建结束后再试。", "A build is running. Try again when it has finished."),+ "engine.checking": ("正在检查新引擎…", "Checking for a new engine…"),+ "engine.switching": ("正在切换引擎…", "Switching the engine…"),+ "engine.upToDate": ("引擎已是最新(%@)", "The engine is up to date (%@)"),+ "engine.available": ("引擎 %@ 可用", "Engine %@ is available"),+ "engine.waitsForBuild": ("引擎 %@ 已安装。当前构建结束后切换到它。", "Engine %@ is installed. The build tools switch to it when the running build has finished."),+ "engine.installed": ("引擎 %@ 已安装", "Engine %@ is installed"),+ "engine.chainChanged": ("引擎 %@ 已安装。着色器链已从 %@ 变为 %@,每个游戏下次构建时都会重新编译着色器。", "Engine %@ is installed. The shader chain changed from %@ to %@, so every game compiles its shaders again on its next build."),+ "engine.switch.title": ("切换引擎通道?", "Switch the engine channel?"),+ "engine.switch.go": ("切换到%@", "Switch to %@"),+ "engine.switch.cancel": ("取消", "Cancel"),+ "engine.switch.toExperimental": ("实验版跟随最新的上游。它通过了自动检查,但还没有人玩过。如果它的着色器链不同,每个游戏下次构建时都会重新编译着色器。切换回稳定版时也是如此。", "Experimental follows the newest upstream. It passed the automated checks, but nobody has played it yet. If its shader chain differs, every game compiles its shaders again on its next build. Switching back to Stable does the same."),+ "engine.switch.toStable": ("稳定版是与本版本应用一起测试过的引擎。如果它的着色器链与实验版不同,每个游戏下次构建时都会重新编译着色器。", "Stable is the engine tested with this app version. If its shader chain differs from the experimental one, every game compiles its shaders again on its next build."),+ "engine.fail.network": ("无法连接 GitHub 检查引擎。请检查网络后重试。", "Could not reach GitHub to check the engine. Check the connection and try again."),+ "engine.fail.noManifest": ("%@通道还没有适用于此应用版本的引擎", "The %@ channel has no engine for this app version yet"),+ "engine.fail.unsigned": ("引擎清单没有用应用的密钥签名。未安装任何内容。", "The engine list is not signed with the app's key. Nothing was installed."),+ "engine.fail.manifest": ("无法读取引擎清单。未安装任何内容。", "The engine list could not be read. Nothing was installed."),+ "engine.fail.download": ("无法下载引擎。请检查网络后重试。", "The engine could not be downloaded. Check the connection and try again."),+ "engine.fail.digest": ("下载的引擎与校验和不符。未安装任何内容。", "The downloaded engine does not match its checksum. Nothing was installed."),+ "engine.fail.install": ("无法安装引擎。请检查可用空间后重试。", "The engine could not be installed. Check the free space and try again."),]/// Swedish translations are kept as an overlay so adding a language does not require a@@ -1759,6 +1790,37 @@ enum L10n {"fail.showFolder": "Visa mapp","fail.openXcode": "Öppna Xcode","fail.retry": "Försök igen",+ "engine.title": "Byggmotor",+ "engine.detail": "%@ · uppström %@",+ "engine.none": "Inte förberedd än",+ "engine.install": "Installera %@",+ "engine.update": "Motoruppdatering",+ "engine.channelNote": "Stabil är motorn som testats med den här appversionen. Experimentell följer senaste uppström och publiceras när den klarat de automatiska kontrollerna.",+ "engine.channel.stable": "Stabil",+ "engine.channel.experimental": "Experimentell",+ "engine.autoNote": "Installerar en nyare motor i den valda kanalen när appen öppnas",+ "engine.preparing": "Förbereder motorn…",+ "engine.seedFail": "Kunde inte kopiera motorn från appen till Application Support. Kontrollera ledigt utrymme och öppna appen igen.",+ "engine.waitForBuild": "Ett bygge pågår. Försök igen när det är klart.",+ "engine.checking": "Söker efter en ny motor…",+ "engine.switching": "Byter motor…",+ "engine.upToDate": "Motorn är uppdaterad (%@)",+ "engine.available": "Motor %@ finns",+ "engine.waitsForBuild": "Motor %@ är installerad. Byggverktygen byter till den när det pågående bygget är klart.",+ "engine.installed": "Motor %@ är installerad",+ "engine.chainChanged": "Motor %@ är installerad. Shaderkedjan har ändrats från %@ till %@, så varje spel kompilerar sina shaders igen vid nästa bygge.",+ "engine.switch.title": "Byta motorkanal?",+ "engine.switch.go": "Byt till %@",+ "engine.switch.cancel": "Avbryt",+ "engine.switch.toExperimental": "Experimentell följer senaste uppström. Den har klarat de automatiska kontrollerna, men ingen har spelat den än. Om dess shaderkedja skiljer sig kompilerar varje spel sina shaders igen vid nästa bygge. Att byta tillbaka till Stabil gör samma sak.",+ "engine.switch.toStable": "Stabil är motorn som testats med den här appversionen. Om dess shaderkedja skiljer sig från den experimentella kompilerar varje spel sina shaders igen vid nästa bygge.",+ "engine.fail.network": "Kunde inte nå GitHub för att kontrollera motorn. Kontrollera anslutningen och försök igen.",+ "engine.fail.noManifest": "Kanalen %@ har ännu ingen motor för den här appversionen",+ "engine.fail.unsigned": "Motorlistan är inte signerad med appens nyckel. Inget installerades.",+ "engine.fail.manifest": "Motorlistan kunde inte läsas. Inget installerades.",+ "engine.fail.download": "Motorn kunde inte laddas ner. Kontrollera anslutningen och försök igen.",+ "engine.fail.digest": "Den nedladdade motorn stämmer inte med sin kontrollsumma. Inget installerades.",+ "engine.fail.install": "Motorn kunde inte installeras. Kontrollera ledigt utrymme och försök igen.",]/// German translations, an overlay like Swedish: informal "du", Apple's German terms for system@@ -2642,6 +2704,37 @@ enum L10n {"settings.returnAfterPlay": "Zurückkehren, wenn ein Spiel beendet wird","settings.returnAfterPlayNote": "Wenn ein Spiel beendet wird, das mit Spielen oder im Konsolenmodus gestartet wurde, kommt der Launcher nach vorn, damit du das nächste wählen kannst","settings.language.de": "Deutsch",+ "engine.title": "Build-Engine",+ "engine.detail": "%@ · Upstream %@",+ "engine.none": "Noch nicht eingerichtet",+ "engine.install": "%@ installieren",+ "engine.update": "Engine-Update",+ "engine.channelNote": "Stabil ist die Engine, die mit dieser App-Version getestet wurde. Experimentell folgt dem neuesten Upstream und erscheint, sobald sie die automatischen Prüfungen besteht.",+ "engine.channel.stable": "Stabil",+ "engine.channel.experimental": "Experimentell",+ "engine.autoNote": "Installiert beim Öffnen der App eine neuere Engine des gewählten Kanals",+ "engine.preparing": "Engine wird vorbereitet…",+ "engine.seedFail": "Die Engine konnte nicht aus der App nach Application Support kopiert werden. Prüfe den freien Speicher und öffne die App erneut.",+ "engine.waitForBuild": "Ein Build läuft. Versuche es erneut, wenn er fertig ist.",+ "engine.checking": "Suche nach einer neuen Engine…",+ "engine.switching": "Engine wird gewechselt…",+ "engine.upToDate": "Die Engine ist aktuell (%@)",+ "engine.available": "Engine %@ ist verfügbar",+ "engine.waitsForBuild": "Engine %@ ist installiert. Die Build-Werkzeuge wechseln zu ihr, wenn der laufende Build fertig ist.",+ "engine.installed": "Engine %@ ist installiert",+ "engine.chainChanged": "Engine %@ ist installiert. Die Shader-Kette hat sich von %@ zu %@ geändert, daher kompiliert jedes Spiel seine Shader beim nächsten Build neu.",+ "engine.switch.title": "Engine-Kanal wechseln?",+ "engine.switch.go": "Zu %@ wechseln",+ "engine.switch.cancel": "Abbrechen",+ "engine.switch.toExperimental": "Experimentell folgt dem neuesten Upstream. Sie hat die automatischen Prüfungen bestanden, wurde aber noch nicht gespielt. Weicht ihre Shader-Kette ab, kompiliert jedes Spiel seine Shader beim nächsten Build neu. Der Wechsel zurück zu Stabil hat dieselbe Folge.",+ "engine.switch.toStable": "Stabil ist die Engine, die mit dieser App-Version getestet wurde. Weicht ihre Shader-Kette von der experimentellen ab, kompiliert jedes Spiel seine Shader beim nächsten Build neu.",+ "engine.fail.network": "GitHub war nicht erreichbar, um die Engine zu prüfen. Prüfe die Verbindung und versuche es erneut.",+ "engine.fail.noManifest": "Der Kanal %@ hat noch keine Engine für diese App-Version",+ "engine.fail.unsigned": "Die Engine-Liste ist nicht mit dem Schlüssel der App signiert. Es wurde nichts installiert.",+ "engine.fail.manifest": "Die Engine-Liste konnte nicht gelesen werden. Es wurde nichts installiert.",+ "engine.fail.download": "Die Engine konnte nicht geladen werden. Prüfe die Verbindung und versuche es erneut.",+ "engine.fail.digest": "Die geladene Engine passt nicht zu ihrer Prüfsumme. Es wurde nichts installiert.",+ "engine.fail.install": "Die Engine konnte nicht installiert werden. Prüfe den freien Speicher und versuche es erneut.",]static func string(_ key: String, _ lang: Lang) -> String {diff --git a/frontend/Tests/NSPortBuilderTests/EngineUpdateModelTests.swift b/frontend/Tests/NSPortBuilderTests/EngineUpdateModelTests.swiftnew file mode 100644index 00000000..3766dbb0--- /dev/null+++ b/frontend/Tests/NSPortBuilderTests/EngineUpdateModelTests.swift@@ -0,0 +1,74 @@+import XCTest+@testable import NSPortBuilder++/// The engine in the model (EngineUpdateModel.swift): what the release app does with an update check's outcome, and+/// that it never runs git. Nothing here touches the network or the store.+final class EngineUpdateModelTests: XCTestCase {+ private let root = URL(fileURLWithPath: "/nonexistent-engine-bundle")++ private func id(_ c: Character) -> String { String(repeating: c, count: 40) + "-0123456789ab" }++ /// A launcher built from the repository keeps git, the release app never touches it.+ func testTheReleaseAppNeverRunsGit() {+ let m = BuildModel()+ m.engineBundle = root+ m.cloneRepo()+ m.pullRepo()+ m.autoPull(3)+ m.adoptRepoAsGit()+ m.checkRepoUpdates()+ XCTAssertFalse(m.repoBusy)+ XCTAssertEqual(m.repoStatus, "")+ }++ func testAnEngineInstalledDuringABuildWaits() {+ let m = BuildModel()+ m.lang = .en+ m.engineBundle = root+ m.running = true+ let path = m.repoPath+ m.applyEngineOutcome(.installed(.init(id: id("a"), version: "0.7.4"), .download), channel: .stable, quiet: false)+ XCTAssertEqual(m.repoPath, path, "the running build keeps its tools")+ XCTAssertEqual(m.pendingEngine?.engine.id, id("a"))+ XCTAssertEqual(m.engineStatus, String(format: L10n.string("engine.waitsForBuild", .en), "0.7.4"))+ m.checkEngineUpdate()+ XCTAssertFalse(m.engineBusy, "no check while a build runs")+ }++ func testTheLaunchCheckIsQuietWhenOffline() {+ let m = BuildModel()+ m.lang = .en+ m.applyEngineOutcome(.failed(.network), channel: .stable, quiet: true)+ XCTAssertEqual(m.engineStatus, "")+ m.applyEngineOutcome(.failed(.digest), channel: .stable, quiet: true)+ XCTAssertEqual(m.engineStatus, L10n.string("engine.fail.digest", .en))+ m.applyEngineOutcome(.failed(.noManifest), channel: .experimental, quiet: false)+ XCTAssertEqual(m.engineStatus, "The Experimental channel has no engine for this app version yet")+ }++ func testChangingTheChannelAsksFirst() {+ let m = BuildModel()+ m.engineBundle = root+ m.engineSelection.channel = .stable+ m.requestEngineChannel(.stable)+ XCTAssertNil(m.confirmingChannel, "the same channel asks nothing")+ m.requestEngineChannel(.experimental)+ XCTAssertEqual(m.confirmingChannel, .experimental)+ XCTAssertEqual(m.engineSelection.channel, .stable, "nothing changes before the answer")+ m.cancelEngineChannel()+ XCTAssertNil(m.confirmingChannel)+ XCTAssertEqual(m.engineSelection.channel, .stable)+ }++ // MARK: Strings++ func testEveryEngineStringIsTranslated() {+ let failures: [EngineUpdate.Failure] = [.network, .noManifest, .unsigned(.absent), .badManifest(.notJSON),+ .wrongChannel("x"), .download, .digest, .install(.move)]+ for key in failures.map(EngineUpdate.key) + ["engine.switch.toExperimental", "engine.switch.toStable"] {+ for lang: Lang in [.zh, .en, .sv, .de] { XCTAssertNotEqual(L10n.string(key, lang), key, key) }+ }+ for c in EngineChannel.allCases { XCTAssertNotNil(L10n.table[c.labelKey], c.labelKey) }+ XCTAssertEqual(L10n.string("engine.channel.experimental", .zh), "实验版")+ }+}