diff options
| author | Fuwn <[email protected]> | 2025-02-26 23:00:37 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-02-26 23:00:37 -0800 |
| commit | a8ef38a8d17ca8b61a90a25a6c937098db49f83e (patch) | |
| tree | 5fca34efb9330ade1f2cbb2f4e752c3d31e0e689 /Sora/Views/Post/Details/PostDetailsImageView.swift | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-a8ef38a8d17ca8b61a90a25a6c937098db49f83e.tar.xz sora-testing-a8ef38a8d17ca8b61a90a25a6c937098db49f83e.zip | |
feat: Development commit
Diffstat (limited to 'Sora/Views/Post/Details/PostDetailsImageView.swift')
| -rw-r--r-- | Sora/Views/Post/Details/PostDetailsImageView.swift | 38 |
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) + } + } } |