Full project scaffold: XcodeGen project.yml, Core models/protocols/errors, SMBService (kishikawakatsumi/SMBClient), SFTPService (Citadel 0.9.2), PhotoLibraryService, LANMonitor, BackupEngine, BackgroundTaskManager, all feature UIs (Login, Connect, Browse, Backup, History, Settings), Shared components and theme. Builds clean with zero errors. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
54 lines
1.7 KiB
Swift
54 lines
1.7 KiB
Swift
import Foundation
|
|
|
|
enum ConnectField { case host, username, password, folder }
|
|
enum FieldState { case idle, valid, invalid }
|
|
|
|
@MainActor
|
|
final class ConnectViewModel: ObservableObject {
|
|
@Published var host = ""
|
|
@Published var username = ""
|
|
@Published var password = ""
|
|
@Published var remotePath = "/"
|
|
@Published var selectedProtocol: NASProtocol = .smb
|
|
@Published var isVerifying = false
|
|
@Published var isConnected = false
|
|
@Published var verifyError: String? = nil
|
|
@Published var showFolderBrowser = false
|
|
|
|
var fieldState: FieldState {
|
|
isConnected ? .valid : (verifyError != nil ? .invalid : .idle)
|
|
}
|
|
|
|
var canConnect: Bool {
|
|
!host.isEmpty && !username.isEmpty && !password.isEmpty && !isVerifying
|
|
}
|
|
|
|
func verify() async {
|
|
isVerifying = true
|
|
isConnected = false
|
|
verifyError = nil
|
|
|
|
let connection = NASConnection(
|
|
host: host,
|
|
nasProtocol: selectedProtocol,
|
|
username: username,
|
|
password: password,
|
|
remotePath: remotePath
|
|
)
|
|
|
|
let service: any NASTransferProtocol = selectedProtocol == .smb ? SMBService() : SFTPService()
|
|
do {
|
|
try await service.connect(to: connection.host, port: connection.port,
|
|
username: connection.username, password: connection.password)
|
|
service.disconnect()
|
|
isConnected = true
|
|
ConnectionStore.shared.savedConnection = connection
|
|
} catch let e as BackupError {
|
|
verifyError = e.errorDescription
|
|
} catch {
|
|
verifyError = error.localizedDescription
|
|
}
|
|
isVerifying = false
|
|
}
|
|
}
|