Discovery: wide-area bridge DNS-SD
# Conflicts: # apps/ios/Sources/Bridge/BridgeDiscoveryModel.swift # src/cli/dns-cli.ts
This commit is contained in:
@@ -192,7 +192,7 @@ actor GatewayChannelActor {
|
||||
let clientName = InstanceIdentity.displayName
|
||||
|
||||
let reqId = UUID().uuidString
|
||||
let client: [String: ProtoAnyCodable] = [
|
||||
var client: [String: ProtoAnyCodable] = [
|
||||
"name": ProtoAnyCodable(clientName),
|
||||
"version": ProtoAnyCodable(
|
||||
Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "dev"),
|
||||
@@ -200,6 +200,10 @@ actor GatewayChannelActor {
|
||||
"mode": ProtoAnyCodable("app"),
|
||||
"instanceId": ProtoAnyCodable(InstanceIdentity.instanceId),
|
||||
]
|
||||
client["deviceFamily"] = ProtoAnyCodable("Mac")
|
||||
if let model = InstanceIdentity.modelIdentifier {
|
||||
client["modelIdentifier"] = ProtoAnyCodable(model)
|
||||
}
|
||||
var params: [String: ProtoAnyCodable] = [
|
||||
"minProtocol": ProtoAnyCodable(GATEWAY_PROTOCOL_VERSION),
|
||||
"maxProtocol": ProtoAnyCodable(GATEWAY_PROTOCOL_VERSION),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import Darwin
|
||||
import Foundation
|
||||
|
||||
enum InstanceIdentity {
|
||||
@@ -30,4 +31,15 @@ enum InstanceIdentity {
|
||||
}
|
||||
return "clawdis-mac"
|
||||
}()
|
||||
|
||||
static let modelIdentifier: String? = {
|
||||
var size = 0
|
||||
guard sysctlbyname("hw.model", nil, &size, nil, 0) == 0, size > 1 else { return nil }
|
||||
|
||||
var buffer = [CChar](repeating: 0, count: size)
|
||||
guard sysctlbyname("hw.model", &buffer, &size, nil, 0) == 0 else { return nil }
|
||||
|
||||
let s = String(cString: buffer).trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
return s.isEmpty ? nil : s
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -70,6 +70,11 @@ struct InstancesSettings: View {
|
||||
if let platform = inst.platform, let prettyPlatform = self.prettyPlatform(platform) {
|
||||
self.label(icon: self.platformIcon(platform), text: prettyPlatform)
|
||||
}
|
||||
if let deviceText = self.deviceDescription(inst),
|
||||
let deviceIcon = self.deviceIcon(inst)
|
||||
{
|
||||
self.label(icon: deviceIcon, text: deviceText)
|
||||
}
|
||||
self.label(icon: "clock", text: inst.lastInputDescription)
|
||||
if let mode = inst.mode { self.label(icon: "network", text: mode) }
|
||||
if let reason = inst.reason, !reason.isEmpty {
|
||||
@@ -115,6 +120,28 @@ struct InstancesSettings: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func deviceIcon(_ inst: InstanceInfo) -> String? {
|
||||
let family = inst.deviceFamily?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||
if family.isEmpty { return nil }
|
||||
switch family.lowercased() {
|
||||
case "ipad":
|
||||
return "ipad"
|
||||
case "iphone":
|
||||
return "iphone"
|
||||
case "mac":
|
||||
return "laptopcomputer"
|
||||
default:
|
||||
return "cpu"
|
||||
}
|
||||
}
|
||||
|
||||
private func deviceDescription(_ inst: InstanceInfo) -> String? {
|
||||
let model = inst.modelIdentifier?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||
if !model.isEmpty { return model }
|
||||
let family = inst.deviceFamily?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||
return family.isEmpty ? nil : family
|
||||
}
|
||||
|
||||
private func prettyPlatform(_ raw: String) -> String? {
|
||||
let (prefix, version) = self.parsePlatform(raw)
|
||||
if prefix.isEmpty { return nil }
|
||||
|
||||
@@ -10,6 +10,8 @@ struct InstanceInfo: Identifiable, Codable {
|
||||
let ip: String?
|
||||
let version: String?
|
||||
let platform: String?
|
||||
let deviceFamily: String?
|
||||
let modelIdentifier: String?
|
||||
let lastInputSeconds: Int?
|
||||
let mode: String?
|
||||
let reason: String?
|
||||
@@ -284,6 +286,8 @@ final class InstancesStore {
|
||||
ip: entry.ip,
|
||||
version: entry.version,
|
||||
platform: entry.platform,
|
||||
deviceFamily: entry.devicefamily,
|
||||
modelIdentifier: entry.modelidentifier,
|
||||
lastInputSeconds: entry.lastinputseconds,
|
||||
mode: entry.mode,
|
||||
reason: entry.reason,
|
||||
@@ -308,6 +312,8 @@ extension InstancesStore {
|
||||
ip: "10.0.0.12",
|
||||
version: "1.2.3",
|
||||
platform: "macos 26.2.0",
|
||||
deviceFamily: "Mac",
|
||||
modelIdentifier: "Mac16,6",
|
||||
lastInputSeconds: 12,
|
||||
mode: "local",
|
||||
reason: "preview",
|
||||
@@ -319,6 +325,8 @@ extension InstancesStore {
|
||||
ip: "100.64.0.2",
|
||||
version: "1.2.3",
|
||||
platform: "linux 6.6.0",
|
||||
deviceFamily: "Linux",
|
||||
modelIdentifier: "x86_64",
|
||||
lastInputSeconds: 45,
|
||||
mode: "remote",
|
||||
reason: "preview",
|
||||
|
||||
@@ -35,6 +35,7 @@ final class PresenceReporter {
|
||||
let host = InstanceIdentity.displayName
|
||||
let ip = Self.primaryIPv4Address() ?? "ip-unknown"
|
||||
let version = Self.appVersionString()
|
||||
let platform = Self.platformString()
|
||||
let lastInput = Self.lastInputSeconds()
|
||||
let text = Self.composePresenceSummary(mode: mode, reason: reason)
|
||||
var params: [String: AnyHashable] = [
|
||||
@@ -43,8 +44,11 @@ final class PresenceReporter {
|
||||
"ip": AnyHashable(ip),
|
||||
"mode": AnyHashable(mode),
|
||||
"version": AnyHashable(version),
|
||||
"platform": AnyHashable(platform),
|
||||
"deviceFamily": AnyHashable("Mac"),
|
||||
"reason": AnyHashable(reason),
|
||||
]
|
||||
if let model = InstanceIdentity.modelIdentifier { params["modelIdentifier"] = AnyHashable(model) }
|
||||
if let lastInput { params["lastInputSeconds"] = AnyHashable(lastInput) }
|
||||
do {
|
||||
try await ControlChannel.shared.sendSystemEvent(text, params: params)
|
||||
@@ -78,6 +82,11 @@ final class PresenceReporter {
|
||||
return version
|
||||
}
|
||||
|
||||
private static func platformString() -> String {
|
||||
let v = ProcessInfo.processInfo.operatingSystemVersion
|
||||
return "macos \(v.majorVersion).\(v.minorVersion).\(v.patchVersion)"
|
||||
}
|
||||
|
||||
private static func lastInputSeconds() -> Int? {
|
||||
let anyEvent = CGEventType(rawValue: UInt32.max) ?? .null
|
||||
let seconds = CGEventSource.secondsSinceLastEventType(.combinedSessionState, eventType: anyEvent)
|
||||
|
||||
@@ -168,6 +168,8 @@ public struct PresenceEntry: Codable {
|
||||
public let ip: String?
|
||||
public let version: String?
|
||||
public let platform: String?
|
||||
public let devicefamily: String?
|
||||
public let modelidentifier: String?
|
||||
public let mode: String?
|
||||
public let lastinputseconds: Int?
|
||||
public let reason: String?
|
||||
@@ -181,6 +183,8 @@ public struct PresenceEntry: Codable {
|
||||
ip: String?,
|
||||
version: String?,
|
||||
platform: String?,
|
||||
devicefamily: String?,
|
||||
modelidentifier: String?,
|
||||
mode: String?,
|
||||
lastinputseconds: Int?,
|
||||
reason: String?,
|
||||
@@ -193,6 +197,8 @@ public struct PresenceEntry: Codable {
|
||||
self.ip = ip
|
||||
self.version = version
|
||||
self.platform = platform
|
||||
self.devicefamily = devicefamily
|
||||
self.modelidentifier = modelidentifier
|
||||
self.mode = mode
|
||||
self.lastinputseconds = lastinputseconds
|
||||
self.reason = reason
|
||||
@@ -206,6 +212,8 @@ public struct PresenceEntry: Codable {
|
||||
case ip
|
||||
case version
|
||||
case platform
|
||||
case devicefamily = "deviceFamily"
|
||||
case modelidentifier = "modelIdentifier"
|
||||
case mode
|
||||
case lastinputseconds = "lastInputSeconds"
|
||||
case reason
|
||||
|
||||
Reference in New Issue
Block a user