Minor fixes

This commit is contained in:
世界
2025-12-13 19:30:33 +08:00
parent 14c0b34368
commit 9be752ea94
7 changed files with 62 additions and 18 deletions
+8 -11
View File
@@ -112,6 +112,7 @@ public class CommandClient: ObservableObject {
}
private func flushPendingLogs() {
logBatchTimer = nil
guard !pendingLogs.isEmpty else { return }
// Batch append all pending logs
@@ -254,19 +255,15 @@ public class CommandClient: ObservableObject {
guard !newLogs.isEmpty else { return }
DispatchQueue.main.async { [self] in
// Add to pending batch
commandClient.pendingLogs.append(contentsOf: newLogs)
// Cancel existing timer
commandClient.logBatchTimer?.cancel()
// Schedule batch flush
let workItem = DispatchWorkItem { [weak commandClient] in
guard let commandClient else { return }
commandClient.flushPendingLogs()
if commandClient.logBatchTimer == nil {
let workItem = DispatchWorkItem { [weak commandClient] in
guard let commandClient else { return }
commandClient.flushPendingLogs()
}
commandClient.logBatchTimer = workItem
DispatchQueue.main.asyncAfter(deadline: .now() + commandClient.logBatchInterval, execute: workItem)
}
commandClient.logBatchTimer = workItem
DispatchQueue.main.asyncAfter(deadline: .now() + commandClient.logBatchInterval, execute: workItem)
}
}
+8
View File
@@ -17,3 +17,11 @@ extension ExtensionStartupError: LocalizedError {
message
}
}
extension ExtensionStartupError: CustomNSError {
public static var errorDomain: String { "ExtensionStartupError" }
public var errorCode: Int { 1 }
public var errorUserInfo: [String: Any] {
[NSLocalizedDescriptionKey: message]
}
}