Merge pull request #105 from McNight/fix/file-transfer-error-alert

fix: show alert on file transfer failure in File Browser
This commit is contained in:
Lakr
2026-03-05 10:24:19 +08:00
committed by GitHub
2 changed files with 12 additions and 3 deletions

View File

@@ -172,9 +172,13 @@ class VPhoneFileBrowserModel {
}
func uploadFiles(urls: [URL]) async {
var uploadError: String?
for url in urls {
guard let data = try? Data(contentsOf: url) else { continue }
let name = url.lastPathComponent
guard let data = try? Data(contentsOf: url) else {
uploadError = "Could not read \"\(name)\" from disk."
break
}
let dest = (currentPath as NSString).appendingPathComponent(name)
transferName = name
transferTotal = Int64(data.count)
@@ -184,11 +188,14 @@ class VPhoneFileBrowserModel {
transferCurrent = Int64(data.count)
print("[files] uploaded \(name) (\(data.count) bytes)")
} catch {
self.error = "Upload failed: \(error)"
uploadError = "Upload failed for \"\(name)\": \(error)"
break
}
}
transferName = nil
await refresh()
// Set error after refresh so refresh() doesn't clear it before the alert fires.
if let e = uploadError { self.error = e }
}
func createNewFolder(name: String) async {

View File

@@ -313,7 +313,9 @@ struct VPhoneFileBrowserView: View {
urls.append(url)
}
}
if !urls.isEmpty {
if urls.isEmpty {
model.error = "Could not load any files from the dropped items."
} else {
await model.uploadFiles(urls: urls)
}
}