Files
bot/apps/macos/Sources/Bot/HeartbeatStore.swift
zeekay 4bdc9ee3e4 chore: rebrand openclaw → hanzo-bot for bridge merge
Comprehensive rename of all openclaw references to hanzo-bot equivalents:
- Package: openclaw → @hanzo/bot
- Binary: openclaw → hanzo-bot
- Types: OpenClaw* → Bot*
- Env vars: OPENCLAW_* → BOT_*
- Android: ai.openclaw.android → ai.hanzo.bot.android
- iOS/macOS: ai.openclaw.* → ai.hanzo.*
- Swift modules: OpenClaw* → Bot*
- Plugins: openclaw.plugin.json → bot.plugin.json
- Paths: .openclaw/ → .hanzo/bot/
- URLs: github.com/openclaw → github.com/hanzoai
2026-02-26 22:36:01 -08:00

40 lines
1.0 KiB
Swift

import Foundation
import Observation
import SwiftUI
@MainActor
@Observable
final class HeartbeatStore {
static let shared = HeartbeatStore()
private(set) var lastEvent: ControlHeartbeatEvent?
private var observer: NSObjectProtocol?
private init() {
self.observer = NotificationCenter.default.addObserver(
forName: .controlHeartbeat,
object: nil,
queue: .main)
{ [weak self] note in
guard let data = note.object as? Data else { return }
if let decoded = try? JSONDecoder().decode(ControlHeartbeatEvent.self, from: data) {
Task { @MainActor in self?.lastEvent = decoded }
}
}
Task {
if self.lastEvent == nil {
if let evt = try? await ControlChannel.shared.lastHeartbeat() {
self.lastEvent = evt
}
}
}
}
@MainActor
deinit {
if let observer { NotificationCenter.default.removeObserver(observer) }
}
}