Run a virtual iPhone on an Apple Silicon Mac.
Swift
Batch actions, export progress and cancel in Launchpad
Lakr73bbf18ba0d6
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Support/VPhoneProgressBar.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Support/VPhoneProgressBar.swiftindex 44d22a4e..ab0e897d 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Support/VPhoneProgressBar.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Support/VPhoneProgressBar.swift@@ -5,9 +5,17 @@ import Foundation/// A single-line, redrawing byte progress bar for long transfers. Renders to/// stderr only when it is a TTY, so piped/`--json`/GUI-subprocess invocations/// (stdout consumed elsewhere) stay clean and the bar simply no-ops.+///+/// A caller that reads the output through a pipe, such as vphone-launchpad,+/// sets `VPHONE_PROGRESS=lines` to get `progress <done> <total>` lines on+/// stderr instead, at most a few per second.final class VPhoneProgressBar {+ private enum Mode {+ case off, bar, lines+ }+private let label: String- private let enabled: Bool+ private let mode: Modeprivate let start = Date()private let width = 28private var lastRender = Date.distantPast@@ -15,27 +23,44 @@ final class VPhoneProgressBar {init(label: String) {self.label = label- enabled = isatty(FileHandle.standardError.fileDescriptor) != 0+ mode = if isatty(FileHandle.standardError.fileDescriptor) != 0 {+ .bar+ } else if ProcessInfo.processInfo.environment["VPHONE_PROGRESS"] == "lines" {+ .lines+ } else {+ .off+ }}func update(done: Int64, total: Int64) {- guard enabled else { return }+ guard mode != .off else { return }self.total = totallet now = Date()- if done < total, now.timeIntervalSince(lastRender) < 0.066 {+ let interval = mode == .bar ? 0.066 : 0.25 // ~15 fps, or 4 lines a second+ if done < total, now.timeIntervalSince(lastRender) < interval {return- } // ~15 fps+ }lastRender = nowrender(done: done, now: now)}func finish() {- guard enabled else { return }- render(done: total, now: Date())- FileHandle.standardError.write(Data("\n".utf8))+ switch mode {+ case .off:+ return+ case .bar:+ render(done: total, now: Date())+ FileHandle.standardError.write(Data("\n".utf8))+ case .lines:+ render(done: total, now: Date())+ }}private func render(done: Int64, now: Date) {+ if mode == .lines {+ FileHandle.standardError.write(Data("progress \(done) \(total)\n".utf8))+ return+ }let frac = total > 0 ? min(1.0, Double(done) / Double(total)) : 0let filled = Int(frac * Double(width))let bar = String(repeating: "█", count: filled) + String(repeating: "░", count: width - filled)diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swiftindex 9aa6805b..2c1fd522 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift@@ -103,11 +103,11 @@}model.machines.selection = [labMachine]if let machine = model.machines.selected {- await sheet(.settings(machine), "09-machine-settings", suffix)+ await sheet(.settings([machine]), "09-machine-settings", suffix)}await sheet(.patches(labMachine), "09b-patch-settings", suffix)await sheet(.clone(labMachine), "10-clone", suffix)- await sheet(.export(labMachine), "11-export", suffix)+ await sheet(.export([labMachine]), "11-export", suffix)await sheet(.console(path("research-01")), "12-console", suffix)}NSApp.terminate(nil)diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadChildProcess.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadChildProcess.swiftindex d4c4af8b..d15b4791 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadChildProcess.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadChildProcess.swift@@ -67,6 +67,11 @@ final nonisolated class VPhoneLaunchpadChildProcess: @unchecked Sendable {let pipe = Pipe()process.standardOutput = pipeprocess.standardError = pipe+ // Transfers report `progress <done> <total>` lines instead of a+ // terminal bar, which the pipe would drop.+ var environment = ProcessInfo.processInfo.environment+ environment["VPHONE_PROGRESS"] = "lines"+ process.environment = environmenttry process.run()let reader = pipe.fileHandleForReadingThread.detachNewThread { [self] indiff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadCommandLine.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadCommandLine.swiftindex 0f415649..ac1d443a 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadCommandLine.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadCommandLine.swift@@ -108,16 +108,32 @@ struct VPhoneLaunchpadCommandLine {return plain && !argument.isEmpty ? argument : "'\(argument.replacingOccurrences(of: "'", with: "'\\''"))'"}+ /// The fraction a `progress <done> <total>` line reports, or nil for any+ /// other line.+ nonisolated static func progress(in line: String) -> Double? {+ let fields = line.split(separator: " ")+ guard fields.count == 3, fields[0] == "progress",+ let done = Double(fields[1]), let total = Double(fields[2]), total > 0+ else { return nil }+ return min(1, done / total)+ }+/// Runs to completion. Cancelling the calling task sends SIGINT.- /// `onLine` runs on the reader thread, never on the main actor.+ /// `onLine` and `onProgress` run on the reader thread, never on the main+ /// actor. Progress lines go only to `onProgress`, never to the output.func run(_ arguments: [String],recordInHistory: Bool = true,onLine: (@Sendable (String) -> Void)? = nil,+ onProgress: (@Sendable (Double) -> Void)? = nil,) async throws -> VPhoneLaunchpadCommandResult {let entry = recordInHistory ? history.record(Self.display(arguments)) : nillet collector = VPhoneLaunchpadLineCollector()let child = try VPhoneLaunchpadChildProcess(executable: executable, arguments: arguments) { line in+ if let fraction = Self.progress(in: line) {+ onProgress?(fraction)+ return+ }collector.append(line)onLine?(line)}@@ -137,8 +153,9 @@ struct VPhoneLaunchpadCommandLine {func runChecked(_ arguments: [String],onLine: (@Sendable (String) -> Void)? = nil,+ onProgress: (@Sendable (Double) -> Void)? = nil,) async throws -> VPhoneLaunchpadCommandResult {- let result = try await run(arguments, onLine: onLine)+ let result = try await run(arguments, onLine: onLine, onProgress: onProgress)try Task.checkCancellation()guard result.succeeded else {throw VPhoneLaunchpadError(diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings b/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstringsindex 21f35b50..583e3397 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings@@ -1645,6 +1645,40 @@}}},+ "Cancel Export" : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Cancel Export"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "書き出しをキャンセル"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "내보내기 취소"+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Hủy xuất"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "取消导出"+ }+ }+ }+ },"Cannot create an authorization (OSStatus %d)." : {"localizations" : {"en" : {@@ -3255,6 +3289,40 @@}}},+ "Creates a .tzst archive for each machine in the folder you choose." : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Creates a .tzst archive for each machine in the folder you choose."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "選択したフォルダに、マシンごとの .tzst アーカイブを作成します。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "선택한 폴더에 머신마다 .tzst 아카이브를 만듭니다."+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Tạo một bản lưu trữ .tzst cho mỗi máy trong thư mục bạn chọn."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "在你选择的文件夹中为每台虚拟机创建一个 .tzst 归档。"+ }+ }+ }+ },"Creates a smaller .txz archive. Export takes much longer." : {"localizations" : {"en" : {@@ -4275,6 +4343,40 @@}}},+ "Export" : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Export"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "書き出す"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "내보내기"+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Xuất"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "导出"+ }+ }+ }+ },"Export %@" : {"localizations" : {"en" : {@@ -4343,6 +4445,40 @@}}},+ "Export %lld Machines" : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Export %lld Machines"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%lld 台のマシンを書き出す"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "머신 %lld대 내보내기"+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Xuất %lld máy"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "导出 %lld 台虚拟机"+ }+ }+ }+ },"Export…" : {"localizations" : {"en" : {@@ -7540,6 +7676,40 @@}}},+ "Only the settings you change are applied to each machine." : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Only the settings you change are applied to each machine."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "変更した設定だけが各マシンに適用されます。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "변경한 설정만 각 머신에 적용됩니다."+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Chỉ những cài đặt bạn thay đổi mới được áp dụng cho từng máy."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "只有你更改的设置会应用到每台虚拟机。"+ }+ }+ }+ },"Open Console" : {"localizations" : {"en" : {@@ -9750,6 +9920,40 @@}}},+ "Settings for %lld Machines" : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Settings for %lld Machines"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%lld 台のマシンの設定"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "머신 %lld대 설정"+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Cài đặt cho %lld máy"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%lld 台虚拟机的设置"+ }+ }+ }+ },"Settings…" : {"localizations" : {"en" : {@@ -13151,6 +13355,40 @@}}},+ "Waiting to export…" : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Waiting to export…"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "書き出し待ち…"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "내보내기 대기 중…"+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Đang chờ xuất…"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "等待导出…"+ }+ }+ }+ },"Writes a .txz archive with xz -9. Smaller, and much slower." : {"localizations" : {"en" : {diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swiftindex 1aef0bc9..8132d2f4 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swift@@ -6,6 +6,8 @@ import SwiftUI/// A machine's run state as the table and the inspector show it.struct VPhoneLaunchpadMachineStateLabel: View {let state: VPhoneLaunchpadMachineLibrary.RunState+ /// An export's progress, shown as a bar in place of the activity text.+ var progress: Double?var body: some View {let (status, text): (VPhoneLaunchpadStatus, String) = switch state {@@ -13,10 +15,21 @@ struct VPhoneLaunchpadMachineStateLabel: View {case .stopped: (.pending, String(localized: "Stopped"))case let .busy(activity): (.running, activity)}- Label {- Text(text).lineLimit(1)- } icon: {- VPhoneLaunchpadStatusIcon(status: status)+ if let progress {+ HStack(spacing: 6) {+ ProgressView(value: progress)+ .controlSize(.small)+ Text(progress, format: .percent.precision(.fractionLength(0)))+ .monospacedDigit()+ .foregroundStyle(.secondary)+ }+ .help(text)+ } else {+ Label {+ Text(text).lineLimit(1)+ } icon: {+ VPhoneLaunchpadStatusIcon(status: status)+ }}}}@@ -46,7 +59,10 @@ struct VPhoneLaunchpadMachineInspector: View {creationSummary(creation)}LabeledContent("State") {- VPhoneLaunchpadMachineStateLabel(state: library.state(of: machine.path))+ VPhoneLaunchpadMachineStateLabel(+ state: library.state(of: machine.path),+ progress: library.exports[machine.path]?.fraction,+ )}if let started = library.startedAt[machine.path] {LabeledContent("Started", value: started.formatted(date: .omitted, time: .shortened))diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swiftindex 009ae520..ef85a90d 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift@@ -97,6 +97,9 @@ final class VPhoneLaunchpadMachineLibrary {if let activity = activities[machine] {return .busy(activity)}+ if exports[machine]?.isWaiting == true {+ return .busy(String(localized: "Waiting to export…"))+ }if launched[machine]?.isRunning == true || externallyRunning.contains(machine) {return .running}@@ -355,7 +358,54 @@ final class VPhoneLaunchpadMachineLibrary {await perform(String(localized: "Deleting…"), on: machine, ["vm", "delete", machine.name, "--force"] + machine.libraryArguments)}- func export(_ machine: Path, to destination: URL, densest: Bool, includeIPSW: Bool) async {+ // MARK: - Export++ /// An export queued or under way. `fraction` is nil until the command+ /// reports progress; `task` is nil while the export waits its turn.+ struct Export {+ var fraction: Double?+ fileprivate var task: Task<Void, Never>?++ var isWaiting: Bool {+ task == nil+ }+ }++ private(set) var exports: [Path: Export] = [:]++ /// Exports each machine to its destination file, one at a time: each+ /// export reads a whole disk image.+ func export(_ items: [(machine: Path, destination: URL)], densest: Bool, includeIPSW: Bool) async {+ for item in items {+ exports[item.machine] = Export()+ }+ for item in items {+ // Cancelled while it waited.+ guard exports[item.machine] != nil else {+ continue+ }+ let task = Task {+ await runExport(item.machine, to: item.destination, densest: densest, includeIPSW: includeIPSW)+ }+ exports[item.machine]?.task = task+ await task.value+ exports[item.machine] = nil+ }+ }++ /// Stops an export under way, or takes a waiting one out of the queue.+ func cancelExport(_ machine: Path) {+ guard let export = exports[machine] else {+ return+ }+ if let task = export.task {+ task.cancel()+ } else {+ exports[machine] = nil+ }+ }++ private func runExport(_ machine: Path, to destination: URL, densest: Bool, includeIPSW: Bool) async {var arguments = ["vm", "export", machine.name, "--out", destination.path] + machine.libraryArgumentsif densest {arguments.append("--max")@@ -363,7 +413,14 @@ final class VPhoneLaunchpadMachineLibrary {if includeIPSW {arguments.append("--include-ipsw")}- await perform(String(localized: "Exporting…"), on: machine, arguments)+ await perform(String(localized: "Exporting…"), on: machine, arguments) { [weak self] fraction in+ Task { @MainActor in self?.exports[machine]?.fraction = fraction }+ }+ // `vm export` writes the archive in place, so a cancelled one leaves+ // a partial file behind.+ if Task.isCancelled {+ try? FileManager.default.removeItem(at: destination)+ }}func importArchive(_ archive: URL) async {@@ -374,8 +431,15 @@ final class VPhoneLaunchpadMachineLibrary {)}+ /// Runs one command with `activity` shown as the machine's state. False+ /// when it failed, or was cancelled, which is not reported as an error.@discardableResult- private func perform(_ activity: String, on machine: Path?, _ arguments: [String]) async -> Bool {+ private func perform(+ _ activity: String,+ on machine: Path?,+ _ arguments: [String],+ onProgress: (@Sendable (Double) -> Void)? = nil,+ ) async -> Bool {guard let commandLine = bundles.commandLine() else {return false}@@ -392,10 +456,14 @@ final class VPhoneLaunchpadMachineLibrary {}}do {- try await commandLine.runChecked(arguments)+ try await commandLine.runChecked(arguments, onProgress: onProgress)await refresh()return true} catch {+ if error is CancellationError || Task.isCancelled {+ await refresh()+ return false+ }actionError = error as? VPhoneLaunchpadError?? VPhoneLaunchpadError(String(localized: "Unable to Complete Action"), detail: error.localizedDescription)await refresh()diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineSheets.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineSheets.swiftindex 9febcff9..0ad7f977 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineSheets.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineSheets.swift@@ -3,21 +3,38 @@ import SwiftUI// MARK: - Settings+/// Hardware and network for one machine, or for several at once. The 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.struct VPhoneLaunchpadMachineSettingsView: View {- let machine: VPhoneLaunchpadMachine+ private enum Field {+ case cpu, memory, network+ }++ let machines: [VPhoneLaunchpadMachine]@Environment(VPhoneLaunchpadModel.self) private var model@Environment(\.dismiss) private var dismiss- @State private var cpu = 8- @State private var memoryMB = 8192- @State private var network = "nat"- @State private var bridgeInterface = ""+ @State private var cpu: Int+ @State private var memoryMB: Int+ @State private var network: String+ @State private var bridgeInterface: String+ @State private var edited: Set<Field> = []++ init(machines: [VPhoneLaunchpadMachine]) {+ self.machines = machines+ let first = machines.first+ _cpu = State(initialValue: first?.cpuCount ?? 8)+ _memoryMB = State(initialValue: first?.memoryMB ?? 8192)+ _network = State(initialValue: first.map { $0.network.mode == "hostOnly" ? "none" : $0.network.mode } ?? "nat")+ _bridgeInterface = State(initialValue: first?.network.bridgeInterface ?? "")+ }- private var currentNetwork: String {- machine.network.mode == "hostOnly" ? "none" : machine.network.mode+ private var title: Text {+ machines.count == 1 ? Text("\(machines[0].name) Settings") : Text("Settings for \(machines.count) Machines")}var body: some View {- VPhoneLaunchpadSheet(Text("\(machine.name) Settings")) {+ VPhoneLaunchpadSheet(title) {Form {Section {Stepper("CPU: \(cpu) cores", value: $cpu, in: 1 ... ProcessInfo.processInfo.activeProcessorCount)@@ -25,7 +42,7 @@ struct VPhoneLaunchpadMachineSettingsView: View {} header: {Text("Hardware")}- Section("Network") {+ Section {Picker("Mode", selection: $network) {Text("NAT").tag("nat")Text("Bridged").tag("bridged")@@ -34,6 +51,13 @@ struct VPhoneLaunchpadMachineSettingsView: View {if network == "bridged" {TextField("Interface", text: $bridgeInterface, prompt: Text("First available"))}+ } header: {+ Text("Network")+ } footer: {+ if machines.count > 1 {+ Text("Only the settings you change are applied to each machine.")+ .foregroundStyle(.secondary)+ }}}.formStyle(.grouped)@@ -42,27 +66,27 @@ struct VPhoneLaunchpadMachineSettingsView: View {.keyboardShortcut(.cancelAction)Button("Save") { save() }.keyboardShortcut(.defaultAction)+ .disabled(edited.isEmpty)}.frame(width: 440).fixedSize(horizontal: false, vertical: true)- .onAppear {- cpu = machine.cpuCount- memoryMB = machine.memoryMB- network = currentNetwork- bridgeInterface = machine.network.bridgeInterface ?? ""- }+ .onChange(of: cpu) { edited.insert(.cpu) }+ .onChange(of: memoryMB) { edited.insert(.memory) }+ .onChange(of: network) { edited.insert(.network) }+ .onChange(of: bridgeInterface) { edited.insert(.network) }}private func save() {- let bridgeChanged = bridgeInterface != (machine.network.bridgeInterface ?? "")+ let cpu = edited.contains(.cpu) ? cpu : nil+ let memoryMB = edited.contains(.memory) ? memoryMB : nil+ let network = edited.contains(.network) ? network : nil+ let bridgeInterface = network == "bridged" ? bridgeInterface : nil+ let paths = machines.map(\.path)+ let library = model.machinesTask {- await model.machines.configure(- machine.path,- cpu: cpu == machine.cpuCount ? nil : cpu,- memoryMB: memoryMB == machine.memoryMB ? nil : memoryMB,- network: network == currentNetwork && !bridgeChanged ? nil : network,- bridgeInterface: network == "bridged" ? bridgeInterface : nil,- )+ for path in paths {+ await library.configure(path, cpu: cpu, memoryMB: memoryMB, network: network, bridgeInterface: bridgeInterface)+ }}dismiss()}@@ -122,28 +146,41 @@ struct VPhoneLaunchpadNameSheet: View {// MARK: - Export+/// One machine offers the archive options. Several are written with the+/// defaults, one `<name>.tzst` each, into a folder chosen once.struct VPhoneLaunchpadExportView: View {- let machine: VPhoneLaunchpadMachinePath+ let machines: [VPhoneLaunchpadMachinePath]@Environment(VPhoneLaunchpadModel.self) private var model@Environment(\.dismiss) private var dismiss@State private var densest = false@State private var includeIPSW = false- private var name: String {- machine.name+ private var title: Text {+ machines.count == 1 ? Text("Export \(machines[0].name)") : Text("Export \(machines.count) Machines")}var body: some View {- VPhoneLaunchpadSheet(Text("Export \(name)")) {+ VPhoneLaunchpadSheet(title) {Form {- Section {- Toggle("Maximum compression", isOn: $densest)- Toggle("Include the restore IPSW directory", isOn: $includeIPSW)- } footer: {- Text(densest- ? "Creates a smaller .txz archive. Export takes much longer."- : "Creates a .tzst archive.")- .foregroundStyle(.secondary)+ if machines.count == 1 {+ Section {+ Toggle("Maximum compression", isOn: $densest)+ Toggle("Include the restore IPSW directory", isOn: $includeIPSW)+ } footer: {+ Text(densest+ ? "Creates a smaller .txz archive. Export takes much longer."+ : "Creates a .tzst archive.")+ .foregroundStyle(.secondary)+ }+ } else {+ Section {+ ForEach(machines, id: \.self) { machine in+ Text(verbatim: "\(machine.name).tzst")+ }+ } footer: {+ Text("Creates a .tzst archive for each machine in the folder you choose.")+ .foregroundStyle(.secondary)+ }}}.formStyle(.grouped)@@ -158,13 +195,30 @@ struct VPhoneLaunchpadExportView: View {}private func choose() {- let panel = NSSavePanel()- panel.title = String(localized: "Export \(name)")- panel.nameFieldStringValue = "\(name).\(densest ? "txz" : "tzst")"- let densest = densest- let includeIPSW = includeIPSW- panel.present { url in- Task { await model.machines.export(machine, to: url, densest: densest, includeIPSW: includeIPSW) }+ let library = model.machines+ if machines.count == 1 {+ let machine = machines[0]+ let panel = NSSavePanel()+ panel.title = String(localized: "Export \(machine.name)")+ panel.nameFieldStringValue = "\(machine.name).\(densest ? "txz" : "tzst")"+ let densest = densest+ let includeIPSW = includeIPSW+ panel.present { url in+ Task { await library.export([(machine, url)], densest: densest, includeIPSW: includeIPSW) }+ dismiss()+ }+ return+ }+ let panel = NSOpenPanel()+ panel.title = String(localized: "Export \(machines.count) Machines")+ panel.prompt = String(localized: "Export")+ panel.canChooseFiles = false+ panel.canChooseDirectories = true+ panel.canCreateDirectories = true+ let machines = machines+ panel.present { folder in+ let items = machines.map { ($0, folder.appendingPathComponent("\($0.name).tzst")) }+ Task { await library.export(items, densest: false, includeIPSW: false) }dismiss()}}diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swiftindex 8d01c699..5c7afdc8 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift@@ -7,22 +7,22 @@ struct VPhoneLaunchpadMachinesView: View {enum Sheet: Identifiable {case newMachinecase creation(MachinePath)- case settings(VPhoneLaunchpadMachine)+ case settings([VPhoneLaunchpadMachine])case patches(MachinePath)case rename(MachinePath)case clone(MachinePath)- case export(MachinePath)+ case export([MachinePath])case console(MachinePath)var id: String {switch self {case .newMachine: "new"case let .creation(machine): "creation-\(machine.url.path)"- case let .settings(machine): "settings-\(machine.path.url.path)"+ case let .settings(machines): "settings-\(machines.map(\.path.url.path).joined(separator: "|"))"case let .patches(machine): "patches-\(machine.url.path)"case let .rename(machine): "rename-\(machine.url.path)"case let .clone(machine): "clone-\(machine.url.path)"- case let .export(machine): "export-\(machine.url.path)"+ case let .export(machines): "export-\(machines.map(\.url.path).joined(separator: "|"))"case let .console(machine): "console-\(machine.url.path)"}}@@ -132,13 +132,30 @@ struct VPhoneLaunchpadMachinesView: View {let stopped = selected.filter { library.state(of: $0.path) == .stopped }let running = selected.filter { library.state(of: $0.path) == .running }// Host Setup and Core Bundle hold the leading edge; the space pushes- // everything here to the trailing edge: Start or Stop for the- // selection, then New Machine and the actions menu. The inspector+ // everything here to the trailing edge: New Machine, then Start or+ // Stop for the selection beside the actions menu. The inspector// toggle is in the inspector.ToolbarItem(placement: .automatic) {Spacer()}ToolbarItem(placement: .automatic) {+ Menu {+ Button("New Machine…") { sheet = .newMachine }+ Button("Import…") { chooseImport() }+ .disabled(library.globalActivity != nil)+ } label: {+ Label("New Machine", systemImage: "plus")+ }+ .menuIndicator(.hidden)+ .help("Create a machine")+ .disabled(model.bundles.activeVersion == nil)+ }+ // Without it, macOS 26 draws New Machine in the same glass capsule+ // as Start.+ if #available(macOS 26, *) {+ ToolbarSpacer(.fixed)+ }+ ToolbarItemGroup(placement: .automatic) {if stopped.isEmpty, !running.isEmpty {Button {stop(running)@@ -155,25 +172,15 @@ struct VPhoneLaunchpadMachinesView: View {.help("Start the selected machine").disabled(stopped.isEmpty)}- }- ToolbarItemGroup(placement: .automatic) {- Button {- sheet = .newMachine- } label: {- Label("New Machine", systemImage: "plus")- }- .help("Create a machine")- .disabled(model.bundles.activeVersion == nil)Menu {machineActions(selected)- if !selected.isEmpty {- Divider()- }- Button("Import…") { chooseImport() }- .disabled(library.globalActivity != nil || model.bundles.activeVersion == nil)} label: {Label("Actions", systemImage: "ellipsis")}+ .disabled(selected.isEmpty)+ // A menu with its arrow gets a capsule of its own; without it the+ // menu shares Start's.+ .menuIndicator(.hidden)}}@@ -203,12 +210,31 @@ struct VPhoneLaunchpadMachinesView: View {}/// The same actions in the toolbar menu and the table's context menu.- /// Several machines get the actions that apply to each of them.+ /// Several machines get the batch actions: one settings edit, export and+ /// delete, which need every machine stopped, then start and stop.@ViewBuilderprivate func machineActions(_ machines: [VPhoneLaunchpadMachine]) -> some View {+ // Only while one of them is exporting or waiting to.+ let exporting = machines.filter { library.exports[$0.path] != nil }+ if !exporting.isEmpty {+ Button("Cancel Export") {+ for machine in exporting {+ library.cancelExport(machine.path)+ }+ }+ Divider()+ }if machines.count > 1 {let stopped = machines.filter { library.state(of: $0.path) == .stopped }let running = machines.filter { library.state(of: $0.path) == .running }+ let allStopped = stopped.count == machines.count+ Button("Settings…") { sheet = .settings(machines) }+ .disabled(!allStopped)+ Button("Export…") { sheet = .export(machines.map(\.path)) }+ .disabled(!allStopped)+ Button("Delete…", role: .destructive) { deletion = machines.map(\.path) }+ .disabled(!allStopped)+ Divider()Button("Start") { start(stopped) }.disabled(stopped.isEmpty)Button("Start Headless") { start(stopped, headless: true) }@@ -219,15 +245,12 @@ struct VPhoneLaunchpadMachinesView: View {Button("Show in Finder") {NSWorkspace.shared.activateFileViewerSelecting(machines.map(\.path.url))}- Divider()- Button("Delete…", role: .destructive) { deletion = machines.map(\.path) }- .disabled(stopped.count != machines.count)} else if let machine = machines.first {let isStopped = library.state(of: machine.path) == .stoppedButton("Start Headless") { library.start(machine.path, headless: true) }.disabled(!isStopped)Divider()- Button("Settings…") { sheet = .settings(machine) }+ Button("Settings…") { sheet = .settings([machine]) }.disabled(!isStopped)Button("Patch Settings…") { sheet = .patches(machine.path) }.disabled(!isStopped)@@ -235,7 +258,7 @@ struct VPhoneLaunchpadMachinesView: View {.disabled(!isStopped)Button("Clone…") { sheet = .clone(machine.path) }.disabled(!isStopped)- Button("Export…") { sheet = .export(machine.path) }+ Button("Export…") { sheet = .export([machine.path]) }.disabled(!isStopped)Divider()Button("Show in Finder") {@@ -275,7 +298,10 @@ struct VPhoneLaunchpadMachinesView: View {}.width(min: 110, ideal: 120)TableColumn("State") { machine in- VPhoneLaunchpadMachineStateLabel(state: library.state(of: machine.path))+ VPhoneLaunchpadMachineStateLabel(+ state: library.state(of: machine.path),+ progress: library.exports[machine.path]?.fraction,+ )}.width(min: 150, ideal: 160)TableColumn("CPU") { machine in@@ -337,8 +363,8 @@ struct VPhoneLaunchpadMachinesView: View {if let creation = library.creations[path] {VPhoneLaunchpadCreationView(creation: creation)}- case let .settings(machine):- VPhoneLaunchpadMachineSettingsView(machine: machine)+ case let .settings(machines):+ VPhoneLaunchpadMachineSettingsView(machines: machines)case let .patches(path):// The machine's own record is what the editor starts from, so it reads// it back through `fw patches` rather than being handed a copy.@@ -358,8 +384,8 @@ struct VPhoneLaunchpadMachinesView: View {) { newName inTask { await library.clone(path, as: newName) }}- case let .export(path):- VPhoneLaunchpadExportView(machine: path)+ case let .export(paths):+ VPhoneLaunchpadExportView(machines: paths)case let .console(path):VPhoneLaunchpadConsoleView(title: "\(path.name) Console", url: VPhoneLaunchpadMachineLibrary.consoleLog(path))}