Skip to content

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

An update installs under the release's own name (the rename era ends)

LNPANDY75ba8f955496
diff --git a/frontend/Sources/NSPortBuilder/AppUpdate.swift b/frontend/Sources/NSPortBuilder/AppUpdate.swift
index 07634fd1..9a5a0442 100644
--- a/frontend/Sources/NSPortBuilder/AppUpdate.swift
+++ b/frontend/Sources/NSPortBuilder/AppUpdate.swift
@@ -124,10 +124,38 @@ enum AppUpdate {
/// launch shows no Gatekeeper prompt (the release is ad-hoc signed, not notarized).
///
/// Refused while a build runs: the caller relaunches (or the app is quitting), and either ends the build's process group.
- static func install(_ staged: URL, over current: URL, buildRunning: Bool, trashOld: Bool = true) throws {
+ /// Where the staged release goes: its own bundle name when it differs from the running copy's,
+ /// else the current URL.
+ ///
+ /// The two-name case is a rename era (nxnative → NS Port Builder → NX2Apple). Replacing in place
+ /// would keep the old folder's name for ever: the app inside is the new version, but the
+ /// Finder, the Dock and /Applications keep saying the old name, which read as "the update did
+ /// not happen" (a 0.4.6 install updated to 0.4.8 and still saw NS Port Builder). Under the new
+ /// name the old bundle is removed; the Dock entry pointing at it goes stale once, which a log
+ /// line names — the alternative was the old name for ever.
+ static func installTarget(for staged: URL, current: URL) -> URL {
+ staged.lastPathComponent == current.lastPathComponent
+ ? current
+ : current.deletingLastPathComponent().appendingPathComponent(staged.lastPathComponent)
+ }
+
+ /// Install the staged app and return where it ended up (the caller relaunches that path).
+ static func install(_ staged: URL, over current: URL, buildRunning: Bool, trashOld: Bool = true) throws -> URL {
guard !buildRunning else { throw InstallError.buildRunning }
let fm = FileManager.default
let dir = current.deletingLastPathComponent()
+ let target = installTarget(for: staged, current: current)
+ if target != current {
+ // A rename: place the staged bundle under its own name, then retire the old-named one.
+ // The running copy is trashed last — on macOS a running executable survives the removal
+ // of its bundle (the kernel holds the vnode), and the quit-time path runs this as the
+ // app is exiting anyway.
+ try? fm.removeItem(at: target)
+ try fm.copyItem(at: staged, to: target)
+ clearQuarantine(target)
+ if trashOld { try? fm.trashItem(at: current, resultingItemURL: nil) }
+ return target
+ }
let name = current.deletingPathExtension().lastPathComponent
let incoming = dir.appendingPathComponent(name + " (new).app")
let backupName = name + " (old).app"
@@ -140,13 +168,18 @@ enum AppUpdate {
if fm.fileExists(atPath: backup.path) {
if trashOld { try? fm.trashItem(at: backup, resultingItemURL: nil) } else { try? fm.removeItem(at: backup) }
}
- let x = Process()
- x.executableURL = URL(fileURLWithPath: "/usr/bin/xattr")
- x.arguments = ["-dr", "com.apple.quarantine", (placed ?? current).path]
- try? x.run(); x.waitUntilExit()
+ clearQuarantine(placed ?? current)
+ return current
} catch {
try? fm.removeItem(at: incoming)
throw InstallError.failed(error.localizedDescription)
}
}
+
+ private static func clearQuarantine(_ app: URL) {
+ let x = Process()
+ x.executableURL = URL(fileURLWithPath: "/usr/bin/xattr")
+ x.arguments = ["-dr", "com.apple.quarantine", app.path]
+ try? x.run(); x.waitUntilExit()
+ }
}
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swift
index 2c9aff77..5f76f244 100644
--- a/frontend/Sources/NSPortBuilder/ContentView.swift
+++ b/frontend/Sources/NSPortBuilder/ContentView.swift
@@ -501,6 +501,9 @@ final class BuildModel: ObservableObject {
}
/// The release that is downloaded, verified and unpacked: it goes in when the app quits, or with Restart now.
@Published var appStaged: AppUpdate.Staged?
+ /// Where a rename-era install put the new app (the old bundle name is gone): Settings shows it,
+ /// because the Dock entry pointing at the old path is stale until the player re-pins it.
+ static var noteRenamedInstall: String?
/// Whether this copy may replace itself; a launcher built from the repository never does (tests set it).
var appInstallability = AppUpdate.installability(Bundle.main.bundleURL, appVersion: BuildModel.appVersion)
private var quitObserver: NSObjectProtocol?
@@ -677,8 +680,9 @@ final class BuildModel: ObservableObject {
@discardableResult
func installStagedUpdate(relaunch: Bool, at current: URL = Bundle.main.bundleURL) -> Bool {
guard let staged = appStaged, appInstallability == .ok else { return false }
+ let placed: URL
do {
- try AppUpdate.install(staged.app, over: current, buildRunning: !mayInstallAppUpdate)
+ placed = try AppUpdate.install(staged.app, over: current, buildRunning: !mayInstallAppUpdate)
} catch AppUpdate.InstallError.failed(let why) {
appStatus = String(format: t("app.installFail"), why)
return false
@@ -687,9 +691,17 @@ final class BuildModel: ObservableObject {
return false
}
appStaged = nil
+ // A rename era (nxnative → NS Port Builder → NX2Apple) installs under the release's own
+ // bundle name; the Dock entry pointing at the old path goes stale once, so the log says
+ // where the new copy landed instead of leaving the player to find it.
+ if placed != current {
+ fputs("launcher: the update was installed as \(placed.lastPathComponent) (the app was renamed); "
+ + "the previous \(current.lastPathComponent) was removed — re-pin it in the Dock\n", stderr)
+ Self.noteRenamedInstall = placed.path
+ }
if relaunch {
appStatus = String(format: t("app.relaunching"), staged.release.tag)
- NSWorkspace.shared.openApplication(at: current, configuration: NSWorkspace.OpenConfiguration())
+ NSWorkspace.shared.openApplication(at: placed, configuration: NSWorkspace.OpenConfiguration())
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { exit(0) }
}
return true
diff --git a/frontend/Tests/NSPortBuilderTests/AppUpdateTests.swift b/frontend/Tests/NSPortBuilderTests/AppUpdateTests.swift
index 0c9adb46..9056b5bd 100644
--- a/frontend/Tests/NSPortBuilderTests/AppUpdateTests.swift
+++ b/frontend/Tests/NSPortBuilderTests/AppUpdateTests.swift
@@ -167,13 +167,46 @@ final class AppUpdateTests: XCTestCase {
// ---- when ----
- func testInstallSwapsTheBundle() throws {
- let current = try makeApp("Current", in: temporary.appendingPathComponent("Applications"), marker: "old")
- let staged = try makeApp("Staged", in: temporary.appendingPathComponent("staged"), marker: "new")
- try AppUpdate.install(staged, over: current, buildRunning: false, trashOld: false)
+ func testInstallSwapsTheBundleInPlaceWhenTheNameMatches() throws {
+ let dir = temporary.appendingPathComponent("Applications")
+ let current = try makeApp("Current", in: dir, marker: "old")
+ let staged = try makeApp("Current", in: temporary.appendingPathComponent("staged"), marker: "new")
+ let placed = try AppUpdate.install(staged, over: current, buildRunning: false, trashOld: false)
+ XCTAssertEqual(placed, current, "a same-name install stays where it was")
XCTAssertEqual(try marker(current), "new")
- let left = try FileManager.default.contentsOfDirectory(atPath: current.deletingLastPathComponent().path)
- XCTAssertEqual(left, ["Current.app"]) // no "(new)" or "(old)" copy beside it
+ XCTAssertEqual(try FileManager.default.contentsOfDirectory(atPath: dir.path), ["Current.app"]) // no "(new)"/"(old)" copy beside it
+ }
+
+ func testInstallUsesTheStagedNameWhenItDiffers() throws {
+ // The rename era: nxnative → NS Port Builder → NX2Apple. In-place replacement kept the old
+ // folder's name for ever, and an updated app still called itself the old name.
+ let dir = temporary.appendingPathComponent("Applications")
+ let current = try makeApp("Current", in: dir, marker: "old")
+ let staged = try makeApp("Renamed", in: temporary.appendingPathComponent("staged"), marker: "new")
+ let placed = try AppUpdate.install(staged, over: current, buildRunning: false, trashOld: false)
+ XCTAssertEqual(placed.standardizedFileURL.path, dir.appendingPathComponent("Renamed.app").path)
+ XCTAssertEqual(try marker(placed), "new", "the new bundle is the staged one, under its own name")
+ XCTAssertEqual(try marker(current), "old", "with trashOld off the old copy is left alone (the running app in the real flow)")
+ XCTAssertEqual(try FileManager.default.contentsOfDirectory(atPath: dir.path).sorted(), ["Current.app", "Renamed.app"])
+ }
+
+ func testInstallWithTheStagedNameRemovesTheOldBundle() throws {
+ let dir = temporary.appendingPathComponent("Applications")
+ let current = try makeApp("Current", in: dir, marker: "old")
+ let staged = try makeApp("Renamed", in: temporary.appendingPathComponent("staged"), marker: "new")
+ _ = try AppUpdate.install(staged, over: current, buildRunning: false, trashOld: true)
+ XCTAssertEqual(try FileManager.default.contentsOfDirectory(atPath: dir.path), ["Renamed.app"],
+ "the old-named bundle is retired once the new one is in place")
+ }
+
+ func testTheInstallTargetFollowsTheStagedNameOnlyWhenItDiffers() {
+ let dir = URL(fileURLWithPath: "/Applications")
+ XCTAssertEqual(AppUpdate.installTarget(for: dir.appendingPathComponent("NX2Apple.app"),
+ current: dir.appendingPathComponent("NX2Apple.app")),
+ dir.appendingPathComponent("NX2Apple.app"))
+ XCTAssertEqual(AppUpdate.installTarget(for: dir.appendingPathComponent("NX2Apple.app"),
+ current: dir.appendingPathComponent("NS Port Builder.app")),
+ dir.appendingPathComponent("NX2Apple.app"), "a rename installs under the release's own name")
}
func testInstallRefusedWhileBuildRuns() throws {