SPB Git

Repository Public License

WatchView.swift 28.5 KB 485 lines swift

1// ORIX Convert — App/Sources/Features/WatchFolders/WatchView.swift2// Description: Watch Folders: the rules with their real status, global and per-rule pause, the activity log (what3//              was picked up, converted, skipped as a duplicate, failed) and a plain statement of the watcher's4//              limits. Folders are only ever chosen by the user in an open panel.5// Author: Simon-Pierre Boucher — contact@spboucher.ai6import ConvertCore7import SwiftUI89struct WatchFoldersView: View {10    @Environment(AppModel.self) private var model1112    var body: some View {13        let watch = model.watch14        VStack(spacing: 0) {15            HeaderBar(title: L("Watch Folders"), subtitle: subtitle(watch)) {16                if !watch.rules.isEmpty {17                    Button { watch.toggleAll() } label: { Label(watch.isPaused ? L("Resume All") : L("Pause All"), systemImage: watch.isPaused ? "play.fill" : "pause.fill") }18                        .buttonStyle(SecondaryButtonStyle())19                }20                Button { watch.newRule() } label: { Label(L("New Rule"), systemImage: "plus") }.buttonStyle(SecondaryButtonStyle(prominent: true))21            }22            if watch.rules.isEmpty {23                ScrollView {24                    VStack(spacing: ORIX.Space.l) {25                        EmptyState(symbol: "folder.badge.gearshape", title: L("Convert files as they arrive"),26                                   message: L("A rule watches one folder you choose and converts the files that land in it. Nothing is watched until you add a rule, and only while ORIX Convert is open."),27                                   actionTitle: L("New Rule")) { watch.newRule() }28                            .frame(minHeight: 300)29                        LimitsCard().frame(maxWidth: 560)30                    }31                    .padding(ORIX.Space.xl)32                }33            } else {34                GeometryReader { geo in35                    if geo.size.width >= 840 {36                        HStack(spacing: 0) {37                            rulesColumn(watch)38                            ORIX.Palette.hairline.frame(width: 1)39                            ActivityLog(watch: watch).frame(width: min(400, geo.size.width * 0.4))40                        }41                    } else {42                        ScrollView {43                            VStack(spacing: 0) {44                                rulesContent(watch).padding(ORIX.Space.xl)45                                ORIX.Palette.hairline.frame(height: 1)46                                ActivityLog(watch: watch, embedded: true)47                            }48                        }49                    }50                }51            }52        }53        .sheet(item: Binding(get: { watch.draft }, set: { watch.draft = $0 })) { _ in WatchRuleSheet(watch: watch) }54    }5556    private func subtitle(_ watch: WatchModel) -> String? {57        if watch.rules.isEmpty { return L("Runs only while ORIX Convert is open") }58        let count = watch.rules.count == 1 ? L("1 rule") : L("%lld rules", watch.rules.count)59        let state = watch.isPaused ? L("all paused") : (watch.isRunning ? (watch.activeRuleCount == 1 ? L("1 watching") : L("%lld watching", watch.activeRuleCount)) : L("not running"))60        return count + " · " + state61    }6263    private func rulesColumn(_ watch: WatchModel) -> some View {64        ScrollView { rulesContent(watch).padding(ORIX.Space.xl) }.frame(maxWidth: .infinity, maxHeight: .infinity)65    }6667    private func rulesContent(_ watch: WatchModel) -> some View {68        VStack(alignment: .leading, spacing: ORIX.Space.m) {69            if let error = watch.loadError { Banner(kind: .caution, text: L("The saved rules could not be read."), detail: error) }70            if watch.isPaused { Banner(kind: .caution, text: L("Every rule is paused"), detail: L("Files that arrive now are not converted when you resume, unless their rule also processes the files already in the folder.")) }71            ForEach(watch.rules) { RuleCard(watch: watch, rule: $0) }72            MenuBarCard()73            LimitsCard()74        }75    }76}7778private struct RuleCard: View {79    let watch: WatchModel80    let rule: WatchRule8182    private func color(_ status: WatchRuleStatus) -> Color {83        switch status {84        case .watching: ORIX.Palette.success85        case .paused, .pausedGlobally: ORIX.Palette.caution86        case .stopped: ORIX.Palette.textSecondary87        case .error: ORIX.Palette.danger88        }89    }9091    var body: some View {92        let status = watch.status(of: rule)93        let selected = watch.selection == rule.id94        let shape = RoundedRectangle(cornerRadius: ORIX.Radius.l, style: .continuous)95        VStack(alignment: .leading, spacing: ORIX.Space.m) {96            HStack(spacing: ORIX.Space.m) {97                Image(systemName: "folder.badge.gearshape").font(.system(size: 17, weight: .medium)).foregroundStyle(color(status))98                    .frame(width: 40, height: 40)99                    .background(color(status).opacity(0.12), in: RoundedRectangle(cornerRadius: 10, style: .continuous))100                    .accessibilityHidden(true)101                VStack(alignment: .leading, spacing: 3) {102                    Text(rule.name).font(.headline).foregroundStyle(ORIX.Palette.textPrimary).lineLimit(1)103                    Pill(text: status.title, symbol: status.symbol, color: color(status))104                }105                Spacer(minLength: ORIX.Space.s)106                IconButton(symbol: rule.isPaused ? "play.fill" : "pause.fill", label: rule.isPaused ? L("Resume this rule") : L("Pause this rule")) { watch.setPaused(rule, !rule.isPaused) }107                IconButton(symbol: "pencil", label: L("Edit this rule")) { watch.edit(rule) }108                Menu {109                    Button(L("Show the Watched Folder")) { FileActions.reveal([rule.folder]) }110                    Button(L("Show the Destination")) { FileActions.reveal([rule.destinationFolder]) }111                    Divider()112                    Button(L("Delete Rule"), role: .destructive) { watch.remove(rule) }113                } label: { Image(systemName: "ellipsis").font(.system(size: 13, weight: .medium)).foregroundStyle(ORIX.Palette.textSecondary).frame(width: 26, height: 26) }114                .menuStyle(.borderlessButton).menuIndicator(.hidden).fixedSize()115                .accessibilityLabel(L("More actions for this rule"))116            }117            if case .error(let message) = status { Banner(kind: .danger, text: message) }118            HStack(spacing: ORIX.Space.s) {119                folderChip(rule.folder, symbol: "folder")120                Image(systemName: "arrow.right").font(.caption.weight(.bold)).foregroundStyle(ORIX.Palette.textTertiary).accessibilityHidden(true)121                folderChip(rule.destinationFolder, symbol: "folder.fill")122            }123            FlowLayout(spacing: 6, lineSpacing: 6) {124                Pill(text: watch.matchSummary(rule), symbol: "line.3.horizontal.decrease", color: ORIX.Palette.info)125                Pill(text: watch.actionSummary(rule), symbol: "arrow.triangle.2.circlepath", color: ORIX.Palette.accent)126                Pill(text: L("If it exists: %@", rule.conflictPolicy.title), symbol: nil)127                if rule.includeSubfolders { Pill(text: L("Subfolders included"), symbol: nil) }128                if rule.processExistingFiles { Pill(text: L("Also files already there"), symbol: nil) }129            }130        }131        .padding(ORIX.Space.l)132        .frame(maxWidth: .infinity, alignment: .leading)133        .background(ORIX.Palette.surface, in: shape)134        .overlay(shape.strokeBorder(selected ? ORIX.Palette.accent.opacity(0.55) : ORIX.Palette.hairline, lineWidth: selected ? 1.5 : 1))135        .contentShape(shape)136        .onTapGesture { watch.selection = selected ? nil : rule.id }137        .accessibilityElement(children: .contain)138        .accessibilityLabel(L("Rule %@", rule.name))139        .accessibilityValue(status.title)140    }141142    private func folderChip(_ url: URL, symbol: String) -> some View {143        HStack(spacing: 6) {144            Image(systemName: symbol).font(.caption).foregroundStyle(ORIX.Palette.textSecondary)145            Text((url.path as NSString).abbreviatingWithTildeInPath).font(.caption.monospaced()).foregroundStyle(ORIX.Palette.textPrimary).lineLimit(1).truncationMode(.head)146        }147        .padding(.horizontal, 8).padding(.vertical, 5)148        .frame(maxWidth: .infinity, alignment: .leading)149        .background(ORIX.Palette.surfaceSunken, in: RoundedRectangle(cornerRadius: ORIX.Radius.s, style: .continuous))150        .help(url.path)151        .accessibilityLabel(url.path)152    }153}154155/// The optional menu bar item: off by default, and never a login item.156private struct MenuBarCard: View {157    @Environment(AppModel.self) private var model158    var body: some View {159        Card(padding: ORIX.Space.m) {160            VStack(alignment: .leading, spacing: 6) {161                Toggle(isOn: Binding(get: { model.settings.stored.keepInMenuBar }, set: { model.settings.stored.keepInMenuBar = $0 })) {162                    Text(L("Keep watching in the menu bar when the window is closed")).font(.callout.weight(.medium)).foregroundStyle(ORIX.Palette.textPrimary)163                }164                .toggleStyle(.checkbox)165                Text(L("Adds a menu bar item with pause, resume and the recent activity; closing the window then leaves ORIX Convert running. It still stops when you quit, and it is never started at login."))166                    .font(.caption).foregroundStyle(ORIX.Palette.textSecondary).fixedSize(horizontal: false, vertical: true)167            }168        }169    }170}171172/// What the watcher really does and does not do.173private struct LimitsCard: View {174    private let limits: [(String, String)] = [175        ("power", L("Rules run only while ORIX Convert is open. Nothing is installed in the background and nothing starts at login.")),176        ("clock.arrow.circlepath", L("Files that arrive while the app is closed, or while a rule is paused, are converted afterwards only if the rule says “also process the files already in the folder”.")),177        ("doc", L("Only regular files are processed, once they have stopped changing for two seconds. Folders, empty files and partial downloads are ignored.")),178        ("arrow.triangle.2.circlepath", L("A file written by a rule is never processed again, by any rule. A rule that would feed itself is refused.")),179        ("doc.on.doc", L("The same content arriving twice in a rule is converted once; the second arrival is logged as a duplicate.")),180    ]181182    var body: some View {183        Card(padding: ORIX.Space.m) {184            VStack(alignment: .leading, spacing: ORIX.Space.s) {185                SectionLabel(L("What the watcher does, exactly"))186                ForEach(limits, id: \.1) { symbol, text in187                    HStack(alignment: .firstTextBaseline, spacing: ORIX.Space.s) {188                        Image(systemName: symbol).font(.caption).foregroundStyle(ORIX.Palette.textTertiary).frame(width: 16).accessibilityHidden(true)189                        Text(text).font(.caption).foregroundStyle(ORIX.Palette.textSecondary).fixedSize(horizontal: false, vertical: true)190                    }191                }192            }193        }194    }195}196197private struct ActivityLog: View {198    let watch: WatchModel199    var embedded = false200201    var body: some View {202        let entries = watch.selection.map { id in watch.activity.filter { $0.ruleID == id } } ?? watch.activity203        VStack(spacing: 0) {204            HStack {205                VStack(alignment: .leading, spacing: 1) {206                    Text(L("Activity")).font(.headline)207                    Text(watch.selection.map { L("Rule “%@”", watch.ruleName($0)) } ?? L("All rules")).font(.caption).foregroundStyle(ORIX.Palette.textSecondary).lineLimit(1)208                }209                Spacer()210                if watch.selection != nil { Button(L("Show All")) { watch.selection = nil }.buttonStyle(.plain).font(.caption.weight(.medium)).foregroundStyle(ORIX.Palette.accent) }211                if !watch.activity.isEmpty { IconButton(symbol: "trash", label: L("Clear the activity log")) { watch.clearActivity() } }212            }213            .padding(.horizontal, ORIX.Space.l).frame(height: 54)214            ORIX.Palette.hairline.frame(height: 1)215            if entries.isEmpty {216                VStack(spacing: ORIX.Space.s) {217                    Image(systemName: "tray").font(.system(size: 26, weight: .light)).foregroundStyle(ORIX.Palette.textTertiary).accessibilityHidden(true)218                    Text(L("Nothing yet")).font(.callout.weight(.medium))219                    Text(L("Files picked up by the rules appear here with what happened to them.")).font(.caption).foregroundStyle(ORIX.Palette.textSecondary).multilineTextAlignment(.center)220                }221                .padding(ORIX.Space.xl).frame(maxWidth: .infinity, maxHeight: embedded ? nil : .infinity)222            } else if embedded {223                VStack(spacing: 0) { ForEach(entries.prefix(100)) { ActivityRow(watch: watch, entry: $0) } }224            } else {225                ScrollView { LazyVStack(spacing: 0) { ForEach(entries) { ActivityRow(watch: watch, entry: $0) } } }226            }227        }228        .background(ORIX.Palette.surface)229        .accessibilityElement(children: .contain)230        .accessibilityLabel(L("Activity log"))231    }232}233234private struct ActivityRow: View {235    let watch: WatchModel236    let entry: WatchActivity237238    private var color: Color {239        switch entry.kind {240        case .processed: ORIX.Palette.success241        case .nothingWritten, .duplicate: ORIX.Palette.textSecondary242        case .failed: ORIX.Palette.danger243        }244    }245246    var body: some View {247        let name = (entry.path as NSString).lastPathComponent248        HStack(alignment: .top, spacing: ORIX.Space.s) {249            Image(systemName: entry.kind.symbol).font(.callout).foregroundStyle(color).frame(width: 18).padding(.top, 1).accessibilityHidden(true)250            VStack(alignment: .leading, spacing: 2) {251                Text(name).font(.callout.weight(.medium)).foregroundStyle(ORIX.Palette.textPrimary).lineLimit(1).truncationMode(.middle)252                Text(entry.kind.title + " · " + entry.localizedDetail).font(.caption).foregroundStyle(entry.kind == .failed ? ORIX.Palette.danger : ORIX.Palette.textSecondary)253                    .lineLimit(3).fixedSize(horizontal: false, vertical: true)254                Text(watch.ruleName(entry.ruleID) + " · " + Fmt.date(entry.date)).font(.caption2).foregroundStyle(ORIX.Palette.textTertiary).lineLimit(1)255            }256            Spacer(minLength: 4)257            let outputs = entry.outputs.map { URL(fileURLWithPath: $0) }258            IconButton(symbol: "magnifyingglass", label: outputs.isEmpty ? L("Reveal the source in Finder") : L("Reveal the result in Finder")) {259                if !FileActions.reveal(outputs) { FileActions.reveal([URL(fileURLWithPath: entry.path)]) }260            }261        }262        .padding(.horizontal, ORIX.Space.l).padding(.vertical, 8)263        .overlay(alignment: .bottom) { ORIX.Palette.hairline.frame(height: 1).padding(.leading, ORIX.Space.l) }264        .accessibilityElement(children: .combine)265        .accessibilityLabel(name)266        .accessibilityValue(entry.kind.title + ", " + entry.localizedDetail + ", " + watch.ruleName(entry.ruleID))267    }268}269270// MARK: - Rule sheet271272struct WatchRuleSheet: View {273    @Environment(AppModel.self) private var model274    let watch: WatchModel275    @State private var loopWarning: String?276    @State private var engineID: String?277278    private func bind<T>(_ keyPath: WritableKeyPath<WatchRuleDraft, T>, default fallback: T) -> Binding<T> {279        Binding(get: { watch.draft?[keyPath: keyPath] ?? fallback }, set: { value in watch.draft?[keyPath: keyPath] = value; watch.draft?.error = nil })280    }281282    var body: some View {283        if let draft = watch.draft {284            VStack(spacing: 0) {285                HStack {286                    Text(draft.isNew ? L("New Watch Rule") : L("Edit Watch Rule")).font(.title3.weight(.semibold))287                    Spacer()288                }289                .padding(ORIX.Space.l)290                ORIX.Palette.hairline.frame(height: 1)291                ScrollView {292                    VStack(alignment: .leading, spacing: ORIX.Space.xl) {293                        section(L("Watch this folder")) {294                            FolderField(title: L("Watched folder"), url: draft.folder) { watch.chooseFolder(watched: true) }295                            Toggle(L("Include its subfolders"), isOn: bind(\.includeSubfolders, default: false)).toggleStyle(.checkbox)296                            HStack(spacing: ORIX.Space.s) {297                                Text(L("Rule name")).font(.callout)298                                TextField(L("Rule name"), text: bind(\.name, default: ""), prompt: Text(L("The name of the folder"))).textFieldStyle(.roundedBorder).labelsHidden()299                            }300                        }301                        section(L("For these files")) { matchEditor(draft) }302                        section(L("Do this")) { actionEditor(draft) }303                        section(L("Put the results in")) {304                            FolderField(title: L("Destination folder"), url: draft.destinationFolder) { watch.chooseFolder(watched: false) }305                            HStack {306                                Text(L("If a file already exists")).font(.callout)307                                Spacer()308                                Picker(L("If a file already exists"), selection: bind(\.conflictPolicy, default: .rename)) {309                                    ForEach([ConflictPolicy.rename, .skip, .replace], id: \.self) { Text($0.title).tag($0) }310                                }311                                .labelsHidden().pickerStyle(.menu).fixedSize()312                            }313                            if draft.actionKind == .workflow {314                                Text(L("The export steps of the workflow decide where their files go; this folder receives the results of paths without an export step."))315                                    .font(.caption).foregroundStyle(ORIX.Palette.textTertiary).fixedSize(horizontal: false, vertical: true)316                            }317                        }318                        section(L("Files already in the folder")) {319                            Toggle(L("Also process the files already in the folder"), isOn: bind(\.processExistingFiles, default: false)).toggleStyle(.checkbox)320                            Text(L("Off: only files that arrive after the rule starts are converted. On: files already there — including those that arrived while the app was closed or the rule was paused — are converted too."))321                                .font(.caption).foregroundStyle(ORIX.Palette.textTertiary).fixedSize(horizontal: false, vertical: true)322                        }323                        if let loopWarning { Banner(kind: .danger, text: L("This rule would feed itself"), detail: loopWarning) }324                        if let error = draft.error, error != loopWarning { Banner(kind: .danger, text: error) }325                    }326                    .padding(ORIX.Space.l)327                }328                ORIX.Palette.hairline.frame(height: 1)329                HStack {330                    if let missing = draft.missing { Text(missing).font(.caption).foregroundStyle(ORIX.Palette.textSecondary).lineLimit(2) }331                    Spacer()332                    Button(L("Cancel")) { watch.draft = nil }.keyboardShortcut(.cancelAction).buttonStyle(SecondaryButtonStyle())333                    Button(draft.isNew ? L("Add Rule") : L("Save")) { Task { await watch.saveDraft() } }334                        .keyboardShortcut(.defaultAction).buttonStyle(PrimaryButtonStyle()).disabled(draft.missing != nil || loopWarning != nil)335                }336                .padding(ORIX.Space.l)337            }338            .frame(width: 560)339            .frame(minHeight: 520, idealHeight: 680, maxHeight: 760)340            .background(ORIX.Palette.surface)341            .task(id: loopKey(draft)) { loopWarning = await watch.loopRisk(for: draft) }342        }343    }344345    private func loopKey(_ draft: WatchRuleDraft) -> String {346        "\(draft.folder?.path ?? "")|\(draft.destinationFolder?.path ?? "")|\(draft.includeSubfolders)|\(draft.match)|\(draft.actionKind)|\(draft.destination?.rawValue ?? "")|\(draft.operation ?? "")|\(draft.presetID?.uuidString ?? "")|\(draft.workflowID?.uuidString ?? "")"347    }348349    private func section<Content: View>(_ title: String, @ViewBuilder content: () -> Content) -> some View {350        VStack(alignment: .leading, spacing: ORIX.Space.s) {351            SectionLabel(title)352            content()353        }354    }355356    @ViewBuilder private func matchEditor(_ draft: WatchRuleDraft) -> some View {357        SegmentedPicker(selection: bind(\.matchKind, default: .any), options: WatchRuleDraft.MatchKind.allCases.map { ($0, $0.title, 0) })358        switch draft.matchKind {359        case .any:360            Text(L("Every regular file that lands in the folder. A rule that matches any file cannot write into the folder it watches."))361                .font(.caption).foregroundStyle(ORIX.Palette.textTertiary).fixedSize(horizontal: false, vertical: true)362        case .categories:363            FlowLayout(spacing: 6, lineSpacing: 6) {364                ForEach(FormatCategory.allCases.filter { category in category != .other && model.registry.sourceFormats.contains { $0.category == category } }, id: \.self) { category in365                    let on = draft.categories.contains(category)366                    chip(category.title, symbol: category.symbol, color: category.color, on: on) {367                        if on { watch.draft?.categories.remove(category) } else { watch.draft?.categories.insert(category) }368                    }369                }370            }371        case .formats:372            HStack {373                Menu {374                    ForEach(FormatCategory.allCases, id: \.self) { category in375                        let formats = model.registry.sourceFormats.filter { $0.category == category && $0 != .folder }376                        if !formats.isEmpty {377                            Menu(category.title) {378                                ForEach(formats, id: \.self) { format in379                                    Button { if draft.formats.contains(format) { watch.draft?.formats.remove(format) } else { watch.draft?.formats.insert(format) } } label: {380                                        if draft.formats.contains(format) { Label(format.displayName, systemImage: "checkmark") } else { Text(format.displayName) }381                                    }382                                }383                            }384                        }385                    }386                } label: { Label(L("Add Formats"), systemImage: "plus") }387                .menuStyle(.button).buttonStyle(SecondaryButtonStyle()).fixedSize()388                Spacer()389            }390            FlowLayout(spacing: 6, lineSpacing: 6) {391                ForEach(draft.formats.sorted(), id: \.self) { format in392                    chip(format.displayName, symbol: "xmark", color: format.category.color, on: true) { watch.draft?.formats.remove(format) }393                }394            }395        case .glob:396            TextField("*.heic", text: bind(\.glob, default: "")).textFieldStyle(.roundedBorder).font(.callout.monospaced()).accessibilityLabel(L("Name pattern"))397            Text(L("* matches any text, ? one character. Upper and lower case are the same.")).font(.caption).foregroundStyle(ORIX.Palette.textTertiary)398        }399    }400401    private func chip(_ title: String, symbol: String, color: Color, on: Bool, action: @escaping () -> Void) -> some View {402        Button(action: action) {403            HStack(spacing: 5) {404                Image(systemName: symbol).font(.system(size: 10, weight: .semibold)).foregroundStyle(color)405                Text(title).font(.callout.weight(on ? .semibold : .regular)).foregroundStyle(ORIX.Palette.textPrimary)406            }407            .padding(.horizontal, 10).padding(.vertical, 5)408            .background(on ? ORIX.Palette.accentSoft : ORIX.Palette.canvas, in: Capsule())409            .overlay(Capsule().strokeBorder(on ? AnyShapeStyle(ORIX.Palette.transformation) : AnyShapeStyle(ORIX.Palette.hairlineStrong), lineWidth: on ? 1.5 : 1))410            .contentShape(Capsule())411        }412        .buttonStyle(.plain)413        .accessibilityLabel(title)414        .accessibilityAddTraits(on ? [.isSelected] : [])415    }416417    @ViewBuilder private func actionEditor(_ draft: WatchRuleDraft) -> some View {418        SegmentedPicker(selection: bind(\.actionKind, default: .convert), options: WatchRuleDraft.ActionKind.allCases.map { ($0, $0.title, 0) })419        switch draft.actionKind {420        case .convert:421            let entries = TargetCatalog.everyEntry(registry: model.registry)422            TargetButton(entries: entries, current: entries.first { $0.destination == draft.destination && $0.operation == draft.operation }) { entry in423                watch.draft?.destination = entry.destination424                watch.draft?.operation = entry.operation425                watch.draft?.options = ConversionOptions()426            }427            if let destination = draft.destination {428                if draft.operation == nil {429                    Text(L("A file that is already %@ is converted again when a setting here differs from its default; without any, it goes through unchanged.", destination.displayName))430                        .font(.caption).foregroundStyle(ORIX.Palette.textTertiary).fixedSize(horizontal: false, vertical: true)431                }432                let sets = TargetCatalog.optionSets(to: destination, operation: draft.operation, registry: model.registry)433                let active = sets.first { $0.engine == engineID } ?? sets.first434                if sets.count > 1 {435                    HStack {436                        Text(L("Settings for files handled by")).font(.callout)437                        Spacer()438                        Picker(L("Settings for files handled by"), selection: Binding(get: { active?.engine ?? "" }, set: { engineID = $0 })) {439                            ForEach(sets, id: \.engine) { Text($0.name).tag($0.engine) }440                        }441                        .labelsHidden().pickerStyle(.menu).fixedSize()442                    }443                }444                if let active, !active.descriptors.isEmpty {445                    DisclosureGroup {446                        OptionsForm(descriptors: active.descriptors.filter { !ConversionOptions.isSecretKey($0.id) }, values: draft.options.values) { key, value in447                            if let descriptor = active.descriptors.first(where: { $0.id == key }), descriptor.defaultValue == value { watch.draft?.options[key] = nil } else { watch.draft?.options[key] = value }448                        }449                        .padding(.top, ORIX.Space.m)450                    } label: {451                        HStack(spacing: 6) {452                            Text(L("Conversion settings")).font(.callout.weight(.medium))453                            if !draft.options.values.isEmpty { Pill(text: L("%lld changed", draft.options.values.count), symbol: nil, color: ORIX.Palette.accent) }454                        }455                    }456                    if active.descriptors.contains(where: { ConversionOptions.isSecretKey($0.id) }) {457                        Label(L("Passwords cannot be stored in a rule: protected files fail and are logged."), systemImage: "lock").font(.caption).foregroundStyle(ORIX.Palette.textTertiary)458                    }459                }460            }461        case .preset:462            if model.presetList.isEmpty {463                Text(L("No preset yet. Save one from the Convert options or from Quality Lab.")).font(.callout).foregroundStyle(ORIX.Palette.textSecondary)464            } else {465                Picker(L("Preset"), selection: bind(\.presetID, default: nil)) {466                    Text(L("Choose a preset")).tag(UUID?.none)467                    ForEach(model.presetList) { Text($0.name + " · " + $0.destinationFormat.shortLabel).tag(UUID?.some($0.id)) }468                }469                .labelsHidden().pickerStyle(.menu).fixedSize()470            }471        case .workflow:472            let saved = model.flow.saved473            if saved.isEmpty {474                Text(L("No saved workflow yet. Create one in Flow, or duplicate an example there.")).font(.callout).foregroundStyle(ORIX.Palette.textSecondary)475            } else {476                Picker(L("Workflow"), selection: bind(\.workflowID, default: nil)) {477                    Text(L("Choose a workflow")).tag(UUID?.none)478                    ForEach(saved) { Text($0.name).tag(UUID?.some($0.id)) }479                }480                .labelsHidden().pickerStyle(.menu).fixedSize()481            }482        }483    }484}485
Files main
Menu

Theme