Run a virtual iPhone on an Apple Silicon Mac.
Swift
Show imports as rows with progress, stop transfers before quitting; version 2.9.2
Lakrda6906f90fd1
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/Info.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/Info.plistindex 3162cfc6..9f53f36b 100644--- a/VPhoneExecutable/VPhoneVirtualization/Resources/Info.plist+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/Info.plist@@ -9,9 +9,9 @@<key>CFBundlePackageType</key><string>BNDL</string><key>CFBundleVersion</key>- <string>37</string>+ <string>38</string><key>CFBundleShortVersionString</key>- <string>2.9.1</string>+ <string>2.9.2</string><key>NSMicrophoneUsageDescription</key><string>Shares this Mac's microphone with the virtual iPhone so apps running inside it can record.</string></dict>diff --git a/VPhoneLaunchpad/Configuration/Version.xcconfig b/VPhoneLaunchpad/Configuration/Version.xcconfigindex 46b643f8..f1d3a852 100644--- a/VPhoneLaunchpad/Configuration/Version.xcconfig+++ b/VPhoneLaunchpad/Configuration/Version.xcconfig@@ -1,4 +1,4 @@-MARKETING_VERSION = 2.9.1+MARKETING_VERSION = 2.9.2// Bump whenever the helper changes. The app blesses the helper again when the// installed helper's version or bytes differ from the copy it embeds.CURRENT_PROJECT_VERSION = 16diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadApp.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadApp.swiftindex 83e54fe0..c50c8aa9 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadApp.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadApp.swift@@ -32,7 +32,6 @@ struct VPhoneLaunchpadApp: App {.disabled(model.bundles.defaultVersion == nil)Button("Import…") { model.machines.chooseImport() }.keyboardShortcut("o")- .disabled(model.machines.globalActivity != nil)Divider()Button("Downloaded Firmware…") { model.present(.ipswCache) }if model.machines.hasTemplates {@@ -86,8 +85,8 @@ struct VPhoneLaunchpadApp: App {}/// Guests keep running when Launchpad quits (their output goes to a log-/// file, not a pipe). A machine being created does not survive, so quitting-/// then asks first.+/// file, not a pipe). A machine being created, an import and an export do+/// not survive, so quitting then asks first.@MainActorfinal class VPhoneLaunchpadAppDelegate: NSObject, NSApplicationDelegate {weak var model: VPhoneLaunchpadModel? {@@ -140,13 +139,22 @@ final class VPhoneLaunchpadAppDelegate: NSObject, NSApplicationDelegate {return .terminateNow}#endif- if confirmedClose {+ guard let model else {return .terminateNow}- guard let model, model.machines.hasActiveCreation else {+ if !confirmedClose, model.machines.hasActiveCreation || model.machines.hasActiveTransfer, !confirmStopWork() {+ return .terminateCancel+ }+ guard model.machines.hasActiveTransfer else {return .terminateNow}- return confirmStopCreation() ? .terminateNow : .terminateCancel+ // A `vm import` or `vm export` left behind would go on writing with+ // nobody reading its output. Stopped, each removes what it wrote.+ Task {+ await model.machines.stopTransfers()+ NSApp.reply(toApplicationShouldTerminate: true)+ }+ return .terminateLater}/// The close button, Close menu item and ⌘W all ask here, while the@@ -154,22 +162,31 @@ final class VPhoneLaunchpadAppDelegate: NSObject, NSApplicationDelegate {/// quits, so the alert says Quit. Cancel refuses the close. In menu bar/// mode closing only hides the window, so no confirmation is needed.func windowShouldClose(_: NSWindow) -> Bool {- guard !VPhoneLaunchpadMenuBar.isEnabled, let model, model.machines.hasActiveCreation else {+ guard !VPhoneLaunchpadMenuBar.isEnabled, let model,+ model.machines.hasActiveCreation || model.machines.hasActiveTransfer+ else {return true}- guard confirmStopCreation() else {+ guard confirmStopWork() else {return false}confirmedClose = truereturn true}- private func confirmStopCreation() -> Bool {+ private func confirmStopWork() -> Bool {let alert = NSAlert()- alert.messageText = String(localized: "Stop Creating Machine?")- alert.informativeText = String(- localized: "Quitting stops creating this machine. You can retry later from the step where it stopped.",- )+ if model?.machines.hasActiveCreation == true {+ alert.messageText = String(localized: "Stop Creating Machine?")+ alert.informativeText = String(+ localized: "Quitting stops creating this machine. You can retry later from the step where it stopped.",+ )+ } else {+ alert.messageText = String(localized: "Stop Importing and Exporting?")+ alert.informativeText = String(+ localized: "Quitting stops every import and export under way and removes what they had written.",+ )+ }alert.addButton(withTitle: String(localized: "Quit"))alert.addButton(withTitle: String(localized: "Cancel"))return alert.runModal() == .alertFirstButtonReturndiff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings b/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstringsindex 10ebfa0f..2160406c 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings@@ -647,6 +647,40 @@}}},+ "Archive" : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Archive"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "アーカイブ"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "아카이브"+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Tệp lưu trữ"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "归档"+ }+ }+ }+ },"Building template: %@" : {"localizations" : {"en" : {@@ -1701,6 +1735,40 @@}}},+ "Importing…" : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Importing…"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "読み込み中…"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "가져오는 중…"+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Đang nhập…"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "正在导入…"+ }+ }+ }+ },"Its restored disk is deleted. A machine that needs this template builds it again." : {"localizations" : {"en" : {@@ -2347,6 +2415,74 @@}}},+ "Quitting stops every import and export under way and removes what they had written." : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Quitting stops every import and export under way and removes what they had written."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "終了すると、進行中のすべての読み込みと書き出しが停止し、書き込まれた内容は削除されます。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "종료하면 진행 중인 모든 가져오기와 내보내기가 중단되고 기록된 내용이 제거됩니다."+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Thoát sẽ dừng mọi thao tác nhập và xuất đang chạy và xoá những gì chúng đã ghi."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "退出会停止所有进行中的导入和导出,并移除它们已写入的内容。"+ }+ }+ }+ },+ "Remove from Queue" : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Remove from Queue"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "キューから削除"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "대기열에서 제거"+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Xoá khỏi hàng đợi"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "从队列中移除"+ }+ }+ }+ },"Remove system apps" : {"localizations" : {"en" : {@@ -2993,6 +3129,108 @@}}},+ "Stop %lld Imports" : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Stop %lld Imports"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%lld 件の読み込みを停止"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "가져오기 %lld개 중단"+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Dừng %lld lần nhập"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "停止 %lld 个导入"+ }+ }+ }+ },+ "Stop Importing" : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Stop Importing"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "読み込みを停止"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "가져오기 중단"+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Dừng nhập"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "停止导入"+ }+ }+ }+ },+ "Stop Importing and Exporting?" : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Stop Importing and Exporting?"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "読み込みと書き出しを停止しますか?"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "가져오기와 내보내기를 중단하시겠습니까?"+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Dừng nhập và xuất?"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "要停止导入和导出吗?"+ }+ }+ }+ },"System Files" : {"localizations" : {"en" : {@@ -3061,6 +3299,40 @@}}},+ "The machine appears in the list once its files are unpacked and checked. Stopping removes what was unpacked." : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "The machine appears in the list once its files are unpacked and checked. Stopping removes what was unpacked."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "ファイルの展開と確認が終わると、マシンがリストに表示されます。停止すると、展開済みのファイルは削除されます。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "파일 압축 해제와 확인이 끝나면 머신이 목록에 나타납니다. 중단하면 압축 해제된 파일이 제거됩니다."+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Máy xuất hiện trong danh sách sau khi các tệp được giải nén và kiểm tra. Dừng lại sẽ xoá những gì đã giải nén."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "文件解包并检查完成后,机器会出现在列表中。停止会移除已解包的内容。"+ }+ }+ }+ },"TV" : {"localizations" : {"en" : {@@ -3945,6 +4217,40 @@}}},+ "Waiting to import…" : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Waiting to import…"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "読み込み待ち…"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "가져오기 대기 중…"+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Đang chờ nhập…"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "等待导入…"+ }+ }+ }+ },"Wallet" : {"localizations" : {"en" : {@@ -8479,40 +8785,6 @@}}},- "Importing %@" : {- "localizations" : {- "en" : {- "stringUnit" : {- "state" : "translated",- "value" : "Importing %@"- }- },- "ja" : {- "stringUnit" : {- "state" : "translated",- "value" : "%@ を読み込み中"- }- },- "ko" : {- "stringUnit" : {- "state" : "translated",- "value" : "%@ 가져오는 중"- }- },- "vi" : {- "stringUnit" : {- "state" : "translated",- "value" : "Đang nhập %@"- }- },- "zh-Hans" : {- "stringUnit" : {- "state" : "translated",- "value" : "正在导入 %@"- }- }- }- },"In progress" : {"localizations" : {"en" : {diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineActions.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineActions.swiftindex cd4d5265..276f31f8 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineActions.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineActions.swift@@ -306,7 +306,7 @@ extension VPhoneLaunchpadMachineLibrary {UTType(filenameExtension: url.pathExtension)?.conforms(to: type) == true}}- guard !archives.isEmpty, globalActivity == nil else {+ guard !archives.isEmpty else {return false}Task {diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swiftindex 0d9cf52f..b237c3c9 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift@@ -31,7 +31,6 @@ final class VPhoneLaunchpadMachineLibrary {private(set) var creations: [Path: VPhoneLaunchpadCreationPipeline] = [:]/// Each listed machine's Core Bundle, read from its `launchpad.json`.private(set) var bindings: [Path: VPhoneLaunchpadMachineBinding] = [:]- private(set) var globalActivity: String?/// Folders chosen in New Machine, in the order they were added. The/// default library is not among them.private(set) var addedRoots: [String]@@ -233,7 +232,7 @@ final class VPhoneLaunchpadMachineLibrary {listError = errors.firsthasListed = trueforgetEmptyLocations(listed: listed)- selection.formIntersection(machines.map(\.id))+ selection.formIntersection(machines.map(\.id) + imports.map(\.row))if selection.isEmpty, let first = machines.first {selection = [first.id]}@@ -922,7 +921,7 @@ final class VPhoneLaunchpadMachineLibrary {isLaunched: launched[machine] != nil,isHeld: diskHolders[machine]?.isEmpty == false,isBusy: isBusy || creation(for: machine)?.isRunning == true || exports[machine] != nil,- isLibraryBusy: globalActivity != nil,+ isLibraryBusy: isImporting,)}@@ -932,7 +931,7 @@ final class VPhoneLaunchpadMachineLibrary {/// refuses while another process holds the template open.private var templatesMayOpen: Bool {VPhoneLaunchpadDiskAccess.templatesMayOpen(- isLibraryBusy: globalActivity != nil,+ isLibraryBusy: isImporting,creationSteps: creations.values.filter(\.isRunning).compactMap(\.current),)}@@ -1162,12 +1161,131 @@ final class VPhoneLaunchpadMachineLibrary {[.vphoneExportedArchive] + ["tzst", "txz"].compactMap { UTType(filenameExtension: $0) }}+ // MARK: - Import++ /// An import queued or under way, listed as a row of its own until the+ /// machine it brings appears. `fraction` is nil until the command reports+ /// progress; `task` is nil while the import waits its turn.+ struct Import: Identifiable {+ let id = UUID()+ let archive: URL+ /// The default library, which every import writes to.+ let libraryRoot: String+ var fraction: Double?+ fileprivate var task: Task<Void, Never>?++ var isWaiting: Bool {+ task == nil+ }++ /// The archive's name without its extension, which is the machine's+ /// name unless the export was renamed.+ var name: String {+ archive.deletingPathExtension().lastPathComponent+ }++ /// The row's identity in the machine table. No machine has it: a+ /// machine name cannot start with a dot.+ var row: Path {+ Path(libraryRoot: libraryRoot, name: ".import-\(id.uuidString)")+ }+ }++ private(set) var imports: [Import] = []+ /// The last import queued; each one waits for the one before.+ private var lastImport: Task<Void, Never>?++ /// True while an import unpacks into the library.+ var isImporting: Bool {+ imports.contains { !$0.isWaiting }+ }++ func importItem(_ row: Path) -> Import? {+ imports.first { $0.row == row }+ }++ /// Imports one archive after those already queued: each import writes a+ /// whole disk image.func importArchive(_ archive: URL) async {- await perform(- String(localized: "Importing \(archive.lastPathComponent)"),- on: nil,- ["vm", "import", archive.path, "--library-root", libraryRoot],- )+ let item = Import(archive: archive, libraryRoot: libraryRoot)+ imports.append(item)+ // So the inspector shows the import as it runs.+ selection = [item.row]+ let previous = lastImport+ let queued = Task {+ await previous?.value+ await runImport(item.id)+ }+ lastImport = queued+ await queued.value+ }++ private func runImport(_ id: UUID) async {+ // Cancelled while it waited.+ guard let index = imports.firstIndex(where: { $0.id == id }) else {+ return+ }+ let item = imports[index]+ let arguments = ["vm", "import", item.archive.path, "--library-root", libraryRoot]+ let task = Task {+ do {+ let result = try await performChecked(String(localized: "Importing…"), on: nil, arguments) { fraction in+ Task { @MainActor in+ guard let index = self.imports.firstIndex(where: { $0.id == id }) else {+ return+ }+ self.imports[index].fraction = fraction+ }+ }+ // `imported → <name>`: the import's row gives way to the+ // machine, selected in its place.+ if let name = result.lines.last(where: { $0.hasPrefix("imported → ") })?.dropFirst("imported → ".count),+ selection == [item.row]+ {+ selection = [Path(libraryRoot: libraryRoot, name: String(name))]+ }+ } catch {+ if !(error is CancellationError) {+ actionError = VPhoneLaunchpadError(actionFailure: error)+ }+ }+ }+ imports[index].task = task+ await task.value+ imports.removeAll { $0.id == id }+ selection.remove(item.row)+ }++ /// Stops an import under way, or takes a waiting one out of the queue.+ /// `vm import` removes what it had unpacked.+ func cancelImport(_ id: UUID) {+ guard let item = imports.first(where: { $0.id == id }) else {+ return+ }+ if let task = item.task {+ task.cancel()+ } else {+ imports.removeAll { $0.id == id }+ }+ }++ /// True while an import or an export is queued or under way.+ var hasActiveTransfer: Bool {+ !imports.isEmpty || !exports.isEmpty+ }++ /// Stops every import and export and waits for their commands to exit,+ /// so none is left running, or half written, when Launchpad quits.+ func stopTransfers() async {+ let running = imports.compactMap(\.task) + exports.values.compactMap(\.task)+ imports.removeAll { $0.isWaiting }+ exports = exports.filter { !$0.value.isWaiting }+ for task in running {+ task.cancel()+ }+ for task in running {+ await task.value+ }}/// Runs one command with `activity` shown as the machine's state. False@@ -1214,16 +1332,14 @@ final class VPhoneLaunchpadMachineLibrary {}throw CancellationError()}+ // Without a machine, the caller shows the activity itself: Import+ // shows a row of its own.if let machine {activities[machine] = activity- } else {- globalActivity = activity}defer {if let machine {activities[machine] = nil- } else {- globalActivity = nil}}do {diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swiftindex 6827a8ec..fabf97a1 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift@@ -51,9 +51,10 @@ struct VPhoneLaunchpadMachinesView: View {model.machines}- /// The machines in the header's order.+ /// The machines in the header's order, then the imports, which have no+ /// machine yet, in the order they were queued.private var rows: [VPhoneLaunchpadMachineRow] {- library.machines.map { machine in+ let machines = library.machines.map { machine inlet state = switch library.state(of: machine.path) {case .running: 0case .busy: 1@@ -67,6 +68,7 @@ struct VPhoneLaunchpadMachinesView: View {)}.sorted(using: sortOrder)+ return machines + library.imports.map(VPhoneLaunchpadMachineRow.init(importing:))}var body: some View {@@ -74,7 +76,7 @@ struct VPhoneLaunchpadMachinesView: View {@Bindable var model = modelHStack(spacing: 0) {Group {- if library.machines.isEmpty {+ if library.machines.isEmpty, library.imports.isEmpty {emptyState} else {table(selection: $library.selection)@@ -85,7 +87,9 @@ struct VPhoneLaunchpadMachinesView: View {Divider().ignoresSafeArea(.container, edges: .top)Group {- if let machine = library.selected {+ if library.selection.count == 1, let item = library.selection.first.flatMap(library.importItem) {+ VPhoneLaunchpadImportInspector(item: item)+ } else if let machine = library.selected {VPhoneLaunchpadMachineInspector(machine: machine,onShowProgress: { path in sheet = .creation(path) },@@ -296,47 +300,56 @@ struct VPhoneLaunchpadMachinesView: View {private func table(selection: Binding<Set<MachinePath>>) -> some View {Table(rows, selection: selection, sortOrder: $sortOrder) {- TableColumn("Name", value: \.machine.name)- .width(min: 90, ideal: 140)+ TableColumn("Name", value: \.name) { row in+ Text(verbatim: row.name)+ .foregroundStyle(row.machine == nil ? .secondary : .primary)+ }+ .width(min: 90, ideal: 140)if library.spansLibraries {- TableColumn("Location", value: \.machine.libraryRoot) { row in- let machine = row.machine- Text(verbatim: VPhoneLaunchpadMachineLocations.volumeName(machine.libraryRoot))+ TableColumn("Location", value: \.libraryRoot) { row in+ Text(verbatim: VPhoneLaunchpadMachineLocations.volumeName(row.libraryRoot)).lineLimit(1).truncationMode(.middle)- .help(VPhoneLaunchpadHostSetup.abbreviated(URL(fileURLWithPath: machine.libraryRoot, isDirectory: true)))+ .help(VPhoneLaunchpadHostSetup.abbreviated(URL(fileURLWithPath: row.libraryRoot, isDirectory: true)))}.width(min: 80, ideal: 110)}// Standard comparison orders 18.10 after 18.9.- TableColumn("OS", value: \.machine.iosVersion) { row in- let machine = row.machine- Text(verbatim: machine.restoreInfo.map { "\(machine.osName) \($0.ios.version) (\($0.ios.build))" } ?? "—")+ TableColumn("OS", value: \.iosVersion) { row in+ let restore = row.machine.flatMap { machine in+ machine.restoreInfo.map { "\(machine.osName) \($0.ios.version) (\($0.ios.build))" }+ }+ Text(verbatim: restore ?? "—")}.width(min: 130, ideal: 150)TableColumn("Core Bundle", value: \.bundle) { row in- let machine = row.machine- // Each cell is a hosting view of its own. When its row leaves- // the table, the cell is updated once more with an empty- // environment, where reading the model is a fatal error.- VPhoneLaunchpadMachineBundleLabel(machine: machine.path)- .environment(model)+ if let machine = row.machine {+ // Each cell is a hosting view of its own. When its row leaves+ // the table, the cell is updated once more with an empty+ // environment, where reading the model is a fatal error.+ VPhoneLaunchpadMachineBundleLabel(machine: machine.path)+ .environment(model)+ } else {+ Text(verbatim: "—")+ }}.width(min: 60, ideal: 70)TableColumn("State", value: \.state) { row in- let machine = row.machine- VPhoneLaunchpadMachineStateLabel(- state: library.state(of: machine.path),- progress: library.progress(of: machine.path),- isDamaged: library.isDamaged(machine.path),- )+ if let machine = row.machine {+ VPhoneLaunchpadMachineStateLabel(+ state: library.state(of: machine.path),+ progress: library.progress(of: machine.path),+ isDamaged: library.isDamaged(machine.path),+ )+ } else if let item = library.importItem(row.id) {+ VPhoneLaunchpadImportStateLabel(item: item)+ }}.width(min: 100, ideal: 120)// What deleting the machine frees: a clone of a template// shares the rest.TableColumn("Exclusive", value: \.exclusive) { row in- let machine = row.machine- let usage = library.diskUsage[machine.path]+ let usage = row.machine.flatMap { library.diskUsage[$0.path] }Text(verbatim: usage?.exclusive.map { VPhoneLaunchpadDiskUsage.format($0) } ?? "—").monospacedDigit().foregroundStyle(usage?.exclusive == nil ? .secondary : .primary)@@ -345,7 +358,16 @@ struct VPhoneLaunchpadMachinesView: View {.width(min: 70, ideal: 80)}.contextMenu(forSelectionType: MachinePath.self) { paths in- VPhoneLaunchpadMachineActions(machines: library.machines.filter { paths.contains($0.path) })+ let importing = library.imports.filter { paths.contains($0.row) }+ if importing.isEmpty {+ VPhoneLaunchpadMachineActions(machines: library.machines.filter { paths.contains($0.path) })+ } else {+ Button(importing.count == 1 ? LocalizedStringKey("Stop Importing") : LocalizedStringKey("Stop \(importing.count) Imports")) {+ for item in importing {+ library.cancelImport(item.id)+ }+ }+ }} primaryAction: { paths inlibrary.start(library.machines.filter { paths.contains($0.path) && library.state(of: $0.path) == .stopped })}@@ -437,10 +459,16 @@ struct VPhoneLaunchpadMachinesView: View {}}-/// One row of the machine table: the machine, with the values its other-/// columns show, so every column sorts.+/// One row of the machine table: a machine, or an import that has none yet,+/// with the values its columns show, so every column sorts.struct VPhoneLaunchpadMachineRow: Identifiable {- let machine: VPhoneLaunchpadMachine+ let id: VPhoneLaunchpadMachinePath+ /// Nil for an import.+ let machine: VPhoneLaunchpadMachine?+ let name: String+ let libraryRoot: String+ /// The iOS sort key; empty for a machine not yet restored, or an import.+ let iosVersion: String/// The Core Bundle version it runs with.let bundle: String/// Running, then busy, then stopped.@@ -448,7 +476,85 @@ struct VPhoneLaunchpadMachineRow: Identifiable {/// Bytes only it holds; -1 while unknown.let exclusive: Int64- var id: VPhoneLaunchpadMachinePath {- machine.path+ init(machine: VPhoneLaunchpadMachine, bundle: String, state: Int, exclusive: Int64) {+ id = machine.path+ self.machine = machine+ name = machine.name+ libraryRoot = machine.libraryRoot+ iosVersion = machine.iosVersion+ self.bundle = bundle+ self.state = state+ self.exclusive = exclusive+ }++ init(importing item: VPhoneLaunchpadMachineLibrary.Import) {+ id = item.row+ machine = nil+ name = item.name+ libraryRoot = item.libraryRoot+ iosVersion = ""+ bundle = ""+ state = 1+ exclusive = -1+ }+}++// MARK: - Import++/// An import's state: its progress once `vm import` reports it.+struct VPhoneLaunchpadImportStateLabel: View {+ let item: VPhoneLaunchpadMachineLibrary.Import+ var namesActivity = false++ var body: some View {+ VPhoneLaunchpadMachineStateLabel(+ state: .busy(item.isWaiting ? String(localized: "Waiting to import…") : String(localized: "Importing…")),+ progress: item.isWaiting ? nil : item.fraction ?? 0,+ namesActivity: namesActivity,+ )+ }+}++/// The inspector for an import's row: what is being imported, how far it has+/// got, and a way to stop it.+struct VPhoneLaunchpadImportInspector: View {+ let item: VPhoneLaunchpadMachineLibrary.Import+ @Environment(VPhoneLaunchpadModel.self) private var model++ var body: some View {+ Form {+ Section {+ LabeledContent("State") {+ VPhoneLaunchpadImportStateLabel(item: item, namesActivity: true)+ }+ LabeledContent("Archive") {+ Text(verbatim: item.archive.lastPathComponent)+ .lineLimit(1)+ .truncationMode(.middle)+ .help(VPhoneLaunchpadHostSetup.abbreviated(item.archive))+ }+ LabeledContent("Location") {+ Text(verbatim: VPhoneLaunchpadHostSetup.abbreviated(URL(fileURLWithPath: item.libraryRoot, isDirectory: true)))+ .lineLimit(1)+ .truncationMode(.middle)+ }+ } header: {+ Text(verbatim: item.name)+ .font(.headline)+ .lineLimit(1)+ .truncationMode(.middle)+ .foregroundStyle(.primary)+ }+ Section {+ Button(item.isWaiting ? LocalizedStringKey("Remove from Queue") : LocalizedStringKey("Stop Importing"), role: .destructive) {+ model.machines.cancelImport(item.id)+ }+ } footer: {+ Text("The machine appears in the list once its files are unpacked and checked. Stopping removes what was unpacked.")+ .foregroundStyle(.secondary)+ }+ }+ .formStyle(.grouped)+ .contentMargins(.top, 0, for: .scrollContent)}}