summaryrefslogtreecommitdiff
path: root/Sora/Views
diff options
context:
space:
mode:
Diffstat (limited to 'Sora/Views')
-rw-r--r--Sora/Views/Post/Details/PostDetailsImageView.swift38
1 files changed, 38 insertions, 0 deletions
diff --git a/Sora/Views/Post/Details/PostDetailsImageView.swift b/Sora/Views/Post/Details/PostDetailsImageView.swift
index 3f0462f..14b929b 100644
--- a/Sora/Views/Post/Details/PostDetailsImageView.swift
+++ b/Sora/Views/Post/Details/PostDetailsImageView.swift
@@ -1,5 +1,6 @@
import NetworkImage
import SwiftUI
+import UserNotifications
struct PostDetailsImageView<Placeholder: View>: View {
@EnvironmentObject var settings: Settings
@@ -176,6 +177,15 @@ struct PostDetailsImageView<Placeholder: View>: View {
encoding: .utf8
)
}
+
+ #if os(macOS)
+ Task {
+ await sendLocalNotification(
+ title: "Sora",
+ body: "Image \(settings.saveTagsToFile ? "and tags" : "") saved (\(post.id))"
+ )
+ }
+ #endif
} catch {
print("PostDetailsImageView.saveImageToPicturesFolder: \(error)")
}
@@ -191,4 +201,32 @@ struct PostDetailsImageView<Placeholder: View>: View {
NSWorkspace.shared.open(url)
#endif
}
+
+ private func sendLocalNotification(title: String, body: String) async {
+ let notificationCenter = UNUserNotificationCenter.current()
+
+ do {
+ try await notificationCenter.requestAuthorization(options: [.alert, .sound, .badge])
+ } catch {
+ debugPrint(error)
+ }
+
+ let content = UNMutableNotificationContent()
+
+ content.title = title
+ content.body = body
+ content.sound = .default
+
+ do {
+ try await notificationCenter.add(
+ UNNotificationRequest(
+ identifier: UUID().uuidString,
+ content: content,
+ trigger: nil
+ )
+ )
+ } catch {
+ debugPrint(error)
+ }
+ }
}