-
Notifications
You must be signed in to change notification settings - Fork 3
feat(InterfaceManagement): add TCP client community-server wizard #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
torlando-tech
merged 4 commits into
main
from
columba-suite/issue-51-add-community-tcp-server-wizard
May 10, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
920022d
feat(InterfaceManagement): add TCP client community-server wizard
torlando-agent[bot] 66f5086
fix(TCPClientWizard): mirror android server list, drop bootstrap split
torlando-agent[bot] a0cde6f
chore(greptile): iteration 1 — applied 4, rejected 0
torlando-agent[bot] bc7b18e
fix(TcpCommunityServer): remove unwanted servers from wizard list
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
Sources/ColumbaApp/ViewModels/TCPClientWizardViewModel.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| // | ||
| // TCPClientWizardViewModel.swift | ||
| // ColumbaApp | ||
| // | ||
| // State management for the 2-step TCP client interface configuration wizard. | ||
| // Mirrors the Android Columba TcpClientWizardViewModel. | ||
| // | ||
|
|
||
| import Foundation | ||
| import SwiftUI | ||
| import ReticulumSwift | ||
|
|
||
| // MARK: - Wizard Step | ||
|
|
||
| /// Steps in the TCP client configuration wizard. | ||
| @available(iOS 17.0, macOS 14.0, *) | ||
| enum TCPClientWizardStep: Int, CaseIterable, Identifiable { | ||
| case serverSelection = 0 | ||
| case reviewConfigure = 1 | ||
|
|
||
| var id: Int { rawValue } | ||
|
|
||
| var title: String { | ||
| switch self { | ||
| case .serverSelection: return "Select Server" | ||
| case .reviewConfigure: return "Review & Configure" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Parent Save Sink | ||
|
|
||
| /// Minimal protocol the wizard uses to forward a built TCP config to the | ||
| /// parent `InterfaceManagementViewModel`. Lets tests stub the parent without | ||
| /// pulling in repository / AppServices wiring. | ||
| @available(iOS 17.0, macOS 14.0, *) | ||
| protocol TCPClientWizardSaveSink: AnyObject { | ||
| func saveTCPInterface( | ||
| editing: InterfaceEntity?, | ||
| name: String, | ||
| enabled: Bool, | ||
| mode: InterfaceMode, | ||
| config: TCPClientConfig | ||
| ) | ||
| } | ||
|
|
||
| // MARK: - ViewModel | ||
|
|
||
| /// ViewModel for the TCP client configuration wizard. | ||
| /// | ||
| /// Manages step navigation, server selection vs custom mode, edit-mode | ||
| /// pre-population, and forwards the built `TCPClientConfig` through a | ||
| /// `TCPClientWizardSaveSink` so the existing add/update path on | ||
| /// `InterfaceManagementViewModel` stays the single source of persistence. | ||
| @available(iOS 17.0, macOS 14.0, *) | ||
| @Observable | ||
| @MainActor | ||
| final class TCPClientWizardViewModel { | ||
|
|
||
| // MARK: - Navigation | ||
|
|
||
| var currentStep: TCPClientWizardStep = .serverSelection | ||
|
|
||
| // MARK: - Step 1: Server Selection | ||
|
|
||
| var selectedServer: TcpCommunityServer? | ||
| var isCustomMode: Bool = false | ||
|
|
||
| // MARK: - Step 2: Review & Configure | ||
|
|
||
| var interfaceName: String = "" | ||
| var targetHost: String = "" | ||
| var targetPort: String = "4242" | ||
| var networkName: String = "" | ||
| var passphrase: String = "" | ||
| var showPassphrase: Bool = false | ||
| var mode: InterfaceMode = .full | ||
| var enabled: Bool = true | ||
| var showAdvanced: Bool = false | ||
|
|
||
| // MARK: - Edit Context | ||
|
|
||
| /// The interface being edited (nil for create flow). | ||
| private(set) var editingInterface: InterfaceEntity? | ||
|
|
||
| /// Whether this wizard run is editing an existing interface. | ||
| var isEditing: Bool { editingInterface != nil } | ||
|
|
||
| // MARK: - Step 1 Actions | ||
|
|
||
| /// Pre-fill name/host/port from a community server and clear custom mode. | ||
| func selectServer(_ server: TcpCommunityServer) { | ||
| selectedServer = server | ||
| isCustomMode = false | ||
| interfaceName = server.name | ||
| targetHost = server.host | ||
| targetPort = String(server.port) | ||
| } | ||
|
|
||
| /// Switch to custom-server mode: clear the selection and blank | ||
| /// the name/host/port fields so the user types fresh values in step 2. | ||
| func enableCustomMode() { | ||
| selectedServer = nil | ||
| isCustomMode = true | ||
| interfaceName = "" | ||
| targetHost = "" | ||
| targetPort = "" | ||
| } | ||
|
|
||
| // MARK: - Edit Pre-population | ||
|
|
||
| /// Populate fields from an existing TCP interface. | ||
| /// | ||
| /// If `(host, port)` matches a known `TcpCommunityServer`, that server | ||
| /// is selected and the wizard opens at step 1. Otherwise the wizard opens | ||
| /// at step 1 in custom mode so the user can confirm or change the entry. | ||
| func loadExisting(_ entity: InterfaceEntity) { | ||
| guard case .tcpClient(let config) = entity.config else { return } | ||
| editingInterface = entity | ||
| interfaceName = entity.name | ||
| targetHost = config.targetHost | ||
| targetPort = String(config.targetPort) | ||
| networkName = config.networkName ?? "" | ||
| passphrase = config.passphrase ?? "" | ||
| mode = entity.mode | ||
| enabled = entity.enabled | ||
|
|
||
| let match = TcpCommunityServer.servers.first { server in | ||
| server.host == config.targetHost && server.port == config.targetPort | ||
| } | ||
| if let match = match { | ||
| selectedServer = match | ||
| isCustomMode = false | ||
| } else { | ||
| selectedServer = nil | ||
| isCustomMode = true | ||
| } | ||
| currentStep = .serverSelection | ||
| } | ||
|
|
||
| // MARK: - Validation | ||
|
|
||
| /// Whether the wizard can advance / save from the given step. | ||
| func canProceed(from step: TCPClientWizardStep) -> Bool { | ||
| switch step { | ||
| case .serverSelection: | ||
| return selectedServer != nil || isCustomMode | ||
| case .reviewConfigure: | ||
| let host = targetHost.trimmingCharacters(in: .whitespaces) | ||
| guard !host.isEmpty else { return false } | ||
| guard let port = UInt16(targetPort.trimmingCharacters(in: .whitespaces)), | ||
| port > 0 else { | ||
| return false | ||
| } | ||
| let trimmedName = interfaceName.trimmingCharacters(in: .whitespaces) | ||
| return !trimmedName.isEmpty | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Step Navigation | ||
|
|
||
| func goToReview() { | ||
| currentStep = .reviewConfigure | ||
| } | ||
|
|
||
| func goToServerSelection() { | ||
| currentStep = .serverSelection | ||
| } | ||
|
|
||
| // MARK: - Save | ||
|
|
||
| /// Build the `TCPClientConfig` and forward it to the parent through the | ||
| /// save sink. Persistence + apply-changes stay on the parent. | ||
| func save(into sink: TCPClientWizardSaveSink) { | ||
| let trimmedHost = targetHost.trimmingCharacters(in: .whitespaces) | ||
| let port = UInt16(targetPort.trimmingCharacters(in: .whitespaces)) ?? 4242 | ||
| let trimmedNetwork = networkName.trimmingCharacters(in: .whitespaces) | ||
| let trimmedPassphrase = passphrase.trimmingCharacters(in: .whitespaces) | ||
|
|
||
| let config = TCPClientConfig( | ||
| targetHost: trimmedHost, | ||
| targetPort: port, | ||
| networkName: trimmedNetwork.isEmpty ? nil : trimmedNetwork, | ||
| passphrase: trimmedPassphrase.isEmpty ? nil : trimmedPassphrase | ||
| ) | ||
|
|
||
| sink.saveTCPInterface( | ||
| editing: editingInterface, | ||
| name: interfaceName.trimmingCharacters(in: .whitespaces), | ||
| enabled: enabled, | ||
| mode: mode, | ||
| config: config | ||
| ) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"noDNS1"and"noDNS2"look like internal identifiers rather than display-ready names. Both appear directly in theTCPServerSelectionStepserver picker as theText(server.name)label, so users will see these literal strings when choosing a community server. If these nodes have recognisable operator names (e.g. from the Android list or directory.rns.recipes), replace them before this lands; if they are intentionally anonymous nodes, a more descriptive label (e.g."Anonymous Node 1"with the IP shown as the address) would communicate the distinction more clearly.Prompt To Fix With AI