summaryrefslogtreecommitdiff
path: root/Sora
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-02-25 02:02:11 -0800
committerFuwn <[email protected]>2025-02-25 02:02:11 -0800
commit410ed9edec893469c70f13bc0991b9af8dfb0413 (patch)
treeecfad0b394e1e3f7f9055ffcc7bc6d302d1f920e /Sora
parentfeat: Development commit (diff)
downloadsora-testing-410ed9edec893469c70f13bc0991b9af8dfb0413.tar.xz
sora-testing-410ed9edec893469c70f13bc0991b9af8dfb0413.zip
feat: Development commit
Diffstat (limited to 'Sora')
-rw-r--r--Sora/Sora.entitlements2
-rw-r--r--Sora/Views/Post/Details/PostDetailsImageView.swift51
-rw-r--r--Sora/Views/Post/Details/PostDetailsView.swift2
3 files changed, 51 insertions, 4 deletions
diff --git a/Sora/Sora.entitlements b/Sora/Sora.entitlements
index bcc27ba..a2c464c 100644
--- a/Sora/Sora.entitlements
+++ b/Sora/Sora.entitlements
@@ -4,6 +4,8 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
+ <key>com.apple.security.assets.pictures.read-write</key>
+ <true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.network.client</key>
diff --git a/Sora/Views/Post/Details/PostDetailsImageView.swift b/Sora/Views/Post/Details/PostDetailsImageView.swift
index f36904f..46a8c5e 100644
--- a/Sora/Views/Post/Details/PostDetailsImageView.swift
+++ b/Sora/Views/Post/Details/PostDetailsImageView.swift
@@ -6,8 +6,9 @@ struct PostDetailsImageView<Placeholder: View>: View {
var url: URL?
@Binding var loadingState: BooruPostLoadingState
var finalLoadingState: BooruPostLoadingState
- var postURL: URL?
+ private var postURL: URL?
let placeholder: () -> Placeholder
+ let post: BooruPost?
@State private var currentScale: CGFloat = 1.0
@State private var finalScale: CGFloat = 1.0
@State private var currentOffset: CGSize = .zero
@@ -54,6 +55,15 @@ struct PostDetailsImageView<Placeholder: View>: View {
}
#endif
+ #if os(macOS)
+ Button {
+ saveImageToPicturesFolder()
+ } label: {
+ Label("Save Image", systemImage: "square.and.arrow.down")
+ }
+ .keyboardShortcut("s", modifiers: [.command])
+ #endif
+
#if os(iOS)
if settings.enableShareShortcut {
Button {
@@ -92,7 +102,7 @@ struct PostDetailsImageView<Placeholder: View>: View {
url: URL?,
loadingStage: Binding<BooruPostLoadingState>,
finalLoadingState: BooruPostLoadingState = .loadingFile,
- postURL: URL? = nil,
+ post: BooruPost? = nil,
@ViewBuilder placeholder: @escaping () -> Placeholder = {
GeometryReader { geometry in
ProgressView()
@@ -105,7 +115,42 @@ struct PostDetailsImageView<Placeholder: View>: View {
self.url = url
_loadingState = loadingStage
self.finalLoadingState = finalLoadingState
- self.postURL = postURL
+ self.postURL =
+ post != nil ? URL(string: "https://yande.re/post/show/\(String(post?.id ?? "0"))")! : nil
self.placeholder = placeholder
+ self.post = post
+ }
+
+ private func saveImageToPicturesFolder() {
+ guard let url = self.url else { return }
+
+ URLSession.shared.dataTask(with: url) { data, _, _ in
+ guard let data, let post else { return }
+
+ let picturesURL = FileManager.default.homeDirectoryForCurrentUser
+ .appendingPathComponent("Pictures/Sora")
+
+ do {
+ try FileManager.default.createDirectory(
+ at: picturesURL,
+ withIntermediateDirectories: true
+ )
+ try data.write(
+ to:
+ picturesURL
+ .appendingPathComponent("\(post.id).\(url.pathExtension)")
+ )
+ try post.tags.joined(separator: "\n").write(
+ to: picturesURL.appendingPathComponent(
+ "\(post.id).txt"
+ ),
+ atomically: true,
+ encoding: .utf8
+ )
+ } catch {
+ print("PostDetailsImageView.saveImageToPicturesFolder: \(error)")
+ }
+ }
+ .resume()
}
}
diff --git a/Sora/Views/Post/Details/PostDetailsView.swift b/Sora/Views/Post/Details/PostDetailsView.swift
index 802abb6..d1099ea 100644
--- a/Sora/Views/Post/Details/PostDetailsView.swift
+++ b/Sora/Views/Post/Details/PostDetailsView.swift
@@ -23,7 +23,7 @@ struct PostDetailsView: View {
url: imageURL,
loadingStage: $loadingStage,
finalLoadingState: .loaded,
- postURL: URL(string: "https://yande.re/post/show/\(post.id)")!
+ post: post
) {
PostDetailsImageView(
url: post.previewURL,