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
A new version says what it changes before asking to install (0.4.8)
LNPANDY5e6847c2fe36
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swiftindex 99647052..26c3e95a 100644--- a/frontend/Sources/NSPortBuilder/ContentView.swift+++ b/frontend/Sources/NSPortBuilder/ContentView.swift@@ -474,9 +474,15 @@ final class BuildModel: ObservableObject {// ---- App self-update (GitHub Releases) ----/// Bump together with each release tag; the update check compares it with the latest release.- static let appVersion = "0.4.7"- @Published var appUpdate: (tag: String, url: String)?+ static let appVersion = "0.4.8"+ /// The update found by checkAppUpdate: its tag, the asset to download, and the release notes the+ /// sheet shows. The notes are why the sheet exists — "update available" alone told a user nothing+ /// about what they would get (the 0.4.x releases each changed a lot).+ @Published var appUpdate: (tag: String, url: String, notes: String)?@Published var appBusy = false+ /// Whether the "a new version is out" sheet is up: opened by the launch check and by Check for+ /// updates, so a user learns what changed before deciding, not after downloading.+ @Published var showUpdateSheet = false@Published var appStatus = ""nonisolated static func isNewer(_ tag: String, than current: String) -> Bool {@@ -496,15 +502,16 @@ final class BuildModel: ObservableObject {appBusy = trueif !silent { appStatus = t("app.checking") }URLSession.shared.dataTask(with: URL(string: "https://api.github.com/repos/LNPANDY/NX2Apple/releases/latest")!) { data, _, _ in- var found: (String, String)?+ var found: (String, String, String)?if let d = data, let obj = try? JSONSerialization.jsonObject(with: d) as? [String: Any] {let tag = obj["tag_name"] as? String ?? ""if Self.isNewer(tag, than: Self.appVersion),let assets = obj["assets"] as? [[String: Any]] {// nxnative-macOS-arm64.zip; releases from before the rename name it NS-Port-Builder-macOS-arm64.zip+ let notes = (obj["body"] as? String) ?? ""for name in ["NX2Apple-macOS-arm64.zip", "nxnative-macOS-arm64.zip", "NS-Port-Builder-macOS-arm64.zip"] where found == nil {for a in assets where (a["name"] as? String) == name {- if let u = a["browser_download_url"] as? String { found = (tag, u) }+ if let u = a["browser_download_url"] as? String { found = (tag, u, notes) }}}}@@ -512,8 +519,9 @@ final class BuildModel: ObservableObject {DispatchQueue.main.async {self.appBusy = falseif let f = found {- self.appUpdate = f+ self.appUpdate = (tag: f.0, url: f.1, notes: f.2)self.appStatus = String(format: self.t("app.found"), f.0)+ self.showUpdateSheet = true // the sheet names what the new version does} else if !silent {self.appStatus = data == nil ? self.t("app.netFail") : self.t("app.upToDate")}diff --git a/frontend/Sources/NSPortBuilder/LauncherView.swift b/frontend/Sources/NSPortBuilder/LauncherView.swiftindex 25d204e1..fbe16529 100644--- a/frontend/Sources/NSPortBuilder/LauncherView.swift+++ b/frontend/Sources/NSPortBuilder/LauncherView.swift@@ -127,6 +127,7 @@ struct ContentView: View {if let id = optionsFor { LaunchOptionsView(m: m, library: library, gameID: id).environmentObject(padFocus) }}.sheet(isPresented: $controlsOpen) { ControlsView(m: m, layout: controls).environmentObject(padFocus) }+ .sheet(isPresented: $m.showUpdateSheet) { UpdateSheet(m: m) }.onChange(of: optionsFor) { id in padFocus.scope = id != nil ? "launch" : (controlsOpen ? "controls" : "main") }.onChange(of: controlsOpen) { open in padFocus.scope = open ? "controls" : (optionsFor != nil ? "launch" : "main") }.onChange(of: page) { _ in padFocus.focused = nil }diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swiftindex 7a02530a..4454dd15 100644--- a/frontend/Sources/NSPortBuilder/Localization.swift+++ b/frontend/Sources/NSPortBuilder/Localization.swift@@ -189,6 +189,12 @@ enum L10n {"app.upToDate": ("App 已是最新版本", "The app is up to date"),"app.found": ("App 有新版本 %@,点右上角按钮更新", "A new version %@ is out — update from the top-right button"),"app.updateBtn": ("更新到 %@", "Update to %@"),+ "update.title": ("有新版本可用", "A new version is out"),+ "update.fromTo": ("当前 %@ → 新版本 %@", "You have %@ — the new version is %@"),+ "update.noNotes": ("这一版没有写更新说明,可以打开发布页查看。", "This release has no notes; open the release page to see it."),+ "update.now": ("现在更新", "Update now"),+ "update.later": ("稍后", "Later"),+ "update.openPage": ("打开发布页", "Open the release page"),"app.downloading": ("正在下载新版本…", "Downloading the new version…"),"app.installing": ("正在安装…(旧版本会进废纸篓)", "Installing… (the old version goes to the Trash)"),"app.relaunching": ("已更新到 %@,正在重启 App…", "Updated to %@ — restarting…"),diff --git a/frontend/Sources/NSPortBuilder/UpdateSheet.swift b/frontend/Sources/NSPortBuilder/UpdateSheet.swiftnew file mode 100644index 00000000..d8a26190--- /dev/null+++ b/frontend/Sources/NSPortBuilder/UpdateSheet.swift@@ -0,0 +1,129 @@+import SwiftUI++/// "A new version is out", with what it changes, shown when the app opens or Check for updates finds+/// one. The app already had the update machinery (checkAppUpdate / performAppUpdate); what it lacked+/// was a reason to press the button: the status line said a tag name and nothing else, and a user who+/// was working fine had no way to tell whether the new version mattered to them.+///+/// The notes come from the release body, which this project writes in both languages (see+/// docs/RELEASE-NOTES-GUIDE.md). The sheet does not try to translate them; it shows the lines that+/// match the interface language and falls back to the whole body when it cannot tell them apart.+struct UpdateSheet: View {+ @ObservedObject var m: BuildModel+ @Environment(\.dismiss) private var dismiss++ private var update: (tag: String, url: String, notes: String)? { m.appUpdate }++ var body: some View {+ VStack(alignment: .leading, spacing: 0) {+ VStack(alignment: .leading, spacing: 6) {+ Text(m.t("update.title"))+ .font(.manrope(24, .heavy)).tracking(-0.5)+ Text(String(format: m.t("update.fromTo"), BuildModel.appVersion, update?.tag ?? ""))+ .font(.manrope(13)).foregroundStyle(.secondary)+ }+ .padding(.horizontal, 28).padding(.top, 26).padding(.bottom, 18)++ ScrollView {+ VStack(alignment: .leading, spacing: 10) {+ if let notes = update?.notes, !notes.isEmpty {+ ForEach(Array(Self.lines(notes, for: m.lang).enumerated()), id: \.offset) { _, line in+ Text(line)+ .font(.manrope(13))+ .fixedSize(horizontal: false, vertical: true)+ .frame(maxWidth: .infinity, alignment: .leading)+ }+ } else {+ Text(m.t("update.noNotes")).font(.manrope(13)).foregroundStyle(.secondary)+ }+ }+ .padding(.horizontal, 28).padding(.bottom, 20)+ }+ .frame(maxHeight: 340)++ 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)")!)+ .font(.manrope(12.5))+ }+ Spacer(minLength: 8)+ Button(m.t("update.later")) { dismiss() }+ .buttonStyle(LauncherSecondaryButtonStyle())+ .keyboardShortcut(.cancelAction)+ Button {+ m.performAppUpdate()+ dismiss()+ } label: {+ Text(m.t("update.now")).font(.manrope(13.5, .bold)).foregroundStyle(.black)+ .padding(.horizontal, 20).padding(.vertical, 9)+ .background(LauncherPalette.cream, in: Capsule())+ }+ .buttonStyle(.plain)+ .disabled(m.appBusy)+ .keyboardShortcut(.defaultAction)+ }+ .padding(.horizontal, 28).padding(.vertical, 16)+ }+ .frame(width: 560)+ .background(LauncherPalette.background)+ .preferredColorScheme(.dark)+ .tint(LauncherPalette.cream)+ }++ /// The release body's lines for one language.+ ///+ /// The notes are written to a fixed shape (docs/RELEASE-NOTES-GUIDE.md): a bilingual heading+ /// ("## 这一版做了什么 / What this release does"), then `**中文** …` and `**English** …` paragraphs,+ /// then a bullet list that interleaves the two languages one item at a time. So the language is+ /// known from the line's own marker, not from whether it happens to contain Chinese characters —+ /// the first version of this did that and gave an English reader the Chinese paragraph, because+ /// `**中文** …` contains both.+ static func lines(_ notes: String, for lang: Lang) -> [String] {+ var zh: [String] = [], en: [String] = []+ // Headings go to both lists, so "one list is empty" is not the test for a bilingual body —+ // a monolingual body with a heading fills both. Count the tagged and bulleted lines instead.+ var bilingual = 0+ for raw in notes.split(separator: "\n", omittingEmptySubsequences: false) {+ var s = raw.trimmingCharacters(in: .whitespaces)+ if s.isEmpty || s.hasPrefix("---") { continue }+ if s.hasPrefix("#") { // a heading: keep it once, in either list+ while s.hasPrefix("#") { s.removeFirst() }+ s = s.trimmingCharacters(in: .whitespaces)+ if !s.isEmpty { zh.append(s); en.append(s) }+ continue+ }+ // `**中文** …` / `**English** …` — the marker decides, and it is removed from the text+ if let r = s.range(of: "**中文**") {+ bilingual += 1+ zh.append(s[r.upperBound...].replacingOccurrences(of: "**", with: "").trimmingCharacters(in: .whitespaces))+ } else if let r = s.range(of: "**English**") {+ bilingual += 1+ en.append(s[r.upperBound...].replacingOccurrences(of: "**", with: "").trimmingCharacters(in: .whitespaces))+ } else {+ // A bullet or plain line: no marker, so it belongs to whichever language it is in.+ // Chinese text has Han characters; English does not. (A bullet naming a title in+ // Chinese would land in the Chinese list, which is the right place for it.)+ s = s.replacingOccurrences(of: "**", with: "")+ if s.range(of: "\u{4e00}", options: []) != nil || s.unicodeScalars.contains(where: { (0x4e00...0x9fff).contains($0.value) }) {+ zh.append(s)+ } else { en.append(s) }+ }+ }+ // A body with no language markers at all is shown whole: splitting it would silently drop+ // half of it, which is what the first version did to a plain English body.+ if bilingual == 0 || zh.isEmpty || en.isEmpty {+ var all: [String] = []+ for raw in notes.split(separator: "\n", omittingEmptySubsequences: false) {+ var s = raw.trimmingCharacters(in: .whitespaces)+ if s.isEmpty || s.hasPrefix("---") { continue }+ while s.hasPrefix("#") { s.removeFirst() }+ s = s.replacingOccurrences(of: "**中文**", with: "").replacingOccurrences(of: "**English**", with: "")+ s = s.replacingOccurrences(of: "**", with: "").trimmingCharacters(in: .whitespaces)+ if !s.isEmpty { all.append(s) }+ }+ return all+ }+ return lang == .zh ? zh : en+ }+}diff --git a/frontend/Tests/NSPortBuilderTests/UpdateSheetTests.swift b/frontend/Tests/NSPortBuilderTests/UpdateSheetTests.swiftnew file mode 100644index 00000000..378be39a--- /dev/null+++ b/frontend/Tests/NSPortBuilderTests/UpdateSheetTests.swift@@ -0,0 +1,57 @@+import XCTest+@testable import NSPortBuilder++/// The update sheet's bilingual split (UpdateSheet.lines): the release bodies follow+/// docs/RELEASE-NOTES-GUIDE.md — a bilingual heading, `**中文** …` / `**English** …` paragraphs, then+/// bullets that interleave. A Chinese reader must not get the English paragraph and vice versa.+final class UpdateSheetTests: XCTestCase {+ private let body = """+ ## 这一版做了什么 / What this release does++ **中文** 游戏数据现在打成一个 `romfs.img`,拷到手机上快得多。++ **English** Game data is now one `romfs.img`, which copies to a phone far faster.++ ## 修复 / Fixes++ - iOS 构建修好了:两处宏未定义。+ - The iOS build is fixed: two macros were left undefined.+ """++ func testChineseReaderGetsTheChineseParagraphNotTheEnglishOne() {+ let zh = UpdateSheet.lines(body, for: .zh)+ XCTAssertTrue(zh.contains { $0.contains("拷到手机上快得多") })+ XCTAssertFalse(zh.contains { $0.contains("copies to a phone far faster") },+ "the English paragraph must not reach a Chinese reader: \(zh)")+ }++ func testEnglishReaderGetsTheEnglishParagraphNotTheChineseOne() {+ let en = UpdateSheet.lines(body, for: .en)+ XCTAssertTrue(en.contains { $0.contains("copies to a phone far faster") })+ XCTAssertFalse(en.contains { $0.contains("拷到手机上快得多") })+ }++ func testTheHeadingAppearsInBoth() {+ for lang in [Lang.zh, Lang.en] {+ XCTAssertTrue(UpdateSheet.lines(body, for: lang).contains { $0.contains("这一版做了什么") }, "\(lang)")+ }+ }++ func testBulletsGoToTheirOwnLanguage() {+ let zh = UpdateSheet.lines(body, for: .zh)+ let en = UpdateSheet.lines(body, for: .en)+ XCTAssertTrue(zh.contains { $0.hasPrefix("- iOS 构建修好了") })+ XCTAssertFalse(zh.contains { $0.hasPrefix("- The iOS build is fixed") })+ XCTAssertTrue(en.contains { $0.hasPrefix("- The iOS build is fixed") })+ }++ func testAMonolingualBodyComesThroughWhole() {+ let one = "## What changed\n\n- One thing.\n- Another thing."+ XCTAssertEqual(UpdateSheet.lines(one, for: .zh), ["What changed", "- One thing.", "- Another thing."])+ }++ func testMarkdownMarksAreStripped() {+ let bold = "**中文** 见 **NX2Apple** 的设置。"+ XCTAssertEqual(UpdateSheet.lines(bold, for: .zh), ["见 NX2Apple 的设置。"])+ }+}