fix(macos): hide local bridge discovery
This commit is contained in:
@@ -85,6 +85,7 @@ final class GatewayDiscoveryModel {
|
||||
lanHost: lanHost,
|
||||
tailnetDns: tailnetDns,
|
||||
displayName: prettyName,
|
||||
serviceName: decodedName,
|
||||
local: self.localIdentity)
|
||||
return DiscoveredGateway(
|
||||
displayName: prettyName,
|
||||
@@ -180,6 +181,7 @@ final class GatewayDiscoveryModel {
|
||||
lanHost: String?,
|
||||
tailnetDns: String?,
|
||||
displayName: String?,
|
||||
serviceName: String?,
|
||||
local: LocalIdentity) -> Bool
|
||||
{
|
||||
if let host = normalizeHostToken(lanHost),
|
||||
@@ -197,6 +199,13 @@ final class GatewayDiscoveryModel {
|
||||
{
|
||||
return true
|
||||
}
|
||||
if let service = normalizeServiceToken(serviceName) {
|
||||
for token in local.hostTokens {
|
||||
if service.contains(token) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -250,4 +259,11 @@ final class GatewayDiscoveryModel {
|
||||
if trimmed.isEmpty { return nil }
|
||||
return trimmed.lowercased()
|
||||
}
|
||||
|
||||
private static func normalizeServiceToken(_ raw: String?) -> String? {
|
||||
guard let raw else { return nil }
|
||||
let trimmed = raw.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
if trimmed.isEmpty { return nil }
|
||||
return trimmed.lowercased()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1335,8 +1335,12 @@ struct OnboardingView: View {
|
||||
let shouldMonitor = isConnectionPage
|
||||
if shouldMonitor, !self.monitoringDiscovery {
|
||||
self.monitoringDiscovery = true
|
||||
self.gatewayDiscovery.start()
|
||||
Task { await self.refreshLocalGatewayProbe() }
|
||||
Task { @MainActor in
|
||||
try? await Task.sleep(nanoseconds: 250_000_000)
|
||||
guard self.monitoringDiscovery else { return }
|
||||
self.gatewayDiscovery.start()
|
||||
await self.refreshLocalGatewayProbe()
|
||||
}
|
||||
} else if !shouldMonitor, self.monitoringDiscovery {
|
||||
self.monitoringDiscovery = false
|
||||
self.gatewayDiscovery.stop()
|
||||
|
||||
@@ -10,6 +10,7 @@ import Testing
|
||||
lanHost: "studio.local",
|
||||
tailnetDns: nil,
|
||||
displayName: nil,
|
||||
serviceName: nil,
|
||||
local: local))
|
||||
}
|
||||
|
||||
@@ -21,6 +22,7 @@ import Testing
|
||||
lanHost: nil,
|
||||
tailnetDns: "studio.tailnet.example",
|
||||
displayName: nil,
|
||||
serviceName: nil,
|
||||
local: local))
|
||||
}
|
||||
|
||||
@@ -32,6 +34,7 @@ import Testing
|
||||
lanHost: nil,
|
||||
tailnetDns: nil,
|
||||
displayName: "Peter's Mac Studio (Clawdis)",
|
||||
serviceName: nil,
|
||||
local: local))
|
||||
}
|
||||
|
||||
@@ -43,6 +46,19 @@ import Testing
|
||||
lanHost: "other.local",
|
||||
tailnetDns: "other.tailnet.example",
|
||||
displayName: "Other Mac",
|
||||
serviceName: "other-bridge",
|
||||
local: local))
|
||||
}
|
||||
|
||||
@Test func localGatewayMatchesServiceName() {
|
||||
let local = GatewayDiscoveryModel.LocalIdentity(
|
||||
hostTokens: ["studio"],
|
||||
displayTokens: [])
|
||||
#expect(GatewayDiscoveryModel.isLocalGateway(
|
||||
lanHost: nil,
|
||||
tailnetDns: nil,
|
||||
displayName: nil,
|
||||
serviceName: "studio-bridge",
|
||||
local: local))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user