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: keep this build, and a badge when a game's own profile updated
LNPANDY627e7b527b4a
diff --git a/frontend-qt/nspb_qt/localization.py b/frontend-qt/nspb_qt/localization.pyindex f34caa9a..2464d279 100644--- a/frontend-qt/nspb_qt/localization.py+++ b/frontend-qt/nspb_qt/localization.py@@ -408,6 +408,15 @@ TABLE: dict[str, tuple[str, str, str, str]] = {'library.olderTools': ('用旧版构建工具构建', 'Built with older tools', 'Byggt med äldre verktyg', 'Mit älteren Werkzeugen gebaut'),'library.olderToolsShort': ('工具较旧', 'Older tools', 'Äldre verktyg', 'Ältere Werkzeuge'),'library.olderToolsHelp': ('这个游戏构建之后,构建工具有了会影响它的更改。重新构建即可用上这些更改。', 'The build tools changed in ways that affect this game since it was built. Rebuild it to get the changes.', 'Byggverktygen har ändrats på ett sätt som påverkar spelet sedan det byggdes. Bygg om det för att få ändringarna.', 'Die Build-Werkzeuge haben sich seit dem Build so geändert, dass es dieses Spiel betrifft. Baue es neu, um die Änderungen zu bekommen.'),+ 'library.pin': ('保持此构建', 'Keep this build', 'Keep this build', 'Diesen Build behalten'),+ 'library.pinHelp': ('这个构建已验证可玩。引擎更新后不再提醒重新构建;游戏档案的更新仍会显示。', "This build is known to play. Engine updates stop marking it older; this game's own profile updates are still shown.", "This build is known to play. Engine updates stop marking it older; this game's own profile updates are still shown.", 'Dieser Build ist als spielbar bekannt. Engine-Updates markieren ihn nicht mehr als älter. Änderungen am Spielprofil werden weiterhin gezeigt.'),+ 'library.unpin': ('解除保持', 'Stop keeping this build', 'Stop keeping this build', 'Build nicht mehr behalten'),+ 'library.pinned': ('已保持此构建', 'Kept build', 'Kept build', 'Behaltener Build'),+ 'library.pinnedShort': ('已保持', 'Kept', 'Kept', 'Behalten'),+ 'library.pinnedHelp': ('你选择保持这个构建:引擎更新后不会再提醒重新构建它。', 'You chose to keep this build: engine updates no longer mark it older.', 'You chose to keep this build: engine updates no longer mark it older.', 'Du hast diesen Build behalten: Engine-Updates markieren ihn nicht mehr als älter.'),+ 'library.profileUpdated': ('游戏档案有更新', "This game's profile updated", "This game's profile updated", 'Spielprofil aktualisiert'),+ 'library.profileUpdatedShort': ('档案有更新', 'Profile updated', 'Profile updated', 'Profil aktualisiert'),+ 'library.profileUpdatedHelp': ('这个游戏的档案(dm/games)自上次构建后有了更改:修复、着色器表或兼容性调整。重新构建即可用上。', "This game's own profile (dm/games) changed since it was built: fixes, shader tables or compatibility work. Rebuild to get them.", "This game's own profile (dm/games) changed since it was built: fixes, shader tables or compatibility work. Rebuild to get them.", 'Das eigene Spielprofil (dm/games) hat sich seit dem Build geändert: Fehlerbehebungen, Shader-Tabellen oder Kompatibilitätsarbeit. Zum Übernehmen neu bauen.'),'library.rebuild': ('用当前工具重新构建…', 'Rebuild with current tools…', 'Bygg om med aktuella verktyg …', 'Mit aktuellen Werkzeugen neu bauen …'),'library.rebuildShort': ('重新构建', 'Rebuild', 'Bygg om', 'Neu bauen'),'library.buildForMac': ('为 Mac 构建', 'Build for Mac', 'Bygg för Mac', 'Für Mac bauen'),diff --git a/frontend/Sources/NSPortBuilder/LauncherView.swift b/frontend/Sources/NSPortBuilder/LauncherView.swiftindex 1cda1815..6e094f87 100644--- a/frontend/Sources/NSPortBuilder/LauncherView.swift+++ b/frontend/Sources/NSPortBuilder/LauncherView.swift@@ -585,11 +585,20 @@ struct ContentView: View {.font(prominent ? .manrope(12, .bold) : .manrope(13, .medium)).tracking(prominent ? 1.3 : 0) // the eyebrow: the same face, in tracked capitals.foregroundStyle(color)- if !building && toolsAge.older.contains(game.id) { // a quiet note beside the status, not a warning+ if !building && game.pinned { // "keep this build": the lock replaces the older-tools note+ Text("· " + m.t(prominent ? "library.pinned" : "library.pinnedShort"))+ .font(.manrope(prominent ? 13 : 12)).foregroundStyle(.secondary).lineLimit(1)+ .help(m.t("library.pinnedHelp"))+ } else if !building && toolsAge.older.contains(game.id) { // a quiet note beside the status, not a warningText("· " + m.t(prominent ? "library.olderTools" : "library.olderToolsShort")).font(.manrope(prominent ? 13 : 12)).foregroundStyle(.secondary).lineLimit(1).help(m.t("library.olderToolsHelp"))}+ if !building && toolsAge.profileChanged.contains(game.id) { // this game's own profile changed since its build+ Text("· " + m.t(prominent ? "library.profileUpdated" : "library.profileUpdatedShort"))+ .font(.manrope(prominent ? 13 : 12)).foregroundStyle(.secondary).lineLimit(1)+ .help(m.t("library.profileUpdatedHelp"))+ }// A free Apple ID's profile lasts 7 days: the card says when it runs out, the hero offers to renew it.if !building, let expiry = signatureExpiry[game.id] {Text("· " + AppSignature.short(expiry, m.t))@@ -776,7 +785,8 @@ struct ContentView: View {changeArtwork: { chooseArtwork(game) }, resetArtwork: { library.setArtwork("", for: game.id) },reveal: { if let path = game.revealTarget { NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: path)]) } },showLog: { if let log = GameLog.latest(titleID: game.titleID, appPath: game.appPath) { GameLog.show(log) } },- freeSpace: { freeSpaceFor = game.id }, remove: { removing = game }))+ freeSpace: { freeSpaceFor = game.id }, remove: { removing = game },+ togglePin: { library.setPinned(!game.pinned, for: game.id) }))}private func manageItems(for game: LibraryGame?) -> [ManageItem] { game.map(manageItems) ?? [] }diff --git a/frontend/Sources/NSPortBuilder/Library.swift b/frontend/Sources/NSPortBuilder/Library.swiftindex 5612cef4..290e62af 100644--- a/frontend/Sources/NSPortBuilder/Library.swift+++ b/frontend/Sources/NSPortBuilder/Library.swift@@ -23,6 +23,9 @@ struct LibraryGame: Codable, Identifiable, Equatable {var installedDevice = ""/// The repository checkout's commit the last finished build used (ToolsAge); empty for a build from before it was recorded.var toolsCommit = ""+ /// "Keep this build": the player says this build plays well, so engine updates stop marking it older and+ /// nagging a rebuild. A rebuild stays one click away, and this game's profile changes keep being shown.+ var pinned = falsevar isReady: Bool {guard let app = try? MacGameBundle.read(URL(fileURLWithPath: appPath)) else { return false }@@ -71,6 +74,7 @@ extension LibraryGame {iosAppPath = try c.decodeIfPresent(String.self, forKey: .iosAppPath) ?? ""installedDevice = try c.decodeIfPresent(String.self, forKey: .installedDevice) ?? ""toolsCommit = try c.decodeIfPresent(String.self, forKey: .toolsCommit) ?? ""+ pinned = try c.decodeIfPresent(Bool.self, forKey: .pinned) ?? false}}@@ -546,6 +550,14 @@ final class GameLibrary: ObservableObject {upsert(game)}+ /// "Keep this build" (LibraryGame.pinned): the player says this build plays well. The Manage menu's+ /// row toggles it; ToolsAge reads it to stop marking the game older.+ func setPinned(_ pinned: Bool, for id: UUID) {+ guard var game = games.first(where: { $0.id == id }) else { return }+ game.pinned = pinned+ upsert(game)+ }+func remove(_ id: UUID) {games.removeAll { $0.id == id }if selectedID == id { selectedID = games.first?.id }diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swiftindex d2fa2248..f8bdaf99 100644--- a/frontend/Sources/NSPortBuilder/Localization.swift+++ b/frontend/Sources/NSPortBuilder/Localization.swift@@ -451,6 +451,15 @@ enum L10n {"library.olderTools": ("用旧版构建工具构建", "Built with older tools"),"library.olderToolsShort": ("工具较旧", "Older tools"),"library.olderToolsHelp": ("这个游戏构建之后,构建工具有了会影响它的更改。重新构建即可用上这些更改。", "The build tools changed in ways that affect this game since it was built. Rebuild it to get the changes."),+ "library.pin": ("保持此构建", "Keep this build"),+ "library.pinHelp": ("这个构建已验证可玩。引擎更新后不再提醒重新构建;游戏档案的更新仍会显示。", "This build is known to play. Engine updates stop marking it older; this game's own profile updates are still shown."),+ "library.unpin": ("解除保持", "Stop keeping this build"),+ "library.pinned": ("已保持此构建", "Kept build"),+ "library.pinnedShort": ("已保持", "Kept"),+ "library.pinnedHelp": ("你选择保持这个构建:引擎更新后不会再提醒重新构建它。", "You chose to keep this build: engine updates no longer mark it older."),+ "library.profileUpdated": ("游戏档案有更新", "This game's profile updated"),+ "library.profileUpdatedShort": ("档案有更新", "Profile updated"),+ "library.profileUpdatedHelp": ("这个游戏的档案(dm/games)自上次构建后有了更改:修复、着色器表或兼容性调整。重新构建即可用上。", "This game's own profile (dm/games) changed since it was built: fixes, shader tables or compatibility work. Rebuild to get them."),"library.rebuild": ("用当前工具重新构建…", "Rebuild with current tools…"),"library.rebuildShort": ("重新构建", "Rebuild"),"library.buildForMac": ("\u{4e3a} Mac \u{6784}\u{5efa}", "Build for Mac"),@@ -2165,6 +2174,15 @@ enum L10n {"library.olderTools": "Mit älteren Werkzeugen gebaut","library.olderToolsShort": "Ältere Werkzeuge","library.olderToolsHelp": "Die Build-Werkzeuge haben sich seit dem Build so geändert, dass es dieses Spiel betrifft. Baue es neu, um die Änderungen zu bekommen.",+ "library.pin": "Diesen Build behalten",+ "library.pinHelp": "Dieser Build ist als spielbar bekannt. Engine-Updates markieren ihn nicht mehr als älter. Änderungen am Spielprofil werden weiterhin gezeigt.",+ "library.unpin": "Build nicht mehr behalten",+ "library.pinned": "Behaltener Build",+ "library.pinnedShort": "Behalten",+ "library.pinnedHelp": "Du hast diesen Build behalten: Engine-Updates markieren ihn nicht mehr als älter.",+ "library.profileUpdated": "Spielprofil aktualisiert",+ "library.profileUpdatedShort": "Profil aktualisiert",+ "library.profileUpdatedHelp": "Das eigene Spielprofil (dm/games) hat sich seit dem Build geändert: Fehlerbehebungen, Shader-Tabellen oder Kompatibilitätsarbeit. Zum Übernehmen neu bauen.","library.rebuild": "Mit aktuellen Werkzeugen neu bauen …","library.rebuildShort": "Neu bauen","library.buildForMac": "Für Mac bauen",diff --git a/frontend/Sources/NSPortBuilder/ManageMenu.swift b/frontend/Sources/NSPortBuilder/ManageMenu.swiftindex 9b4bf2de..a84d1bbc 100644--- a/frontend/Sources/NSPortBuilder/ManageMenu.swift+++ b/frontend/Sources/NSPortBuilder/ManageMenu.swift@@ -13,6 +13,7 @@ struct ManageActions {var showLog: () -> Void = {}var freeSpace: () -> Void = {}var remove: () -> Void = {}+ var togglePin: () -> Void = {}}/// One row of the Manage menu.@@ -32,6 +33,12 @@ struct ManageItem: Identifiable {hasBuildFolder: Bool, hasLog: Bool = false, actions a: ManageActions) -> [ManageItem] {var items = [ManageItem(id: "rebuild", symbol: "arrow.clockwise", title: t(olderTools ? "library.rebuild" : "library.buildAgain"),enabled: !running && !game.inputs["base", default: []].isEmpty, run: a.rebuild)]+ // "Keep this build": the build plays well, so engine updates stop marking it older. Only a build whose+ // commit was recorded can be kept — without it there is nothing to compare against.+ if game.isReady, !game.toolsCommit.isEmpty {+ items.append(.init(id: "pin", symbol: game.pinned ? "lock.open" : "lock",+ title: t(game.pinned ? "library.unpin" : "library.pin"), run: a.togglePin))+ }if game.isReady { items.append(.init(id: "options", symbol: "slider.horizontal.3", title: t("launch.title"), run: a.options)) }items.append(.init(id: "saves", symbol: "tray.and.arrow.down", title: t("saves.menu"), run: a.saves))items.append(.init(id: "cheats", symbol: "wand.and.stars", title: t("cheats.menu"), run: a.cheats))diff --git a/frontend/Sources/NSPortBuilder/OlderTools.swift b/frontend/Sources/NSPortBuilder/OlderTools.swiftindex 16a432fb..75b478b8 100644--- a/frontend/Sources/NSPortBuilder/OlderTools.swift+++ b/frontend/Sources/NSPortBuilder/OlderTools.swift@@ -5,22 +5,31 @@ import Foundation/// build uses changed between that commit and HEAD. Only a change that can alter the built game counts, so a docs-only/// pull marks nothing. A game built before the commit was recorded, or in a checkout that is not a git one, is never marked.final class ToolsAge: ObservableObject {- /// The games whose build is older than the tools in the checkout now.+ /// The games whose build is older than the tools in the checkout now. A pinned game ("keep this build")+ /// is never here: the player said it plays well.@Published private(set) var older: Set<UUID> = []+ /// The games whose own profile (`dm/games/<title ID>/`) changed since their build: informative even for+ /// a pinned game, since the fixes are the player's to take or leave.+ @Published private(set) var profileChanged: Set<UUID> = []private var generation = 0- init(older: Set<UUID> = []) { self.older = older }+ init(older: Set<UUID> = [], profileChanged: Set<UUID> = []) {+ self.older = older+ self.profileChanged = profileChanged+ }/// Runs git off the main thread; a check started later wins over one still running (the repository may move in between).func check(games: [LibraryGame], repo: String) {generation += 1let mine = generation- let builds = games.map { (id: $0.id, titleID: $0.titleID, commit: $0.toolsCommit) }+ let builds = games.map { (id: $0.id, titleID: $0.titleID, commit: $0.toolsCommit, pinned: $0.pinned) }DispatchQueue.global(qos: .utility).async {- let result = Self.olderGames(builds, repo: repo)+ let result = Self.classify(builds: builds, repo: repo)DispatchQueue.main.async {- guard mine == self.generation, result != self.older else { return }- self.older = result+ guard mine == self.generation,+ result != Verdict(older: self.older, profileChanged: self.profileChanged) else { return }+ self.older = result.older+ self.profileChanged = result.profileChanged}}}@@ -57,16 +66,30 @@ final class ToolsAge: ObservableObject {return r.out.split(separator: "\n").map(String.init).filter { !$0.isEmpty }}- /// The games marked: one `git diff` per distinct recorded commit, then each game's files are filtered by its title ID.- nonisolated static func olderGames(_ builds: [(id: UUID, titleID: String, commit: String)], repo: String) -> Set<UUID> {+ /// The verdict for a set of builds: which are older than the checkout's tools, and which games' own+ /// profiles changed since their build. `pinned` keeps a game out of `older` — the player said this build+ /// plays well — while its profile changes are still reported.+ struct Verdict: Equatable {+ let older: Set<UUID>+ let profileChanged: Set<UUID>+ }++ nonisolated static func classify(builds: [(id: UUID, titleID: String, commit: String, pinned: Bool)], repo: String) -> Verdict {let recorded = builds.filter { !$0.commit.isEmpty }- guard !recorded.isEmpty, let head = head(repo: repo) else { return [] }+ guard !recorded.isEmpty, let head = head(repo: repo) else { return Verdict(older: [], profileChanged: []) }var diffs: [String: [String]] = [:]- var marked: Set<UUID> = []+ var older: Set<UUID> = [], profileChanged: Set<UUID> = []for build in recorded where build.commit != head {if diffs[build.commit] == nil { diffs[build.commit] = changedFiles(since: build.commit, repo: repo) ?? [] }- if diffs[build.commit]!.contains(where: { affects($0, titleID: build.titleID) }) { marked.insert(build.id) }+ let profileTouched = diffs[build.commit]!.contains { affects($0, titleID: build.titleID) && $0.hasPrefix("dm/games/") }+ if profileTouched { profileChanged.insert(build.id) }+ if !build.pinned, diffs[build.commit]!.contains(where: { affects($0, titleID: build.titleID) }) { older.insert(build.id) }}- return marked+ return Verdict(older: older, profileChanged: profileChanged)+ }++ /// Compatibility with the older entry point: which games are older, none pinned.+ nonisolated static func olderGames(builds: [(id: UUID, titleID: String, commit: String)], repo: String) -> Set<UUID> {+ classify(builds: builds.map { (id: $0.id, titleID: $0.titleID, commit: $0.commit, pinned: false) }, repo: repo).older}}diff --git a/frontend/Tests/NSPortBuilderTests/LibraryTests.swift b/frontend/Tests/NSPortBuilderTests/LibraryTests.swiftindex 7fd751ae..9c8e9a2b 100644--- a/frontend/Tests/NSPortBuilderTests/LibraryTests.swift+++ b/frontend/Tests/NSPortBuilderTests/LibraryTests.swift@@ -35,6 +35,20 @@ final class LibraryTests: XCTestCase {return app}+ /// "Keep this build" survives the library file, as the ToolsAge check reads it back.+ func testPinRoundTripsThroughTheLibraryFile() throws {+ let file = temporary.appendingPathComponent("pin.json")+ let library = GameLibrary(file: file)+ let game = LibraryGame(titleID: titleID, name: "Hades")+ try library.addApp(makeApp(titleID, name: "Hades")) // upsert is private: addApp records a game+ let id = try XCTUnwrap(library.games.first?.id)+ XCTAssertFalse(GameLibrary(file: file).games.first?.pinned ?? true, "off by default")+ library.setPinned(true, for: id)+ XCTAssertEqual(GameLibrary(file: file).games.first?.pinned, true)+ library.setPinned(false, for: id)+ XCTAssertEqual(GameLibrary(file: file).games.first?.pinned, false)+ }+func testReadyRequiresMatchingGameAndCompleteExecutables() throws {let app = try makeApp(titleID)var game = LibraryGame(titleID: titleID, name: "Hades", appPath: app.path)diff --git a/frontend/Tests/NSPortBuilderTests/OlderToolsTests.swift b/frontend/Tests/NSPortBuilderTests/OlderToolsTests.swiftindex ddf68ad0..13b0b653 100644--- a/frontend/Tests/NSPortBuilderTests/OlderToolsTests.swift+++ b/frontend/Tests/NSPortBuilderTests/OlderToolsTests.swift@@ -50,42 +50,66 @@ final class OlderToolsTests: XCTestCase {let (repo, built) = try fixture()try commit(["dm/host/hle_fs.c": "two"], in: repo)let hades = game(built)- XCTAssertEqual(ToolsAge.olderGames([hades], repo: repo.path), [hades.id])+ XCTAssertEqual(ToolsAge.olderGames(builds: [hades], repo: repo.path), [hades.id])}func testAChangeOnlyInTheDocsMarksNothing() throws {let (repo, built) = try fixture()try commit(["docs/development.md": "two", "dm/host/README.md": "notes"], in: repo)- XCTAssertEqual(ToolsAge.olderGames([game(built)], repo: repo.path), [])+ XCTAssertEqual(ToolsAge.olderGames(builds: [game(built)], repo: repo.path), [])}func testAGameWithNoRecordedCommitIsNotMarked() throws {let (repo, _) = try fixture()try commit(["dm/host/hle_fs.c": "two"], in: repo)- XCTAssertEqual(ToolsAge.olderGames([game("")], repo: repo.path), [])+ XCTAssertEqual(ToolsAge.olderGames(builds: [game("")], repo: repo.path), [])}func testOnlyTheGamesOwnProfileCounts() throws {let (repo, built) = try fixture()try commit(["dm/games/01007EF00011E000/game.tsv": "name\tZelda 2"], in: repo)- XCTAssertEqual(ToolsAge.olderGames([game(built)], repo: repo.path), [], "another game's profile")+ XCTAssertEqual(ToolsAge.olderGames(builds: [game(built)], repo: repo.path), [], "another game's profile")try commit(["dm/games/\(titleID)/game.tsv": "name\tHades 2"], in: repo)let hades = game(built)- XCTAssertEqual(ToolsAge.olderGames([hades], repo: repo.path), [hades.id])+ XCTAssertEqual(ToolsAge.olderGames(builds: [hades], repo: repo.path), [hades.id])}func testABuildAtHeadOrFromAnUnknownCommitIsNotMarked() throws {let (repo, _) = try fixture()let head = try commit(["dm/host/hle_fs.c": "two"], in: repo)- XCTAssertEqual(ToolsAge.olderGames([game(head)], repo: repo.path), [])- XCTAssertEqual(ToolsAge.olderGames([game(String(repeating: "0", count: 40))], repo: repo.path), [], "a commit the checkout does not have")+ XCTAssertEqual(ToolsAge.olderGames(builds: [game(head)], repo: repo.path), [])+ XCTAssertEqual(ToolsAge.olderGames(builds: [game(String(repeating: "0", count: 40))], repo: repo.path), [], "a commit the checkout does not have")}func testAFolderThatIsNotAGitCheckoutMarksNothing() throws {let zip = temporary.appendingPathComponent("zip")try FileManager.default.createDirectory(at: zip.appendingPathComponent("dm/host"), withIntermediateDirectories: true)XCTAssertNil(ToolsAge.head(repo: zip.path))- XCTAssertEqual(ToolsAge.olderGames([game("abc")], repo: zip.path), [])+ XCTAssertEqual(ToolsAge.olderGames(builds: [game("abc")], repo: zip.path), [])+ }++ /// "Keep this build": a pinned game stops being nagged for a rebuild, while its own profile's changes+ /// are still reported — the player decides whether to take them.+ func testAPinnedGameIsNotMarkedOlderButItsProfileChangesStillShow() throws {+ let (repo, built) = try fixture()+ try commit(["dm/host/hle_fs.c": "two", "dm/games/\(titleID)/game.tsv": "name\tHades 2"], in: repo)+ let pinned = (id: UUID(), titleID: titleID, commit: built, pinned: true)+ let verdict = ToolsAge.classify(builds: [pinned], repo: repo.path)+ XCTAssertFalse(verdict.older.contains(pinned.id), "pinned: no rebuild nag")+ XCTAssertTrue(verdict.profileChanged.contains(pinned.id), "the profile note still shows for a pinned game")+ let unpinned = (id: UUID(), titleID: titleID, commit: built, pinned: false)+ let unpinnedVerdict = ToolsAge.classify(builds: [unpinned], repo: repo.path)+ XCTAssertTrue(unpinnedVerdict.older.contains(unpinned.id))+ XCTAssertTrue(unpinnedVerdict.profileChanged.contains(unpinned.id))+ }++ func testAProfileOnlyChangeStillMarksTheGameOlderWhenNotPinned() throws {+ let (repo, built) = try fixture()+ try commit(["dm/games/\(titleID)/game.tsv": "name\tHades 2"], in: repo)+ let hades = (id: UUID(), titleID: titleID, commit: built, pinned: false)+ let verdict = ToolsAge.classify(builds: [hades], repo: repo.path)+ XCTAssertTrue(verdict.older.contains(hades.id))+ XCTAssertTrue(verdict.profileChanged.contains(hades.id))}func testWhatABuildReads() {