secretive/SecretAgent/Notifier.swift

35 lines
1.2 KiB
Swift
Raw Normal View History

2020-03-04 07:14:38 +00:00
import Foundation
import SecretKit
import SecretAgentKit
2020-03-04 07:14:38 +00:00
import UserNotifications
class Notifier {
func prompt() {
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.requestAuthorization(options: .alert) { _, _ in
}
}
2020-03-17 07:56:55 +00:00
func notify(accessTo secret: AnySecret, by provenance: SigningRequestProvenance) {
2020-03-04 07:14:38 +00:00
let notificationCenter = UNUserNotificationCenter.current()
let notificationContent = UNMutableNotificationContent()
notificationContent.title = "Signed Request"
2020-03-17 07:56:55 +00:00
notificationContent.body = "\(secret.name) was used to sign a request from \(provenance.origin.name)."
2020-03-04 07:14:38 +00:00
let request = UNNotificationRequest(identifier: UUID().uuidString, content: notificationContent, trigger: nil)
notificationCenter.add(request, withCompletionHandler: nil)
}
}
extension Notifier: SigningWitness {
2020-03-19 03:04:24 +00:00
func speakNowOrForeverHoldYourPeace(forAccessTo secret: AnySecret, by provenance: SigningRequestProvenance) throws {
}
2020-03-17 07:56:55 +00:00
func witness(accessTo secret: AnySecret, by provenance: SigningRequestProvenance) throws {
notify(accessTo: secret, by: provenance)
}
}