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: add fallback banners for Switch 2 titles missing from titledb
LNPANDYfee5c163d1ab
diff --git a/frontend-qt/nspb_qt/library.py b/frontend-qt/nspb_qt/library.pyindex 84357279..450244b5 100644--- a/frontend-qt/nspb_qt/library.py+++ b/frontend-qt/nspb_qt/library.py@@ -853,6 +853,16 @@ class GameLibrary:class ArtworkStore:TITLEDB_URL = 'https://raw.githubusercontent.com/blawar/titledb/master/US.en.json'+ FALLBACK_BANNERS: dict[str, str] = {+ '0400245021D2C000': 'https://cdn2.steamgriddb.com/grid/4019460f699df3ca57bb36a6cc8b1ce5.png', # Yoshi and the Mysterious Book+ '0400380020056000': 'https://cdn2.steamgriddb.com/grid/220a08c045f283231e519ed83cd21466.png', # Splatoon Raiders+ '04003F40232DE000': 'https://cdn2.steamgriddb.com/grid/30430599d3640690ebddef63609c5f31.png', # Hyrule Warriors: Age of Imprisonment+ '0400486024DEC000': 'https://cdn2.steamgriddb.com/grid/925526bdfb5910517494acb4db2537d5.png', # The Legend of Zelda: Ocarina of Time+ '04007EF01F8AE000': 'https://cdn2.steamgriddb.com/grid/f73cc1e0813d90b30a22ca9af2e9c8b0.png', # Fire Emblem: Fortune's Weave+ '0400A3A01EE4C000': 'https://cdn2.steamgriddb.com/grid/00b97e285bef52b2826cfbeecd4d30f7.png', # Pokémon Pokopia+ '0400D4201C6EA000': 'https://cdn2.steamgriddb.com/grid/eb3353d1afeb0b6b1c6507bb5d39c757.png', # Mario Tennis Fever+ '0400E88025B1A000': 'https://cdn2.steamgriddb.com/grid/a82908cc940793dc1d63acfc0218b2f9.jpg', # Star Fox+ }def __init__(self, state_dir: Path | None = None, on_updated: Callable[[str], None] | None = None) -> None:self.state_dir = state_dir or default_state_dir()@@ -948,7 +958,7 @@ class ArtworkStore:if os.environ.get('QT_QPA_PLATFORM') == 'offscreen':returntid = title_id.upper()- if self.has_custom(tid) or (self.banners_dir / f'{tid}.jpg').is_file():+ if self.has_custom(tid) or (self.banners_dir / f'{tid}.jpg').is_file() or (self.banners_dir / f'{tid}.png').is_file():returnwith self._lock:if tid in self._fetching:@@ -990,8 +1000,10 @@ class ArtworkStore:index_file.write_text(json.dumps(mapping), encoding='utf-8')url = mapping.get(tid)except Exception:- return+ pass+ if not url:+ url = self.FALLBACK_BANNERS.get(tid)if not url:returntry:@@ -1000,7 +1012,8 @@ class ArtworkStore:data = resp.read()if len(data) > 1024:self.banners_dir.mkdir(parents=True, exist_ok=True)- dest = self.banners_dir / f'{tid}.jpg'+ ext = 'png' if data[:8] == b'\x89PNG\r\n\x1a\n' else 'jpg'+ dest = self.banners_dir / f'{tid}.{ext}'dest.write_bytes(data)if self.on_updated:self.on_updated(tid)diff --git a/frontend-qt/tests/test_swift_parity.py b/frontend-qt/tests/test_swift_parity.pyindex 59c8e7d9..4075744b 100644--- a/frontend-qt/tests/test_swift_parity.py+++ b/frontend-qt/tests/test_swift_parity.py@@ -210,6 +210,61 @@ class LibraryAndSpaceTests(unittest.TestCase):self.assertEqual(failed, [])self.assertTrue((bf / 'run' / 'save.dat').is_file())+ def test_switch2_fallback_banners(self) -> None:+ import json+ from unittest import mock++ self.assertEqual(len(lib.ArtworkStore.FALLBACK_BANNERS), 8)+ self.assertIn('0400486024DEC000', lib.ArtworkStore.FALLBACK_BANNERS)++ updated: list[str] = []+ store = lib.ArtworkStore(state_dir=self.dir / 'art_state', on_updated=updated.append)+ store.banners_dir.mkdir(parents=True, exist_ok=True)+ (store.banners_dir / 'banners_index.json').write_text(+ json.dumps({'040074A01BF12000': 'https://img-eshop.cdn.nintendo.net/i/bananza.jpg'}),+ encoding='utf-8',+ )++ png_payload = b'\x89PNG\r\n\x1a\n' + b'P' * 2048+ jpg_payload = b'\xff\xd8\xff\xe0' + b'J' * 2048+ requested_urls: list[str] = []++ class _FakeResp:+ def __init__(self, data: bytes) -> None:+ self._data = data+ def read(self) -> bytes:+ return self._data+ def __enter__(self) -> _FakeResp:+ return self+ def __exit__(self, *args: object) -> None:+ pass++ def fake_urlopen(req, timeout=15):+ url = req.full_url if hasattr(req, 'full_url') else str(req)+ requested_urls.append(url)+ return _FakeResp(png_payload if url.endswith('.png') else jpg_payload)++ with mock.patch('urllib.request.urlopen', side_effect=fake_urlopen):+ store._fetch_one('0400486024DEC000')+ store._fetch_one('040074A01BF12000')++ self.assertEqual(+ requested_urls,+ [+ lib.ArtworkStore.FALLBACK_BANNERS['0400486024DEC000'],+ 'https://img-eshop.cdn.nintendo.net/i/bananza.jpg',+ ],+ )+ self.assertEqual(updated, ['0400486024DEC000', '040074A01BF12000'])+ self.assertEqual(+ store.image_path('0400486024DEC000'),+ str(store.banners_dir / '0400486024DEC000.png'),+ )+ self.assertEqual(+ store.image_path('040074A01BF12000'),+ str(store.banners_dir / '040074A01BF12000.jpg'),+ )+class ParityWindowTests(unittest.TestCase):@classmethoddiff --git a/frontend/Sources/NX2Apple/Artwork.swift b/frontend/Sources/NX2Apple/Artwork.swiftindex 0d1d1f8d..607f9bd3 100644--- a/frontend/Sources/NX2Apple/Artwork.swift+++ b/frontend/Sources/NX2Apple/Artwork.swift@@ -14,7 +14,7 @@ actor ArtworkStore {static let shared = ArtworkStore(directory: BannerCache.directory)static let titleListURL = URL(string: "https://raw.githubusercontent.com/blawar/titledb/master/US.en.json")!- static let imageHosts: Set<String> = ["img-eshop.cdn.nintendo.net"]+ static let imageHosts: Set<String> = ["img-eshop.cdn.nintendo.net", "cdn2.steamgriddb.com"]/// The index format. An index written by an older launcher (no version: the first product per title ID won) is fetched/// again once, so its picks are made by `BannerPick`.static let indexVersion = 2@@ -58,7 +58,7 @@ actor ArtworkStore {var added: [String] = []for id in wanted.sorted() {let cached = Self.cachedBanner(id, in: directory) != nil- guard let link = index.banners[id] else {+ guard let link = index.banners[id] ?? fallbackBanner(for: id) else {if cached && current { sources[id] = "" } // the list no longer has it: keep the banner, check it no morecontinue}@@ -123,7 +123,33 @@ actor ArtworkStore {try? JSONEncoder().encode(sources).write(to: directory.appendingPathComponent("sources.json"), options: .atomic)}- /// Only Nintendo's image CDN over HTTPS: the list is third-party data.+ /// Switch 2 and Nintendo Classics titles that blawar/titledb's regional lists do not carry yet: verified 16:9 key art+ /// with the official logo on SteamGridDB's CDN, used only while the title list has no entry for the ID.+ static let fallbackBanners: [String: String] = [+ "0400245021D2C000": "https://cdn2.steamgriddb.com/grid/4019460f699df3ca57bb36a6cc8b1ce5.png", // Yoshi and the Mysterious Book+ "0400380020056000": "https://cdn2.steamgriddb.com/grid/220a08c045f283231e519ed83cd21466.png", // Splatoon Raiders+ "04003F40232DE000": "https://cdn2.steamgriddb.com/grid/30430599d3640690ebddef63609c5f31.png", // Hyrule Warriors: Age of Imprisonment+ "0400486024DEC000": "https://cdn2.steamgriddb.com/grid/925526bdfb5910517494acb4db2537d5.png", // The Legend of Zelda: Ocarina of Time+ "04007EF01F8AE000": "https://cdn2.steamgriddb.com/grid/f73cc1e0813d90b30a22ca9af2e9c8b0.png", // Fire Emblem: Fortune's Weave+ "0400A3A01EE4C000": "https://cdn2.steamgriddb.com/grid/00b97e285bef52b2826cfbeecd4d30f7.png", // Pokémon Pokopia+ "0400D4201C6EA000": "https://cdn2.steamgriddb.com/grid/eb3353d1afeb0b6b1c6507bb5d39c757.png", // Mario Tennis Fever+ "0400E88025B1A000": "https://cdn2.steamgriddb.com/grid/a82908cc940793dc1d63acfc0218b2f9.jpg", // Star Fox+ ]+ private var customFallbacks: [String: String]?++ init(directory: URL, titleList: URL, fallbacks: [String: String]) {+ self.directory = directory+ self.titleList = titleList+ self.allowsFileURLs = true+ self.customFallbacks = fallbacks+ }++ private func fallbackBanner(for id: String) -> String? {+ if let customFallbacks { return customFallbacks[id] }+ return allowsFileURLs ? nil : Self.fallbackBanners[id]+ }++ /// Only Nintendo's image CDN or the verified fallback host over HTTPS: the list is third-party data.private func allowed(_ url: URL) -> Bool {if allowsFileURLs && url.isFileURL { return true }return url.scheme == "https" && Self.imageHosts.contains(url.host ?? "")diff --git a/frontend/Tests/NX2AppleTests/ArtworkPickTests.swift b/frontend/Tests/NX2AppleTests/ArtworkPickTests.swiftindex e80585e3..e6680bf4 100644--- a/frontend/Tests/NX2AppleTests/ArtworkPickTests.swift+++ b/frontend/Tests/NX2AppleTests/ArtworkPickTests.swift@@ -205,6 +205,33 @@ import NXLauncherXCTAssertEqual(GameLibrary.artwork(for: game, repo: repo.path, banners: f.folder)?.size, NSSize(width: 640, height: 360))}+ /// Switch 2 titles absent from blawar/titledb (such as Ocarina of Time, 0400486024DEC000) use the verified fallback map,+ /// while a title present in the list (Donkey Kong Bananza) keeps the list's own banner.+ func testFallbackBannersCoverMissingSwitch2TitlesWithoutOverridingTheList() async throws {+ XCTAssertEqual(ArtworkStore.fallbackBanners.count, 8)+ XCTAssertNotNil(ArtworkStore.fallbackBanners["0400486024DEC000"])+ for (id, link) in ArtworkStore.fallbackBanners {+ XCTAssertNotNil(id.range(of: "^0400[0-9A-F]{12}$", options: .regularExpression), id)+ let url = try XCTUnwrap(URL(string: link), id)+ XCTAssertEqual(url.scheme, "https")+ XCTAssertTrue(ArtworkStore.imageHosts.contains(url.host ?? ""), link)+ }++ let f = try fixture()+ let ocarina = temporary.appendingPathComponent("cdn/ocarina.jpg")+ try image(.systemIndigo, "Ocarina of Time\n(fallback banner)", to: ocarina)+ let store = ArtworkStore(directory: f.folder, titleList: f.list, fallbacks: [+ "0400486024DEC000": ocarina.absoluteString,+ "040074A01BF12000": ocarina.absoluteString,+ ])+ let added = await store.fetchMissing(["0400486024DEC000", "040074A01BF12000"])+ XCTAssertEqual(added, ["0400486024DEC000", "040074A01BF12000"])+ XCTAssertEqual(bytes(ArtworkStore.cachedBanner("0400486024DEC000", in: f.folder)), bytes(ocarina))+ XCTAssertEqual(bytes(ArtworkStore.cachedBanner("040074A01BF12000", in: f.folder)), bytes(f.bananza))+ let again = await store.fetchMissing(["0400486024DEC000", "040074A01BF12000"])+ XCTAssertEqual(again, [])+ }+// MARK: Visual QA (matched by --filter testRenderLauncherForVisualQA)/// The library before and after the update: covers an older launcher saved (the bundle, the Switch 2 Edition), then the