@@ -11,6 +11,7 @@ import Foundation
1111extension CbfClient {
1212 // Track monitoring tasks per client for clean cancellation
1313 private static var monitoringTasks : [ ObjectIdentifier : Task < Void , Never > ] = [ : ]
14+ private static var warningTasks : [ ObjectIdentifier : Task < Void , Never > ] = [ : ]
1415 private static var heartbeatTasks : [ ObjectIdentifier : Task < Void , Never > ] = [ : ]
1516 private static var lastInfoAt : [ ObjectIdentifier : Date ] = [ : ]
1617 private static let monitoringTasksQueue = DispatchQueue ( label: " cbf.monitoring.tasks " )
@@ -132,6 +133,36 @@ extension CbfClient {
132133 Self . monitoringTasksQueue. sync {
133134 Self . heartbeatTasks [ id] = heartbeat
134135 }
136+
137+ // Minimal warnings listener for visibility while syncing
138+ let warnings = Task { [ self ] in
139+ while true {
140+ if Task . isCancelled { break }
141+ do {
142+ let warning = try await self . nextWarning ( )
143+ #if DEBUG
144+ print ( " [Kyoto][warning] \( String ( describing: warning) ) " )
145+ #endif
146+ if case . needConnections = warning {
147+ await MainActor . run {
148+ NotificationCenter . default. post (
149+ name: NSNotification . Name ( " KyotoConnectionUpdate " ) ,
150+ object: nil ,
151+ userInfo: [ " connected " : false ]
152+ )
153+ }
154+ }
155+ } catch is CancellationError {
156+ break
157+ } catch {
158+ // ignore
159+ }
160+ }
161+ }
162+
163+ Self . monitoringTasksQueue. sync {
164+ Self . warningTasks [ id] = warnings
165+ }
135166 }
136167
137168 func stopBackgroundMonitoring( ) {
@@ -140,15 +171,18 @@ extension CbfClient {
140171 guard let task = Self . monitoringTasks. removeValue ( forKey: id) else { return }
141172 task. cancel ( )
142173 if let hb = Self . heartbeatTasks. removeValue ( forKey: id) { hb. cancel ( ) }
174+ if let wt = Self . warningTasks. removeValue ( forKey: id) { wt. cancel ( ) }
143175 Self . lastInfoAt. removeValue ( forKey: id)
144176 }
145177 }
146178
147179 static func cancelAllMonitoring( ) {
148180 Self . monitoringTasksQueue. sync {
149181 for (_, task) in Self . monitoringTasks { task. cancel ( ) }
182+ for (_, wt) in Self . warningTasks { wt. cancel ( ) }
150183 for (_, hb) in Self . heartbeatTasks { hb. cancel ( ) }
151184 Self . monitoringTasks. removeAll ( )
185+ Self . warningTasks. removeAll ( )
152186 Self . heartbeatTasks. removeAll ( )
153187 Self . lastInfoAt. removeAll ( )
154188 }
0 commit comments