Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bGzgsxrmbBhDzeMV2L57D
115 lines
5.0 KiB
Swift
115 lines
5.0 KiB
Swift
import SwiftUI
|
|
|
|
/// PM-style Tasks window: ingest, uploads and Lightroom jobs with live progress.
|
|
struct TasksWindow: View {
|
|
@EnvironmentObject var state: AppState
|
|
@EnvironmentObject var tasks: TaskCenter
|
|
@EnvironmentObject var uploads: UploadQueue
|
|
@State private var showFiles = false
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
if tasks.tasks.isEmpty {
|
|
Text("Keine Aufgaben").foregroundStyle(.secondary).frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
} else {
|
|
List(tasks.tasks) { t in TaskRow(task: t) }
|
|
.listStyle(.inset(alternatesRowBackgrounds: true))
|
|
}
|
|
if showFiles {
|
|
Divider()
|
|
Table(uploads.jobs) {
|
|
TableColumn("Datei") { j in Text(j.file.lastPathComponent) }
|
|
TableColumn("Als") { j in Text(j.remoteName).foregroundStyle(.secondary) }
|
|
TableColumn("Ziel") { j in Text(j.targetName) }
|
|
TableColumn("Status") { j in UploadStatusView(status: j.status) }
|
|
TableColumn("Fortschritt") { j in
|
|
if j.status == .running {
|
|
HStack {
|
|
ProgressView(value: j.progress).frame(width: 90)
|
|
Text("\(Int(j.progress * 100)) %").monospacedDigit().font(.caption)
|
|
}
|
|
} else {
|
|
Text(ByteCountFormatter.string(fromByteCount: j.fileSize, countStyle: .file)).foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
}
|
|
.frame(minHeight: 180)
|
|
}
|
|
Divider()
|
|
HStack {
|
|
Toggle("Einzelne Upload-Dateien", isOn: $showFiles).toggleStyle(.checkbox)
|
|
if uploads.rate > 0 {
|
|
Label(uploads.rateText, systemImage: "speedometer").monospacedDigit().foregroundStyle(LK.amber)
|
|
}
|
|
Spacer()
|
|
Button("Fehlgeschlagene Uploads wiederholen") { uploads.retryFailed() }.disabled(uploads.failedCount == 0)
|
|
Button("Erledigte entfernen") { tasks.clearFinished(); uploads.clearFinished() }
|
|
}
|
|
.padding(10)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct TaskRow: View {
|
|
@EnvironmentObject var state: AppState
|
|
@EnvironmentObject var tasks: TaskCenter
|
|
let task: BackgroundTask
|
|
|
|
var body: some View {
|
|
HStack(alignment: .top, spacing: 10) {
|
|
Image(systemName: task.systemImage).font(.title2).frame(width: 28).foregroundStyle(.secondary)
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
HStack {
|
|
Text(task.title).bold().lineLimit(1)
|
|
Spacer()
|
|
stateLabel
|
|
}
|
|
if task.isRunning {
|
|
if task.total > 0 {
|
|
ProgressView(value: task.progress)
|
|
Text("\(task.done) / \(task.total) · \(task.detail)").font(.caption).foregroundStyle(.secondary).lineLimit(1)
|
|
} else {
|
|
ProgressView().progressViewStyle(.linear)
|
|
Text(task.detail).font(.caption).foregroundStyle(.secondary).lineLimit(1)
|
|
}
|
|
} else if !task.detail.isEmpty {
|
|
Text(task.detail).font(.caption).foregroundStyle(.secondary).lineLimit(2)
|
|
}
|
|
}
|
|
VStack(spacing: 4) {
|
|
if task.isRunning && tasks.canCancel(task.id) {
|
|
Button("Abbrechen") { tasks.cancel(task.id) }
|
|
}
|
|
if let f = task.folder {
|
|
Button("Öffnen") { state.open(folder: f) }
|
|
}
|
|
}
|
|
.controlSize(.small)
|
|
}
|
|
.padding(.vertical, 4)
|
|
}
|
|
|
|
@ViewBuilder private var stateLabel: some View {
|
|
switch task.state {
|
|
case .running: Text(task.started, style: .timer).font(.caption.monospacedDigit()).foregroundStyle(.secondary)
|
|
case .finished: Label("Fertig", systemImage: "checkmark.circle.fill").foregroundStyle(.green).font(.caption)
|
|
case .cancelled: Label("Abgebrochen", systemImage: "stop.circle").foregroundStyle(.secondary).font(.caption)
|
|
case .failed(let m): Label(m, systemImage: "xmark.octagon.fill").foregroundStyle(.red).font(.caption).lineLimit(1).help(m)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct UploadStatusView: View {
|
|
let status: UploadJob.Status
|
|
|
|
var body: some View {
|
|
switch status {
|
|
case .waiting: Label("Wartet", systemImage: "clock").foregroundStyle(.secondary)
|
|
case .running: HStack { ProgressView().controlSize(.small); Text("Lädt …") }
|
|
case .done: Label("Fertig", systemImage: "checkmark.circle.fill").foregroundStyle(.green)
|
|
case .duplicate: Label("Schon vorhanden", systemImage: "equal.circle").foregroundStyle(.secondary)
|
|
case .failed(let m): Label(m, systemImage: "xmark.octagon.fill").foregroundStyle(.red).help(m)
|
|
}
|
|
}
|
|
}
|