11import FluidMenuBarExtra
22import NetworkExtension
3+ import os
34import SDWebImageSVGCoder
45import SDWebImageSwiftUI
56import SwiftUI
7+ import UserNotifications
68import VPNLib
79
810@main
@@ -36,13 +38,16 @@ struct DesktopApp: App {
3638
3739@MainActor
3840class AppDelegate : NSObject , NSApplicationDelegate {
41+ private var logger = Logger ( subsystem: Bundle . main. bundleIdentifier!, category: " app-delegate " )
3942 private var menuBar : MenuBarController ?
4043 let vpn : CoderVPNService
4144 let state : AppState
4245 let fileSyncDaemon : MutagenDaemon
4346 let urlHandler : URLHandler
47+ let notifDelegate : NotifDelegate
4448
4549 override init ( ) {
50+ notifDelegate = NotifDelegate ( )
4651 vpn = CoderVPNService ( )
4752 let state = AppState ( onChange: vpn. configureTunnelProviderProtocol)
4853 vpn. onStart = {
@@ -67,6 +72,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
6772 }
6873 self . fileSyncDaemon = fileSyncDaemon
6974 urlHandler = URLHandler ( state: state, vpn: vpn)
75+ // `delegate` is weak
76+ UNUserNotificationCenter . current ( ) . delegate = notifDelegate
7077 }
7178
7279 func applicationDidFinishLaunching( _: Notification ) {
@@ -141,9 +148,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
141148 // We only accept one at time, for now
142149 return
143150 }
144- do { try urlHandler. handle ( url) } catch {
145- // TODO: Push notification
146- print ( error. description)
151+ do { try urlHandler. handle ( url) } catch let handleError {
152+ Task {
153+ do {
154+ try await sendNotification ( title: " Failed to handle link " , body: handleError. description)
155+ } catch let notifError {
156+ logger. error ( " Failed to send notification ( \( handleError. description) ): \( notifError) " )
157+ }
158+ }
147159 }
148160 }
149161
0 commit comments