mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
refactor(swift): share discovery status text
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import Foundation
|
||||
import Network
|
||||
|
||||
public enum GatewayDiscoveryStatusText {
|
||||
public static func make(states: [NWBrowser.State], hasBrowsers: Bool) -> String {
|
||||
if states.isEmpty {
|
||||
return hasBrowsers ? "Setup" : "Idle"
|
||||
}
|
||||
|
||||
if let failed = states.first(where: { state in
|
||||
if case .failed = state { return true }
|
||||
return false
|
||||
}) {
|
||||
if case let .failed(err) = failed {
|
||||
return "Failed: \(err)"
|
||||
}
|
||||
}
|
||||
|
||||
if let waiting = states.first(where: { state in
|
||||
if case .waiting = state { return true }
|
||||
return false
|
||||
}) {
|
||||
if case let .waiting(err) = waiting {
|
||||
return "Waiting: \(err)"
|
||||
}
|
||||
}
|
||||
|
||||
if states.contains(where: { if case .ready = $0 { true } else { false } }) {
|
||||
return "Searching…"
|
||||
}
|
||||
|
||||
if states.contains(where: { if case .setup = $0 { true } else { false } }) {
|
||||
return "Setup"
|
||||
}
|
||||
|
||||
return "Searching…"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user