Repository Public License
1// ORIX Convert — App/Sources/Features/SmartDrop/ConvertView.swift2// Description: The Convert section: header with global progress, the Smart Drop welcome when nothing is staged, and3// the Prepare / Queue panes.4// Author: Simon-Pierre Boucher — contact@spboucher.ai5import ConvertCore6import SwiftUI78struct ConvertView: View {9 @Environment(AppModel.self) private var model1011 var body: some View {12 @Bindable var model = model13 let workspace = model.workspace, queue = model.queue14 VStack(spacing: 0) {15 HeaderBar(title: L("Convert"), subtitle: subtitle) {16 GlobalProgressView()17 if !(workspace.isEmpty && queue.isEmpty) {18 SegmentedPicker(selection: $model.convertPane, options: ConvertPane.allCases.map { pane in19 (pane, pane.title, pane == .prepare ? workspace.fileCount : queue.order.count)20 })21 }22 Menu {23 Button(L("Add Files…")) { model.addFiles() }24 Button(L("Add Folder…")) { model.addFolder() }25 Button(L("Paste Files")) { model.pasteFiles() }26 } label: {27 Label(L("Add"), systemImage: "plus")28 } primaryAction: { model.addFiles() }29 .menuStyle(.button).buttonStyle(SecondaryButtonStyle()).fixedSize()30 .accessibilityLabel(L("Add files or folders"))31 }32 if workspace.isEmpty && queue.isEmpty {33 DropZoneWelcome()34 } else if model.convertPane == .prepare {35 PrepareView()36 } else {37 QueueView()38 }39 }40 }4142 private var subtitle: String? {43 let workspace = model.workspace44 if workspace.isAnalyzing { return L("Analysing %lld items…", workspace.analyzingCount) }45 if model.convertPane == .prepare, !workspace.groups.isEmpty {46 return workspace.fileCount == 1 ? L("1 file ready") : L("%lld files ready", workspace.fileCount)47 }48 return nil49 }50}5152/// Global progress of the running batch, in the header. Indeterminate until something has been measured.53struct GlobalProgressView: View {54 @Environment(AppModel.self) private var model55 var body: some View {56 let queue = model.queue57 if let run = queue.runProgress {58 HStack(spacing: 8) {59 ORIXProgressRing(fraction: run.fraction, size: 18, lineWidth: 2.5, label: L("Batch progress"))60 Text(L("%lld of %lld", run.done, run.total)).font(.orixCaptionNumber).foregroundStyle(ORIX.Palette.textSecondary)61 if queue.isPaused { Pill(text: L("Paused"), symbol: "pause.fill", color: ORIX.Palette.caution) }62 }63 .accessibilityElement(children: .ignore)64 .accessibilityLabel(L("Batch progress"))65 .accessibilityValue(L("%lld of %lld conversions finished", run.done, run.total) + (run.fraction.map { ", " + Fmt.percent($0) } ?? ""))66 } else if queue.isPaused && queue.waitingCount > 0 {67 Pill(text: L("Queue paused"), symbol: "pause.fill", color: ORIX.Palette.caution)68 }69 }70}7172/// Segmented control drawn by the app (looks the same whether or not the window is key).73struct SegmentedPicker<Value: Hashable>: View {74 @Binding var selection: Value75 let options: [(value: Value, title: String, count: Int)]76 var body: some View {77 HStack(spacing: 2) {78 ForEach(Array(options.enumerated()), id: \.offset) { _, option in79 let selected = option.value == selection80 Button { selection = option.value } label: {81 HStack(spacing: 5) {82 Text(option.title).font(.callout.weight(selected ? .semibold : .regular))83 if option.count > 0 {84 Text(Fmt.count(option.count)).font(.caption2.weight(.semibold).monospacedDigit())85 .padding(.horizontal, 5).padding(.vertical, 1)86 .background((selected ? ORIX.Palette.accent : ORIX.Palette.textTertiary).opacity(0.16), in: Capsule())87 }88 }89 .foregroundStyle(selected ? ORIX.Palette.accent : ORIX.Palette.textSecondary)90 .padding(.horizontal, 11).padding(.vertical, 4.5)91 .background(selected ? ORIX.Palette.surface : .clear, in: RoundedRectangle(cornerRadius: 7, style: .continuous))92 .overlay(RoundedRectangle(cornerRadius: 7, style: .continuous).strokeBorder(selected ? ORIX.Palette.hairlineStrong : .clear, lineWidth: 1))93 .contentShape(Rectangle())94 }95 .buttonStyle(.plain)96 .accessibilityLabel(option.title)97 .accessibilityValue(option.count > 0 ? Fmt.count(option.count) : "")98 .accessibilityAddTraits(selected ? [.isSelected] : [])99 }100 }101 .padding(2)102 .background(ORIX.Palette.surfaceSunken, in: RoundedRectangle(cornerRadius: 9, style: .continuous))103 .overlay(RoundedRectangle(cornerRadius: 9, style: .continuous).strokeBorder(ORIX.Palette.hairline, lineWidth: 1))104 .fixedSize()105 }106}107108/// The empty state of the app: a universal drop zone that doubles as the welcome.109struct DropZoneWelcome: View {110 @Environment(AppModel.self) private var model111 @Environment(\.accessibilityReduceMotion) private var reduceMotion112113 var body: some View {114 let targeted = model.isDropTargeted115 let shape = RoundedRectangle(cornerRadius: ORIX.Radius.xl, style: .continuous)116 VStack(spacing: ORIX.Space.l) {117 Spacer(minLength: 0)118 TransformGlyph(active: targeted)119 VStack(spacing: 6) {120 Text(L("Every Format. One App.")).font(.system(size: 28, weight: .bold)).foregroundStyle(ORIX.Palette.textPrimary)121 Text(L("Drop files or folders anywhere in this window. ORIX Convert reads what each file really is, then proposes what it can become."))122 .font(.body).foregroundStyle(ORIX.Palette.textSecondary).multilineTextAlignment(.center).frame(maxWidth: 520)123 .fixedSize(horizontal: false, vertical: true)124 }125 HStack(spacing: ORIX.Space.m) {126 Button { model.addFiles() } label: { Label(L("Add Files…"), systemImage: "plus") }.buttonStyle(PrimaryButtonStyle())127 Button(L("Add Folder…")) { model.addFolder() }.buttonStyle(SecondaryButtonStyle())128 if !model.pasteboardFileURLs.isEmpty { Button(L("Paste Files")) { model.pasteFiles() }.buttonStyle(SecondaryButtonStyle()) }129 }130 ExampleChips()131 Spacer(minLength: 0)132 Label(L("Everything happens on this Mac. No network, no account."), systemImage: "lock.shield")133 .font(.caption).foregroundStyle(ORIX.Palette.textTertiary)134 }135 .padding(ORIX.Space.xl)136 .frame(maxWidth: .infinity, maxHeight: .infinity)137 .background(targeted ? ORIX.Palette.accentSoft : ORIX.Palette.surface, in: shape)138 .overlay(shape.strokeBorder(targeted ? AnyShapeStyle(ORIX.Palette.transformationDiagonal) : AnyShapeStyle(ORIX.Palette.hairlineStrong),139 style: StrokeStyle(lineWidth: targeted ? 3 : 1.5, dash: targeted ? [] : [7, 6])))140 .padding(ORIX.Space.xl)141 .animation(reduceMotion ? nil : ORIX.Motion.quick, value: targeted)142 .accessibilityElement(children: .contain)143 .accessibilityLabel(L("Drop zone"))144 .accessibilityHint(L("Drop files or folders here, or use Add Files."))145 }146}147148/// Two tiles joined by the transformation gradient: the app's signature mark.149private struct TransformGlyph: View {150 let active: Bool151 var body: some View {152 HStack(spacing: 0) {153 tile(symbol: "doc", color: Color(hex: 0xFB7A5C))154 ORIX.Palette.transformation.frame(width: 64, height: 4).clipShape(Capsule())155 .overlay(alignment: .trailing) {156 Image(systemName: "arrowtriangle.right.fill").font(.system(size: 10)).foregroundStyle(Color(hex: 0x22D3EE)).offset(x: 7)157 }158 .padding(.horizontal, 10)159 tile(symbol: "sparkles.rectangle.stack", color: Color(hex: 0x5B8DF8))160 }161 .scaleEffect(active ? 1.06 : 1)162 .accessibilityHidden(true)163 }164165 private func tile(symbol: String, color: Color) -> some View {166 Image(systemName: symbol).font(.system(size: 26, weight: .medium)).foregroundStyle(color)167 .frame(width: 64, height: 64)168 .background(color.opacity(0.12), in: RoundedRectangle(cornerRadius: 16, style: .continuous))169 .overlay(RoundedRectangle(cornerRadius: 16, style: .continuous).strokeBorder(color.opacity(0.35), lineWidth: 1))170 }171}172173/// A few conversions this build really supports, read from the registry (never a hard-coded promise).174private struct ExampleChips: View {175 @Environment(AppModel.self) private var model176177 /// A varied set of everyday conversions, each shown only when this build really has a verified path for it.178 private static let curated: [(FormatID, FormatID, String?)] = [179 (.heic, .jpeg, nil), (.png, .svg, "image.vectorize"), (.mov, .mp4, nil), (.wav, .mp3, nil), (.docx, .pdf, nil),180 (.pdf, .png, nil), (.markdown, .pdf, nil), (.pptx, .pdf, nil), (.srt, .vtt, nil), (.jpeg, .webp, nil), (.csv, .xlsx, nil), (.epub, .pdf, nil),181 ]182183 private var examples: [ConversionPath] {184 let registry = model.registry185 var picked: [ConversionPath] = []186 for (source, destination, operation) in Self.curated where picked.count < 8 {187 if let path = registry.paths(from: source, to: destination, operation: .some(operation)).first(where: { $0.status == .supported }) { picked.append(path) }188 }189 if picked.count >= 4 { return picked }190 // Fallback when few of the curated pairs exist: plain conversions first, one per source format, at most two191 // per category.192 let paths = registry.paths.filter { $0.status == .supported && $0.source != .folder }193 var seenSources = Set(picked.map(\.source)), seenCategories: [FormatCategory: Int] = [:]194 for path in paths.filter({ $0.operation == nil && $0.source != $0.destination }) + paths.filter({ $0.operation != nil }) {195 guard picked.count < 6, seenSources.insert(path.source).inserted, seenCategories[path.source.category, default: 0] < 2 else { continue }196 seenCategories[path.source.category, default: 0] += 1197 picked.append(path)198 }199 return picked200 }201202 var body: some View {203 let counts = model.registry.counts204 VStack(spacing: ORIX.Space.s) {205 if !examples.isEmpty {206 FlowLayout(spacing: 8, lineSpacing: 8) {207 ForEach(examples) { path in208 HStack(spacing: 6) {209 ConversionPairBadge(source: path.source, destination: path.destination)210 if let title = path.title { Text(LE(title)).font(.caption).foregroundStyle(ORIX.Palette.textSecondary) }211 }212 .padding(.horizontal, 8).padding(.vertical, 5)213 .background(ORIX.Palette.canvas, in: Capsule())214 .overlay(Capsule().strokeBorder(ORIX.Palette.hairline, lineWidth: 1))215 }216 }217 .frame(maxWidth: 620)218 }219 Button {220 model.section = .formats221 } label: {222 Text(L("%lld formats · %lld verified conversions in this build", counts.formatsWithPath, counts.verifiedPairs))223 .font(.caption.weight(.medium)).foregroundStyle(ORIX.Palette.accent)224 }225 .buttonStyle(.plain)226 .accessibilityHint(L("Opens the Formats browser"))227 }228 .padding(.top, ORIX.Space.s)229 }230}231