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
Tests: wait for the console to come to rest, and pin the export setting in the no-device test
v0lumehi8c5e76517141
diff --git a/frontend/Tests/NX2AppleTests/ConsoleTests.swift b/frontend/Tests/NX2AppleTests/ConsoleTests.swiftindex 102825d7..248b7625 100644--- a/frontend/Tests/NX2AppleTests/ConsoleTests.swift+++ b/frontend/Tests/NX2AppleTests/ConsoleTests.swift@@ -288,10 +288,30 @@ import NXModelwindow.contentView = hostwindow.orderBack(nil)defer { window.orderOut(nil); window.contentView = nil; window.close() }- func settle() { RunLoop.main.run(until: Date().addingTimeInterval(0.4)); host.layoutSubtreeIfNeeded() }- func snapshot(_ name: String) throws -> NSBitmapImageRep {+ func render() throws -> NSBitmapImageRep {let rep = try XCTUnwrap(host.bitmapImageRepForCachingDisplay(in: host.bounds))host.cacheDisplay(in: host.bounds, to: rep)+ return rep+ }+ func pixels(_ rep: NSBitmapImageRep) -> Data { Data(bytes: rep.bitmapData!, count: rep.bytesPerRow * rep.pixelsHigh) }+ /// Waits for what the row does after a focus change: it must first differ from `previous` (the focus change and its scroll have+ /// landed) and then stop changing for two renders in a row. The scroll is a 0.2 s animation on the wall clock, so on a busy+ /// machine a fixed pause caught it half way (the ring was then somewhere between the tiles, or not on screen).+ func settle(after previous: NSBitmapImageRep? = nil) throws {+ let deadline = Date().addingTimeInterval(15)+ var last = previous.map(pixels), moved = previous == nil, stableRenders = 0+ while Date() < deadline {+ RunLoop.main.run(until: Date().addingTimeInterval(0.1)); host.layoutSubtreeIfNeeded()+ let now = pixels(try render())+ if !moved { moved = now != last; last = now; continue }+ stableRenders = now == last ? stableRenders + 1 : 0+ last = now+ if stableRenders >= 2 { return }+ }+ XCTFail("the console did not come to rest within 15 s")+ }+ func snapshot(_ name: String) throws -> NSBitmapImageRep {+ let rep = try render()if let directory = ProcessInfo.processInfo.environment["NX_CONSOLE_CAPTURE_DIR"] {let output = URL(fileURLWithPath: directory)try FileManager.default.createDirectory(at: output, withIntermediateDirectories: true)@@ -299,12 +319,12 @@ import NXModel}return rep}- settle()+ try settle()let first = try XCTUnwrap(driver.state.games.first).id, last = try XCTUnwrap(driver.state.games.last).idlet start = try snapshot("clip-1-start")- driver.focus(last); settle()- _ = try snapshot("clip-2-last")- driver.focus(first); settle()+ driver.focus(last); try settle(after: start)+ let atEnd = try snapshot("clip-2-last")+ driver.focus(first); try settle(after: atEnd)let rep = try snapshot("clip-3-back")// the ring is a vertical cream line along the image's left edge: the leftmost column with a long run of cream pixelsfunc ringColumn(_ rep: NSBitmapImageRep) -> Int? {diff --git a/frontend/Tests/NX2AppleTests/ShellInstallTests.swift b/frontend/Tests/NX2AppleTests/ShellInstallTests.swiftindex ceb3c3dc..1658038d 100644--- a/frontend/Tests/NX2AppleTests/ShellInstallTests.swift+++ b/frontend/Tests/NX2AppleTests/ShellInstallTests.swift@@ -948,13 +948,16 @@ import NXModel}@MainActor func testShellTargetWithoutDeviceStopsBeforeBuilding() throws {- let saved = ["repoPath", "buildTarget", "installDevice", "signingTeam"].map { ($0, UserDefaults.standard.object(forKey: $0)) }+ let saved = ["repoPath", "buildTarget", "installDevice", "signingTeam", DeviceStore.exportKey].map { ($0, UserDefaults.standard.object(forKey: $0)) }defer { for (key, value) in saved { UserDefaults.standard.set(value, forKey: key) } }let modelStores = LauncherStores(); let model = modelStores.buildmodelStores.repo.path = temporary.pathtry write(temporary.path + "/dm/tools/nx_extract/Program.cs", "")model.target = "ios"modelStores.deviceStore.installDevice = ""+ // "Export the IPA" is read from the shared preferences of the test process, so a value left there (a killed run, a run in+ // another worktree at the same time) skipped the device check and the test saw the stale-tools note instead.+ modelStores.deviceStore.exportIPA = falsemodel.startBuild()XCTAssertFalse(model.running)XCTAssertEqual(model.doneNote, model.t("shell.needsDevice"))