From a8ef38a8d17ca8b61a90a25a6c937098db49f83e Mon Sep 17 00:00:00 2001 From: Fuwn Date: Wed, 26 Feb 2025 23:00:37 -0800 Subject: feat: Development commit --- Sora/Data/Booru/BooruManager.swift | 24 ++++---------- Sora/Info.plist | 2 ++ Sora/SoraApp.swift | 6 ++++ Sora/Views/Post/Details/PostDetailsImageView.swift | 38 ++++++++++++++++++++++ 4 files changed, 52 insertions(+), 18 deletions(-) diff --git a/Sora/Data/Booru/BooruManager.swift b/Sora/Data/Booru/BooruManager.swift index a72df6c..8cf1ac6 100644 --- a/Sora/Data/Booru/BooruManager.swift +++ b/Sora/Data/Booru/BooruManager.swift @@ -114,9 +114,7 @@ class BooruManager: ObservableObject { } } catch { if (error as? URLError)?.code != .cancelled { - #if DEBUG - print("fetchPosts: \(error)") - #endif + debugPrint("BooruManager.fetchPosts: \(error)") } } } @@ -158,9 +156,7 @@ class BooruManager: ObservableObject { } } catch { if (error as? URLError)?.code != .cancelled { - #if DEBUG - print("fetchAllTags: \(error)") - #endif + debugPrint("BooruManager.fetchAllTags: \(error)") } } } @@ -200,9 +196,7 @@ class BooruManager: ObservableObject { try data.write(to: url) updateTagsCacheSize() } catch { - #if DEBUG - print("saveTagsToCache: \(error)") - #endif + debugPrint("BooruManager.saveTagsToCache: \(error)") } } @@ -218,9 +212,7 @@ class BooruManager: ObservableObject { self.updateTagsCacheSize() } } catch { - #if DEBUG - print("loadCachedTags: \(error)") - #endif + debugPrint("BooruManager.loadCachedTags: \(error)") } } @@ -231,9 +223,7 @@ class BooruManager: ObservableObject { try FileManager.default.removeItem(at: url) updateTagsCacheSize() } catch { - #if DEBUG - print("clearCachedTags: \(error)") - #endif + debugPrint("BooruManager.clearCachedTags: \(error)") } } @@ -254,9 +244,7 @@ class BooruManager: ObservableObject { } catch { cacheSize = nil - #if DEBUG - print("updateCacheSize: \(error)") - #endif + debugPrint("BooruManager.updateCacheSize: \(error)") } } diff --git a/Sora/Info.plist b/Sora/Info.plist index 4674f0c..79622d0 100644 --- a/Sora/Info.plist +++ b/Sora/Info.plist @@ -2,6 +2,8 @@ + NSUserNotificationsUsageDescription + Sora must be able to access permissions to inform users of successful saved image operations. NSPhotoLibraryAddUsageDescription Sora must be able to access permissions to write photos to the user's photo library to use the image-saving feature. CFBundleIconFile diff --git a/Sora/SoraApp.swift b/Sora/SoraApp.swift index 12f614c..df0f8e1 100644 --- a/Sora/SoraApp.swift +++ b/Sora/SoraApp.swift @@ -1,5 +1,11 @@ import SwiftUI +func debugPrint(_ items: Any...) { + #if DEBUG + Swift.print(items, terminator: "\n") + #endif +} + @main struct SoraApp: App { @StateObject private var settings = Settings() 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: View { @EnvironmentObject var settings: Settings @@ -176,6 +177,15 @@ struct PostDetailsImageView: 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: 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) + } + } } -- cgit v1.2.3