parent
8815e6fdf7
commit
91a3e42533
|
@ -143,7 +143,7 @@ private extension AppInlineCoordinator {
|
||||||
func modalDestination(for item: ModalRoute?) -> some View {
|
func modalDestination(for item: ModalRoute?) -> some View {
|
||||||
switch item {
|
switch item {
|
||||||
case .editProviderEntity(let profile, let module, let provider):
|
case .editProviderEntity(let profile, let module, let provider):
|
||||||
ProviderSelectorView(
|
ProviderEntitySelector(
|
||||||
profileManager: profileManager,
|
profileManager: profileManager,
|
||||||
tunnel: tunnel,
|
tunnel: tunnel,
|
||||||
profile: profile,
|
profile: profile,
|
||||||
|
|
|
@ -135,7 +135,7 @@ extension AppModalCoordinator {
|
||||||
}
|
}
|
||||||
|
|
||||||
case .editProviderEntity(let profile, let module, let provider):
|
case .editProviderEntity(let profile, let module, let provider):
|
||||||
ProviderSelectorView(
|
ProviderEntitySelector(
|
||||||
profileManager: profileManager,
|
profileManager: profileManager,
|
||||||
tunnel: tunnel,
|
tunnel: tunnel,
|
||||||
profile: profile,
|
profile: profile,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// ProviderSelectorView.swift
|
// ProviderEntitySelector.swift
|
||||||
// Passepartout
|
// Passepartout
|
||||||
//
|
//
|
||||||
// Created by Davide De Rosa on 10/22/24.
|
// Created by Davide De Rosa on 10/22/24.
|
||||||
|
@ -27,7 +27,7 @@ import AppLibrary
|
||||||
import PassepartoutKit
|
import PassepartoutKit
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ProviderSelectorView: View {
|
struct ProviderEntitySelector: View {
|
||||||
|
|
||||||
@EnvironmentObject
|
@EnvironmentObject
|
||||||
private var profileProcessor: ProfileProcessor
|
private var profileProcessor: ProfileProcessor
|
||||||
|
@ -53,7 +53,7 @@ struct ProviderSelectorView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension ProviderSelectorView {
|
private extension ProviderEntitySelector {
|
||||||
func onSelect(_ entity: any ProviderEntity & Encodable) async throws {
|
func onSelect(_ entity: any ProviderEntity & Encodable) async throws {
|
||||||
pp_log(.app, .info, "Select new provider entity: \(entity)")
|
pp_log(.app, .info, "Select new provider entity: \(entity)")
|
||||||
|
|
|
@ -49,15 +49,8 @@ extension OpenVPNModule: ProviderEntityViewProviding {
|
||||||
with provider: ModuleMetadata.Provider,
|
with provider: ModuleMetadata.Provider,
|
||||||
onSelect: @escaping (any ProviderEntity & Encodable) async throws -> Void
|
onSelect: @escaping (any ProviderEntity & Encodable) async throws -> Void
|
||||||
) -> some View {
|
) -> some View {
|
||||||
let selectedEntity: VPNEntity<OpenVPN.Configuration>? = try? provider
|
VPNProviderServerCoordinator<OpenVPN.Configuration>(
|
||||||
.entity
|
|
||||||
.map {
|
|
||||||
try providerEntity(from: $0.data)
|
|
||||||
}
|
|
||||||
|
|
||||||
return VPNProviderEntityCoordinator(
|
|
||||||
providerId: provider.id,
|
providerId: provider.id,
|
||||||
selectedEntity: selectedEntity,
|
|
||||||
onSelect: onSelect
|
onSelect: onSelect
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// VPNProviderEntityCoordinator.swift
|
// VPNProviderServerCoordinator.swift
|
||||||
// Passepartout
|
// Passepartout
|
||||||
//
|
//
|
||||||
// Created by Davide De Rosa on 10/16/24.
|
// Created by Davide De Rosa on 10/16/24.
|
||||||
|
@ -27,15 +27,13 @@ import PassepartoutKit
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import UtilsLibrary
|
import UtilsLibrary
|
||||||
|
|
||||||
struct VPNProviderEntityCoordinator<Configuration>: View where Configuration: ProviderConfigurationIdentifiable & Codable {
|
struct VPNProviderServerCoordinator<Configuration>: View where Configuration: ProviderConfigurationIdentifiable & Codable {
|
||||||
|
|
||||||
@Environment(\.dismiss)
|
@Environment(\.dismiss)
|
||||||
private var dismiss
|
private var dismiss
|
||||||
|
|
||||||
let providerId: ProviderID
|
let providerId: ProviderID
|
||||||
|
|
||||||
let selectedEntity: VPNEntity<Configuration>?
|
|
||||||
|
|
||||||
let onSelect: (VPNEntity<Configuration>) async throws -> Void
|
let onSelect: (VPNEntity<Configuration>) async throws -> Void
|
||||||
|
|
||||||
@StateObject
|
@StateObject
|
||||||
|
@ -44,10 +42,9 @@ struct VPNProviderEntityCoordinator<Configuration>: View where Configuration: Pr
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
VPNProviderServerView(
|
VPNProviderServerView(
|
||||||
apis: API.shared,
|
|
||||||
providerId: providerId,
|
providerId: providerId,
|
||||||
configurationType: Configuration.self,
|
configurationType: Configuration.self,
|
||||||
selectedEntity: selectedEntity,
|
selectedEntity: nil,
|
||||||
onSelect: onSelect
|
onSelect: onSelect
|
||||||
)
|
)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
|
@ -68,7 +65,7 @@ struct VPNProviderEntityCoordinator<Configuration>: View where Configuration: Pr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension VPNProviderEntityCoordinator {
|
private extension VPNProviderServerCoordinator {
|
||||||
func onSelect(server: VPNServer, preset: VPNPreset<Configuration>) {
|
func onSelect(server: VPNServer, preset: VPNPreset<Configuration>) {
|
||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
|
@ -76,7 +73,7 @@ private extension VPNProviderEntityCoordinator {
|
||||||
try await onSelect(entity)
|
try await onSelect(entity)
|
||||||
dismiss()
|
dismiss()
|
||||||
} catch {
|
} catch {
|
||||||
pp_log(.app, .fault, "Unable to select server \(server.serverId): \(error)")
|
pp_log(.app, .fault, "Unable to select server \(server.serverId) for provider \(server.provider.id): \(error)")
|
||||||
errorHandler.handle(error, title: Strings.Global.servers)
|
errorHandler.handle(error, title: Strings.Global.servers)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue