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 ) {
@@ -141,9 +148,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
141
148
// We only accept one at time, for now
142
149
return
143
150
}
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 open link " , body: handleError. description)
155
+ } catch let notifError {
156
+ logger. error ( " Failed to send notification ( \( handleError. description) ): \( notifError) " )
157
+ }
158
+ }
147
159
}
148
160
}
149
161
0 commit comments