diff options
| author | Fuwn <[email protected]> | 2025-02-25 21:14:13 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-02-25 21:14:13 -0800 |
| commit | 5c9d5f5f9e39fb669921889b453fbb4e46b48bec (patch) | |
| tree | 0be7551f15774000ce1efda52efe94b58f38985c /Sora/Views | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-5c9d5f5f9e39fb669921889b453fbb4e46b48bec.tar.xz sora-testing-5c9d5f5f9e39fb669921889b453fbb4e46b48bec.zip | |
feat: Development commit
Diffstat (limited to 'Sora/Views')
| -rw-r--r-- | Sora/Views/Post/Details/PostDetailsImageView.swift | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/Sora/Views/Post/Details/PostDetailsImageView.swift b/Sora/Views/Post/Details/PostDetailsImageView.swift index bc40fae..67d3d68 100644 --- a/Sora/Views/Post/Details/PostDetailsImageView.swift +++ b/Sora/Views/Post/Details/PostDetailsImageView.swift @@ -7,7 +7,6 @@ struct PostDetailsImageView<Placeholder: View>: View { var url: URL? @Binding var loadingState: BooruPostLoadingState var finalLoadingState: BooruPostLoadingState - private var postURL: URL? let placeholder: () -> Placeholder let post: BooruPost? @State private var currentScale: CGFloat = 1.0 @@ -79,15 +78,17 @@ struct PostDetailsImageView<Placeholder: View>: View { } #endif - if let url = postURL { + Button { + openURL(postURL(for: post?.id ?? "")) + } label: { + Label("Open in Safari", systemImage: "safari") + } + + if let source = post?.source { Button { - #if os(iOS) - UIApplication.shared.open(url) - #else - NSWorkspace.shared.open(url) - #endif + openURL(URL(string: source)!) } label: { - Label("Open in Safari", systemImage: "safari") + Label("Open Source in Safari", systemImage: "safari") } } } @@ -129,12 +130,20 @@ struct PostDetailsImageView<Placeholder: View>: View { self.url = url _loadingState = loadingStage self.finalLoadingState = finalLoadingState - self.postURL = - post != nil ? URL(string: "https://yande.re/post/show/\(String(post?.id ?? "0"))")! : nil self.placeholder = placeholder self.post = post } + private func postURL(for id: String) -> URL { + switch manager.flavor { + case .moebooru: + return URL(string: "https://\(manager.domain)/post/show/\(id)")! + + case .gelbooru: + return URL(string: "https://\(manager.domain)/index.php?page=post&s=view&id=\(id)")! + } + } + #if os(macOS) private func saveImageToPicturesFolder() { guard let url = self.url else { return } @@ -174,4 +183,12 @@ struct PostDetailsImageView<Placeholder: View>: View { .resume() } #endif + + private func openURL(_ url: URL) { + #if os(iOS) + UIApplication.shared.open(url) + #else + NSWorkspace.shared.open(url) + #endif + } } |