fix crash when adding line to log from background thread

Signed-off-by: Bryan Montz <bryanmontz@me.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Bryan Montz
2023-07-09 08:45:39 -05:00
committed by William Casarin
parent 51d71f11c1
commit 2d9f7128ee

View File

@@ -81,15 +81,18 @@ final class RelayLog: ObservableObject {
/// Adds content to the log
/// - Parameter content: what to add to the log. The date and time are prepended to the content.
func add(_ content: String) {
let line = "\(formatter.string(from: .now)) - \(content)"
lines.insert(line, at: 0)
truncateLines()
Task {
await addLine(content)
await publishChanges()
}
}
@MainActor private func addLine(_ line: String) {
let line = "\(formatter.string(from: .now)) - \(line)"
lines.insert(line, at: 0)
truncateLines()
}
/// Tells views that our log has been updated
@MainActor private func publishChanges() {
objectWillChange.send()