Update library with provider entities (#978)

This commit is contained in:
Davide 2024-12-04 12:40:47 +01:00 committed by GitHub
parent d4543b49ac
commit 355974292e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 15 additions and 21 deletions

View File

@ -41,7 +41,7 @@
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source", "location" : "git@github.com:passepartoutvpn/passepartoutkit-source",
"state" : { "state" : {
"revision" : "97f2662bcfa8dff6983fe19320c85611047ab73d" "revision" : "51288509f90b0d4dd2c4ceee2af5cfb36e6319f1"
} }
}, },
{ {

View File

@ -52,7 +52,7 @@ let package = Package(
], ],
dependencies: [ dependencies: [
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.12.0"), // .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.12.0"),
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "97f2662bcfa8dff6983fe19320c85611047ab73d"), .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "51288509f90b0d4dd2c4ceee2af5cfb36e6319f1"),
// .package(path: "../../passepartoutkit-source"), // .package(path: "../../passepartoutkit-source"),
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", from: "0.9.1"), .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", from: "0.9.1"),
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"), // .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"),

View File

@ -39,7 +39,7 @@ final class CDVPNProviderServerRepositoryV3: VPNProviderServerRepository {
self.providerId = providerId self.providerId = providerId
} }
func availableOptions<Configuration>(for configurationType: Configuration.Type) async throws -> VPNFilterOptions where Configuration: ProviderConfigurationIdentifiable { func availableOptions<Configuration>(for configurationType: Configuration.Type) async throws -> VPNFilterOptions where Configuration: ConfigurationIdentifiable {
try await context.perform { try await context.perform {
let mapper = DomainMapper() let mapper = DomainMapper()
@ -69,7 +69,7 @@ final class CDVPNProviderServerRepositoryV3: VPNProviderServerRepository {
let presetsRequest = CDVPNPresetV3.fetchRequest() let presetsRequest = CDVPNPresetV3.fetchRequest()
presetsRequest.predicate = NSPredicate( presetsRequest.predicate = NSPredicate(
format: "providerId == %@ AND configurationId == %@", self.providerId.rawValue, format: "providerId == %@ AND configurationId == %@", self.providerId.rawValue,
Configuration.providerConfigurationIdentifier Configuration.configurationIdentifier
) )
let presetsResults = try presetsRequest.execute() let presetsResults = try presetsRequest.execute()

View File

@ -135,7 +135,7 @@ private struct ProvidersSubmenu: View {
var editable = EditableProfile() var editable = EditableProfile()
editable.name = provider.description editable.name = provider.description
let newModule = moduleType.newModule(with: registry, providerId: provider.id) let newModule = moduleType.newModule(with: registry, providerId: provider.id)
if let providerBuilder = newModule as? any ProviderBuilder { if let providerBuilder = newModule as? any ProviderSelecting {
assert(providerBuilder.providerId == provider.id) assert(providerBuilder.providerId == provider.id)
} }
editable.modules.append(newModule) editable.modules.append(newModule)

View File

@ -218,7 +218,6 @@ private extension OpenVPNView {
VPNProviderServerView( VPNProviderServerView(
moduleId: module.id, moduleId: module.id,
providerId: $0.id, providerId: $0.id,
configurationType: OpenVPN.Configuration.self,
selectedEntity: $0.entity, selectedEntity: $0.entity,
filtersWithSelection: true, filtersWithSelection: true,
onSelect: onSelectServer onSelect: onSelectServer

View File

@ -115,7 +115,6 @@ private extension WireGuardView {
VPNProviderServerView( VPNProviderServerView(
moduleId: module.id, moduleId: module.id,
providerId: $0.id, providerId: $0.id,
configurationType: WireGuard.Configuration.self,
selectedEntity: $0.entity, selectedEntity: $0.entity,
filtersWithSelection: true, filtersWithSelection: true,
onSelect: onSelectServer onSelect: onSelectServer

View File

@ -122,7 +122,7 @@ private extension ProviderContentModifier {
providerManager providerManager
.providers .providers
.filter { .filter {
$0.supports(Entity.ConfigurationType.self) $0.supports(Entity.Template.self)
} }
} }

View File

@ -28,7 +28,7 @@ import CommonLibrary
import PassepartoutKit import PassepartoutKit
import SwiftUI import SwiftUI
struct VPNProviderContentModifier<Configuration, ProviderRows>: ViewModifier where Configuration: ProviderConfigurationIdentifiable, ProviderRows: View { struct VPNProviderContentModifier<Configuration, ProviderRows>: ViewModifier where Configuration: ConfigurationIdentifiable, ProviderRows: View {
var apis: [APIMapper] = API.shared var apis: [APIMapper] = API.shared
@Binding @Binding

View File

@ -27,7 +27,7 @@ import CommonUtils
import PassepartoutKit import PassepartoutKit
import SwiftUI import SwiftUI
struct VPNProviderServerCoordinator<Configuration>: View where Configuration: ProviderConfigurationIdentifiable { struct VPNProviderServerCoordinator<Configuration>: View where Configuration: ConfigurationIdentifiable {
@Environment(\.dismiss) @Environment(\.dismiss)
private var dismiss private var dismiss
@ -47,7 +47,6 @@ struct VPNProviderServerCoordinator<Configuration>: View where Configuration: Pr
VPNProviderServerView( VPNProviderServerView(
moduleId: moduleId, moduleId: moduleId,
providerId: providerId, providerId: providerId,
configurationType: Configuration.self,
selectedEntity: selectedEntity, selectedEntity: selectedEntity,
filtersWithSelection: false, filtersWithSelection: false,
selectTitle: Strings.Global.Actions.connect, selectTitle: Strings.Global.Actions.connect,

View File

@ -29,7 +29,7 @@ import CommonUtils
import PassepartoutKit import PassepartoutKit
import SwiftUI import SwiftUI
struct VPNProviderServerView<Configuration>: View where Configuration: ProviderConfigurationIdentifiable { struct VPNProviderServerView<Configuration>: View where Configuration: ConfigurationIdentifiable {
@EnvironmentObject @EnvironmentObject
private var providerManager: ProviderManager private var providerManager: ProviderManager
@ -40,8 +40,6 @@ struct VPNProviderServerView<Configuration>: View where Configuration: ProviderC
let providerId: ProviderID let providerId: ProviderID
let configurationType: Configuration.Type
let selectedEntity: VPNEntity<Configuration>? let selectedEntity: VPNEntity<Configuration>?
let filtersWithSelection: Bool let filtersWithSelection: Bool
@ -202,7 +200,7 @@ private extension VPNProviderServerView {
func onSelectServer(_ server: VPNServer) { func onSelectServer(_ server: VPNServer) {
guard let preset = compatiblePreset(with: server) else { guard let preset = compatiblePreset(with: server) else {
pp_log(.app, .error, "Unable to find a compatible preset. Supported IDs: \(server.provider.supportedPresetIds ?? [])") pp_log(.app, .error, "Unable to find a compatible preset. Supported IDs: \(server.provider.supportedPresetIds ?? [])")
assertionFailure("No compatible presets for server \(server.serverId) (provider=\(vpnManager.providerId), configuration=\(Configuration.providerConfigurationIdentifier), supported=\(server.provider.supportedPresetIds ?? []))") assertionFailure("No compatible presets for server \(server.serverId) (provider=\(vpnManager.providerId), configuration=\(Configuration.configurationIdentifier), supported=\(server.provider.supportedPresetIds ?? []))")
return return
} }
onSelect(server, preset) onSelect(server, preset)
@ -217,8 +215,7 @@ private extension VPNProviderServerView {
apis: [API.bundled], apis: [API.bundled],
moduleId: UUID(), moduleId: UUID(),
providerId: .protonvpn, providerId: .protonvpn,
configurationType: OpenVPN.Configuration.self, selectedEntity: nil as VPNEntity<OpenVPN.Configuration>?,
selectedEntity: nil,
filtersWithSelection: false, filtersWithSelection: false,
selectTitle: "Select", selectTitle: "Select",
onSelect: { _, _ in } onSelect: { _, _ in }

View File

@ -34,7 +34,7 @@ extension ModuleDraftEditing {
} }
@MainActor @MainActor
extension ModuleDraftEditing where Draft: ProviderBuilder { extension ModuleDraftEditing where Draft: MutableProviderSelecting {
public var providerId: Binding<ProviderID?> { public var providerId: Binding<ProviderID?> {
Binding { Binding {
draft.providerId.wrappedValue draft.providerId.wrappedValue
@ -43,7 +43,7 @@ extension ModuleDraftEditing where Draft: ProviderBuilder {
} }
} }
public var providerEntity: Binding<Draft.SelectionType.EntityType?> { public var providerEntity: Binding<Draft.CustomSelectionType.EntityType?> {
Binding { Binding {
draft.providerEntity.wrappedValue draft.providerEntity.wrappedValue
} set: { } set: {
@ -51,7 +51,7 @@ extension ModuleDraftEditing where Draft: ProviderBuilder {
} }
} }
public var providerOptions: Binding<Set<Draft.SelectionType.OptionType>?> { public var providerOptions: Binding<Set<Draft.CustomSelectionType.OptionType>?> {
Binding { Binding {
draft.providerOptions.wrappedValue draft.providerOptions.wrappedValue
} set: { } set: {

View File

@ -49,7 +49,7 @@ extension ProfileManager {
var moduleBuilder = moduleType.newModule(with: registry, providerId: parameters.providerId) var moduleBuilder = moduleType.newModule(with: registry, providerId: parameters.providerId)
if moduleBuilder.buildsConnectionModule { if moduleBuilder.buildsConnectionModule {
assert((moduleBuilder as? any ProviderBuilder)?.providerId == parameters.providerId) assert((moduleBuilder as? any ProviderSelecting)?.providerId == parameters.providerId)
} }
if parameters.name == "Hide.me", if parameters.name == "Hide.me",