mirror of
https://github.com/maxgoedjen/secretive.git
synced 2024-11-22 13:37:07 +00:00
35 lines
1.2 KiB
Swift
35 lines
1.2 KiB
Swift
import Foundation
|
|
import SecretKit
|
|
import SecretAgentKit
|
|
import UserNotifications
|
|
|
|
class Notifier {
|
|
|
|
func prompt() {
|
|
let notificationCenter = UNUserNotificationCenter.current()
|
|
notificationCenter.requestAuthorization(options: .alert) { _, _ in
|
|
}
|
|
}
|
|
|
|
func notify(accessTo secret: AnySecret, by provenance: SigningRequestProvenance) {
|
|
let notificationCenter = UNUserNotificationCenter.current()
|
|
let notificationContent = UNMutableNotificationContent()
|
|
notificationContent.title = "Signed Request"
|
|
notificationContent.body = "\(secret.name) was used to sign a request from \(provenance.origin.name)."
|
|
let request = UNNotificationRequest(identifier: UUID().uuidString, content: notificationContent, trigger: nil)
|
|
notificationCenter.add(request, withCompletionHandler: nil)
|
|
}
|
|
|
|
}
|
|
|
|
extension Notifier: SigningWitness {
|
|
|
|
func speakNowOrForeverHoldYourPeace(forAccessTo secret: AnySecret, by provenance: SigningRequestProvenance) throws {
|
|
}
|
|
|
|
func witness(accessTo secret: AnySecret, by provenance: SigningRequestProvenance) throws {
|
|
notify(accessTo: secret, by: provenance)
|
|
}
|
|
|
|
}
|