summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Sora/Data/Booru/BooruManager.swift24
-rw-r--r--Sora/Info.plist2
-rw-r--r--Sora/SoraApp.swift6
-rw-r--r--Sora/Views/Post/Details/PostDetailsImageView.swift38
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 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
+ <key>NSUserNotificationsUsageDescription</key>
+ <string>Sora must be able to access permissions to inform users of successful saved image operations.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Sora must be able to access permissions to write photos to the user&apos;s photo library to use the image-saving feature.</string>
<key>CFBundleIconFile</key>
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<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)
+ }
+ }
}