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
Read devicectl devices from the new properties layout, a missing reality is physical (#488)
v0lumehi174375c043ca
diff --git a/frontend/Sources/NXCore/Devices.swift b/frontend/Sources/NXCore/Devices.swiftindex ed6b1191..ac19653b 100644--- a/frontend/Sources/NXCore/Devices.swift+++ b/frontend/Sources/NXCore/Devices.swift@@ -66,15 +66,28 @@ package enum DeviceTools {guard let root = try? JSONSerialization.jsonObject(with: data) as? [String: Any],let result = root["result"] as? [String: Any], let list = result["devices"] as? [[String: Any]] else { return [] }let devices: [AppleDevice] = list.compactMap { d in- let hardware = d["hardwareProperties"] as? [String: Any] ?? [:]- let properties = d["deviceProperties"] as? [String: Any] ?? [:]- let connection = d["connectionProperties"] as? [String: Any] ?? [:]- guard hardware["reality"] as? String == "physical", hardware["platform"] as? String == "iOS",+ // Xcode 27.2 deprecates hardwareProperties, deviceProperties and connectionProperties for `properties`+ // (connection, hardware, software, state), and a device may carry only the new one. Read the old block, else the new.+ let new = d["properties"] as? [String: Any] ?? [:]+ func block(_ old: String, _ key: String) -> [String: Any] {+ (d[old] as? [String: Any] ?? [:]).merging(new[key] as? [String: Any] ?? [:]) { old, _ in old }+ }+ let hardware = block("hardwareProperties", "hardware")+ let connection = block("connectionProperties", "connection")+ let device = d["deviceProperties"] as? [String: Any] ?? [:]+ let software = new["software"] as? [String: Any] ?? [:]+ let state = new["state"] as? [String: Any] ?? [:]+ // A missing reality is physical: only a device that says "simulated" is left out.+ guard hardware["reality"] as? String != "simulated", hardware["platform"] as? String == "iOS",connection["pairingState"] as? String == "paired",let udid = hardware["udid"] as? String, !udid.isEmpty else { return nil }- return AppleDevice(id: udid, name: properties["name"] as? String ?? udid,+ // osVersionNumber is a string in the old block and {"stringValue": "26.2.1", ...} in `software`.+ let os = device["osVersionNumber"] as? String+ ?? (software["osVersionNumber"] as? [String: Any])?["stringValue"] as? String+ ?? software["osVersionNumber"] as? String ?? ""+ return AppleDevice(id: udid, name: device["name"] as? String ?? state["name"] as? String ?? udid,model: hardware["marketingName"] as? String ?? "",- os: properties["osVersionNumber"] as? String ?? "",+ os: os,reachable: connection["transportType"] is String,transport: connection["transportType"] as? String ?? "")}diff --git a/frontend/Tests/NX2AppleTests/LibraryTests.swift b/frontend/Tests/NX2AppleTests/LibraryTests.swiftindex 64a00c84..562beede 100644--- a/frontend/Tests/NX2AppleTests/LibraryTests.swift+++ b/frontend/Tests/NX2AppleTests/LibraryTests.swift@@ -348,6 +348,34 @@ final class LibraryTests: XCTestCase {XCTAssertEqual(model.doneNote, model.t("msg.stopped"))}+ /// Xcode 27.2 may give a device only in `properties`, without `reality`. A missing reality is physical, a simulated one,+ /// another platform and an unpaired device are left out (#488).+ func testDevicesAreReadFromTheOldAndTheNewDevicectlLayout() {+ func parse(_ device: String) -> [AppleDevice] {+ DeviceTools.parseDevices(Data("{\"result\": {\"devices\": [\(device)]}}".utf8))+ }+ let old = parse("""+ {"hardwareProperties": {"reality": "physical", "platform": "iOS", "udid": "OLD-1", "marketingName": "iPhone 17"},+ "deviceProperties": {"name": "Old", "osVersionNumber": "26.1"}, "connectionProperties": {"pairingState": "paired", "transportType": "wired"}}+ """)+ XCTAssertEqual(old, [AppleDevice(id: "OLD-1", name: "Old", model: "iPhone 17", os: "26.1", reachable: true, transport: "wired")])+ let new = parse("""+ {"properties": {"hardware": {"platform": "iOS", "udid": "NEW-1", "marketingName": "iPad mini"},+ "software": {"osVersionNumber": {"stringValue": "26.2.1", "components": [26, 2, 1]}}, "state": {"name": "Pad"},+ "connection": {"pairingState": "paired", "transportType": "localNetwork"}}}+ """)+ XCTAssertEqual(new, [AppleDevice(id: "NEW-1", name: "Pad", model: "iPad mini", os: "26.2.1", reachable: true, transport: "localNetwork")])+ XCTAssertEqual(parse("""+ {"properties": {"hardware": {"reality": "simulated", "platform": "iOS", "udid": "SIM-1"}, "connection": {"pairingState": "paired"}}}+ """), [])+ XCTAssertEqual(parse("""+ {"properties": {"hardware": {"platform": "watchOS", "udid": "WATCH-1"}, "connection": {"pairingState": "paired"}}}+ """), [])+ XCTAssertEqual(parse("""+ {"properties": {"hardware": {"platform": "iOS", "udid": "UN-1"}, "connection": {"pairingState": "unpaired"}}}+ """), [])+ }+func testPairedDevicesAndSigningTeamsAreRead() {let json = """{"result": {"devices": [