You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.9 KiB
57 lines
1.9 KiB
import SwiftUI
|
|
import UniformTypeIdentifiers
|
|
|
|
struct DropZoneView: View {
|
|
@EnvironmentObject private var settings: AppSettings
|
|
@EnvironmentObject private var coordinator: ConversionCoordinator
|
|
@State private var isTargeted = false
|
|
|
|
var body: some View {
|
|
VStack(spacing: 12) {
|
|
Image(systemName: "arrow.down.doc")
|
|
.font(.system(size: 36))
|
|
.foregroundStyle(.secondary)
|
|
Text("9:16-Dateien hierher ziehen")
|
|
.font(.headline)
|
|
Button("Datei(en) wählen…", action: chooseFiles)
|
|
}
|
|
.frame(maxWidth: .infinity, minHeight: 140)
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 12)
|
|
.strokeBorder(style: StrokeStyle(lineWidth: 2, dash: [6]))
|
|
.foregroundStyle(isTargeted ? Color.accentColor : Color.secondary.opacity(0.35))
|
|
)
|
|
.onDrop(of: [.fileURL], isTargeted: $isTargeted, perform: handleDrop)
|
|
}
|
|
|
|
private func chooseFiles() {
|
|
let panel = NSOpenPanel()
|
|
panel.allowsMultipleSelection = true
|
|
panel.canChooseDirectories = false
|
|
panel.canChooseFiles = true
|
|
panel.allowedContentTypes = [.movie, .quickTimeMovie, .mpeg4Movie]
|
|
if let sourceFolder = settings.sourceFolder {
|
|
panel.directoryURL = sourceFolder
|
|
}
|
|
guard panel.runModal() == .OK else { return }
|
|
coordinator.addFiles(panel.urls)
|
|
}
|
|
|
|
private func handleDrop(providers: [NSItemProvider]) -> Bool {
|
|
guard !providers.isEmpty else { return false }
|
|
let group = DispatchGroup()
|
|
var urls: [URL] = []
|
|
for provider in providers {
|
|
group.enter()
|
|
_ = provider.loadObject(ofClass: URL.self) { url, _ in
|
|
if let url { urls.append(url) }
|
|
group.leave()
|
|
}
|
|
}
|
|
group.notify(queue: .main) {
|
|
coordinator.addFiles(urls)
|
|
}
|
|
return true
|
|
}
|
|
}
|