Skip to content

Commit e9ccd2f

Browse files
committed
refactor: Load local files' view asynchronously
1 parent cec8d48 commit e9ccd2f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

FileBrowserClient/FileBrowserClient/Views/LocalFileContentContainer.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,22 @@ struct LocalFileContentContainer: View {
7373

7474
private func loadContent() {
7575
errorMessage = nil
76+
content = nil
7677

77-
do {
78-
self.content = try Data(contentsOf: localFile)
79-
} catch {
80-
Log.warn("❌ Error loading file: \(error)")
81-
errorMessage = error.localizedDescription
78+
// DispatchQueue.main.async - Main thread where all UI updates happen
79+
// DispatchQueue.global(qos:) - Background thread used for non-UI tasks
80+
DispatchQueue.global(qos: .userInitiated).async {
81+
do {
82+
let data = try Data(contentsOf: localFile)
83+
DispatchQueue.main.async {
84+
self.content = data
85+
}
86+
} catch {
87+
Log.warn("❌ Error loading file: \(error)")
88+
DispatchQueue.main.async {
89+
errorMessage = error.localizedDescription
90+
}
91+
}
8292
}
8393
}
8494
}

0 commit comments

Comments
 (0)