SwiftUI and dragging a file onto the app icon

I'm playing around with using an app to automate some of my personal work flows, and one of the things I wanted to do was to be able to drag a .webloc file onto my app icon in the dock, to launch it.

I've got public.data set up as a document type for it in Xcode, which translated to

<key>CFBundleDocumentTypes</key>
<array>
        <dict>
                <key>CFBundleTypeRole</key>
                <string>Viewer</string>
                <key>LSHandlerRank</key>
                <string>Default</string>
                <key>LSItemContentTypes</key>
                <array>
                        <string>public.data</string>
                </array>
        </dict>
</array>

in the Info.plist for it, which seems correct. When I drag a .webloc file onto the Dock icon, it appears to be willing to accept it, but nothing seems to happen.

In the app, I've got an AppDelegate.swift file which has

extension Notification.Name {
    static let receivedURLsNotification = Notification.Name("ReceivedURLsNotification")
}

class AppDelegate: NSObject, NSApplicationDelegate {
    func application(_ application: NSApplication, open urls: [URL]) {
        guard !urls.isEmpty else { return }
        
        NotificationCenter.default.post(name: .receivedURLsNotification, object: nil, userInfo: ["URLs": urls])
    }
}

(I copied it almost verbatim from a Medium post.)

In the app swift file, I have

@main
struct LoggerApp: App, DropDelegate {
    @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

I set a breakpoint on application(_:NSApplication, open:[URL]), and did my drag, and the breakpoint never triggered.

I added the application(didFinishLaunching(_:Notification) method, and that does get invoked when the app launches, so the app delegate does seem to be working. That seems to indicate the problem is somewhere else?

So it does help to drag the file to the right icon... (since I was debugging it under Xcode, but had the "real" one in my dock).

That seems to do it better, but weirdly, it's not happening the first time I drag a file onto the icon. Also, I have this in the main view:

  .handlesExternalEvents(preferring: ["my-scheme"], allowing: ["my-scheme"]) // activate existing window if exists
 .onOpenURL { url in
                  // stuff
               }

and both the .openURL and the app delegate method are being triggered. I think this is probably due to confusion on my part, though.

SwiftUI and dragging a file onto the app icon
 
 
Q