Run a virtual iPhone on an Apple Silicon Mac.
Swift
Page the machine settings and New Machine sheets with a segmented control
Jacky293a74c3dc8f
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swiftindex 23486ea6..2f524f68 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift@@ -17,6 +17,9 @@static let sheetNotification = Notification.Name("VPhoneLaunchpadPreviewSheet")/// The source a Core Bundle sheet opens on.static var coreBundleSource = VPhoneLaunchpadCoreBundleView.Source.releases+ /// The pages New Machine and machine settings open on.+ static var newMachinePage = VPhoneLaunchpadNewMachineView.Page.general+ static var machineSettingsPage = VPhoneLaunchpadMachineSettingsView.Page.general// MARK: - Driver@@ -93,17 +96,11 @@await shot("06-machines-creating", suffix)await sheet(.newMachine, "07-new-machine", suffix)- await standalone("07b-new-machine-advanced", suffix, size: NSSize(width: 520, height: 560)) {- VPhoneLaunchpadNewMachineAdvancedView(- network: .constant("nat"),- patches: .constant(VPhoneLaunchpadPatchSelection()),- keepArtifacts: .constant(false),- patchCatalog: nil,- patchCatalogError: nil,- reloadPatches: {},- )- .environment(model)- }+ newMachinePage = .hardware+ await sheet(.newMachine, "07-new-machine-hardware", suffix)+ newMachinePage = .advanced+ await sheet(.newMachine, "07-new-machine-advanced", suffix)+ newMachinePage = .generalawait sheet(.creation(path("ios27-rc")), "08-creation-progress", suffix)creation.applyPreview(failed: true)await sheet(.creation(path("ios27-rc")), "08b-creation-failed", suffix)@@ -114,6 +111,11 @@model.machines.selection = [labMachine]if let machine = model.machines.selected {await sheet(.settings([machine]), "09-machine-settings", suffix)+ machineSettingsPage = .network+ await sheet(.settings([machine]), "09-machine-settings-network", suffix)+ machineSettingsPage = .forwards+ await sheet(.settings([machine]), "09-machine-settings-forwards", suffix)+ machineSettingsPage = .general}await standalone("09b-patch-settings", suffix, size: NSSize(width: 920, height: 680)) {VPhoneLaunchpadPatchSettingsView(initial: VPhoneLaunchpadPatchSelection()) { _ in }diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadSheet.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadSheet.swiftindex 043121e7..85a1ab47 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadSheet.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadSheet.swift@@ -53,6 +53,27 @@ struct VPhoneLaunchpadSheet<Content: View, Accessory: View, Actions: View>: View}}+/// A segmented control over a sheet's form that shows one page of it at a+/// time, so a sheet with several groups of settings stays short instead of+/// growing past the screen. The sheet resizes to the page, as a settings+/// window does.+struct VPhoneLaunchpadSheetPages<Page: Hashable, Labels: View>: View {+ @Binding var selection: Page+ @ViewBuilder let labels: Labels++ var body: some View {+ Picker(selection: $selection) {+ labels+ } label: {+ EmptyView()+ }+ .pickerStyle(.segmented)+ .labelsHidden()+ .fixedSize()+ .padding(.top, 16)+ }+}+extension VPhoneLaunchpadSheet where Accessory == EmptyView {init(_ title: Text,diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings b/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstringsindex a8131df6..ca229328 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings@@ -1394,40 +1394,6 @@}}},- "Advanced Options" : {- "localizations" : {- "en" : {- "stringUnit" : {- "state" : "translated",- "value" : "Advanced Options"- }- },- "ja" : {- "stringUnit" : {- "state" : "translated",- "value" : "詳細オプション"- }- },- "ko" : {- "stringUnit" : {- "state" : "translated",- "value" : "고급 옵션"- }- },- "vi" : {- "stringUnit" : {- "state" : "translated",- "value" : "Tùy chọn nâng cao"- }- },- "zh-Hans" : {- "stringUnit" : {- "state" : "translated",- "value" : "高级选项"- }- }- }- },"Advisory" : {"localizations" : {"en" : {@@ -4291,40 +4257,6 @@}}},- "Edit…" : {- "localizations" : {- "en" : {- "stringUnit" : {- "state" : "translated",- "value" : "Edit…"- }- },- "ja" : {- "stringUnit" : {- "state" : "translated",- "value" : "編集…"- }- },- "ko" : {- "stringUnit" : {- "state" : "translated",- "value" : "편집…"- }- },- "vi" : {- "stringUnit" : {- "state" : "translated",- "value" : "Sửa…"- }- },- "zh-Hans" : {- "stringUnit" : {- "state" : "translated",- "value" : "编辑…"- }- }- }- },"Effect" : {"localizations" : {"en" : {@@ -13015,6 +12947,24 @@"zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "此模式不能转发端口,保存后会移除端口转发。" } }}},+ "Port forwarding needs NAT or Tunnel. Change the mode in Network." : {+ "localizations" : {+ "en" : { "stringUnit" : { "state" : "translated", "value" : "Port forwarding needs NAT or Tunnel. Change the mode in Network." } },+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "ポートフォワーディングには NAT またはトンネルが必要です。モードは「ネットワーク」で変更します。" } },+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "포트 포워딩에는 NAT 또는 터널이 필요합니다. 모드는 네트워크에서 변경하세요." } },+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "Chuyển tiếp cổng cần NAT hoặc Đường hầm. Đổi chế độ trong Mạng." } },+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "端口转发需要 NAT 或隧道模式,请在“网络”中更改模式。" } }+ }+ },+ "General" : {+ "localizations" : {+ "en" : { "stringUnit" : { "state" : "translated", "value" : "General" } },+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "一般" } },+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "일반" } },+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "Chung" } },+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "通用" } }+ }+ },"mDNS Name" : {"localizations" : {"en" : { "stringUnit" : { "state" : "translated", "value" : "mDNS Name" } },@@ -13503,4 +13453,4 @@}},"version" : "1.0"-}\ No newline at end of file+}diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineSheets.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineSheets.swiftindex f4e2f799..5d0b785a 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineSheets.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineSheets.swift@@ -7,15 +7,20 @@ import SwiftUI/// fields start from the first machine; only the ones edited are written, to/// every machine, so values the machines do not share are left alone. A fixed/// address, a MAC and forwarded ports belong to one machine, so they are only-/// offered when one is selected.+/// offered when one is selected, on pages of their own.struct VPhoneLaunchpadMachineSettingsView: View {private enum Field {case cpu, memory, network, address, mac, forwards, mdns, macName, unlock}+ enum Page: Hashable {+ case general, network, forwards+ }+let machines: [VPhoneLaunchpadMachine]@Environment(VPhoneLaunchpadModel.self) private var model@Environment(\.dismiss) private var dismiss+ @State private var page = Page.general@State private var cpu: Int@State private var memoryMB: Int@State private var network: String@@ -104,55 +109,35 @@ struct VPhoneLaunchpadMachineSettingsView: View {var body: some View {VPhoneLaunchpadSheet(title) {- Form {- Section {- Stepper("CPU: \(cpu) cores", value: $cpu, in: 1 ... ProcessInfo.processInfo.activeProcessorCount)- Stepper("Memory: \(memoryMB) MB", value: $memoryMB, in: 2048 ... 65536, step: 1024)- } header: {- Text("Hardware")- }- Section {- Picker("Mode", selection: $network) {- Text("NAT").tag("nat")- Text("Bridged").tag("bridged")- Text("Tunnel").tag("tunnel")- Text("None").tag("none")+ VStack(spacing: 0) {+ // Several machines share only hardware, the network mode and+ // startup, which fit on one page.+ if single {+ VPhoneLaunchpadSheetPages(selection: $page) {+ Text("General").tag(Page.general)+ Text("Network").tag(Page.network)+ Text("Port Forwarding").tag(Page.forwards)}- if network == "bridged" {- TextField("Interface", text: $bridgeInterface, prompt: Text("First available"))+ }+ Form {+ if !single || page == .general {+ hardwareSection}- if network == "tunnel" {- Text("Traffic leaves through this Mac's own connections, so it follows the Mac's VPN.")- .foregroundStyle(.secondary)+ if !single || page == .network {+ networkSection+ if single {+ addressSection+ }}- if dropsForwards {- Text("This mode cannot forward ports, so saving removes the port forwards.")- .foregroundStyle(.secondary)+ if single, page == .forwards {+ forwardsSection}- } header: {- Text("Network")- } footer: {- if machines.count > 1 {- Text("Only the settings you change are applied to each machine.")- .foregroundStyle(.secondary)+ if !single || page == .general {+ startupSection}}- if single {- addressSection- }- if single, forwardsSupported {- forwardsSection- }- Section {- Toggle("Unlock at startup", isOn: $unlocksAtStartup)- } header: {- Text("Startup")- } footer: {- Text("Each time the guest starts, its screen is turned on and the Lock Screen dismissed.")- .foregroundStyle(.secondary)- }+ .formStyle(.grouped)}- .formStyle(.grouped)} actions: {Button("Cancel") { dismiss() }.keyboardShortcut(.cancelAction)@@ -175,6 +160,64 @@ struct VPhoneLaunchpadMachineSettingsView: View {.onChange(of: advertisesName) { edited.insert(.mdns) }.onChange(of: resolvesMacName) { edited.insert(.macName) }.onChange(of: unlocksAtStartup) { edited.insert(.unlock) }+ #if DEBUG+ .onAppear {+ if VPhoneLaunchpadPreview.isActive {+ page = VPhoneLaunchpadPreview.machineSettingsPage+ }+ }+ #endif+ }++ private var hardwareSection: some View {+ Section {+ Stepper("CPU: \(cpu) cores", value: $cpu, in: 1 ... ProcessInfo.processInfo.activeProcessorCount)+ Stepper("Memory: \(memoryMB) MB", value: $memoryMB, in: 2048 ... 65536, step: 1024)+ } header: {+ Text("Hardware")+ }+ }++ private var startupSection: some View {+ Section {+ Toggle("Unlock at startup", isOn: $unlocksAtStartup)+ } header: {+ Text("Startup")+ } footer: {+ Text("Each time the guest starts, its screen is turned on and the Lock Screen dismissed.")+ .foregroundStyle(.secondary)+ }+ }++ private var networkSection: some View {+ Section {+ Picker("Mode", selection: $network) {+ Text("NAT").tag("nat")+ Text("Bridged").tag("bridged")+ Text("Tunnel").tag("tunnel")+ Text("None").tag("none")+ }+ if network == "bridged" {+ TextField("Interface", text: $bridgeInterface, prompt: Text("First available"))+ }+ if network == "tunnel" {+ Text("Traffic leaves through this Mac's own connections, so it follows the Mac's VPN.")+ .foregroundStyle(.secondary)+ }+ if dropsForwards {+ Text("This mode cannot forward ports, so saving removes the port forwards.")+ .foregroundStyle(.secondary)+ }+ } header: {+ if !single {+ Text("Network")+ }+ } footer: {+ if machines.count > 1 {+ Text("Only the settings you change are applied to each machine.")+ .foregroundStyle(.secondary)+ }+ }}private var addressSection: some View {@@ -217,7 +260,23 @@ struct VPhoneLaunchpadMachineSettingsView: View {}}+ /// The page stays when the mode cannot forward, so the segments do not+ /// change under the pointer; it says why it is empty instead.+ @ViewBuilderprivate var forwardsSection: some View {+ if forwardsSupported {+ forwardsList+ } else {+ Section {+ Text(dropsForwards+ ? "This mode cannot forward ports, so saving removes the port forwards."+ : "Port forwarding needs NAT or Tunnel. Change the mode in Network.")+ .foregroundStyle(.secondary)+ }+ }+ }++ private var forwardsList: some View {Section {ForEach(forwards, id: \.self) { forward inHStack {@@ -255,8 +314,6 @@ struct VPhoneLaunchpadMachineSettingsView: View {.help("Add")}Toggle("Reachable from other devices", isOn: $newOnAllAddresses)- } header: {- Text("Port Forwarding")} footer: {Text("A forwarded port listens on this Mac only, unless it is reachable from other devices.").foregroundStyle(.secondary)diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineAdvancedView.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineAdvancedView.swiftindex 2627c467..c7e9b8bb 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineAdvancedView.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineAdvancedView.swift@@ -1,7 +1,7 @@import SwiftUI-/// New Machine's second page: network, patches and restore options. It edits-/// New Machine's own state, so Done only closes it.+/// New Machine's Advanced page: network, patches and restore options, as+/// sections of New Machine's form. It edits New Machine's own state.struct VPhoneLaunchpadNewMachineAdvancedView: View {@Binding var network: String@Binding var patches: VPhoneLaunchpadPatchSelection@@ -15,53 +15,26 @@ struct VPhoneLaunchpadNewMachineAdvancedView: View {var bundleVersion: String?@Environment(VPhoneLaunchpadModel.self) private var model- @Environment(\.dismiss) private var dismiss@State private var showsPatchSettings = false- static func networkTitle(_ mode: String) -> String {- switch mode {- case "bridged": String(localized: "Bridged")- case "tunnel": String(localized: "Tunnel")- case "none": String(localized: "None")- default: String(localized: "NAT")- }- }-var body: some View {- VPhoneLaunchpadSheet(Text("Advanced Options")) {- Form {- Section("Network") {- Picker("Mode", selection: $network) {- Text("NAT").tag("nat")- Text("Bridged").tag("bridged")- Text("Tunnel").tag("tunnel")- Text("None").tag("none")- }- if network == "tunnel" {- Text("Traffic leaves through this Mac's own connections, so it follows the Mac's VPN.")- .foregroundStyle(.secondary)- }- }-- patchSection-- Section("Options") {- Toggle("Keep prepared restore files", isOn: $keepArtifacts)- }+ Section("Network") {+ Picker("Mode", selection: $network) {+ Text("NAT").tag("nat")+ Text("Bridged").tag("bridged")+ Text("Tunnel").tag("tunnel")+ Text("None").tag("none")}- .formStyle(.grouped)- } actions: {- Button("Done") { dismiss() }- .keyboardShortcut(.defaultAction)- }- .frame(width: 520)- .fixedSize(horizontal: false, vertical: true)- .sheet(isPresented: $showsPatchSettings) {- VPhoneLaunchpadPatchSettingsView(initial: patches, bundleVersion: bundleVersion) { selection in- patches = selection- reloadPatches()+ if network == "tunnel" {+ Text("Traffic leaves through this Mac's own connections, so it follows the Mac's VPN.")+ .foregroundStyle(.secondary)}- .environment(model)+ }++ patchSection++ Section("Options") {+ Toggle("Keep prepared restore files", isOn: $keepArtifacts)}}@@ -77,6 +50,13 @@ struct VPhoneLaunchpadNewMachineAdvancedView: View {}LabeledContent("Patches") {Button("Patch Settings…") { showsPatchSettings = true }+ .sheet(isPresented: $showsPatchSettings) {+ VPhoneLaunchpadPatchSettingsView(initial: patches, bundleVersion: bundleVersion) { selection in+ patches = selection+ reloadPatches()+ }+ .environment(model)+ }}} else if let patchCatalogError {Label(patchCatalogError, systemImage: "exclamationmark.triangle")diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineView.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineView.swiftindex c0cf92b7..58325ee3 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineView.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineView.swift@@ -2,7 +2,8 @@ import AppKitimport SwiftUI/// Name, location, Core Bundle, guest device and firmware pairing from-/// `fw catalog`, hardware and options.+/// `fw catalog`, hardware and options, on three pages. Every page has+/// defaults, so Create works from any of them./// Create hands off to the pipeline sheet.struct VPhoneLaunchpadNewMachineView: View {let onCreate: (VPhoneLaunchpadMachinePath) -> Void@@ -31,8 +32,12 @@ struct VPhoneLaunchpadNewMachineView: View {@State private var patches = VPhoneLaunchpadPatchSelection()@State private var patchCatalog: VPhoneLaunchpadPatchCatalog?@State private var patchCatalogError: String?- @State private var showsAdvanced = false@State private var keepArtifacts = false+ @State private var page = Page.general++ enum Page: Hashable {+ case general, hardware, advanced+ }private var selectedGuest: VPhoneLaunchpadFirmwareCatalog.Device? {catalog?.guests.first { $0.id == guest }@@ -108,33 +113,49 @@ struct VPhoneLaunchpadNewMachineView: View {var body: some View {VPhoneLaunchpadSheet(Text("New Machine")) {- Form {- Section {- TextField("Name", text: $name)- locationPicker- } footer: {- if let problem = nameProblem ?? locationProblem {- Text(problem).foregroundStyle(.red)- }+ VStack(spacing: 0) {+ VPhoneLaunchpadSheetPages(selection: $page) {+ Text("General").tag(Page.general)+ Text("Hardware").tag(Page.hardware)+ Text("Advanced").tag(Page.advanced)}+ Form {+ switch page {+ case .general:+ Section {+ TextField("Name", text: $name)+ locationPicker+ } footer: {+ if let problem = nameProblem ?? locationProblem {+ Text(problem).foregroundStyle(.red)+ }+ }- bundleSection-- firmware+ bundleSection- Section {- Stepper("CPU: \(cpu) cores", value: $cpu, in: 1 ... ProcessInfo.processInfo.activeProcessorCount)- Stepper("Memory: \(memoryMB) MB", value: $memoryMB, in: 2048 ... 65536, step: 1024)- Stepper("Disk: \(diskSizeGB) GB", value: $diskSizeGB, in: 32 ... 512, step: 16)- } header: {- Text("Hardware")- } footer: {- Text(spaceNote).foregroundStyle(.secondary)+ firmware+ case .hardware:+ Section {+ Stepper("CPU: \(cpu) cores", value: $cpu, in: 1 ... ProcessInfo.processInfo.activeProcessorCount)+ Stepper("Memory: \(memoryMB) MB", value: $memoryMB, in: 2048 ... 65536, step: 1024)+ Stepper("Disk: \(diskSizeGB) GB", value: $diskSizeGB, in: 32 ... 512, step: 16)+ } footer: {+ Text(spaceNote).foregroundStyle(.secondary)+ }+ case .advanced:+ VPhoneLaunchpadNewMachineAdvancedView(+ network: $network,+ patches: $patches,+ keepArtifacts: $keepArtifacts,+ patchCatalog: patchCatalog,+ patchCatalogError: patchCatalogError,+ reloadPatches: { Task { await loadPatchCatalog() } },+ bundleVersion: bundleVersion,+ )+ }}-- advancedSection+ .formStyle(.grouped)}- .formStyle(.grouped)} actions: {Button("Cancel") { dismiss() }.keyboardShortcut(.cancelAction)@@ -144,18 +165,6 @@ struct VPhoneLaunchpadNewMachineView: View {}.frame(width: 560).fixedSize(horizontal: false, vertical: true)- .sheet(isPresented: $showsAdvanced) {- VPhoneLaunchpadNewMachineAdvancedView(- network: $network,- patches: $patches,- keepArtifacts: $keepArtifacts,- patchCatalog: patchCatalog,- patchCatalogError: patchCatalogError,- reloadPatches: { Task { await loadPatchCatalog() } },- bundleVersion: bundleVersion,- )- .environment(model)- }// Each bundle version has its own firmware pairings and patch sets..task(id: bundleVersion) { await loadCatalog() }.task(id: bundleVersion) { await loadPatchCatalog() }@@ -163,43 +172,12 @@ struct VPhoneLaunchpadNewMachineView: View {let root = model.machines.preferredRootlocation = rootname = suggestedName(in: root)- }- }-- // MARK: - Advanced-- /// Network, patches and restore options, which rarely change, behind one row.- private var advancedSection: some View {- Section {- LabeledContent("Advanced") {- HStack(spacing: 8) {- Text(verbatim: advancedSummary)- .foregroundStyle(.secondary)- .lineLimit(1)- .truncationMode(.tail)- Button("Edit…") { showsAdvanced = true }+ #if DEBUG+ if VPhoneLaunchpadPreview.isActive {+ page = VPhoneLaunchpadPreview.newMachinePage}- }- } footer: {- let essentialOff = patchCatalog.map { patches.bootEssentialOff(in: $0) } ?? []- if !essentialOff.isEmpty {- Label {- Text("^[\(essentialOff.count) boot-essential patch](inflect: true) off: \(essentialOff.map(\.identifier).joined(separator: ", "))")- } icon: {- Image(systemName: "exclamationmark.triangle.fill")- }- .foregroundStyle(.orange)- }- }- }-- /// The network mode and the patch preset, the two choices most likely to matter.- private var advancedSummary: String {- let network = VPhoneLaunchpadNewMachineAdvancedView.networkTitle(network)- guard let preset = patchCatalog?.preset(patches.preset)?.displayTitle else {- return network+ #endif}- return "\(network) · \(preset)"}// MARK: - Core Bundle