feat(nodes): add mac node mode + permission UX

This commit is contained in:
Peter Steinberger
2025-12-19 01:48:19 +01:00
parent beb5b1ad58
commit 1fbd84da39
8 changed files with 1108 additions and 3 deletions

View File

@@ -44,6 +44,8 @@ final class InstancesStore {
private var task: Task<Void, Never>?
private let interval: TimeInterval = 30
private var eventTask: Task<Void, Never>?
private var lastPresenceById: [String: InstanceInfo] = [:]
private var lastLoginNotifiedAtMs: [String: Double] = [:]
private struct PresenceEventPayload: Codable {
let presence: [PresenceEntry]
@@ -302,10 +304,37 @@ final class InstancesStore {
private func applyPresence(_ entries: [PresenceEntry]) {
let withIDs = self.normalizePresence(entries)
self.notifyOnNodeLogin(withIDs)
self.lastPresenceById = Dictionary(uniqueKeysWithValues: withIDs.map { ($0.id, $0) })
self.instances = withIDs
self.statusMessage = nil
self.lastError = nil
}
private func notifyOnNodeLogin(_ instances: [InstanceInfo]) {
for inst in instances {
guard let reason = inst.reason?.trimmingCharacters(in: .whitespacesAndNewlines) else { continue }
guard reason == "node-connected" else { continue }
if let mode = inst.mode?.lowercased(), mode == "local" { continue }
let previous = self.lastPresenceById[inst.id]
if previous?.reason == "node-connected", previous?.ts == inst.ts { continue }
let lastNotified = self.lastLoginNotifiedAtMs[inst.id] ?? 0
if inst.ts <= lastNotified { continue }
self.lastLoginNotifiedAtMs[inst.id] = inst.ts
let name = inst.host?.trimmingCharacters(in: .whitespacesAndNewlines)
let device = name?.isEmpty == false ? name! : inst.id
Task { @MainActor in
_ = await NotificationManager().send(
title: "Node connected",
body: device,
sound: nil,
priority: .active)
}
}
}
}
extension InstancesStore {