Skip to content

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

Update sheet: pick release notes by language headings, keep the shared footer

v0lumehic92aac4d620f
diff --git a/frontend/Sources/NSPortBuilder/ReleaseNotes.swift b/frontend/Sources/NSPortBuilder/ReleaseNotes.swift
index 60b0513f..79106be0 100644
--- a/frontend/Sources/NSPortBuilder/ReleaseNotes.swift
+++ b/frontend/Sources/NSPortBuilder/ReleaseNotes.swift
@@ -4,8 +4,11 @@ import Foundation
/// blocks (headings, bullets, paragraphs) and how a line's inline Markdown becomes an AttributedString
/// with links. All pure, so the tests run it on real release bodies. UpdateSheet only styles the result.
///
-/// The release body follows docs/RELEASE-NOTES-GUIDE.md. Two shapes are in the wild:
+/// The release body follows docs/RELEASE-NOTES-GUIDE.md. Three shapes are in the wild:
///
+/// * **Language sections** (0.7.2): `## 中文` and `## English` headings (also `###`, or a line of just
+/// `**中文**` / `**English**`), each running to the next such heading or a `---`. Text after the last
+/// `---` is a shared footer (the install line) and follows the chosen section.
/// * **Current**: English written out in full, `---`, then Chinese in full. The `---` is the split.
/// * **Older releases (0.4.7 and before)**: `**中文** …` and `**English** …` paragraphs with bullet
/// lists interleaved one line each. Those are split on the markers.
@@ -26,6 +29,9 @@ enum ReleaseNotes {
/// The body's Markdown lines for one language, still carrying their Markdown (`##`, `- `, `**`).
static func lines(_ notes: String, for lang: Lang) -> [String] {
+ // Shape 0: explicit language headings.
+ if let sectioned = sections(notes, for: lang) { return sectioned }
+
// Shape 1: two halves around a `---` line.
let halves = notes.components(separatedBy: "\n---\n")
if halves.count == 2 {
@@ -58,6 +64,42 @@ enum ReleaseNotes {
return clean(notes)
}
+ /// A line that is only a language marker: `## English`, `### 中文`, `**English**`.
+ private static func languageHeading(_ line: String) -> Lang? {
+ var s = line.trimmingCharacters(in: .whitespaces)
+ if s.hasPrefix("#") { s = String(s.drop { $0 == "#" }).trimmingCharacters(in: .whitespaces) }
+ else if s.hasPrefix("**"), s.hasSuffix("**"), s.count > 4 { s = String(s.dropFirst(2).dropLast(2)).trimmingCharacters(in: .whitespaces) }
+ else { return nil }
+ s = s.trimmingCharacters(in: CharacterSet(charactersIn: "::")).trimmingCharacters(in: .whitespaces)
+ switch s.lowercased() {
+ case "中文", "简体中文", "chinese": return .zh
+ case "english": return .en
+ default: return nil
+ }
+ }
+
+ /// The chosen language's section plus the shared footer, or nil when the body has no pair of language headings.
+ private static func sections(_ notes: String, for lang: Lang) -> [String]? {
+ let all = notes.components(separatedBy: "\n")
+ let marks = all.enumerated().compactMap { i, l in languageHeading(l).map { (i, $0) } }
+ guard marks.contains(where: { $0.1 == .zh }), marks.contains(where: { $0.1 == .en }) else { return nil }
+ func isRule(_ l: String) -> Bool { l.trimmingCharacters(in: .whitespaces).hasPrefix("---") }
+ let want: Lang = lang == .zh ? .zh : .en // Swedish (and any other language) reads the English section
+ var picked: [String] = []
+ for (n, mark) in marks.enumerated() where mark.1 == want {
+ let end = marks.indices.contains(n + 1) ? marks[n + 1].0 : all.count
+ let body = all[(mark.0 + 1)..<end]
+ picked += body.prefix { !isRule($0) }
+ }
+ // Footer: after the last rule that follows the last language heading.
+ var footer: [String] = []
+ if let last = marks.last?.0, let rule = all.indices.last(where: { $0 > last && isRule(all[$0]) }) {
+ footer = Array(all[(rule + 1)...])
+ }
+ let out = clean((picked + [""] + footer).joined(separator: "\n"))
+ return out.isEmpty ? nil : out
+ }
+
/// The Markdown for one language as a single string, ready for `blocks(from:)`.
static func markdown(_ notes: String, for lang: Lang) -> String { lines(notes, for: lang).joined(separator: "\n") }
diff --git a/frontend/Tests/Fixtures/release_v0.7.2.md b/frontend/Tests/Fixtures/release_v0.7.2.md
new file mode 100644
index 00000000..7bbfd9b7
--- /dev/null
+++ b/frontend/Tests/Fixtures/release_v0.7.2.md
@@ -0,0 +1,14 @@
+## 中文
+
+- 修复部分游戏打开后黑屏(如《超级马里奥兄弟 惊奇》):Mac 管线存档改为按本机系统版本生成,不再在首次启动时重新编译全部管线(上游 #673)
+- 同步上游 26 个提交:sampler 边框颜色模拟、NVN 逻辑运算、同 pass 反馈快照自动识别等
+
+## English
+
+- Fixed games opening to a black screen (e.g. Super Mario Bros. Wonder): the Mac pipeline archive is stamped for this Mac's OS version instead of the SDK's, so pipelines load instead of recompiling at first start (upstream #673)
+- 26 upstream commits: emulated sampler border colours, NVN logic operations, automatic same-pass feedback snapshots
+
+---
+
+**Install:** download `NX2Apple-macOS-arm64.zip`, unzip, drag to Applications. 中文:下载后解压,拖进「应用程序」。
+
diff --git a/frontend/Tests/NSPortBuilderTests/ReleaseNotesTests.swift b/frontend/Tests/NSPortBuilderTests/ReleaseNotesTests.swift
index c9c4a4ec..ff3f45e1 100644
--- a/frontend/Tests/NSPortBuilderTests/ReleaseNotesTests.swift
+++ b/frontend/Tests/NSPortBuilderTests/ReleaseNotesTests.swift
@@ -123,6 +123,59 @@ final class ReleaseNotesTests: XCTestCase {
XCTAssertTrue(b.map(text).flatMap(links).contains { $0.0 == "#185" })
}
+ // ---- v0.7.2's real body (language sections and a shared footer) ----
+
+ static func body072() throws -> String {
+ try String(contentsOf: root.appendingPathComponent("frontend/Tests/Fixtures/release_v0.7.2.md"), encoding: .utf8)
+ }
+
+ func testSectionedBodyEnglish() throws {
+ let lines = ReleaseNotes.lines(try Self.body072(), for: .en)
+ XCTAssertEqual(lines.count, 3)
+ XCTAssertTrue(lines[0].hasPrefix("- Fixed games opening to a black screen"))
+ XCTAssertTrue(lines[1].hasPrefix("- 26 upstream commits"))
+ XCTAssertTrue(lines[2].hasPrefix("**Install:**"))
+ let all = lines.joined(separator: "\n")
+ XCTAssertEqual(all.components(separatedBy: "Install:").count, 2, "footer once")
+ XCTAssertFalse(all.contains("修复部分游戏"))
+ XCTAssertFalse(all.contains("## "))
+ }
+
+ func testSectionedBodyChinese() throws {
+ let lines = ReleaseNotes.lines(try Self.body072(), for: .zh)
+ XCTAssertEqual(lines.count, 3)
+ XCTAssertTrue(lines[0].hasPrefix("- 修复部分游戏打开后黑屏"))
+ XCTAssertTrue(lines[1].hasPrefix("- 同步上游 26 个提交"))
+ XCTAssertTrue(lines[2].hasPrefix("**Install:**"))
+ let all = lines.joined(separator: "\n")
+ XCTAssertEqual(all.components(separatedBy: "Install:").count, 2, "footer once")
+ XCTAssertFalse(all.contains("Fixed games opening"))
+ XCTAssertFalse(all.contains("upstream commits"))
+ }
+
+ func testSwedishUsesTheEnglishSection() throws {
+ let body = try Self.body072()
+ for lang in [Lang.sv] {
+ XCTAssertEqual(ReleaseNotes.lines(body, for: lang), ReleaseNotes.lines(body, for: .en))
+ }
+ }
+
+ func testHeadingAndBoldMarkerVariants() {
+ let body = "### English\n- a\n\n**中文**\n- 乙\n\n---\nfoot"
+ XCTAssertEqual(ReleaseNotes.lines(body, for: .en), ["- a", "foot"])
+ XCTAssertEqual(ReleaseNotes.lines(body, for: .zh), ["- 乙", "foot"])
+ // Without a footer, and with the Chinese section first.
+ let two = "## 中文\n- 乙\n---\n## English\n- a"
+ XCTAssertEqual(ReleaseNotes.lines(two, for: .en), ["- a"])
+ XCTAssertEqual(ReleaseNotes.lines(two, for: .zh), ["- 乙"])
+ }
+
+ func testOldShapesStillSplitWithoutLanguageHeadings() throws {
+ // v0.7.0 has `---` halves and no language headings.
+ XCTAssertFalse(ReleaseNotes.lines(try Self.body(), for: .en).joined().contains("这一版"))
+ XCTAssertEqual(ReleaseNotes.lines("just text", for: .zh), ["just text"])
+ }
+
// ---- Visual QA ----
/// Opt-in native rendering for pull request screenshots (NX_LAUNCHER_CAPTURE_DIR).
@@ -136,11 +189,13 @@ final class ReleaseNotesTests: XCTestCase {
// The body as it is, and the middle of it (the code spans, the links and the Fixes section) as the sheet shows it scrolled.
let middle = "## New\n\n" + String(body[body.range(of: "- **Reinstall")!.lowerBound...body.range(of: "## Known issues")!.lowerBound])
+ "\n---\n\n## 新增\n\n" + String(body[body.range(of: "- **不重构建")!.lowerBound...body.range(of: "## 已知问题")!.lowerBound])
- for (name, lang, notes) in [("update-sheet-notes-en", Lang.en, body), ("update-sheet-notes-zh", Lang.zh, body),
- ("update-sheet-notes-middle-en", Lang.en, middle), ("update-sheet-notes-middle-zh", Lang.zh, middle)] {
+ let body072 = try Self.body072()
+ for (name, lang, notes, tag) in [("update-sheet-notes-v072-en", Lang.en, body072, "v0.7.2"), ("update-sheet-notes-v072-zh", Lang.zh, body072, "v0.7.2")]
+ + [("update-sheet-notes-en", Lang.en, body, "v0.7.0"), ("update-sheet-notes-zh", Lang.zh, body, "v0.7.0"),
+ ("update-sheet-notes-middle-en", Lang.en, middle, "v0.7.0"), ("update-sheet-notes-middle-zh", Lang.zh, middle, "v0.7.0")] {
let m = BuildModel()
m.lang = lang
- m.appUpdate = AppUpdate.Release(tag: "v0.7.0", url: "", digest: nil, notes: notes)
+ 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 window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: width, height: height), styleMask: [.titled], backing: .buffered, defer: false)