aboutsummaryrefslogtreecommitdiff
path: root/Hotline/macOS/FilesView.swift
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2024-07-24 12:32:41 -0700
committerDustin Mierau <dustin@mierau.me>2024-07-24 12:32:41 -0700
commit8633db7e6ca9f38345d7be0ab90193d6325904bf (patch)
treea950663e587c0bb0b051a61882ca9df6949a2446 /Hotline/macOS/FilesView.swift
parent844317f8a3f5c7b11394653c8563c6e9c24d7e85 (diff)
First pass at uploads and a big refactoring of transfer clients. Also now showing download progress bar on file icon in dock (like Safari).
Diffstat (limited to 'Hotline/macOS/FilesView.swift')
-rw-r--r--Hotline/macOS/FilesView.swift59
1 files changed, 49 insertions, 10 deletions
diff --git a/Hotline/macOS/FilesView.swift b/Hotline/macOS/FilesView.swift
index 2afa1a8..e34c7b5 100644
--- a/Hotline/macOS/FilesView.swift
+++ b/Hotline/macOS/FilesView.swift
@@ -133,6 +133,7 @@ struct FilesView: View {
@State private var selection: FileInfo?
@State private var fileDetails: FileDetails?
+ @State private var uploadFileSelectorDisplayed: Bool = false
private func openPreviewWindow(_ previewInfo: PreviewFileInfo) {
switch previewInfo.previewType {
@@ -143,7 +144,6 @@ struct FilesView: View {
default:
return
}
-// let _ = FilePreviewWindowController(info: previewInfo)
}
@MainActor private func getFileInfo(_ file: FileInfo) {
@@ -164,6 +164,15 @@ struct FilesView: View {
model.downloadFile(file.name, path: file.path)
}
+ @MainActor private func uploadFile(file fileURL: URL, to path: [String]) {
+ model.uploadFile(url: fileURL, path: path) { info in
+ Task {
+ // Refresh file listing to display newly uploaded file.
+ let _ = await model.getFileList(path: path)
+ }
+ }
+ }
+
@MainActor private func previewFile(_ file: FileInfo) {
guard file.isPreviewable else {
return
@@ -290,15 +299,6 @@ struct FilesView: View {
}
}
.toolbar {
-// ToolbarItem(placement: .primaryAction) {
-// Button {
-// } label: {
-// Label("Delete", systemImage: "trash")
-// }
-// .help("Delete")
-// .disabled(true)
-// }
-
ToolbarItem(placement: .primaryAction) {
Button {
if let selectedFile = selection, selectedFile.isPreviewable {
@@ -325,6 +325,15 @@ struct FilesView: View {
ToolbarItem(placement: .primaryAction) {
Button {
+ uploadFileSelectorDisplayed = true
+ } label: {
+ Label("Upload", systemImage: "arrow.up")
+ }
+ .help("Upload")
+ }
+
+ ToolbarItem(placement: .primaryAction) {
+ Button {
if let selectedFile = selection, !selectedFile.isFolder {
downloadFile(selectedFile)
}
@@ -339,6 +348,36 @@ struct FilesView: View {
.sheet(item: $fileDetails ) { item in
FileDetailsView(fd: item)
}
+ .fileImporter(isPresented: $uploadFileSelectorDisplayed, allowedContentTypes: [.data], allowsMultipleSelection: false, onCompletion: { results in
+ switch results {
+ case .success(let fileURLS):
+ guard fileURLS.count > 0 else {
+ return
+ }
+
+ let fileURL = fileURLS.first!
+
+ print(fileURL)
+
+ var uploadPath: [String] = []
+
+ if let selection = selection {
+ if selection.isFolder {
+ uploadPath = selection.path
+ }
+ else {
+ uploadPath = Array<String>(selection.path)
+ uploadPath.removeLast()
+ }
+ }
+
+ print("UPLOAD PATH: \(uploadPath)")
+ uploadFile(file: fileURL, to: uploadPath)
+
+ case .failure(let error):
+ print(error)
+ }
+ })
}
}