Initial commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// Notifier.swift
|
||||
// GreenshotMac
|
||||
//
|
||||
// Small wrapper around UserNotifications with a Finder-reveal fallback.
|
||||
|
||||
import AppKit
|
||||
import UserNotifications
|
||||
|
||||
@MainActor
|
||||
enum Notifier {
|
||||
private static var authorizationRequested = false
|
||||
private static var lastSavedURL: URL?
|
||||
|
||||
static func show(title: String, body: String?, revealing url: URL? = nil) {
|
||||
lastSavedURL = url ?? lastSavedURL
|
||||
|
||||
let center = UNUserNotificationCenter.current()
|
||||
if !authorizationRequested {
|
||||
authorizationRequested = true
|
||||
center.requestAuthorization(options: [.alert, .sound]) { _, _ in }
|
||||
}
|
||||
|
||||
let content = UNMutableNotificationContent()
|
||||
content.title = title
|
||||
if let body { content.body = body }
|
||||
|
||||
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
|
||||
center.add(request, withCompletionHandler: nil)
|
||||
}
|
||||
|
||||
static var mostRecentSavedURL: URL? { lastSavedURL }
|
||||
|
||||
static func revealMostRecent() {
|
||||
guard let url = lastSavedURL, FileManager.default.fileExists(atPath: url.path) else { return }
|
||||
NSWorkspace.shared.activateFileViewerSelecting([url])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user