Click UINotification on Mac without opening a Window

27 views Asked by At

I'm developing a status bar app for mac, and I have local notifications. When I click on one of these notifications I would like my status bar app to popup and respond to the contents of the notification (which in itself works fine).

Sadly, whenever I click one of the notifications, my (first?) WindowGroup will show up. It's not coming from the handlesExternalEvents modifier though.

@main
struct sportnewsApp: App {
    @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
    var body: some Scene {
        // pops up, after every opening any notification
        WindowGroup {
            Text("I should never be visible, except for a specific URI link")
        }
         .handlesExternalEvents(matching: "theOnlyLinkThatOpensThisWindow/"
    }
}

My notification code is super basic, but just for reference:

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    if statusBar != nil {
        DispatchQueue.main.async {
            self.statusBar?.newsToPush = response.notification.request.content.userInfo["id"] as? String ?? nil
            self.statusBar?.showNews(sender: self.statusBar!.newsButton)
        }
    }
}

I need to keep the WindowGroup, as I need to show it in very specific cases. How can I prevent it from popping up when I click any Notification though?

Sadly my Swift/SwiftUI experience on mac is limited, so I'm not really sure where I could research this. Hoping for some helpful ideas.

0

There are 0 answers