Skip to content

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

A newer release with no download for this build is not "up to date"

LNPANDYfb4d6dbbd842
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swift
index 26c3e95a..aa7b7270 100644
--- a/frontend/Sources/NSPortBuilder/ContentView.swift
+++ b/frontend/Sources/NSPortBuilder/ContentView.swift
@@ -485,6 +485,12 @@ final class BuildModel: ObservableObject {
@Published var showUpdateSheet = false
@Published var appStatus = ""
+ /// The download names this build accepts, newest first. Every release must carry at least one of
+ /// them or an install from that era cannot update itself: NX2Apple is current, nxnative is for
+ /// installs from before the rename to NX2Apple, NS-Port-Builder for installs before that.
+ nonisolated static let appAssetNames = ["NX2Apple-macOS-arm64.zip", "nxnative-macOS-arm64.zip",
+ "NS-Port-Builder-macOS-arm64.zip"]
+
nonisolated static func isNewer(_ tag: String, than current: String) -> Bool {
func nums(_ s: String) -> [Int] { s.split(separator: ".").map { Int($0.filter { $0.isNumber }) ?? 0 } }
let a = nums(tag), b = nums(current)
@@ -503,15 +509,22 @@ final class BuildModel: ObservableObject {
if !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, String)?
+ // A newer release whose download this build cannot name is NOT "up to date". That
+ // distinction is the difference between a user who updates and one who sits on 0.4.6
+ // for ever: 0.4.6 and 0.4.7 look for exactly "NS-Port-Builder-macOS-arm64.zip", and if a
+ // release ever ships without that name they report "已是最新" and stop. Keep the name and
+ // report the mismatch honestly.
+ var newerTag: 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, notes) }
+ if Self.isNewer(tag, than: Self.appVersion) {
+ newerTag = tag
+ if let assets = obj["assets"] as? [[String: Any]] {
+ let notes = (obj["body"] as? String) ?? ""
+ for name in Self.appAssetNames 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, notes) }
+ }
}
}
}
@@ -523,7 +536,15 @@ final class BuildModel: ObservableObject {
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")
+ if data == nil {
+ self.appStatus = self.t("app.netFail")
+ } else if let tag = newerTag {
+ // The release exists; this app just cannot find its own asset name in it.
+ self.appStatus = String(format: self.t("app.noAsset"), tag)
+ self.appUpdate = nil
+ } else {
+ self.appStatus = self.t("app.upToDate")
+ }
}
}
}.resume()
diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swift
index 4454dd15..163da946 100644
--- a/frontend/Sources/NSPortBuilder/Localization.swift
+++ b/frontend/Sources/NSPortBuilder/Localization.swift
@@ -188,6 +188,7 @@ enum L10n {
"app.checking": ("正在检查 App 更新…", "Checking for a new app version…"),
"app.upToDate": ("App 已是最新版本", "The app is up to date"),
"app.found": ("App 有新版本 %@,点右上角按钮更新", "A new version %@ is out — update from the top-right button"),
+ "app.noAsset": ("发现新版本 %@,但这个版本找不到对应的安装包——请到发布页手动下载", "Version %@ is out, but this build cannot find its own download in it — get it from the release page"),
"app.updateBtn": ("更新到 %@", "Update to %@"),
"update.title": ("有新版本可用", "A new version is out"),
"update.fromTo": ("当前 %@ → 新版本 %@", "You have %@ — the new version is %@"),
diff --git a/frontend/Tests/NSPortBuilderTests/AppUpdateTests.swift b/frontend/Tests/NSPortBuilderTests/AppUpdateTests.swift
new file mode 100644
index 00000000..26ec04f1
--- /dev/null
+++ b/frontend/Tests/NSPortBuilderTests/AppUpdateTests.swift
@@ -0,0 +1,28 @@
+import XCTest
+@testable import NSPortBuilder
+
+/// The update check's three outcomes must be distinguishable: a newer release with a download, a
+/// newer release whose download this build cannot name, and genuinely being current.
+///
+/// The middle one used to be reported as "已是最新" (issue: an installed 0.4.6 said it was current
+/// while 0.4.8 was out). A build that looks for one exact asset name and does not find it has not
+/// established that it is up to date — it has established that it cannot tell, and saying "up to
+/// date" leaves that install stuck for ever.
+final class AppUpdateTests: XCTestCase {
+ func testAVersionComparisonReadsTheNumbers() {
+ XCTAssertTrue(BuildModel.isNewer("v0.4.8", than: "0.4.6"))
+ XCTAssertTrue(BuildModel.isNewer("v0.4.10", than: "0.4.8"), "0.4.10 is newer than 0.4.8, not older")
+ XCTAssertFalse(BuildModel.isNewer("v0.4.8", than: "0.4.8"))
+ XCTAssertFalse(BuildModel.isNewer("v0.4.6", than: "0.4.8"))
+ }
+
+ /// The asset names this app will accept, oldest first. A release that carries any of them can
+ /// update every install back to 0.4.5; one that carries none leaves those installs stuck, which
+ /// is why checkAppUpdate has to say so rather than report "up to date".
+ func testTheAssetNamesCoverEveryInstallThatCanStillUpdate() {
+ let names = BuildModel.appAssetNames
+ XCTAssertTrue(names.contains("NX2Apple-macOS-arm64.zip"), "the current name")
+ XCTAssertTrue(names.contains("nxnative-macOS-arm64.zip"), "installs from before the rename to NX2Apple")
+ XCTAssertTrue(names.contains("NS-Port-Builder-macOS-arm64.zip"), "installs from before the rename to nxnative")
+ }
+}