HeartbeatStore: fix main-actor cleanup
This commit is contained in:
29
apps/macos/Sources/Clawdis/HeartbeatStore.swift
Normal file
29
apps/macos/Sources/Clawdis/HeartbeatStore.swift
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
final class HeartbeatStore: ObservableObject {
|
||||||
|
static let shared = HeartbeatStore()
|
||||||
|
|
||||||
|
@Published private(set) var lastEvent: AgentRPC.HeartbeatEvent?
|
||||||
|
|
||||||
|
private var observer: NSObjectProtocol?
|
||||||
|
|
||||||
|
private init() {
|
||||||
|
self.observer = NotificationCenter.default.addObserver(
|
||||||
|
forName: AgentRPC.heartbeatNotification,
|
||||||
|
object: nil,
|
||||||
|
queue: .main
|
||||||
|
) { [weak self] note in
|
||||||
|
guard let event = note.object as? AgentRPC.HeartbeatEvent else { return }
|
||||||
|
Task { @MainActor in
|
||||||
|
self?.lastEvent = event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
deinit {
|
||||||
|
if let observer { NotificationCenter.default.removeObserver(observer) }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user