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 ) {
@@ -135,9 +142,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
135142 // We only accept one at time, for now
136143 return
137144 }
138- do { try urlHandler. handle ( url) } catch {
139- // TODO: Push notification
140- print ( error. description)
145+ do { try urlHandler. handle ( url) } catch let handleError {
146+ Task {
147+ do {
148+ try await sendNotification ( title: " Failed to open link " , body: handleError. description)
149+ } catch let notifError {
150+ logger. error ( " Failed to send notification ( \( handleError. description) ): \( notifError) " )
151+ }
152+ }
141153 }
142154 }
143155}
0 commit comments