Run a virtual iPhone on an Apple Silicon Mac.
Swift
Launchpad: Apple Watch machines
Maximilian Paß6e25ceb2b8e6
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/IPSWCache/VPhoneLaunchpadIPSW.swift b/VPhoneLaunchpad/VPhoneLaunchpad/IPSWCache/VPhoneLaunchpadIPSW.swiftindex e0269c6f..f6c15a4d 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/IPSWCache/VPhoneLaunchpadIPSW.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/IPSWCache/VPhoneLaunchpadIPSW.swift@@ -9,7 +9,7 @@ import Foundation/// manifest cannot be read.nonisolated struct VPhoneLaunchpadIPSW: Hashable, Sendable {enum Kind: Hashable, Sendable {- case iPhone, iPad, appleTV, cloudOS, unknown+ case iPhone, iPad, appleTV, watch, cloudOS, unknown/// The system the IPSW installs: the first word of its title.var systemName: String? {@@ -17,6 +17,7 @@ nonisolated struct VPhoneLaunchpadIPSW: Hashable, Sendable {case .iPhone: "iOS"case .iPad: "iPadOS"case .appleTV: "tvOS"+ case .watch: "watchOS"case .cloudOS: "cloudOS"case .unknown: nil}@@ -50,6 +51,9 @@ nonisolated struct VPhoneLaunchpadIPSW: Hashable, Sendable {if productTypes.contains(where: { $0.hasPrefix("AppleTV") }) {return .appleTV}+ if productTypes.contains(where: { $0.hasPrefix("Watch") }) {+ return .watch+ }return .unknown}diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/IPSWCache/VPhoneLaunchpadIPSWRows.swift b/VPhoneLaunchpad/VPhoneLaunchpad/IPSWCache/VPhoneLaunchpadIPSWRows.swiftindex e371d907..6a76a249 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/IPSWCache/VPhoneLaunchpadIPSWRows.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/IPSWCache/VPhoneLaunchpadIPSWRows.swift@@ -137,8 +137,9 @@ nonisolated enum VPhoneLaunchpadIPSWRows {case .iPhone: 0case .iPad: 1case .appleTV: 2- case .cloudOS: 3- case .unknown: 4+ case .watch: 3+ case .cloudOS: 4+ case .unknown: 5}}@@ -159,6 +160,7 @@ nonisolated enum VPhoneLaunchpadIPSWRows {case .iPhone: String(localized: "iPhone")case .iPad: String(localized: "iPad")case .appleTV: String(localized: "Apple TV")+ case .watch: String(localized: "Apple Watch")case .cloudOS: String(localized: "cloudOS")case .unknown: String(localized: "Unknown")}diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swiftindex ebf53200..c21f84ef 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swift@@ -150,15 +150,22 @@ nonisolated struct VPhoneLaunchpadMachine: Decodable, Hashable, Identifiable, SeguestProductType?.hasPrefix("AppleTV") == true}- /// The guest OS's name: iPadOS on an iPad, tvOS on an Apple TV.+ /// True for an Apple Watch guest.+ var isWatch: Bool {+ guestProductType?.hasPrefix("Watch") == true+ }++ /// The guest OS's name: iPadOS on an iPad, tvOS on an Apple TV, watchOS+ /// on an Apple Watch.var osName: String {- isAppleTV ? "tvOS" : isPad ? "iPadOS" : "iOS"+ isWatch ? "watchOS" : isAppleTV ? "tvOS" : 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- /// and `iPhoneOS_AppleTV5,3_…_Restore` for an Apple TV),+ /// and `iPhoneOS_AppleTV5,3_…_Restore` for an Apple TV, `iPhoneOS_Watch7,18_…`+ /// for an Apple Watch),/// for configs written before the key.static func guestProductType(in folder: URL) -> String? {let config = NSDictionary(contentsOf: folder.appendingPathComponent("config.plist"))@@ -168,7 +175,7 @@ nonisolated struct VPhoneLaunchpadMachine: Decodable, Hashable, Identifiable, Selet 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|AppleTV)\d+,\d+/) != nil }) {+ if let type = name.split(separator: "_").first(where: { $0.wholeMatch(of: /(iPhone|iPad|AppleTV|Watch)\d+,\d+/) != nil }) {return String(type)}}@@ -261,7 +268,7 @@ nonisolated struct VPhoneLaunchpadFirmwareCatalog: Decodable, Sendable {/// The product type `fw prepare --device` takes.let productType: Stringlet name: String- /// `iPhone`, `iPad` or `appleTV`.+ /// `iPhone`, `iPad`, `appleTV` or `watch`.let family: Stringlet pairings: [Pairing]@@ -277,9 +284,13 @@ nonisolated struct VPhoneLaunchpadFirmwareCatalog: Decodable, Sendable {family == "appleTV"}+ var isWatch: Bool {+ family == "watch"+ }+/// The system its IPSWs install.var osName: String {- isAppleTV ? "tvOS" : isPad ? "iPadOS" : "iOS"+ isWatch ? "watchOS" : isAppleTV ? "tvOS" : isPad ? "iPadOS" : "iOS"}/// The name with its product type, `iPhone 16 (iPhone17,3)`: Launchpaddiff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineView.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineView.swiftindex fae2d083..21612052 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineView.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineView.swift@@ -91,6 +91,13 @@ struct VPhoneLaunchpadNewMachineView: View {usesOwnCloudOS && !usesCustomSources ? selectedPairing?.matchingCloudOS : nil}+ /// Whether `fw patch` rebuilds the kernelcache, which needs the ipsw: on+ /// the release's own cloudOS, and always for a watch, whose kexts no+ /// cloudOS kernelcache has.+ private var rebuildsKernelcache: Bool {+ ownCloudOS != nil || !usesCustomSources && selectedGuest?.isWatch == true+ }+private var hasKernelcacheIPSW: Bool {FileManager.default.isExecutableFile(atPath: kernelcacheIPSW)}@@ -182,7 +189,7 @@ struct VPhoneLaunchpadNewMachineView: View {private var canCreate: Bool {nameProblem == nil && advancedProblem == nil && sources != nil && bundleVersion != nil- && (ownCloudOS == nil || hasKernelcacheIPSW)+ && (!rebuildsKernelcache || hasKernelcacheIPSW)}var body: some View {@@ -411,6 +418,11 @@ struct VPhoneLaunchpadNewMachineView: View {? "On its own cloudOS, \(own.name): the kernelcache is rebuilt, which asks for administrator access once.": "Choose an ipsw with `kernel extract --kdk` in Advanced Options to run on \(own.name).").foregroundStyle(hasKernelcacheIPSW ? Color.secondary : Color.red)+ } else if rebuildsKernelcache, let cloudOS = selectedPairing?.recommendedCloudOS.name {+ Text(hasKernelcacheIPSW+ ? "With \(cloudOS): the kernelcache is rebuilt with the watch's kexts, which asks for administrator access once."+ : "Choose an ipsw with `kernel extract --kdk` in Advanced Options: the watch's kernelcache is rebuilt with its kexts.")+ .foregroundStyle(hasKernelcacheIPSW ? Color.secondary : Color.red)} else if let selectedGuest, let cloudOS = selectedPairing?.recommendedCloudOS.name {Text("Recommended firmware pairings for \(selectedGuest.detailedName), with \(cloudOS).").foregroundStyle(.secondary)@@ -594,6 +606,9 @@ struct VPhoneLaunchpadNewMachineView: View {}} else {LabeledContent("cloudOS", value: selectedPairing?.recommendedCloudOS.name ?? "—")+ if rebuildsKernelcache {+ sourceField("ipsw", $kernelcacheIPSW)+ }}} header: {Text("Firmware")@@ -602,6 +617,8 @@ struct VPhoneLaunchpadNewMachineView: View {? "These two files replace the device and version chosen on the basic page.": ownCloudOS != nil? "On its own cloudOS the release boots its own kernel, rebuilt with the vphone600 virtualisation kexts: the ipsw (with `kernel extract --kdk`) stages it as you, and the helper links it as root."+ : rebuildsKernelcache+ ? "A watch boots the cloudOS kernel rebuilt with its own kexts: the ipsw (with `kernel extract --kdk`) stages it as you, and the helper links it as root.": "The device and version are chosen on the basic page; cloudOS goes with them.").foregroundStyle(.secondary)}@@ -732,16 +749,17 @@ struct VPhoneLaunchpadNewMachineView: View {/// Select a guest device and its newest release.private func choose(_ productType: String?) {- let wasAppleTV = isAppleTVGuest+ let hadOwnPreset = hasOwnPresetGuestlet wasGuest = guestguest = productTypepairing = selectedGuest?.defaultPairing?.id- // Each Apple TV starts from a preset of its own.- guard isAppleTVGuest != wasAppleTV || isAppleTVGuest && wasGuest != productType else { return }- // An Apple TV guest is restored on its own with a tvOS preset:- // templates and slimming drive iOS Setup Assistant and its apps.+ // Each Apple TV and Apple Watch starts from a preset of its own.+ guard hasOwnPresetGuest != hadOwnPreset || hasOwnPresetGuest && wasGuest != productType else { return }+ // An Apple TV or Apple Watch guest is restored on its own with a+ // preset of its own: templates and slimming drive iOS Setup Assistant+ // and its apps.patches = VPhoneLaunchpadPatchSelection()- if isAppleTVGuest {+ if hasOwnPresetGuest {patches.preset = VPhoneLaunchpadPatchSelection.defaultPreset(forDevice: productType)usesTemplate = falseslimming.slim = false@@ -757,6 +775,11 @@ struct VPhoneLaunchpadNewMachineView: View {!usesCustomSources && selectedGuest?.isAppleTV == true}+ /// An Apple TV or Apple Watch from the catalog: each has a preset of its own.+ private var hasOwnPresetGuest: Bool {+ !usesCustomSources && (selectedGuest?.isAppleTV == true || selectedGuest?.isWatch == true)+ }+/// Read again whenever the preset or the version changes: `inPreset`, which/// the note and the editor read the checkmarks against, is reported per/// preset, and each version declares its own patches.@@ -803,8 +826,9 @@ struct VPhoneLaunchpadNewMachineView: View {iphoneSource: iphone,cloudOSSource: cloudOS,// An iPad IPSW often covers two sizes; name the one chosen. An- // Apple TV is named too, so the restore tree and log say which.- device: usesCustomSources ? nil : selectedGuest.flatMap { $0.isPad || $0.isAppleTV ? $0.productType : nil },+ // Apple TV or Apple Watch is named too, so the restore tree and+ // log say which.+ device: usesCustomSources ? nil : selectedGuest.flatMap { $0.isPad || $0.isAppleTV || $0.isWatch ? $0.productType : nil },cpuCount: cpu,memoryMB: memoryMB,diskSizeGB: diskSizeGB,@@ -814,7 +838,7 @@ struct VPhoneLaunchpadNewMachineView: View {keepArtifacts: keepArtifacts,usesTemplate: usesTemplate,slimming: slimming,- kernelcacheIPSW: ownCloudOS == nil ? nil : kernelcacheIPSW,+ kernelcacheIPSW: rebuildsKernelcache ? kernelcacheIPSW : nil,)let pipeline = model.machines.create(options)model.machines.selection = [pipeline.machine]diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchCatalog.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchCatalog.swiftindex 9c25b7c3..39923cec 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchCatalog.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchCatalog.swift@@ -287,12 +287,16 @@ nonisolated struct VPhoneLaunchpadPatchSelection: Hashable, Sendable {/// no boot chain: `fw patch` runs as root, and nothing writes the system/// afterwards, so there is no template and no slimming.static let minimalPreset = "minimal"+ /// The preset an Apple Watch guest gets, mirroring+ /// `VPhonePatchPreset.watchOSIdentifier`: `minimal` for the watch board.+ static let watchOSPreset = "watchos"/// The preset a new machine of `productType` starts from.static func defaultPreset(forDevice productType: String?) -> String {switch productType {case "AppleTV14,1": tvOS4KPresetcase let type? where type.hasPrefix("AppleTV"): tvOSPreset+ case let type? where type.hasPrefix("Watch"): watchOSPresetdefault: defaultPreset}}@@ -321,7 +325,7 @@ nonisolated struct VPhoneLaunchpadPatchSelection: Hashable, Sendable {/// The `--preset` flag `fw patch` and `fw patches` carry, if any.var customisesRestoredSystem: Bool {- preset == Self.minimalPreset+ preset == Self.minimalPreset || preset == Self.watchOSPreset}var presetArguments: [String] {diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadTemplates.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadTemplates.swiftindex 35c5c971..75f45901 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadTemplates.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadTemplates.swift@@ -436,7 +436,7 @@ nonisolated struct VPhoneLaunchpadTemplate: Decodable, Identifiable, Hashable, S}var osName: String {- device.hasPrefix("iPad") ? "iPadOS" : "iOS"+ device.hasPrefix("iPad") ? "iPadOS" : device.hasPrefix("Watch") ? "watchOS" : "iOS"}}