1
1
import FluidMenuBarExtra
2
2
import NetworkExtension
3
+ import os
3
4
import SDWebImageSVGCoder
4
5
import SDWebImageSwiftUI
5
6
import SwiftUI
7
+ import UserNotifications
6
8
import VPNLib
7
9
8
10
@main
@@ -36,13 +38,16 @@ struct DesktopApp: App {
36
38
37
39
@MainActor
38
40
class AppDelegate : NSObject , NSApplicationDelegate {
41
+ private var logger = Logger ( subsystem: Bundle . main. bundleIdentifier!, category: " app-delegate " )
39
42
private var menuBar : MenuBarController ?
40
43
let vpn : CoderVPNService
41
44
let state : AppState
42
45
let fileSyncDaemon : MutagenDaemon
43
46
let urlHandler : URLHandler
47
+ let notifDelegate : NotifDelegate
44
48
45
49
override init ( ) {
50
+ notifDelegate = NotifDelegate ( )
46
51
vpn = CoderVPNService ( )
47
52
let state = AppState ( onChange: vpn. configureTunnelProviderProtocol)
48
53
vpn. onStart = {
@@ -67,6 +72,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
67
72
}
68
73
self . fileSyncDaemon = fileSyncDaemon
69
74
urlHandler = URLHandler ( state: state, vpn: vpn)
75
+ // `delegate` is weak
76
+ UNUserNotificationCenter . current ( ) . delegate = notifDelegate
70
77
}
71
78
72
79
func applicationDidFinishLaunching( _: Notification ) {
@@ -135,9 +142,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
135
142
// We only accept one at time, for now
136
143
return
137
144
}
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
+ }
141
153
}
142
154
}
143
155
}
0 commit comments