diff options
| author | Dustin Mierau <dustin@mierau.me> | 2024-05-22 17:35:01 -0700 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2024-05-22 17:35:01 -0700 |
| commit | 842611754debec7d1814e44e6a2cf302e84c0d66 (patch) | |
| tree | e5c92e2abde5038df695faf4371bbaf9a477ff7a /Hotline/macOS | |
| parent | c7a2970c7f17a1b19a76d9cb6addda8fb877a63a (diff) | |
Support for drag and drop of old Hotline Bookmark files onto the Servers window.
Diffstat (limited to 'Hotline/macOS')
| -rw-r--r-- | Hotline/macOS/TrackerView.swift | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Hotline/macOS/TrackerView.swift b/Hotline/macOS/TrackerView.swift index 104e15d..5a9db9b 100644 --- a/Hotline/macOS/TrackerView.swift +++ b/Hotline/macOS/TrackerView.swift @@ -1,5 +1,6 @@ import SwiftUI import SwiftData +import UniformTypeIdentifiers struct TrackerView: View { // @Environment(BookmarksOld.self) private var bookmarks: BookmarksOld @@ -12,6 +13,7 @@ struct TrackerView: View { @State private var trackerSheetPresented: Bool = false @State private var trackerSheetBookmark: Bookmark? = nil @State private var attemptedPrepopulate: Bool = false + @State private var fileDropActive = false @Query(sort: \Bookmark.order) private var bookmarks: [Bookmark] @State private var selection: Bookmark? = nil @@ -137,6 +139,33 @@ struct TrackerView: View { } return .ignored } + .onDrop(of: [UTType.fileURL], isTargeted: $fileDropActive) { providers, dropPoint in + for provider in providers { + let _ = provider.loadDataRepresentation(for: UTType.fileURL) { dataRepresentation, err in + // HOTLINE CREATOR CODE: 1213484099 + // HOTLINE BOOKMARK TYPE CODE: 1213489773 + + if let filePathData = dataRepresentation, + let filePath = String(data: filePathData, encoding: .utf8), + let fileURL = URL(string: filePath) { + + print("Hotline Bookmark: Dropped from ", fileURL.path(percentEncoded: false)) + + DispatchQueue.main.async { + if let newBookmark = Bookmark(fileURL: fileURL) { + print("Hotline Bookmark: Added bookmark.") + Bookmark.add(newBookmark, context: modelContext) + } + else { + print("Hotline Bookmark: Failed to parse.") + } + } + } + } + } + + return true + } .sheet(item: $trackerSheetBookmark) { item in TrackerBookmarkSheet(item) } |