2024-10-10 22:24:06 +00:00
|
|
|
//
|
|
|
|
// VPNProviderServerView.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 10/7/24.
|
|
|
|
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
|
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
2024-11-02 09:11:59 +00:00
|
|
|
import CommonAPI
|
2024-10-26 11:29:26 +00:00
|
|
|
import CommonLibrary
|
2024-11-02 09:11:59 +00:00
|
|
|
import CommonUtils
|
2024-10-10 22:24:06 +00:00
|
|
|
import PassepartoutKit
|
|
|
|
import SwiftUI
|
|
|
|
|
2024-10-15 19:34:02 +00:00
|
|
|
struct VPNProviderServerView<Configuration>: View where Configuration: ProviderConfigurationIdentifiable & Codable {
|
2024-10-23 13:42:54 +00:00
|
|
|
var apis: [APIMapper] = API.shared
|
2024-10-18 16:12:28 +00:00
|
|
|
|
2024-10-26 11:29:26 +00:00
|
|
|
let moduleId: UUID
|
|
|
|
|
2024-10-18 16:12:28 +00:00
|
|
|
let providerId: ProviderID
|
|
|
|
|
|
|
|
let configurationType: Configuration.Type
|
|
|
|
|
2024-10-23 15:58:04 +00:00
|
|
|
let selectedEntity: VPNEntity<Configuration>?
|
2024-10-10 22:24:06 +00:00
|
|
|
|
2024-10-23 20:57:30 +00:00
|
|
|
let filtersWithSelection: Bool
|
|
|
|
|
2024-11-23 19:31:22 +00:00
|
|
|
var selectTitle = Strings.Views.Providers.selectEntity
|
2024-10-25 09:38:27 +00:00
|
|
|
|
2024-10-26 18:28:02 +00:00
|
|
|
let onSelect: (VPNServer, VPNPreset<Configuration>) -> Void
|
2024-10-10 22:24:06 +00:00
|
|
|
|
2024-10-18 16:12:28 +00:00
|
|
|
@StateObject
|
2024-10-26 18:28:02 +00:00
|
|
|
private var vpnManager = VPNProviderManager<Configuration>(sorting: [
|
2024-10-18 16:12:28 +00:00
|
|
|
.localizedCountry,
|
|
|
|
.area,
|
2024-11-14 23:24:22 +00:00
|
|
|
.serverId
|
2024-10-18 16:12:28 +00:00
|
|
|
])
|
|
|
|
|
2024-10-26 18:28:02 +00:00
|
|
|
@StateObject
|
|
|
|
private var filtersViewModel = VPNFiltersView.Model()
|
2024-10-26 11:29:26 +00:00
|
|
|
|
2024-10-18 16:12:28 +00:00
|
|
|
@StateObject
|
|
|
|
private var errorHandler: ErrorHandler = .default()
|
|
|
|
|
2024-10-10 22:24:06 +00:00
|
|
|
var body: some View {
|
2024-10-18 16:12:28 +00:00
|
|
|
debugChanges()
|
2024-10-26 18:28:02 +00:00
|
|
|
return contentView
|
|
|
|
.themeNavigationDetail()
|
|
|
|
.withErrorHandler(errorHandler)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension VPNProviderServerView {
|
2024-11-25 21:54:22 +00:00
|
|
|
var containerView: some View {
|
|
|
|
ContainerView(
|
2024-10-26 18:28:02 +00:00
|
|
|
vpnManager: vpnManager,
|
|
|
|
apis: apis,
|
|
|
|
moduleId: moduleId,
|
|
|
|
providerId: providerId,
|
2024-11-11 19:21:02 +00:00
|
|
|
selectedServer: selectedEntity?.server,
|
2024-11-25 21:54:22 +00:00
|
|
|
filtersViewModel: filtersViewModel,
|
|
|
|
initialFilters: initialFilters,
|
2024-10-25 09:38:27 +00:00
|
|
|
selectTitle: selectTitle,
|
2024-10-26 18:28:02 +00:00
|
|
|
onSelect: onSelect,
|
|
|
|
errorHandler: errorHandler
|
2024-10-18 16:12:28 +00:00
|
|
|
)
|
2024-10-26 18:28:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var filtersView: some View {
|
|
|
|
VPNFiltersView(model: filtersViewModel)
|
|
|
|
}
|
|
|
|
|
2024-11-25 21:54:22 +00:00
|
|
|
var initialFilters: VPNFilters? {
|
|
|
|
guard let selectedEntity, filtersWithSelection else {
|
|
|
|
return nil
|
2024-10-18 16:12:28 +00:00
|
|
|
}
|
2024-11-25 21:54:22 +00:00
|
|
|
var filters = VPNFilters()
|
|
|
|
filters.categoryName = selectedEntity.server.provider.categoryName
|
|
|
|
#if os(macOS)
|
|
|
|
filters.countryCode = selectedEntity.server.provider.countryCode
|
|
|
|
#endif
|
|
|
|
return filters
|
2024-10-18 16:12:28 +00:00
|
|
|
}
|
2024-10-10 22:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Preview
|
|
|
|
|
|
|
|
#Preview {
|
|
|
|
NavigationStack {
|
2024-10-23 15:17:20 +00:00
|
|
|
VPNProviderServerView(
|
2024-10-18 16:12:28 +00:00
|
|
|
apis: [API.bundled],
|
2024-10-26 11:29:26 +00:00
|
|
|
moduleId: UUID(),
|
2024-10-18 16:12:28 +00:00
|
|
|
providerId: .protonvpn,
|
2024-10-23 15:58:04 +00:00
|
|
|
configurationType: OpenVPN.Configuration.self,
|
|
|
|
selectedEntity: nil,
|
2024-10-23 20:57:30 +00:00
|
|
|
filtersWithSelection: false,
|
2024-10-25 09:38:27 +00:00
|
|
|
selectTitle: "Select",
|
2024-10-23 15:58:04 +00:00
|
|
|
onSelect: { _, _ in }
|
|
|
|
)
|
2024-10-10 22:24:06 +00:00
|
|
|
}
|
|
|
|
.withMockEnvironment()
|
|
|
|
}
|