Repository Public License
1// ORIX Convert — App/Sources/App/RootView.swift2// Description: Main window: the ORIX sidebar (labels, or icons only in narrow windows) and the visible section.3// The whole window is a drop target. SectionHost maps each AppSection to its view.4// Author: Simon-Pierre Boucher — contact@spboucher.ai5import ConvertCore6import SwiftUI7import UniformTypeIdentifiers89struct RootView: View {10 @Environment(AppModel.self) private var model11 @Environment(\.openSettings) private var openSettings12 @Environment(\.openWindow) private var openWindow1314 var body: some View {15 GeometryReader { geo in16 let compact = geo.size.width < ORIX.Metric.compactSidebarBreakpoint17 HStack(spacing: 0) {18 Sidebar(compact: compact)19 ORIX.Palette.hairline.frame(width: 1)20 SectionHost(section: model.section)21 .frame(maxWidth: .infinity, maxHeight: .infinity)22 .background(ORIX.Palette.canvas)23 }24 }25 .background(ORIX.Palette.canvas)26 .ignoresSafeArea(.container, edges: .top)27 .foregroundStyle(ORIX.Palette.textPrimary)28 .onDrop(of: [.fileURL], isTargeted: Binding(get: { model.isDropTargeted }, set: { model.isDropTargeted = $0 })) { providers in29 DropLoader.load(providers) { model.receive(urls: $0) }30 return true31 }32 .overlay { if model.isDropTargeted && !(model.section == .convert && model.workspace.isEmpty && model.queue.isEmpty) { DropHighlight(text: model.dropHint) } }33 .onPasteCommand(of: [.fileURL]) { providers in DropLoader.load(providers) { model.receive(urls: $0) } }34 .onAppear {35 model.openMainWindow = { openWindow(id: "main") }36 if model.launch.section?.hasPrefix("settings") == true { openSettings() }37 }38 }39}4041/// Reads file URLs out of drag or paste item providers.42enum DropLoader {43 static func load(_ providers: [NSItemProvider], completion: @escaping @MainActor ([URL]) -> Void) {44 let group = DispatchGroup()45 let box = URLBox()46 for provider in providers where provider.canLoadObject(ofClass: URL.self) {47 group.enter()48 _ = provider.loadObject(ofClass: URL.self) { url, _ in49 if let url, url.isFileURL { box.add(url) }50 group.leave()51 }52 }53 group.notify(queue: .main) {54 let urls = box.all55 MainActor.assumeIsolated { if !urls.isEmpty { completion(urls) } }56 }57 }5859 private nonisolated final class URLBox: @unchecked Sendable {60 private let lock = NSLock()61 private var urls: [URL] = []62 func add(_ url: URL) { lock.lock(); urls.append(url); lock.unlock() }63 var all: [URL] { lock.lock(); defer { lock.unlock() }; return urls }64 }65}6667/// Outline shown over the window while files are dragged over a section that is not the empty drop zone.68struct DropHighlight: View {69 var text = L("Drop to add to the batch")70 var body: some View {71 RoundedRectangle(cornerRadius: ORIX.Radius.l, style: .continuous)72 .strokeBorder(ORIX.Palette.transformationDiagonal, lineWidth: 3)73 .background(ORIX.Palette.accent.opacity(0.06), in: RoundedRectangle(cornerRadius: ORIX.Radius.l, style: .continuous))74 .padding(6)75 .overlay(alignment: .bottom) {76 Label(text, systemImage: "plus.circle.fill")77 .font(.callout.weight(.semibold)).foregroundStyle(.white)78 .padding(.horizontal, 14).padding(.vertical, 8)79 .background(ORIX.Palette.action, in: Capsule())80 .padding(.bottom, 28)81 }82 .allowsHitTesting(false)83 .accessibilityHidden(true)84 }85}8687/// THE table of sections: one view per AppSection.88struct SectionHost: View {89 let section: AppSection90 var body: some View {91 switch section {92 case .convert: ConvertView()93 case .history: HistoryView()94 case .metadata: MetadataStudioView()95 case .formats: FormatsView()96 case .qualityLab: QualityLabView()97 case .vectorStudio: VectorStudioView()98 case .flow: FlowView()99 case .watchFolders: WatchFoldersView()100 }101 }102}103104struct Sidebar: View {105 @Environment(AppModel.self) private var model106 @Environment(\.openSettings) private var openSettings107 let compact: Bool108109 var body: some View {110 VStack(alignment: .leading, spacing: 0) {111 // Room for the window controls of the hidden title bar.112 Color.clear.frame(height: 44)113 if !compact {114 HStack(spacing: 8) {115 RoundedRectangle(cornerRadius: 4, style: .continuous).fill(ORIX.Palette.transformationDiagonal).frame(width: 14, height: 14).accessibilityHidden(true)116 Text("ORIX Convert").font(.headline).foregroundStyle(ORIX.Palette.textPrimary)117 }118 .padding(.horizontal, ORIX.Space.l).padding(.bottom, ORIX.Space.m)119 .accessibilityAddTraits(.isHeader)120 }121 ScrollView {122 VStack(alignment: .leading, spacing: 2) {123 ForEach(AppSection.Group.allCases, id: \.self) { group in124 if compact {125 if group != .workspace { ORIX.Palette.hairline.frame(height: 1).padding(.vertical, 6).padding(.horizontal, 14) }126 } else {127 SectionLabel(group.title).padding(.horizontal, ORIX.Space.s).padding(.top, group == .workspace ? 2 : ORIX.Space.l).padding(.bottom, 4)128 }129 ForEach(AppSection.allCases.filter { $0.group == group }) { section in130 SidebarItem(title: section.title, symbol: section.symbol, selected: model.section == section, compact: compact,131 badge: section == .convert ? convertBadge : nil, muted: section.placeholderSummary != nil) {132 model.section = section133 }134 }135 }136 }137 .padding(.horizontal, ORIX.Space.s)138 }139 Spacer(minLength: 0)140 SidebarItem(title: L("Settings"), symbol: "gearshape", selected: false, compact: compact, badge: nil, muted: false) { openSettings() }141 .padding(.horizontal, ORIX.Space.s).padding(.bottom, ORIX.Space.m)142 }143 .frame(width: compact ? ORIX.Metric.sidebarCompactWidth : ORIX.Metric.sidebarWidth)144 .background(ORIX.Palette.sidebar)145 .accessibilityElement(children: .contain)146 .accessibilityLabel(L("Sections"))147 }148149 private var convertBadge: String? {150 let count = model.queue.activeCount + model.queue.waitingCount + model.queue.awaitingDecision.count151 return count > 0 ? Fmt.count(count) : nil152 }153}154155private struct SidebarItem: View {156 let title: String157 let symbol: String158 let selected: Bool159 let compact: Bool160 let badge: String?161 let muted: Bool162 let action: () -> Void163 @State private var hovering = false164165 var body: some View {166 Button(action: action) {167 HStack(spacing: 9) {168 Image(systemName: symbol)169 .font(.system(size: 14, weight: selected ? .semibold : .regular))170 .foregroundStyle(selected ? AnyShapeStyle(ORIX.Palette.accent) : AnyShapeStyle(muted ? ORIX.Palette.textTertiary : ORIX.Palette.textSecondary))171 .frame(width: 22)172 if !compact {173 Text(title).font(.callout.weight(selected ? .semibold : .regular))174 .foregroundStyle(selected ? ORIX.Palette.textPrimary : (muted ? ORIX.Palette.textSecondary : ORIX.Palette.textPrimary))175 // A long title (French: « Studio de métadonnées », in semibold when selected) wraps onto a176 // second line instead of being cut.177 .lineLimit(2).multilineTextAlignment(.leading).fixedSize(horizontal: false, vertical: true)178 Spacer(minLength: 0)179 if let badge {180 Text(badge).font(.caption2.weight(.bold).monospacedDigit()).foregroundStyle(.white)181 .padding(.horizontal, 6).padding(.vertical, 1.5).background(ORIX.Palette.accent, in: Capsule())182 }183 }184 }185 .padding(.horizontal, compact ? 0 : 9).padding(.vertical, 6.5)186 .frame(maxWidth: .infinity, alignment: compact ? .center : .leading)187 .background(selected ? ORIX.Palette.accentSoft : (hovering ? ORIX.Palette.hairline.opacity(0.6) : .clear), in: RoundedRectangle(cornerRadius: ORIX.Radius.m, style: .continuous))188 .overlay(alignment: .topTrailing) {189 if compact, badge != nil { Circle().fill(ORIX.Palette.accent).frame(width: 7, height: 7).offset(x: -8, y: 5) }190 }191 .contentShape(Rectangle())192 }193 .buttonStyle(.plain)194 .onHover { hovering = $0 }195 .help(title)196 .accessibilityLabel(title)197 .accessibilityValue(badge.map { L("%@ jobs in the queue", $0) } ?? "")198 .accessibilityAddTraits(selected ? [.isSelected] : [])199 }200}201202/// A studio that is not built yet: says so plainly, fakes nothing.203struct PlaceholderSection: View {204 let section: AppSection205 var body: some View {206 VStack(spacing: 0) {207 HeaderBar(title: section.title, subtitle: nil) { Pill(text: L("Not built yet"), symbol: "hammer", color: ORIX.Palette.textSecondary) }208 EmptyState(symbol: section.symbol, title: L("%@ is not built yet", section.title),209 message: (section.placeholderSummary ?? "") + "\n\n" + L("This section is planned. Nothing here works yet, and nothing is simulated."))210 }211 }212}213