Skip to content

A native macOS app for managing virtual iPhones - browse, create, and boot iOS research VMs from a single window.

Swift

ui: Add SwiftUI app — library, detail, wizard, readiness

zqxwceb7e89d022e9f
diff --git a/Sources/vphone-ws/App.swift b/Sources/vphone-ws/App.swift
new file mode 100644
index 0000000..949384a
--- /dev/null
+++ b/Sources/vphone-ws/App.swift
@@ -0,0 +1,50 @@
+import SwiftUI
+import VPhoneWSCore
+
+@main
+struct VPhoneWSApp: App {
+ var body: some Scene {
+ WindowGroup("vPhone Workstation") {
+ RootView()
+ .frame(minWidth: 940, minHeight: 640)
+ }
+ .windowStyle(.hiddenTitleBar)
+ }
+}
+
+struct RootView: View {
+ @State private var services = AppEnvironment.makeServices()
+
+ var body: some View {
+ Group {
+ if let services {
+ LibraryView(services: services)
+ } else {
+ notFound
+ }
+ }
+ .background(Theme.bg)
+ }
+
+ private var notFound: some View {
+ ZStack {
+ Theme.bg
+ VStack(spacing: 14) {
+ Image(systemName: "terminal")
+ .font(.system(size: 40))
+ .foregroundStyle(Theme.faint)
+ Text("vphone-cli not found")
+ .font(.ws(18, weight: .semibold))
+ .foregroundStyle(Theme.text)
+ Text("Install vphone-cli (e.g. brew install zqxwce/tap/vphone-cli) or set its path in Preferences.")
+ .font(.ws(13))
+ .foregroundStyle(Theme.dim)
+ .multilineTextAlignment(.center)
+ .fixedSize(horizontal: false, vertical: true)
+ .frame(maxWidth: 360)
+ }
+ .padding(32)
+ }
+ .frame(maxWidth: .infinity, maxHeight: .infinity)
+ }
+}
diff --git a/Sources/vphone-ws/Theme.swift b/Sources/vphone-ws/Theme.swift
new file mode 100644
index 0000000..25b47e7
--- /dev/null
+++ b/Sources/vphone-ws/Theme.swift
@@ -0,0 +1,342 @@
+import AppKit
+import SwiftUI
+
+private extension NSColor {
+ convenience init(hex: UInt32) {
+ self.init(
+ srgbRed: CGFloat((hex >> 16) & 0xff) / 255,
+ green: CGFloat((hex >> 8) & 0xff) / 255,
+ blue: CGFloat(hex & 0xff) / 255,
+ alpha: 1)
+ }
+}
+
+enum Theme {
+ static func dynamic(light: UInt32, dark: UInt32) -> Color {
+ Color(nsColor: NSColor(name: nil) { appearance in
+ let isDark = appearance.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua
+ return NSColor(hex: isDark ? dark : light)
+ })
+ }
+
+ static let bg = dynamic(light: 0xeef0f4, dark: 0x101216)
+ static let surface = dynamic(light: 0xffffff, dark: 0x1b1e24)
+ static let surface2 = dynamic(light: 0xf6f7f9, dark: 0x21252c)
+ static let inset = dynamic(light: 0xeceff3, dark: 0x15181d)
+ static let border = dynamic(light: 0xdfe3ea, dark: 0x2b303a)
+ static let borderStrong = dynamic(light: 0xc9cfd9, dark: 0x3a404c)
+ static let text = dynamic(light: 0x1a1d23, dark: 0xe7eaef)
+ static let dim = dynamic(light: 0x5b6472, dark: 0x9aa4b2)
+ static let faint = dynamic(light: 0x8a94a3, dark: 0x69727f)
+ static let accent = dynamic(light: 0x2f6fe0, dark: 0x5b9bff)
+ static let accentInk = dynamic(light: 0xffffff, dark: 0x0b1220)
+ static let good = dynamic(light: 0x1f9d40, dark: 0x3fb950)
+ static let warn = dynamic(light: 0xb57d00, dark: 0xd29922)
+ static let crit = dynamic(light: 0xcf2231, dark: 0xf85149)
+
+ static let radius: CGFloat = 12
+ static let radiusSmall: CGFloat = 8
+
+ static let sidebarWidth: CGFloat = 264
+
+ static let logBackground = Color(nsColor: NSColor(hex: 0x0e1013))
+ static let logText = Color(nsColor: NSColor(hex: 0xc7d0dc))
+}
+
+extension Font {
+ static func ws(_ size: CGFloat, weight: Font.Weight = .regular) -> Font {
+ .system(size: size, weight: weight)
+ }
+ static func wsMono(_ size: CGFloat, weight: Font.Weight = .regular) -> Font {
+ .system(size: size, weight: weight, design: .monospaced)
+ }
+}
+
+enum VMStatus { case running, stopped }
+
+struct StatusDot: View {
+ let running: Bool
+ var body: some View {
+ Circle()
+ .fill(running ? Theme.good : Theme.faint.opacity(0.7))
+ .frame(width: 8, height: 8)
+ }
+}
+
+struct StatusPill: View {
+ enum Kind { case running, stopped, warn }
+ let kind: Kind
+ let label: String
+
+ private var color: Color {
+ switch kind {
+ case .running: Theme.good
+ case .stopped: Theme.faint
+ case .warn: Theme.warn
+ }
+ }
+ private var background: Color {
+ switch kind {
+ case .stopped: Theme.inset
+ default: color.opacity(0.16)
+ }
+ }
+
+ var body: some View {
+ HStack(spacing: 6) {
+ Circle().fill(color).frame(width: 7, height: 7)
+ Text(label).font(.ws(12, weight: .semibold))
+ }
+ .foregroundStyle(kind == .stopped ? Theme.faint : color)
+ .padding(.horizontal, 10)
+ .padding(.vertical, 4)
+ .background(background)
+ .overlay(
+ Capsule().stroke(kind == .stopped ? Theme.border : color.opacity(0.3), lineWidth: 1))
+ .clipShape(.capsule)
+ }
+}
+
+struct StageChip: View {
+ enum State { case completed, current, pending }
+ let label: String
+ let state: State
+
+ private var fg: Color {
+ switch state {
+ case .completed: Theme.good
+ case .current: Theme.accent
+ case .pending: Theme.faint
+ }
+ }
+ private var bg: Color {
+ switch state {
+ case .completed: Theme.good.opacity(0.16)
+ case .current: Theme.accent.opacity(0.18)
+ case .pending: Color.clear
+ }
+ }
+ private var border: Color {
+ switch state {
+ case .completed: Theme.good.opacity(0.3)
+ case .current: Theme.accent
+ case .pending: Theme.border
+ }
+ }
+ private var glyph: String {
+ switch state {
+ case .completed: "✓ "
+ case .current: "▸ "
+ case .pending: ""
+ }
+ }
+
+ var body: some View {
+ Text(glyph + label)
+ .font(.wsMono(11, weight: state == .current ? .semibold : .regular))
+ .foregroundStyle(fg)
+ .padding(.horizontal, 9)
+ .padding(.vertical, 4)
+ .background(bg)
+ .overlay(RoundedRectangle(cornerRadius: 6).stroke(border, lineWidth: 1))
+ .clipShape(.rect(cornerRadius: 6))
+ }
+}
+
+enum SpecValue {
+ case text(String)
+ case mono(String)
+ case variantBadge(String)
+}
+
+struct VariantBadge: View {
+ let variant: String
+
+ private var label: String {
+ switch variant {
+ case "less": "less"
+ case "regular": "regular"
+ case "dev": "developer"
+ case "jb": "jailbreak"
+ case "exp": "experimental"
+ default: variant
+ }
+ }
+ private var color: Color {
+ switch variant {
+ case "less", "regular": Theme.accent
+ case "exp": Theme.crit
+ default: Theme.warn
+ }
+ }
+
+ var body: some View {
+ Text(label)
+ .font(.wsMono(11, weight: .semibold))
+ .foregroundStyle(color)
+ .padding(.horizontal, 7).padding(.vertical, 2)
+ .background(color.opacity(0.16))
+ .clipShape(.rect(cornerRadius: 5))
+ }
+}
+
+struct SpecTile: View {
+ let key: String
+ let value: SpecValue
+
+ var body: some View {
+ VStack(alignment: .leading, spacing: 5) {
+ Text(key.uppercased())
+ .font(.wsMono(10))
+ .tracking(0.6)
+ .foregroundStyle(Theme.faint)
+ content
+ }
+ .padding(12)
+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
+ .background(Theme.surface)
+ }
+
+ @ViewBuilder private var content: some View {
+ switch value {
+ case .text(let s):
+ Text(s).font(.ws(14, weight: .semibold)).foregroundStyle(Theme.text).textSelection(.enabled)
+ case .mono(let s):
+ Text(s).font(.wsMono(12)).foregroundStyle(Theme.text).textSelection(.enabled)
+ case .variantBadge(let v):
+ VariantBadge(variant: v)
+ }
+ }
+}
+
+struct SpecGrid: View {
+ let specs: [(String, SpecValue)]
+ var body: some View {
+ LazyVGrid(
+ columns: [GridItem(.adaptive(minimum: 150), spacing: 1)], spacing: 1
+ ) {
+ ForEach(specs, id: \.0) { key, value in
+ SpecTile(key: key, value: value)
+ }
+ }
+ .background(Theme.border)
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ .overlay(
+ RoundedRectangle(cornerRadius: Theme.radiusSmall).stroke(Theme.border, lineWidth: 1))
+ }
+}
+
+/// Fixed-column spec grid where some keys span two columns (e.g. a long UDID).
+/// Column count is chosen so the given specs fill their rows without gaps.
+struct SpecGridSpanning: View {
+ let specs: [(String, SpecValue)]
+ let columns: Int
+ var wideKeys: Set<String> = []
+
+ private var rows: [[(key: String, value: SpecValue, span: Int)]] {
+ var rows: [[(key: String, value: SpecValue, span: Int)]] = []
+ var current: [(key: String, value: SpecValue, span: Int)] = []
+ var used = 0
+ for (key, value) in specs {
+ let span = min(wideKeys.contains(key) ? 2 : 1, columns)
+ if used + span > columns { rows.append(current); current = []; used = 0 }
+ current.append((key, value, span))
+ used += span
+ }
+ if !current.isEmpty { rows.append(current) }
+ return rows
+ }
+
+ var body: some View {
+ Grid(horizontalSpacing: 1, verticalSpacing: 1) {
+ ForEach(Array(rows.enumerated()), id: \.offset) { _, row in
+ GridRow {
+ ForEach(Array(row.enumerated()), id: \.offset) { _, item in
+ SpecTile(key: item.key, value: item.value)
+ .gridCellColumns(item.span)
+ }
+ }
+ }
+ }
+ .background(Theme.border)
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ .overlay(
+ RoundedRectangle(cornerRadius: Theme.radiusSmall).stroke(Theme.border, lineWidth: 1))
+ }
+}
+
+struct WSStepper: View {
+ @Binding var value: Double
+ let range: ClosedRange<Double>
+ let step: Double
+ let format: (Int) -> String
+
+ var body: some View {
+ HStack(spacing: 0) {
+ Button {
+ value = max(range.lowerBound, value - step)
+ } label: {
+ Text("−").font(.ws(16)).frame(width: 42, height: 34).contentShape(.rect)
+ }.buttonStyle(.plain)
+ Text(format(Int(value)))
+ .font(.wsMono(13, weight: .semibold)).foregroundStyle(Theme.text)
+ .frame(minWidth: 90).frame(height: 34)
+ .overlay(alignment: .leading) { Rectangle().fill(Theme.borderStrong).frame(width: 1) }
+ .overlay(alignment: .trailing) { Rectangle().fill(Theme.borderStrong).frame(width: 1) }
+ Button {
+ value = min(range.upperBound, value + step)
+ } label: {
+ Text("+").font(.ws(15)).frame(width: 42, height: 34).contentShape(.rect)
+ }.buttonStyle(.plain)
+ }
+ .foregroundStyle(Theme.text)
+ .overlay(RoundedRectangle(cornerRadius: Theme.radiusSmall).stroke(Theme.borderStrong, lineWidth: 1))
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ }
+}
+
+struct SectionLabel: View {
+ let text: String
+ var body: some View {
+ Text(text.uppercased())
+ .font(.wsMono(11))
+ .tracking(0.9)
+ .foregroundStyle(Theme.faint)
+ }
+}
+
+struct WSPrimaryButtonStyle: ButtonStyle {
+ func makeBody(configuration: Configuration) -> some View {
+ configuration.label
+ .font(.ws(13, weight: .semibold))
+ .foregroundStyle(Theme.accentInk)
+ .padding(.horizontal, 12)
+ .padding(.vertical, 6)
+ .background(Theme.accent.opacity(configuration.isPressed ? 0.8 : 1))
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ }
+}
+
+struct WSSecondaryButtonStyle: ButtonStyle {
+ var danger = false
+ func makeBody(configuration: Configuration) -> some View {
+ configuration.label
+ .font(.ws(13))
+ .foregroundStyle(danger ? Theme.crit : Theme.text)
+ .padding(.horizontal, 12)
+ .padding(.vertical, 6)
+ .background(Theme.surface.opacity(configuration.isPressed ? 0.6 : 1))
+ .overlay(
+ RoundedRectangle(cornerRadius: Theme.radiusSmall)
+ .stroke(danger ? Theme.crit.opacity(0.4) : Theme.borderStrong, lineWidth: 1))
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ }
+}
+
+extension ButtonStyle where Self == WSPrimaryButtonStyle {
+ static var wsPrimary: WSPrimaryButtonStyle { .init() }
+}
+extension ButtonStyle where Self == WSSecondaryButtonStyle {
+ static var wsSecondary: WSSecondaryButtonStyle { .init() }
+ static var wsDanger: WSSecondaryButtonStyle { .init(danger: true) }
+}
diff --git a/Sources/vphone-ws/Views/CreateWizardView.swift b/Sources/vphone-ws/Views/CreateWizardView.swift
new file mode 100644
index 0000000..151856c
--- /dev/null
+++ b/Sources/vphone-ws/Views/CreateWizardView.swift
@@ -0,0 +1,432 @@
+import SwiftUI
+import VPhoneWSCore
+
+struct CreateWizardView: View {
+ static let variants = ["less", "regular", "dev", "jb", "exp"]
+
+ enum SourceMode: Hashable { case recommended, manual }
+
+ let services: AppEnvironment.Services
+ var onClose: () -> Void = {}
+ @State private var task: TaskModel?
+ @State private var step = 0
+ @State private var name = ""
+ @State private var variant = "regular"
+ @State private var cpu: Double = 8
+ @State private var memory: Double = 8192
+ @State private var disk: Double = 64
+ @State private var catalog: FirmwareCatalog?
+ @State private var catalogError: String?
+ @State private var sourceMode: SourceMode = .recommended
+ @State private var selectedIOS: FirmwareImage?
+ @State private var selectedCloudOS: FirmwareImage?
+
+ private let stepTitles = ["Name", "iOS & variant", "Resources", "Review"]
+
+ private var iphoneSource: String { selectedIOS?.url ?? "" }
+ private var cloudosSource: String { selectedCloudOS?.url ?? "" }
+
+ private var trimmedName: String {
+ name.trimmingCharacters(in: .whitespaces)
+ }
+
+ private var nameValid: Bool {
+ !trimmedName.isEmpty && !trimmedName.contains("/") && !trimmedName.hasPrefix(".")
+ && !services.store.rows.contains { $0.report.name == trimmedName }
+ }
+
+ private var createDisabled: Bool {
+ !nameValid || iphoneSource.isEmpty || cloudosSource.isEmpty
+ }
+
+ private var canAdvance: Bool {
+ switch step {
+ case 0: return nameValid
+ case 1: return !iphoneSource.isEmpty && !cloudosSource.isEmpty
+ default: return true
+ }
+ }
+
+ var body: some View {
+ Group {
+ if let task {
+ progressView(task)
+ } else {
+ wizardBody
+ }
+ }
+ .frame(maxWidth: .infinity, maxHeight: .infinity)
+ .background(Theme.bg)
+ .task {
+ do { catalog = try await services.client.fetchCatalog() }
+ catch { catalogError = "Couldn't load firmware catalog: \(error)" }
+ }
+ }
+
+ private var wizardBody: some View {
+ VStack(spacing: 0) {
+ HStack(spacing: 0) {
+ stepRail
+ Rectangle().fill(Theme.border).frame(width: 1)
+ ScrollView {
+ bodyContent
+ .padding(24)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ }
+ .scrollContentBackground(.hidden)
+ }
+ footer
+ }
+ }
+
+ private func progressView(_ task: TaskModel) -> some View {
+ VStack(spacing: 0) {
+ HStack(spacing: 12) {
+ Text(task.title).font(.ws(15, weight: .semibold)).foregroundStyle(Theme.text)
+ TaskStatusBadge(status: task.status)
+ Spacer(minLength: 8)
+ }
+ .padding(.horizontal, 20).padding(.vertical, 14)
+ .background(Theme.surface2)
+ .overlay(alignment: .bottom) { Rectangle().fill(Theme.border).frame(height: 1) }
+
+ TaskLogView(task: task)
+ .padding(20)
+
+ HStack {
+ Button("Export log…") { TaskLogExporter.export(task, suggestedName: trimmedName) }
+ .buttonStyle(.wsSecondary)
+ Spacer()
+ if task.status == .running {
+ Button("Cancel") { task.cancel() }.buttonStyle(.wsDanger)
+ } else {
+ Button("Done") { onClose() }.buttonStyle(.wsPrimary)
+ }
+ }
+ .padding(.horizontal, 20).padding(.vertical, 14)
+ .background(Theme.surface2)
+ .overlay(alignment: .top) { Rectangle().fill(Theme.border).frame(height: 1) }
+ }
+ }
+
+ private var stepRail: some View {
+ VStack(alignment: .leading, spacing: 4) {
+ ForEach(Array(stepTitles.enumerated()), id: \.offset) { idx, title in
+ stepItem(idx: idx, title: title)
+ }
+ Spacer(minLength: 0)
+ }
+ .padding(16)
+ .frame(width: 210, alignment: .topLeading)
+ .frame(maxHeight: .infinity)
+ .background(Theme.surface2)
+ }
+
+ private func stepItem(idx: Int, title: String) -> some View {
+ let done = idx < step
+ let now = idx == step
+ return HStack(spacing: 11) {
+ ZStack {
+ Circle()
+ .fill(done ? Theme.good : Color.clear)
+ .overlay(Circle().stroke(now ? Theme.accent : (done ? Theme.good : Theme.borderStrong), lineWidth: 1.5))
+ .frame(width: 22, height: 22)
+ if done {
+ Image(systemName: "checkmark").font(.wsMono(10, weight: .semibold)).foregroundStyle(.white)
+ } else {
+ Text("\(idx + 1)").font(.wsMono(11, weight: .semibold))
+ .foregroundStyle(now ? Theme.accent : Theme.faint)
+ }
+ }
+ Text(title)
+ .font(.ws(13.5, weight: now ? .semibold : .regular))
+ .foregroundStyle(now || done ? Theme.text : Theme.faint)
+ Spacer(minLength: 0)
+ }
+ .padding(.horizontal, 8).padding(.vertical, 9)
+ .background(now ? Theme.accent.opacity(0.10) : Color.clear)
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ }
+
+ @ViewBuilder
+ private var bodyContent: some View {
+ switch step {
+ case 0: nameStep
+ case 1: variantStep
+ case 2: resourcesStep
+ default: reviewStep
+ }
+ }
+
+ private var nameStep: some View {
+ VStack(alignment: .leading, spacing: 16) {
+ stepHeader("Name your VM", "A short identifier used for the VM folder and CLI commands.")
+ labeled("VM name") {
+ wsField("e.g. research-jb", text: $name)
+ }
+ if !name.isEmpty && !nameValid {
+ Text("Invalid or already in use")
+ .font(.ws(12)).foregroundStyle(Theme.crit)
+ }
+ }
+ }
+
+ private var variantStep: some View {
+ VStack(alignment: .leading, spacing: 16) {
+ stepHeader("Choose iOS & variant", "Pick how much of iOS's security you want peeled back. You can always create another VM with a different variant.")
+ LazyVGrid(columns: [GridItem(.flexible(), spacing: 10), GridItem(.flexible(), spacing: 10)], spacing: 10) {
+ ForEach(Self.variants, id: \.self) { variantCard($0) }
+ }
+ firmwareSection
+ }
+ }
+
+ private var firmwareSection: some View {
+ VStack(alignment: .leading, spacing: 12) {
+ HStack {
+ Text("Firmware").font(.ws(12, weight: .semibold)).foregroundStyle(Theme.dim)
+ Spacer()
+ modeToggle
+ }
+ if let catalog {
+ if sourceMode == .recommended {
+ labeled("Recommended pairing") {
+ firmwareMenu(
+ title: selectedPairingTitle,
+ rows: catalog.pairings.map { ("\($0.ios.name) → \($0.recommendedCloudOS.name)", $0) },
+ pick: { selectedIOS = $0.ios; selectedCloudOS = $0.recommendedCloudOS })
+ }
+ } else {
+ labeled("iOS — userland") {
+ firmwareMenu(
+ title: selectedIOS?.name ?? "Choose iOS…",
+ rows: catalog.iosImages.map { ($0.name, $0) },
+ pick: { selectedIOS = $0 })
+ }
+ labeled("cloudOS — kernel") {
+ firmwareMenu(
+ title: selectedCloudOS?.name ?? "Choose cloudOS…",
+ rows: catalog.cloudOSImages.map { ($0.name, $0) },
+ pick: { selectedCloudOS = $0 })
+ }
+ Text("Pair any iOS with any cloudOS. Combinations outside the recommended list are untested.")
+ .font(.ws(11.5)).foregroundStyle(Theme.faint)
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ } else if let catalogError {
+ Text(catalogError).font(.ws(12)).foregroundStyle(Theme.crit)
+ .fixedSize(horizontal: false, vertical: true)
+ } else {
+ Text("Loading firmware catalog…").font(.ws(12)).foregroundStyle(Theme.faint)
+ }
+ }
+ }
+
+ private var selectedPairingTitle: String {
+ guard let ios = selectedIOS, let cloud = selectedCloudOS else { return "Choose a pairing…" }
+ return "\(ios.name) → \(cloud.name)"
+ }
+
+ private var modeToggle: some View {
+ HStack(spacing: 0) {
+ ForEach([SourceMode.recommended, .manual], id: \.self) { mode in
+ let on = sourceMode == mode
+ Button { sourceMode = mode } label: {
+ Text(mode == .recommended ? "Recommended" : "Manual")
+ .font(.ws(12, weight: on ? .semibold : .regular))
+ .foregroundStyle(on ? Theme.accentInk : Theme.dim)
+ .padding(.horizontal, 12).padding(.vertical, 5)
+ .background(on ? Theme.accent : Color.clear)
+ .contentShape(.rect)
+ }.buttonStyle(.plain)
+ }
+ }
+ .overlay(RoundedRectangle(cornerRadius: Theme.radiusSmall).stroke(Theme.borderStrong, lineWidth: 1))
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ }
+
+ private func firmwareMenu<Value>(
+ title: String, rows: [(String, Value)], pick: @escaping (Value) -> Void
+ ) -> some View {
+ Menu {
+ ForEach(Array(rows.enumerated()), id: \.offset) { _, row in
+ Button(row.0) { pick(row.1) }
+ }
+ } label: {
+ HStack {
+ Text(title).font(.wsMono(13)).foregroundStyle(Theme.text)
+ Spacer(minLength: 8)
+ Image(systemName: "chevron.up.chevron.down").font(.ws(11)).foregroundStyle(Theme.faint)
+ }
+ .padding(.horizontal, 11).padding(.vertical, 9)
+ .background(Theme.inset)
+ .overlay(RoundedRectangle(cornerRadius: Theme.radiusSmall).stroke(Theme.border, lineWidth: 1))
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ }
+ .menuStyle(.borderlessButton)
+ .menuIndicator(.hidden)
+ }
+
+ private var resourcesStep: some View {
+ VStack(alignment: .leading, spacing: 16) {
+ stepHeader("Resources", "Set the VM's CPU, memory, and disk size. CPU and memory can be changed later in Settings; disk is fixed once the VM is created.")
+ labeled("CPU cores") {
+ WSStepper(value: $cpu, range: 1...32, step: 1) { "\($0) cores" }
+ }
+ labeled("Memory") {
+ WSStepper(value: $memory, range: 1024...65536, step: 1024) { "\($0) MB" }
+ }
+ labeled("Disk size") {
+ WSStepper(value: $disk, range: 16...512, step: 16) { "\($0) GB" }
+ }
+ }
+ }
+
+ private var reviewStep: some View {
+ VStack(alignment: .leading, spacing: 16) {
+ stepHeader("Review & create", "Confirm the plan below, then create.")
+ SpecGrid(specs: [
+ ("Name", .text(trimmedName.isEmpty ? "—" : trimmedName)),
+ ("Variant", .variantBadge(variant)),
+ ("iOS", .text(selectedIOS?.name ?? "—")),
+ ("cloudOS", .text(selectedCloudOS?.name ?? "—")),
+ ("CPU", .text("\(Int(cpu)) cores")),
+ ("Memory", .text("\(Int(memory)) MB")),
+ ("Disk", .text("\(Int(disk)) GB")),
+ ])
+ reviewCallout
+ }
+ }
+
+ private var reviewCallout: some View {
+ HStack(alignment: .top, spacing: 11) {
+ Image(systemName: "info.circle").font(.ws(15)).foregroundStyle(Theme.accent)
+ Text("Creating downloads multi-GB IPSWs, asks you to authenticate once via the native macOS prompt (for the CFW host-mount), and takes several minutes. Progress runs live in the Task console.")
+ .font(.ws(13)).foregroundStyle(Theme.text)
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ .padding(.horizontal, 14).padding(.vertical, 12)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .background(Theme.accent.opacity(0.14))
+ .overlay(RoundedRectangle(cornerRadius: Theme.radiusSmall).stroke(Theme.accent.opacity(0.28), lineWidth: 1))
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ }
+
+ private var footer: some View {
+ HStack {
+ Button("Cancel") { onClose() }.buttonStyle(.wsSecondary)
+ Spacer()
+ if step > 0 {
+ Button("Back") { step -= 1 }.buttonStyle(.wsSecondary)
+ }
+ if step < stepTitles.count - 1 {
+ Button("Continue") { step += 1 }.buttonStyle(.wsPrimary).disabled(!canAdvance)
+ } else {
+ Button("Create") { startCreate() }.buttonStyle(.wsPrimary).disabled(createDisabled)
+ }
+ }
+ .padding(.horizontal, 24).padding(.vertical, 14)
+ .background(Theme.surface2)
+ .overlay(alignment: .top) { Rectangle().fill(Theme.border).frame(height: 1) }
+ }
+
+ private func stepHeader(_ title: String, _ sub: String) -> some View {
+ VStack(alignment: .leading, spacing: 4) {
+ Text(title).font(.ws(18, weight: .semibold)).foregroundStyle(Theme.text)
+ Text(sub).font(.ws(13.5)).foregroundStyle(Theme.dim)
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ }
+
+ private func labeled<Content: View>(_ label: String, @ViewBuilder content: () -> Content) -> some View {
+ VStack(alignment: .leading, spacing: 6) {
+ Text(label).font(.ws(12, weight: .semibold)).foregroundStyle(Theme.dim)
+ content()
+ }
+ }
+
+ private func wsField(_ placeholder: String, text: Binding<String>) -> some View {
+ TextField(placeholder, text: text)
+ .textFieldStyle(.plain)
+ .font(.wsMono(13))
+ .foregroundStyle(Theme.text)
+ .padding(.horizontal, 11).padding(.vertical, 9)
+ .background(Theme.inset)
+ .overlay(RoundedRectangle(cornerRadius: Theme.radiusSmall).stroke(Theme.border, lineWidth: 1))
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ }
+
+ private func variantCard(_ v: String) -> some View {
+ let meta = variantMeta(v)
+ let selected = variant == v
+ return Button {
+ variant = v
+ } label: {
+ VStack(alignment: .leading, spacing: 8) {
+ Text(meta.title).font(.ws(14, weight: .semibold)).foregroundStyle(Theme.text)
+ Text(meta.desc).font(.ws(12)).foregroundStyle(Theme.dim)
+ .fixedSize(horizontal: false, vertical: true)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ securityMeter(meta.level)
+ }
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .padding(13)
+ .background(selected ? Theme.accent.opacity(0.14) : Theme.surface)
+ .overlay(RoundedRectangle(cornerRadius: Theme.radiusSmall).stroke(selected ? Theme.accent : Theme.border, lineWidth: 1))
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ }
+ .buttonStyle(.plain)
+ }
+
+ private func securityMeter(_ level: Int) -> some View {
+ HStack(spacing: 3) {
+ ForEach(0..<5) { i in
+ RoundedRectangle(cornerRadius: 2)
+ .fill(i < level ? Theme.accent : Theme.borderStrong)
+ .frame(height: 4)
+ }
+ }
+ .padding(.top, 2)
+ }
+
+ private func variantMeta(_ v: String) -> (title: String, desc: String, level: Int) {
+ switch v {
+ case "less": return ("Less", "Minimal patch set — closest to stock, fewest bypasses.", 1)
+ case "regular": return ("Regular", "Boots stock-like iOS with core bypasses. Best starting point.", 2)
+ case "dev": return ("Developer", "Adds entitlement & debug bypass for tooling.", 3)
+ case "jb": return ("Jailbreak", "Full JB — Sileo & TrollStore auto-install on first boot.", 4)
+ default: return ("Experimental", "JB + anti-VM-detection research patches.", 5)
+ }
+ }
+
+ private func startCreate() {
+ let trimmed = trimmedName
+ let args = services.commandBuilder.createArgs(
+ name: trimmed, variant: variant, iphoneSource: iphoneSource, cloudosSource: cloudosSource,
+ diskSizeGB: Int(disk))
+ let model = services.taskCenter.start(
+ title: "Create \(trimmed) · \(variant)",
+ plannedStages: VPhoneCommandBuilder.createStages,
+ stageMap: VPhoneCommandBuilder.createStageMap,
+ executable: services.executable,
+ arguments: args)
+ let createdName = trimmed
+ let createdVariant = variant
+ let createdCPU = Int(cpu)
+ let createdMemory = Int(memory)
+ Task {
+ while model.status == .running {
+ try? await Task.sleep(for: .milliseconds(500))
+ }
+ if model.status == .succeeded {
+ try? services.variants.setVariant(createdVariant, forVM: createdName)
+ // vm create has no resource flags — apply the chosen CPU/memory to the
+ // fresh bundle via vm config (effective on the first user launch).
+ try? await services.client.setConfig(
+ name: createdName, cpu: createdCPU, memoryMB: createdMemory, network: nil)
+ await services.store.refresh()
+ }
+ }
+ task = model
+ }
+}
diff --git a/Sources/vphone-ws/Views/HostReadinessSheet.swift b/Sources/vphone-ws/Views/HostReadinessSheet.swift
new file mode 100644
index 0000000..9d7ed6b
--- /dev/null
+++ b/Sources/vphone-ws/Views/HostReadinessSheet.swift
@@ -0,0 +1,88 @@
+import SwiftUI
+import VPhoneWSCore
+
+struct HostReadinessSheet: View {
+ let readiness: HostReadiness
+ var onChecks: ([HostCheck]) -> Void = { _ in }
+ @Environment(\.dismiss) private var dismiss
+ @State private var checks: [HostCheck] = []
+
+ private var attentionCount: Int {
+ checks.filter { $0.status == .attention }.count
+ }
+
+ var body: some View {
+ VStack(spacing: 0) {
+ header
+ ScrollView {
+ VStack(spacing: 0) {
+ ForEach(checks) { check in
+ CheckRow(check: check)
+ if check.id != checks.last?.id {
+ Divider().overlay(Theme.border)
+ }
+ }
+ }
+ }
+ .scrollContentBackground(.hidden)
+ }
+ .frame(width: 520, height: 420)
+ .background(Theme.bg)
+ .task {
+ checks = await readiness.runAll()
+ onChecks(checks)
+ }
+ }
+
+ private var header: some View {
+ HStack {
+ Text("Host readiness")
+ .font(.ws(15, weight: .semibold)).foregroundStyle(Theme.text)
+ Spacer()
+ if !checks.isEmpty {
+ StatusPill(
+ kind: attentionCount == 0 ? .running : .warn,
+ label: attentionCount == 0 ? "Host ready" : "\(attentionCount) need attention")
+ }
+ Button("Done") { dismiss() }.buttonStyle(.wsSecondary)
+ }
+ .padding(.horizontal, 20).padding(.vertical, 14)
+ .background(Theme.surface2)
+ .overlay(alignment: .bottom) { Rectangle().fill(Theme.border).frame(height: 1) }
+ }
+}
+
+private struct CheckRow: View {
+ let check: HostCheck
+
+ private var isOK: Bool { check.status == .ok }
+ private var accent: Color { isOK ? Theme.good : Theme.warn }
+
+ var body: some View {
+ HStack(alignment: .top, spacing: 14) {
+ ZStack {
+ Circle().fill(accent.opacity(0.16)).frame(width: 26, height: 26)
+ Image(systemName: isOK ? "checkmark" : "exclamationmark.triangle.fill")
+ .font(.ws(12, weight: .semibold))
+ .foregroundStyle(accent)
+ }
+ VStack(alignment: .leading, spacing: 4) {
+ Text(check.title).font(.ws(14, weight: .semibold)).foregroundStyle(Theme.text)
+ Text(check.detail).font(.ws(13)).foregroundStyle(Theme.dim)
+ .fixedSize(horizontal: false, vertical: true)
+ if let fix = check.fixCommand {
+ Text(fix).font(.wsMono(12)).foregroundStyle(Theme.text)
+ .textSelection(.enabled)
+ .padding(.horizontal, 9).padding(.vertical, 6)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .background(Theme.inset)
+ .overlay(RoundedRectangle(cornerRadius: Theme.radiusSmall).stroke(Theme.border, lineWidth: 1))
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ .padding(.top, 3)
+ }
+ }
+ Spacer(minLength: 0)
+ }
+ .padding(.horizontal, 20).padding(.vertical, 16)
+ }
+}
diff --git a/Sources/vphone-ws/Views/LibraryView.swift b/Sources/vphone-ws/Views/LibraryView.swift
new file mode 100644
index 0000000..1ee5b8a
--- /dev/null
+++ b/Sources/vphone-ws/Views/LibraryView.swift
@@ -0,0 +1,227 @@
+import AppKit
+import SwiftUI
+import VPhoneWSCore
+
+struct LibraryView: View {
+ let services: AppEnvironment.Services
+ @State private var selection: String?
+ @State private var query = ""
+ @State private var readinessChecks: [HostCheck] = []
+ @State private var showReadiness = false
+ @State private var showCreate = false
+ @State private var operationTask: TaskModel?
+ @State private var actionError: String?
+
+ private var store: VMStore { services.store }
+
+ private var filtered: [VMRow] {
+ query.isEmpty ? store.rows
+ : store.rows.filter { $0.report.name.localizedCaseInsensitiveContains(query) }
+ }
+
+ private var attentionCount: Int {
+ readinessChecks.filter { $0.status == .attention }.count
+ }
+
+ var body: some View {
+ VStack(spacing: 0) {
+ titleBar
+ if showCreate {
+ CreateWizardView(services: services, onClose: { showCreate = false })
+ .frame(maxWidth: .infinity, maxHeight: .infinity)
+ } else {
+ HStack(spacing: 0) {
+ sidebar.frame(width: Theme.sidebarWidth)
+ Rectangle().fill(Theme.border).frame(width: 1)
+ detail.frame(maxWidth: .infinity, maxHeight: .infinity)
+ }
+ }
+ }
+ .ignoresSafeArea(.container, edges: .top)
+ .task {
+ while !Task.isCancelled {
+ await store.refresh()
+ readinessChecks = await services.readiness.runAll()
+ try? await Task.sleep(for: .seconds(3))
+ }
+ }
+ .sheet(isPresented: $showReadiness) {
+ HostReadinessSheet(readiness: services.readiness) { readinessChecks = $0 }
+ }
+ .sheet(item: $operationTask) { task in
+ OperationSheet(task: task, onClose: { operationTask = nil })
+ }
+ .alert("Couldn't start VM", isPresented: startErrorPresented) {
+ Button("OK") {}
+ } message: {
+ Text(actionError ?? "")
+ }
+ }
+
+ private var startErrorPresented: Binding<Bool> {
+ Binding(get: { actionError != nil }, set: { if !$0 { actionError = nil } })
+ }
+
+ private func activate(_ row: VMRow) {
+ selection = row.report.name
+ guard !row.isRunning else {
+ Task { await services.coordinator.showScreen(name: row.report.name) }
+ return
+ }
+ do {
+ try services.coordinator.launch(name: row.report.name)
+ Task { await store.refresh() }
+ } catch {
+ actionError = String(describing: error)
+ }
+ }
+
+ private var titleBar: some View {
+ HStack(spacing: 10) {
+ Text("vPhone Workstation")
+ .font(.ws(13, weight: .semibold))
+ .foregroundStyle(Theme.dim)
+ Spacer()
+ Button { showReadiness = true } label: {
+ StatusPill(
+ kind: attentionCount == 0 ? .running : .warn,
+ label: attentionCount == 0 ? "Host ready" : "\(attentionCount) need attention")
+ }
+ .buttonStyle(.plain)
+ .focusEffectDisabled()
+ }
+ .padding(.leading, 78)
+ .padding(.trailing, 14)
+ .frame(height: 40)
+ .background(Theme.surface2)
+ .overlay(alignment: .bottom) { Rectangle().fill(Theme.border).frame(height: 1) }
+ }
+
+ private var sidebar: some View {
+ VStack(spacing: 0) {
+ searchField
+ ScrollView {
+ LazyVStack(spacing: 2) {
+ ForEach(filtered) { row in
+ SidebarRow(row: row, selected: selection == row.report.name)
+ .contentShape(.rect)
+ // Single tap selects immediately; the double-tap runs
+ // simultaneously so it doesn't hold the single tap for
+ // the double-click timeout.
+ .onTapGesture { selection = row.report.name }
+ .simultaneousGesture(TapGesture(count: 2).onEnded { activate(row) })
+ }
+ }
+ .padding(.horizontal, 8)
+ .padding(.top, 4)
+ }
+ .scrollContentBackground(.hidden)
+ newVMFooter
+ }
+ .background(Theme.surface2)
+ }
+
+ private var searchField: some View {
+ HStack(spacing: 8) {
+ Image(systemName: "magnifyingglass").font(.ws(13)).foregroundStyle(Theme.faint)
+ TextField("Search VMs", text: $query)
+ .textFieldStyle(.plain)
+ .font(.ws(13))
+ .foregroundStyle(Theme.text)
+ }
+ .padding(.horizontal, 10).padding(.vertical, 7)
+ .background(Theme.surface)
+ .overlay(RoundedRectangle(cornerRadius: Theme.radiusSmall).stroke(Theme.border, lineWidth: 1))
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ .padding(12)
+ }
+
+ private var newVMFooter: some View {
+ VStack(spacing: 0) {
+ Divider().overlay(Theme.border)
+ HStack(spacing: 12) {
+ Button { showCreate = true } label: {
+ HStack(spacing: 8) {
+ Image(systemName: "plus").font(.ws(12, weight: .semibold))
+ Text("New VM…").font(.ws(13, weight: .semibold))
+ }
+ .foregroundStyle(Theme.accent)
+ }
+ .buttonStyle(.plain)
+ Spacer()
+ Button { importVM() } label: {
+ Image(systemName: "square.and.arrow.down").font(.ws(14)).foregroundStyle(Theme.dim)
+ }
+ .buttonStyle(.plain).help("Import VM…")
+ }
+ .padding(.horizontal, 12).padding(.vertical, 10)
+ }
+ }
+
+ @ViewBuilder
+ private var detail: some View {
+ if let name = selection, let row = store.rows.first(where: { $0.report.name == name }) {
+ VMDetailView(row: row, services: services, selection: $selection,
+ presentOperation: { operationTask = $0 })
+ .background(Theme.bg)
+ } else {
+ ZStack {
+ Theme.bg
+ if let err = store.loadError {
+ VStack(spacing: 10) {
+ Image(systemName: "exclamationmark.triangle.fill")
+ .font(.system(size: 34)).foregroundStyle(Theme.warn)
+ Text("Couldn't load VMs").font(.ws(15, weight: .semibold))
+ .foregroundStyle(Theme.text)
+ Text(err).font(.ws(12.5)).foregroundStyle(Theme.dim)
+ .multilineTextAlignment(.center)
+ .fixedSize(horizontal: false, vertical: true)
+ .frame(maxWidth: 380)
+ }
+ .padding(24)
+ } else {
+ VStack(spacing: 12) {
+ Image(systemName: "iphone").font(.system(size: 40)).foregroundStyle(Theme.faint)
+ Text("Select a VM").font(.ws(15)).foregroundStyle(Theme.dim)
+ }
+ }
+ }
+ }
+ }
+
+ private func importVM() {
+ let panel = NSOpenPanel()
+ panel.allowedContentTypes = [.init(filenameExtension: "xz")!]
+ if panel.runModal() == .OK, let url = panel.url {
+ let base = url.deletingPathExtension().deletingPathExtension().lastPathComponent
+ operationTask = services.taskCenter.start(
+ title: "Import \(base)", plannedStages: [],
+ executable: services.executable,
+ arguments: services.commandBuilder.importArgs(archive: url.path, name: base))
+ }
+ }
+}
+
+private struct SidebarRow: View {
+ let row: VMRow
+ let selected: Bool
+
+ var body: some View {
+ HStack(spacing: 11) {
+ Image(systemName: "iphone")
+ .font(.system(size: 18))
+ .foregroundStyle(selected ? Theme.accent : Theme.dim)
+ VStack(alignment: .leading, spacing: 2) {
+ HStack(spacing: 7) {
+ StatusDot(running: row.isRunning)
+ Text(row.report.name).font(.ws(13.5, weight: .semibold)).foregroundStyle(Theme.text)
+ }
+ Text(row.displayVersions).font(.wsMono(11.5)).foregroundStyle(Theme.faint)
+ }
+ Spacer(minLength: 0)
+ }
+ .padding(.vertical, 8).padding(.horizontal, 10)
+ .background(selected ? Theme.accent.opacity(0.14) : Color.clear)
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ }
+}
diff --git a/Sources/vphone-ws/Views/SettingsSheet.swift b/Sources/vphone-ws/Views/SettingsSheet.swift
new file mode 100644
index 0000000..da29298
--- /dev/null
+++ b/Sources/vphone-ws/Views/SettingsSheet.swift
@@ -0,0 +1,138 @@
+import SwiftUI
+import VPhoneWSCore
+
+struct SettingsSheet: View {
+ // vm config --network accepts only nat | bridged | none (hostOnly is rejected).
+ static let networkOptions: [(value: String, label: String)] = [
+ ("nat", "NAT"), ("bridged", "Bridged"), ("none", "None"),
+ ]
+
+ let row: VMRow
+ let services: AppEnvironment.Services
+ @Environment(\.dismiss) private var dismiss
+ @State private var cpu: Double
+ @State private var memory: Double
+ @State private var network: String
+ @State private var actionError: String?
+
+ init(row: VMRow, services: AppEnvironment.Services) {
+ self.row = row
+ self.services = services
+ _cpu = State(initialValue: Double(row.report.cpuCount))
+ _memory = State(initialValue: Double(row.report.memoryMB))
+ _network = State(initialValue: row.report.network?.mode ?? "nat")
+ }
+
+ private var errorPresented: Binding<Bool> {
+ Binding(get: { actionError != nil }, set: { if !$0 { actionError = nil } })
+ }
+
+ private var fixedSpecs: [(String, SpecValue)] {
+ [("Disk", .text("\(row.report.diskSizeBytes / 1_073_741_824) GB"))]
+ }
+
+ var body: some View {
+ VStack(spacing: 0) {
+ header
+ ScrollView {
+ VStack(alignment: .leading, spacing: 16) {
+ field("CPU cores") {
+ WSStepper(value: $cpu, range: 1...32, step: 1) { "\($0) cores" }
+ }
+ field("Memory") {
+ WSStepper(value: $memory, range: 1024...65536, step: 1024) { "\($0) MB" }
+ }
+ field("Network") {
+ wsSegmented(selection: $network, options: Self.networkOptions)
+ }
+ VStack(alignment: .leading, spacing: 12) {
+ SectionLabel(text: "Fixed at build time")
+ SpecGrid(specs: fixedSpecs)
+ }
+ .padding(.top, 4)
+ Text("Applies on next boot; the VM must be stopped.")
+ .font(.ws(12)).foregroundStyle(Theme.faint)
+ }
+ .padding(20)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ }
+ .scrollContentBackground(.hidden)
+ footer
+ }
+ .frame(width: 420)
+ .background(Theme.bg)
+ .focusEffectDisabled()
+ .alert("Couldn't save settings", isPresented: errorPresented) {
+ Button("OK") {}
+ } message: {
+ Text(actionError ?? "")
+ }
+ }
+
+ private var header: some View {
+ HStack {
+ Text("\(row.report.name) — Settings")
+ .font(.ws(15, weight: .semibold)).foregroundStyle(Theme.text)
+ Spacer()
+ }
+ .padding(.horizontal, 20).padding(.vertical, 14)
+ .background(Theme.surface2)
+ .overlay(alignment: .bottom) { Rectangle().fill(Theme.border).frame(height: 1) }
+ }
+
+ private var footer: some View {
+ HStack {
+ Button("Cancel") { dismiss() }.buttonStyle(.wsSecondary)
+ Spacer()
+ Button("Save") { save() }.buttonStyle(.wsPrimary).disabled(row.isRunning)
+ }
+ .padding(.horizontal, 20).padding(.vertical, 14)
+ .background(Theme.surface2)
+ .overlay(alignment: .top) { Rectangle().fill(Theme.border).frame(height: 1) }
+ }
+
+ private func field<Content: View>(_ label: String, @ViewBuilder content: () -> Content) -> some View {
+ VStack(alignment: .leading, spacing: 6) {
+ Text(label).font(.ws(12, weight: .semibold)).foregroundStyle(Theme.dim)
+ content()
+ }
+ }
+
+ private func wsSegmented(selection: Binding<String>, options: [(value: String, label: String)]) -> some View {
+ HStack(spacing: 0) {
+ ForEach(Array(options.enumerated()), id: \.element.value) { index, opt in
+ let on = selection.wrappedValue == opt.value
+ Button { selection.wrappedValue = opt.value } label: {
+ Text(opt.label)
+ .font(.ws(13, weight: on ? .semibold : .regular))
+ .foregroundStyle(on ? Theme.accentInk : Theme.dim)
+ .padding(.vertical, 7)
+ .frame(maxWidth: .infinity)
+ .background(on ? Theme.accent : Color.clear)
+ .contentShape(.rect)
+ }.buttonStyle(.plain)
+ if index < options.count - 1 {
+ Rectangle().fill(Theme.borderStrong).frame(width: 1)
+ }
+ }
+ }
+ .overlay(RoundedRectangle(cornerRadius: Theme.radiusSmall).stroke(Theme.borderStrong, lineWidth: 1))
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ }
+
+ private func save() {
+ Task {
+ do {
+ try await services.client.setConfig(
+ name: row.report.name,
+ cpu: Int(cpu),
+ memoryMB: Int(memory),
+ network: network)
+ await services.store.refresh()
+ dismiss()
+ } catch {
+ actionError = String(describing: error)
+ }
+ }
+ }
+}
diff --git a/Sources/vphone-ws/Views/TaskProgressViews.swift b/Sources/vphone-ws/Views/TaskProgressViews.swift
new file mode 100644
index 0000000..6b97f87
--- /dev/null
+++ b/Sources/vphone-ws/Views/TaskProgressViews.swift
@@ -0,0 +1,185 @@
+import AppKit
+import SwiftUI
+import VPhoneWSCore
+
+/// Status pill for a task (Running / Done / Cancelled / Failed).
+struct TaskStatusBadge: View {
+ let status: TaskStatus
+
+ var body: some View {
+ switch status {
+ case .running: StatusPill(kind: .warn, label: "Running")
+ case .succeeded: StatusPill(kind: .running, label: "Done")
+ case .cancelled: StatusPill(kind: .stopped, label: "Cancelled")
+ case .failed(let code): critPill("Failed (\(code))")
+ }
+ }
+
+ private func critPill(_ label: String) -> some View {
+ HStack(spacing: 6) {
+ Circle().fill(Theme.crit).frame(width: 7, height: 7)
+ Text(label).font(.ws(12, weight: .semibold))
+ }
+ .foregroundStyle(Theme.crit)
+ .padding(.horizontal, 10).padding(.vertical, 4)
+ .background(Theme.crit.opacity(0.16))
+ .overlay(Capsule().stroke(Theme.crit.opacity(0.3), lineWidth: 1))
+ .clipShape(.capsule)
+ }
+}
+
+/// Stage chips + the grouped, auto-scrolling log for one task. Fills its
+/// container so it grows with a resizable window.
+struct TaskLogView: View {
+ let task: TaskModel
+
+ var body: some View {
+ VStack(alignment: .leading, spacing: 12) {
+ if !task.plannedStages.isEmpty {
+ HStack(spacing: 6) {
+ ForEach(task.plannedStages, id: \.self) { stage in
+ StageChip(label: stage, state: chipState(stage))
+ }
+ }
+ }
+ ScrollViewReader { proxy in
+ ScrollView {
+ logBody
+ Color.clear.frame(height: 1).id("logBottom")
+ }
+ .scrollContentBackground(.hidden)
+ .background(Theme.logBackground)
+ .overlay(RoundedRectangle(cornerRadius: Theme.radiusSmall).stroke(Theme.border, lineWidth: 1))
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ .onChange(of: task.segments) { _, _ in
+ proxy.scrollTo("logBottom", anchor: .bottom)
+ }
+ }
+ }
+ }
+
+ @ViewBuilder private var logBody: some View {
+ if task.segments.isEmpty {
+ Text(task.status == .running ? "Working…" : " ")
+ .font(.wsMono(12)).foregroundStyle(Theme.logText.opacity(0.5))
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .padding(12)
+ } else {
+ VStack(alignment: .leading, spacing: 0) {
+ ForEach(Array(task.segments.enumerated()), id: \.element.id) { idx, seg in
+ segmentSection(seg)
+ if idx < task.segments.count - 1 {
+ Rectangle().fill(Theme.border).frame(height: 1)
+ }
+ }
+ }
+ }
+ }
+
+ private func segmentSection(_ seg: LogSegment) -> some View {
+ VStack(alignment: .leading, spacing: 5) {
+ HStack(spacing: 7) {
+ segmentGlyph(seg)
+ Text(seg.title)
+ .font(.wsMono(11.5, weight: .semibold))
+ .foregroundStyle(seg.isDone ? Theme.dim : Theme.text)
+ }
+ if !seg.lines.isEmpty || seg.liveLine != nil {
+ VStack(alignment: .leading, spacing: 2) {
+ ForEach(Array(seg.lines.suffix(400).enumerated()), id: \.offset) { _, line in
+ logLine(line)
+ }
+ if let live = seg.liveLine { logLine(live) }
+ }
+ .padding(.leading, 19)
+ }
+ }
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .padding(.horizontal, 12).padding(.vertical, 10)
+ }
+
+ private func logLine(_ line: String) -> some View {
+ Text(line.isEmpty ? " " : line)
+ .font(.wsMono(12))
+ .foregroundStyle(lineColor(line))
+ .textSelection(.enabled)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ }
+
+ private func segmentGlyph(_ seg: LogSegment) -> some View {
+ let (symbol, color): (String, Color) = {
+ if seg.isDone { return ("✓", Theme.good) }
+ switch task.status {
+ case .running: return ("▸", Theme.accent)
+ case .failed: return ("✕", Theme.crit)
+ case .cancelled: return ("–", Theme.faint)
+ case .succeeded: return ("✓", Theme.good)
+ }
+ }()
+ return Text(symbol).font(.wsMono(11, weight: .semibold)).foregroundStyle(color).frame(width: 12)
+ }
+
+ private func chipState(_ stage: String) -> StageChip.State {
+ if task.completedStages.contains(stage) { return .completed }
+ if task.currentStage == stage { return .current }
+ return .pending
+ }
+
+ private func lineColor(_ line: String) -> Color {
+ let t = line.trimmingCharacters(in: .whitespaces)
+ if t.hasPrefix("===") && t.hasSuffix("===") { return Theme.accent }
+ if line.hasPrefix("[+]") { return Theme.good }
+ if line.hasPrefix("[i]") { return Theme.accent }
+ if line.hasPrefix("[*]") { return Theme.dim }
+ if line.hasPrefix("[-]") || line.hasPrefix("[!]") { return Theme.crit }
+ return Theme.logText
+ }
+}
+
+/// Progress for a one-off operation (export/import) shown as a sheet.
+struct OperationSheet: View {
+ let task: TaskModel
+ var onClose: () -> Void
+
+ var body: some View {
+ VStack(spacing: 0) {
+ HStack(spacing: 12) {
+ Text(task.title).font(.ws(15, weight: .semibold)).foregroundStyle(Theme.text)
+ TaskStatusBadge(status: task.status)
+ Spacer()
+ }
+ .padding(.horizontal, 20).padding(.vertical, 14)
+ .background(Theme.surface2)
+ .overlay(alignment: .bottom) { Rectangle().fill(Theme.border).frame(height: 1) }
+
+ TaskLogView(task: task).padding(20)
+
+ HStack {
+ Button("Export log…") { TaskLogExporter.export(task, suggestedName: task.title) }
+ .buttonStyle(.wsSecondary)
+ Spacer()
+ if task.status == .running {
+ Button("Cancel") { task.cancel() }.buttonStyle(.wsDanger)
+ } else {
+ Button("Done") { onClose() }.buttonStyle(.wsPrimary)
+ }
+ }
+ .padding(.horizontal, 20).padding(.vertical, 14)
+ .background(Theme.surface2)
+ .overlay(alignment: .top) { Rectangle().fill(Theme.border).frame(height: 1) }
+ }
+ .frame(width: 640, height: 460)
+ .background(Theme.bg)
+ }
+}
+
+enum TaskLogExporter {
+ /// Save the task's full log to a user-chosen `.log` file.
+ @MainActor static func export(_ task: TaskModel, suggestedName: String) {
+ let panel = NSSavePanel()
+ panel.nameFieldStringValue = "\(suggestedName).log"
+ panel.allowedContentTypes = [.init(filenameExtension: "log") ?? .plainText]
+ guard panel.runModal() == .OK, let url = panel.url else { return }
+ try? task.exportText.write(to: url, atomically: true, encoding: .utf8)
+ }
+}
diff --git a/Sources/vphone-ws/Views/VMDetailView.swift b/Sources/vphone-ws/Views/VMDetailView.swift
new file mode 100644
index 0000000..b6c1886
--- /dev/null
+++ b/Sources/vphone-ws/Views/VMDetailView.swift
@@ -0,0 +1,194 @@
+import AppKit
+import SwiftUI
+import VPhoneWSCore
+
+struct VMDetailView: View {
+ let row: VMRow
+ let services: AppEnvironment.Services
+ @Binding var selection: String?
+ var presentOperation: (TaskModel) -> Void = { _ in }
+
+ @State private var showSettings = false
+ @State private var confirmDelete = false
+ @State private var showCloneAlert = false
+ @State private var showRenameAlert = false
+ @State private var newName = ""
+ @State private var actionError: String?
+
+ private var errorPresented: Binding<Bool> {
+ Binding(get: { actionError != nil }, set: { if !$0 { actionError = nil } })
+ }
+
+ private var specs: [(String, SpecValue)] {
+ let r = row.report
+ let variant = r.restoreInfo?.variant ?? services.variants.variant(forVM: r.name)
+ return [
+ ("iOS", .text(r.restoreInfo.map { "\($0.ios.version) (\($0.ios.build))" } ?? "—")),
+ ("cloudOS", .text(r.restoreInfo.map { "\($0.cloudOS.version) (\($0.cloudOS.build))" } ?? "—")),
+ ("Variant", variant.map { .variantBadge($0) } ?? .text("Unknown")),
+ ("CPU", .text("\(r.cpuCount) cores")),
+ ("Memory", .text("\(r.memoryMB) MB")),
+ ("Disk", .text("\(r.diskSizeBytes / 1_073_741_824) GB")),
+ ("Network", .text(Self.networkLabel(r.network))),
+ ("Device", .mono(r.restoreInfo?.device ?? "Unknown")),
+ ("UDID", .mono(r.udid ?? "Unknown")),
+ ]
+ }
+
+ static func networkLabel(_ network: NetworkInfo?) -> String {
+ guard let network else { return "Unknown" }
+ switch network.mode {
+ case "nat": return "NAT"
+ case "bridged": return "Bridged"
+ case "hostOnly": return "Host-Only"
+ case "none": return "Off"
+ default: return network.mode
+ }
+ }
+
+ var body: some View {
+ ScrollView {
+ VStack(alignment: .leading, spacing: 22) {
+ header
+ callout
+ VStack(alignment: .leading, spacing: 12) {
+ SectionLabel(text: "Overview")
+ SpecGridSpanning(specs: specs, columns: 5, wideKeys: ["UDID"])
+ }
+ Spacer(minLength: 0)
+ }
+ .padding(24)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ }
+ .scrollContentBackground(.hidden)
+ .background(Theme.bg)
+ .sheet(isPresented: $showSettings) { SettingsSheet(row: row, services: services) }
+ .confirmationDialog(
+ "Delete \(row.report.name)?", isPresented: $confirmDelete, titleVisibility: .visible
+ ) {
+ Button("Delete", role: .destructive) {
+ Task {
+ do {
+ try await services.client.delete(name: row.report.name)
+ selection = nil
+ await services.store.refresh()
+ } catch { actionError = String(describing: error) }
+ }
+ }
+ Button("Cancel", role: .cancel) {}
+ } message: {
+ Text("This permanently removes the VM and its disk image.")
+ }
+ .alert("Clone \(row.report.name)", isPresented: $showCloneAlert) {
+ TextField("New name", text: $newName)
+ Button("Clone") {
+ Task {
+ do {
+ try await services.client.clone(name: row.report.name, to: newName)
+ await services.store.refresh()
+ } catch { actionError = String(describing: error) }
+ }
+ }
+ Button("Cancel", role: .cancel) {}
+ }
+ .alert("Rename \(row.report.name)", isPresented: $showRenameAlert) {
+ TextField("New name", text: $newName)
+ Button("Rename") {
+ Task {
+ do {
+ try await services.client.rename(name: row.report.name, to: newName)
+ selection = newName
+ await services.store.refresh()
+ } catch { actionError = String(describing: error) }
+ }
+ }
+ Button("Cancel", role: .cancel) {}
+ }
+ .alert("Action failed", isPresented: errorPresented) {
+ Button("OK") {}
+ } message: {
+ Text(actionError ?? "")
+ }
+ }
+
+ private var header: some View {
+ VStack(alignment: .leading, spacing: 14) {
+ VStack(alignment: .leading, spacing: 6) {
+ HStack(spacing: 12) {
+ Text(row.report.name).font(.ws(24, weight: .bold)).foregroundStyle(Theme.text)
+ .lineLimit(1).truncationMode(.tail)
+ StatusPill(
+ kind: row.isRunning ? .running : .stopped,
+ label: row.isRunning ? "Running" : "Stopped")
+ }
+ Text("~/.vphone/VMs/\(row.report.name)")
+ .font(.wsMono(12)).foregroundStyle(Theme.faint)
+ .lineLimit(1).truncationMode(.middle)
+ }
+ HStack(spacing: 8) {
+ actionRow
+ Spacer(minLength: 0)
+ }
+ }
+ }
+
+ private var callout: some View {
+ HStack(alignment: .top, spacing: 11) {
+ Image(systemName: "info.circle").font(.ws(15)).foregroundStyle(Theme.accent)
+ Text("The iPhone screen opens in its own window. vPhone Workstation manages this VM; the live display, touch, and menus are handled by vphone-cli. “Show screen” brings that window forward.")
+ .font(.ws(13)).foregroundStyle(Theme.text)
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ .padding(.horizontal, 14).padding(.vertical, 12)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .background(Theme.accent.opacity(0.14))
+ .overlay(RoundedRectangle(cornerRadius: Theme.radiusSmall).stroke(Theme.accent.opacity(0.28), lineWidth: 1))
+ .clipShape(.rect(cornerRadius: Theme.radiusSmall))
+ }
+
+ @ViewBuilder
+ private var actionRow: some View {
+ if row.isRunning {
+ Button {
+ Task {
+ do {
+ try await services.coordinator.stop(name: row.report.name)
+ await services.store.refresh()
+ } catch { actionError = String(describing: error) }
+ }
+ } label: {
+ Label("Stop", systemImage: "stop.fill")
+ }.buttonStyle(.wsDanger)
+ Button {
+ Task { await services.coordinator.showScreen(name: row.report.name) }
+ } label: {
+ Label("Show screen", systemImage: "macwindow")
+ }.buttonStyle(.wsSecondary)
+ } else {
+ Button {
+ do {
+ try services.coordinator.launch(name: row.report.name)
+ Task { await services.store.refresh() }
+ } catch { actionError = String(describing: error) }
+ } label: {
+ Label("Start", systemImage: "play.fill")
+ }.buttonStyle(.wsPrimary)
+ }
+ Button("Settings") { showSettings = true }.buttonStyle(.wsSecondary)
+ Button("Clone") { newName = ""; showCloneAlert = true }.buttonStyle(.wsSecondary)
+ Button("Rename") { newName = ""; showRenameAlert = true }.buttonStyle(.wsSecondary)
+ Button("Export") { exportVM() }.buttonStyle(.wsSecondary)
+ Button("Delete") { confirmDelete = true }.buttonStyle(.wsDanger)
+ }
+
+ private func exportVM() {
+ let panel = NSSavePanel()
+ panel.nameFieldStringValue = "\(row.report.name).tar.xz"
+ if panel.runModal() == .OK, let out = panel.url?.path {
+ presentOperation(services.taskCenter.start(
+ title: "Export \(row.report.name)", plannedStages: [],
+ executable: services.executable,
+ arguments: services.commandBuilder.exportArgs(name: row.report.name, out: out)))
+ }
+ }
+}