secretive/SecretAgent/Notifier.swift

24 lines
867 B
Swift
Raw Normal View History

2020-03-04 07:14:38 +00:00
import Foundation
import SecretKit
import UserNotifications
2020-03-16 07:49:43 +00:00
import AppKit
2020-03-04 07:14:38 +00:00
class Notifier {
func prompt() {
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.requestAuthorization(options: .alert) { _, _ in
}
}
2020-03-16 07:49:43 +00:00
func notify<SecretType: Secret>(accessTo secret: SecretType, from caller: NSRunningApplication) {
2020-03-04 07:14:38 +00:00
let notificationCenter = UNUserNotificationCenter.current()
let notificationContent = UNMutableNotificationContent()
notificationContent.title = "Signed Request"
2020-03-16 07:49:43 +00:00
notificationContent.body = "\(secret.name) was used to sign a request from \(caller.localizedName!)."
2020-03-04 07:14:38 +00:00
let request = UNNotificationRequest(identifier: UUID().uuidString, content: notificationContent, trigger: nil)
notificationCenter.add(request, withCompletionHandler: nil)
}
}