@@ -77,11 +77,34 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCent
7777 }
7878
7979 func userNotificationCenter( _ center: NSUserNotificationCenter , didActivate notification: NSUserNotification ) {
80- if let url = URL ( string: notification. userInfo![ " url " ] as! String ) {
81- NSWorkspace . shared. open ( url)
80+ switch notification. activationType {
81+ case . additionalActionClicked:
82+ if notification. additionalActivationAction? . identifier == " snooze5min " {
83+ notification. deliveryDate = Date ( timeIntervalSinceNow: 300 )
84+ nc. scheduleNotification ( notification)
85+ } else if notification. additionalActivationAction? . identifier == " snooze1hour " {
86+ notification. deliveryDate = Date ( timeIntervalSinceNow: 3600 )
87+ nc. scheduleNotification ( notification)
88+ }
89+ case . none:
90+ break
91+ case . contentsClicked:
92+ if let url = URL ( string: notification. userInfo![ " url " ] as! String ) {
93+ NSWorkspace . shared. open ( url)
94+ }
95+ case . actionButtonClicked:
96+ notification. deliveryDate = Date ( timeIntervalSinceNow: 60 )
97+ nc. scheduleNotification ( notification)
98+
99+ case . replied:
100+ break
82101 }
83102 }
84103
104+ func userNotificationCenter( _ center: NSUserNotificationCenter , shouldPresent notification: NSUserNotification ) -> Bool {
105+ return true
106+ }
107+
85108 func createMenu( ) {
86109 let menu = NSMenu ( )
87110 if ( self . username != nil ) {
@@ -401,6 +424,13 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCent
401424 notification. subtitle = subtitle
402425 notification. informativeText = informativeText
403426 notification. soundName = NSUserNotificationDefaultSoundName
427+ // Warning: Private API
428+ //notification.setValue(true, forKey: "_alwaysShowAlternateActionMenu") // show arrow for dropdown
429+ notification. actionButtonTitle = " Later " // add ▼ to make it beautiful ^_^
430+ notification. additionalActions = [
431+ NSUserNotificationAction ( identifier: " snooze5min " , title: " 5 min " ) ,
432+ NSUserNotificationAction ( identifier: " snooze1hour " , title: " 1 hour " )
433+ ]
404434 if url != nil {
405435 notification. userInfo = [ " url " : url!]
406436 }
@@ -410,9 +440,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCent
410440 nc. deliver ( notification)
411441 }
412442
413- func userNotificationCenter( _ center: NSUserNotificationCenter , shouldPresent notification: NSUserNotification ) -> Bool {
414- return true
415- }
416443}
417444
418445enum Result < Value> {
0 commit comments