Skip to content

Commit d16f07a

Browse files
committed
Add snooze action
1 parent d7739eb commit d16f07a

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

GitHubListener/AppDelegate.swift

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

418445
enum Result<Value> {

GitHubListener/NiblessWindowController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class NiblessWindowController: NSWindowController, WKNavigationDelegate {
107107

108108
let appDelegate = NSApplication.shared.delegate as! AppDelegate
109109
appDelegate.accessToken = accessToken
110-
appDelegate.username = login as! String
110+
appDelegate.username = login as? String
111111
appDelegate.updateData()
112112
appDelegate.createMenu()
113113
// print("access_token received", accessToken, "for user", login)

0 commit comments

Comments
 (0)