From c479921a4f2ce7e437154a319dcf8ef2802b758e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 15 Jan 2026 08:16:44 +0800 Subject: [PATCH] refactor: apply connection events --- Library/Network/CommandClient.swift | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Library/Network/CommandClient.swift b/Library/Network/CommandClient.swift index 6a68dc7..b02b073 100644 --- a/Library/Network/CommandClient.swift +++ b/Library/Network/CommandClient.swift @@ -68,7 +68,7 @@ public class CommandClient: ObservableObject { @Published public var connectionSort = ConnectionSort.byDate @Published public var connections: [LibboxConnection]? @Published public var hasAnyConnection: Bool = false - public var rawConnections: LibboxConnections? + private var connectionsStore: LibboxConnections? @Published public var uplinkHistory: [CGFloat] = Array(repeating: 0, count: 30) @Published public var downlinkHistory: [CGFloat] = Array(repeating: 0, count: 30) @@ -144,10 +144,10 @@ public class CommandClient: ObservableObject { } public func filterConnectionsNow() { - guard let message = rawConnections else { + guard let store = connectionsStore else { return } - let result = filterConnections(message) + let result = filterConnections(store) connections = result.connections hasAnyConnection = result.hasAny } @@ -327,13 +327,16 @@ public class CommandClient: ObservableObject { } } - func write(_ message: LibboxConnections?) { - guard let message else { + func write(_ events: LibboxConnectionEvents?) { + guard let events else { return } - let result = commandClient.filterConnections(message) DispatchQueue.main.async { [self] in - commandClient.rawConnections = message + if commandClient.connectionsStore == nil { + commandClient.connectionsStore = LibboxNewConnections() + } + commandClient.connectionsStore?.apply(events) + let result = commandClient.filterConnections(commandClient.connectionsStore!) commandClient.connections = result.connections commandClient.hasAnyConnection = result.hasAny }