Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Show iPadOS for iPad guests in Launchpad

Jacky4d34bbe3b341
diff --git a/VPhoneLaunchpad/Tests/MachineProductTypeTests.sh b/VPhoneLaunchpad/Tests/MachineProductTypeTests.sh
new file mode 100755
index 00000000..81ac54ea
--- /dev/null
+++ b/VPhoneLaunchpad/Tests/MachineProductTypeTests.sh
@@ -0,0 +1,14 @@
+#!/bin/zsh
+set -euo pipefail
+
+launchpad="${0:a:h:h}"
+temporary="$(/usr/bin/mktemp -d)"
+trap '/bin/rm -rf "$temporary"' EXIT
+
+/usr/bin/xcrun swiftc -swift-version 6 -strict-concurrency=complete \
+ -parse-as-library \
+ "$launchpad/VPhoneLaunchpadShared/VPhoneLaunchpadBundleStore.swift" \
+ "$launchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swift" \
+ "$launchpad/Tests/MachineProductTypeTests.swift" \
+ -o "$temporary/machine-product-type-tests"
+"$temporary/machine-product-type-tests" "$@"
diff --git a/VPhoneLaunchpad/Tests/MachineProductTypeTests.swift b/VPhoneLaunchpad/Tests/MachineProductTypeTests.swift
new file mode 100644
index 00000000..8edd42f6
--- /dev/null
+++ b/VPhoneLaunchpad/Tests/MachineProductTypeTests.swift
@@ -0,0 +1,47 @@
+import Foundation
+
+/// The guest product type the Machines table and inspector read from a
+/// machine folder, and the OS name it gives.
+@main
+struct MachineProductTypeTests {
+ static func expect(_ condition: Bool, _ message: @autoclosure () -> String, line: Int = #line) {
+ precondition(condition, "line \(line): \(message())")
+ }
+
+ static func main() throws {
+ let manager = FileManager.default
+ let root = manager.temporaryDirectory.appendingPathComponent("machine-product-type-\(UUID().uuidString)", isDirectory: true)
+ defer { try? manager.removeItem(at: root) }
+
+ // config.plist's key wins over the restore tree.
+ let pad = root.appendingPathComponent("ipad-mini-01", isDirectory: true)
+ try manager.createDirectory(at: pad.appendingPathComponent("FirmwareOriginals/iPhone17,3_26.6.2_23G90_Restore"), withIntermediateDirectories: true)
+ let config: NSDictionary = ["guestProductType": "iPad16,1", "cpuCount": 8]
+ try config.write(to: pad.appendingPathComponent("config.plist"))
+ expect(VPhoneLaunchpadMachine.guestProductType(in: pad) == "iPad16,1", "config.plist")
+
+ // A config written before the key: the iPad restore tree's name.
+ let older = root.appendingPathComponent("ipad-pro-13", isDirectory: true)
+ try manager.createDirectory(at: older.appendingPathComponent("FirmwareOriginals/AVPBooter.vresearch1.bin"), withIntermediateDirectories: true)
+ try manager.createDirectory(at: older.appendingPathComponent("FirmwareOriginals/iPhoneOS_iPad17,3_26.6.2_23G90_Restore"), withIntermediateDirectories: true)
+ try (["cpuCount": 8] as NSDictionary).write(to: older.appendingPathComponent("config.plist"))
+ expect(VPhoneLaunchpadMachine.guestProductType(in: older) == "iPad17,3", "iPad restore tree")
+
+ let phone = root.appendingPathComponent("research-01", isDirectory: true)
+ try manager.createDirectory(at: phone.appendingPathComponent("FirmwareOriginals/iPhone17,3_27.0_24A435_Restore"), withIntermediateDirectories: true)
+ expect(VPhoneLaunchpadMachine.guestProductType(in: phone) == "iPhone17,3", "iPhone restore tree")
+ expect(VPhoneLaunchpadMachine.guestProductType(in: root.appendingPathComponent("missing")) == nil, "nothing to read")
+
+ // restore-info.json's device is the restore identity's, not the guest's.
+ let json = #"""
+ {"name":"ipad-mini-01","cpuCount":8,"memoryMB":8192,"diskSizeBytes":64000000000,
+ "network":{"mode":"nat","macAddress":"9a:84:18:78:7a:31"},
+ "restoreInfo":{"ios":{"version":"26.6.2","build":"23G90"},"cloudOS":{"version":"26.4","build":"23E5207q"},"variant":"jb","device":"iPhone99,11"}}
+ """#
+ var machine = try JSONDecoder().decode(VPhoneLaunchpadMachine.self, from: Data(json.utf8))
+ expect(machine.osName == "iOS" && !machine.isPad, "unknown type reads as iOS")
+ machine.guestProductType = VPhoneLaunchpadMachine.guestProductType(in: pad)
+ expect(machine.isPad && machine.osName == "iPadOS", "iPad guest")
+ print("Machine product type tests passed: config, restore trees, OS name")
+ }
+}
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings b/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings
index f30fd79f..b654216e 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings
@@ -13738,6 +13738,15 @@
"vi" : { "stringUnit" : { "state" : "translated", "value" : "Tạo ảnh chụp nhanh" } },
"zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "拍摄快照" } }
}
+ },
+ "OS" : {
+ "comment" : "Machines table column: the guest OS and its version, such as iOS 26.6.2 or iPadOS 26.6.2.",
+ "localizations" : {
+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "OS" } },
+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "OS" } },
+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "Hệ điều hành" } },
+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "系统" } }
+ }
}
},
"version" : "1.0"
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swift
index 265ce8c4..279a49b0 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swift
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swift
@@ -101,6 +101,10 @@ nonisolated struct VPhoneLaunchpadMachine: Decodable, Hashable, Identifiable, Se
let syncsHostLocation: Bool?
/// The library `vm list` was run on. Not part of the JSON.
var libraryRoot = ""
+ /// The guest's product type, such as iPad16,1, read by the library from
+ /// the machine folder. Not part of the JSON: `restoreInfo.device` is the
+ /// restore identity's model, the same for every guest.
+ var guestProductType: String?
private enum CodingKeys: String, CodingKey {
case name, cpuCount, memoryMB, diskSizeBytes, network, restoreInfo, customFirmwareInstalled, udid, unlocksAtStartup,
@@ -141,6 +145,35 @@ nonisolated struct VPhoneLaunchpadMachine: Decodable, Hashable, Identifiable, Se
restoreInfo?.ios.version ?? ""
}
+ /// True for an iPad guest.
+ var isPad: Bool {
+ guestProductType?.hasPrefix("iPad") == true
+ }
+
+ /// The guest OS's name: iPadOS on an iPad.
+ var osName: String {
+ isPad ? "iPadOS" : "iOS"
+ }
+
+ /// config.plist's `guestProductType`, else the product type in the name
+ /// of the restore tree `fw prepare` keeps in `FirmwareOriginals`
+ /// (`iPhone17,3_…_Restore`, or `iPhoneOS_iPad16,1_…_Restore` for an iPad),
+ /// for configs written before the key.
+ static func guestProductType(in folder: URL) -> String? {
+ let config = NSDictionary(contentsOf: folder.appendingPathComponent("config.plist"))
+ if let type = config?["guestProductType"] as? String {
+ return type
+ }
+ let originals = folder.appendingPathComponent("FirmwareOriginals", isDirectory: true)
+ let names = (try? FileManager.default.contentsOfDirectory(atPath: originals.path)) ?? []
+ for name in names.sorted() where name.hasSuffix("_Restore") {
+ if let type = name.split(separator: "_").first(where: { $0.wholeMatch(of: /(iPhone|iPad)\d+,\d+/) != nil }) {
+ return String(type)
+ }
+ }
+ return nil
+ }
+
var networkDescription: String {
switch network.mode {
case "nat": String(localized: "NAT")
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swift
index c45b10ea..71431f34 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swift
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swift
@@ -118,7 +118,7 @@ struct VPhoneLaunchpadMachineInspector: View {
Section("Firmware") {
if let info = machine.restoreInfo {
- LabeledContent("iOS", value: "\(info.ios.version) (\(info.ios.build))")
+ LabeledContent(machine.osName, value: "\(info.ios.version) (\(info.ios.build))")
LabeledContent("cloudOS", value: "\(info.cloudOS.version) (\(info.cloudOS.build))")
} else {
Text("Not restored").foregroundStyle(.secondary)
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift
index 1a52fe3f..8bbc37a3 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift
@@ -190,6 +190,7 @@ final class VPhoneLaunchpadMachineLibrary {
var machines = try JSONDecoder().decode([VPhoneLaunchpadMachine].self, from: data)
for index in machines.indices {
machines[index].libraryRoot = root
+ machines[index].guestProductType = VPhoneLaunchpadMachine.guestProductType(in: machines[index].path.url)
}
found += machines
listed.insert(root)
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift
index 99c0c931..6528cb00 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift
@@ -367,10 +367,10 @@ struct VPhoneLaunchpadMachinesView: View {
.width(min: 80, ideal: 110)
}
// Standard comparison orders 18.10 after 18.9.
- TableColumn("iOS", value: \.iosVersion) { machine in
- Text(verbatim: machine.restoreInfo.map { "\($0.ios.version) (\($0.ios.build))" } ?? "—")
+ TableColumn("OS", value: \.iosVersion) { machine in
+ Text(verbatim: machine.restoreInfo.map { "\(machine.osName) \($0.ios.version) (\($0.ios.build))" } ?? "—")
}
- .width(min: 110, ideal: 120)
+ .width(min: 140, ideal: 160)
TableColumn("Core Bundle") { machine in
// Each cell is a hosting view of its own. When its row leaves
// the table, the cell is updated once more with an empty
@@ -492,6 +492,7 @@ struct VPhoneLaunchpadMachinesView: View {
machine.name,
machine.restoreInfo?.ios.version,
machine.restoreInfo?.ios.build,
+ machine.guestProductType,
machine.udid,
VPhoneLaunchpadMachineLocations.volumeName(machine.libraryRoot),
]