Update usages of libbox

This commit is contained in:
世界
2025-11-26 22:25:47 +08:00
parent 532c140f05
commit f4b284acd8
6 changed files with 64 additions and 79 deletions
+12 -2
View File
@@ -18,6 +18,7 @@ public class CommandClient: ObservableObject {
@Published public var status: LibboxStatusMessage?
@Published public var groups: [LibboxOutboundGroup]?
@Published public var logList: [String]
@Published public var defaultLogLevel: Int32 = 0
@Published public var clashModeList: [String]
@Published public var clashMode: String
@@ -160,20 +161,29 @@ public class CommandClient: ObservableObject {
}
}
func setDefaultLogLevel(_ level: Int32) {
DispatchQueue.main.async { [self] in
commandClient.defaultLogLevel = level
}
}
func clearLogs() {
DispatchQueue.main.async { [self] in
commandClient.logList.removeAll()
}
}
func writeLogs(_ messageList: (any LibboxStringIteratorProtocol)?) {
func writeLogs(_ messageList: (any LibboxLogIteratorProtocol)?) {
guard let messageList else {
return
}
DispatchQueue.main.async { [self] in
var newLogList = commandClient.logList
while messageList.hasNext() {
newLogList.append(messageList.next())
let logEntry = messageList.next()!
if logEntry.level <= commandClient.defaultLogLevel {
newLogList.append(logEntry.message)
}
}
if newLogList.count >= commandClient.logMaxLines {
newLogList.removeSubrange(0 ... newLogList.count - commandClient.logMaxLines)