mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 20:45:19 +00:00
Use save panel for mac image export
This commit is contained in:
@@ -2260,13 +2260,13 @@ struct ImagePreviewView: View {
|
|||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
showExporter = true
|
showExporter = true
|
||||||
#else
|
#else
|
||||||
|
Task { @MainActor in
|
||||||
|
let panel = NSSavePanel()
|
||||||
|
panel.canCreateDirectories = true
|
||||||
|
panel.nameFieldStringValue = url.lastPathComponent
|
||||||
|
panel.prompt = "save"
|
||||||
|
if panel.runModal() == .OK, let destination = panel.url {
|
||||||
do {
|
do {
|
||||||
guard let downloads = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first else {
|
|
||||||
SecureLogger.error("Missing downloads directory for save", category: .session)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let baseName = url.lastPathComponent
|
|
||||||
let destination = uniqueFileURL(in: downloads, fileName: baseName)
|
|
||||||
if FileManager.default.fileExists(atPath: destination.path) {
|
if FileManager.default.fileExists(atPath: destination.path) {
|
||||||
try FileManager.default.removeItem(at: destination)
|
try FileManager.default.removeItem(at: destination)
|
||||||
}
|
}
|
||||||
@@ -2274,25 +2274,11 @@ struct ImagePreviewView: View {
|
|||||||
} catch {
|
} catch {
|
||||||
SecureLogger.error("Failed to save image preview copy: \(error)", category: .session)
|
SecureLogger.error("Failed to save image preview copy: \(error)", category: .session)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !os(iOS)
|
|
||||||
private func uniqueFileURL(in directory: URL, fileName: String) -> URL {
|
|
||||||
var candidate = directory.appendingPathComponent(fileName)
|
|
||||||
let base = (fileName as NSString).deletingPathExtension
|
|
||||||
let ext = (fileName as NSString).pathExtension
|
|
||||||
var counter = 1
|
|
||||||
while FileManager.default.fileExists(atPath: candidate.path) {
|
|
||||||
let suffix = " (\(counter))"
|
|
||||||
let name = ext.isEmpty ? base + suffix : base + suffix + "." + ext
|
|
||||||
candidate = directory.appendingPathComponent(name)
|
|
||||||
counter += 1
|
|
||||||
}
|
|
||||||
return candidate
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
private struct FileExportWrapper: UIViewControllerRepresentable {
|
private struct FileExportWrapper: UIViewControllerRepresentable {
|
||||||
let url: URL
|
let url: URL
|
||||||
|
|||||||
Reference in New Issue
Block a user