ui(ios): clean up connected bridge list
This commit is contained in:
@@ -10,6 +10,7 @@ struct SettingsTab: View {
|
|||||||
@State private var connectStatus: String?
|
@State private var connectStatus: String?
|
||||||
@State private var isConnecting = false
|
@State private var isConnecting = false
|
||||||
@State private var didAutoConnect = false
|
@State private var didAutoConnect = false
|
||||||
|
@State private var isShowingBridgeList = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
@@ -32,37 +33,24 @@ struct SettingsTab: View {
|
|||||||
LabeledContent("Discovery", value: self.discovery.statusText)
|
LabeledContent("Discovery", value: self.discovery.statusText)
|
||||||
LabeledContent("Status", value: self.appModel.bridgeStatusText)
|
LabeledContent("Status", value: self.appModel.bridgeStatusText)
|
||||||
if let serverName = self.appModel.bridgeServerName {
|
if let serverName = self.appModel.bridgeServerName {
|
||||||
Text("Server: \(serverName)")
|
LabeledContent("Server", value: serverName)
|
||||||
.font(.footnote)
|
|
||||||
.foregroundStyle(.secondary)
|
Button("Disconnect", role: .destructive) {
|
||||||
|
self.appModel.disconnectBridge()
|
||||||
|
}
|
||||||
|
|
||||||
|
DisclosureGroup("Switch bridge", isExpanded: self.$isShowingBridgeList) {
|
||||||
|
self.bridgeList(showConnectedRow: true)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.bridgeList(showConnectedRow: false)
|
||||||
}
|
}
|
||||||
Button("Disconnect") { self.appModel.disconnectBridge() }
|
|
||||||
if let connectStatus {
|
if let connectStatus {
|
||||||
Text(connectStatus)
|
Text(connectStatus)
|
||||||
.font(.footnote)
|
.font(.footnote)
|
||||||
.foregroundStyle(.secondary)
|
.foregroundStyle(.secondary)
|
||||||
}
|
}
|
||||||
if self.discovery.bridges.isEmpty {
|
|
||||||
Text("No bridges found yet.")
|
|
||||||
.foregroundStyle(.secondary)
|
|
||||||
} else {
|
|
||||||
ForEach(self.discovery.bridges) { bridge in
|
|
||||||
HStack {
|
|
||||||
VStack(alignment: .leading, spacing: 2) {
|
|
||||||
Text(bridge.name)
|
|
||||||
Text(bridge.debugID)
|
|
||||||
.font(.caption2)
|
|
||||||
.foregroundStyle(.secondary)
|
|
||||||
.lineLimit(1)
|
|
||||||
}
|
|
||||||
Spacer()
|
|
||||||
Button(self.isConnecting ? "…" : "Connect") {
|
|
||||||
Task { await self.connect(bridge) }
|
|
||||||
}
|
|
||||||
.disabled(self.isConnecting)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle("Settings")
|
.navigationTitle("Settings")
|
||||||
@@ -96,11 +84,61 @@ struct SettingsTab: View {
|
|||||||
displayName: self.displayName,
|
displayName: self.displayName,
|
||||||
platform: self.platformString(),
|
platform: self.platformString(),
|
||||||
version: self.appVersion())
|
version: self.appVersion())
|
||||||
self.connectStatus = "Auto-connected"
|
self.connectStatus = nil
|
||||||
|
}
|
||||||
|
.onChange(of: self.appModel.bridgeServerName) { _, _ in
|
||||||
|
self.connectStatus = nil
|
||||||
|
self.isShowingBridgeList = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func bridgeList(showConnectedRow: Bool) -> some View {
|
||||||
|
if self.discovery.bridges.isEmpty {
|
||||||
|
Text("No bridges found yet.")
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
} else {
|
||||||
|
ForEach(self.discovery.bridges) { bridge in
|
||||||
|
let isConnected = self.isConnectedBridge(bridge)
|
||||||
|
if isConnected, !showConnectedRow {
|
||||||
|
EmptyView()
|
||||||
|
} else {
|
||||||
|
HStack {
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Text(bridge.name)
|
||||||
|
Text(bridge.debugID)
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
if isConnected {
|
||||||
|
Image(systemName: "checkmark.circle.fill")
|
||||||
|
.foregroundStyle(.green)
|
||||||
|
.accessibilityLabel("Connected")
|
||||||
|
} else {
|
||||||
|
Button(self.isConnecting ? "…" : "Connect") {
|
||||||
|
Task { await self.connect(bridge) }
|
||||||
|
}
|
||||||
|
.disabled(self.isConnecting)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func isConnectedBridge(_ bridge: BridgeDiscoveryModel.DiscoveredBridge) -> Bool {
|
||||||
|
guard let serverName = self.appModel.bridgeServerName?.trimmingCharacters(in: .whitespacesAndNewlines),
|
||||||
|
!serverName.isEmpty
|
||||||
|
else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return bridge.name.localizedCaseInsensitiveContains(serverName)
|
||||||
|
}
|
||||||
|
|
||||||
private func keychainAccount() -> String {
|
private func keychainAccount() -> String {
|
||||||
"bridge-token.\(self.instanceId)"
|
"bridge-token.\(self.instanceId)"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user