diff options
| author | Dustin Mierau <dustin@mierau.me> | 2024-05-14 18:12:56 -0700 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2024-05-14 18:12:56 -0700 |
| commit | ac3c8f540751e4138319d9e4e7ffb92a9b2236e2 (patch) | |
| tree | 53df968f49e74223153c61e7a287f0d99faeece3 /Hotline/Models/Hotline.swift | |
| parent | ec78dfa6c0a407cb9160e913886887a764f8e1d3 (diff) | |
Some contextual menus in files and newsgroups. Added functional delete file context menu.
Diffstat (limited to 'Hotline/Models/Hotline.swift')
| -rw-r--r-- | Hotline/Models/Hotline.swift | 72 |
1 files changed, 18 insertions, 54 deletions
diff --git a/Hotline/Models/Hotline.swift b/Hotline/Models/Hotline.swift index 06baf04..ce917cd 100644 --- a/Hotline/Models/Hotline.swift +++ b/Hotline/Models/Hotline.swift @@ -545,14 +545,29 @@ class Hotline: Equatable, HotlineClientDelegate, HotlineFileClientDelegate { } } - @MainActor func fileDetails(_ fileName: String, path: [String], complete callback: ((FileDetails?) -> Void)? = nil) { + @MainActor func getFileDetails(_ fileName: String, path: [String]) async -> FileDetails? { var fullPath: [String] = [] if path.count > 1 { fullPath = Array(path[0..<path.count-1]) } - self.client.sendGetFileInfo(name: fileName, path: fullPath) { info in - callback?(info) + return await withCheckedContinuation { [weak self] continuation in + self?.client.sendGetFileInfo(name: fileName, path: fullPath) { info in + continuation.resume(returning: info) + } + } + } + + @MainActor func deleteFile(_ fileName: String, path: [String]) async -> Bool { + var fullPath: [String] = [] + if path.count > 1 { + fullPath = Array(path[0..<path.count-1]) + } + + return await withCheckedContinuation { [weak self] continuation in + self?.client.sendDeleteFile(name: fileName, path: fullPath) { success in + continuation.resume(returning: success) + } } } @@ -611,57 +626,6 @@ class Hotline: Equatable, HotlineClientDelegate, HotlineFileClientDelegate { } } -// @MainActor func previewFile(_ fileName: String, path: [String], addTransfer: Bool = false, complete callback: ((TransferInfo, Data) -> Void)? = nil) { -// var fullPath: [String] = [] -// if path.count > 1 { -// fullPath = Array(path[0..<path.count-1]) -// } -// -// self.client.sendDownloadFile(name: fileName, path: fullPath, preview: true, sent: { _ in -// -// }, reply: { [weak self] success, downloadReferenceNumber, downloadTransferSize, downloadFileSize, downloadWaitingCount in -// guard success else { -// return -// } -// -// print("GOT DOWNLOAD REPLY:") -// print("SUCCESS?", success) -// print("TRANSFER SIZE: \(downloadTransferSize.debugDescription)") -// print("FILE SIZE: \(downloadFileSize.debugDescription)") -// print("REFERENCE NUM: \(downloadReferenceNumber.debugDescription)") -// print("WAITING COUNT: \(downloadWaitingCount.debugDescription)") -// -// if -// let self = self, -// let address = self.server?.address, -// let port = self.server?.port, -// let referenceNumber = downloadReferenceNumber, -// let transferSize = downloadTransferSize { -// -// let fileClient = HotlineFileClient(address: address, port: UInt16(port), reference: referenceNumber, size: UInt32(transferSize), type: .preview) -// fileClient.delegate = self -// self.downloads.append(fileClient) -// -// if addTransfer { -// let transfer = TransferInfo(id: referenceNumber, title: fileName, size: UInt(transferSize)) -// transfer.previewCallback = callback -// self.transfers.append(transfer) -// } -// -// fileClient.downloadToMemory() -// -// print("DOWNLOADING TO MEMORY") -//// fileClient.downloadToMemory({ [weak self] fileData in -//// print("DOWNLOADED PREVIEW DATA", fileData?.count) -//// self?.downloads.removeAll { $0.referenceNumber == referenceNumber } -//// callback?(fileData != nil, fileData) -//// }) -// -//// self.downloads.append(fileClient) -// } -// }) -// } - @MainActor func deleteTransfer(id: UInt32) { if let b = self.bannerClient, b.referenceNumber == id { b.cancel() |