From d4543b49aca29c4135a3cbe0f1c7969fb57fbad6 Mon Sep 17 00:00:00 2001 From: Davide Date: Wed, 4 Dec 2024 09:26:10 +0100 Subject: [PATCH] Update library with Provider.Metadata renaming --- Library/Package.resolved | 2 +- Library/Package.swift | 2 +- .../AppDataProviders/Domain/CDProviderV3.swift | 2 +- .../AppDataProviders/Domain/CoreDataMapper.swift | 10 +++++----- .../AppDataProviders/Domain/DomainMapper.swift | 16 ++++++++-------- .../Providers.xcdatamodel/contents | 2 +- .../Strategy/CDProviderRepositoryV3.swift | 6 +++--- .../AppUIMain/Views/App/AddProfileMenu.swift | 2 +- .../Providers/ProviderContentModifier.swift | 2 +- .../Views/Providers/ProviderPicker.swift | 2 +- .../Views/Profile/ActiveProfileView.swift | 4 ++-- .../Views/Modules/OpenVPNView+Credentials.swift | 4 ++-- 12 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Library/Package.resolved b/Library/Package.resolved index 7a7eabac..9bbc8192 100644 --- a/Library/Package.resolved +++ b/Library/Package.resolved @@ -41,7 +41,7 @@ "kind" : "remoteSourceControl", "location" : "git@github.com:passepartoutvpn/passepartoutkit-source", "state" : { - "revision" : "f4786bf573ce30f85107b422590d7633d17fb87a" + "revision" : "97f2662bcfa8dff6983fe19320c85611047ab73d" } }, { diff --git a/Library/Package.swift b/Library/Package.swift index 298fea30..9abc174d 100644 --- a/Library/Package.swift +++ b/Library/Package.swift @@ -52,7 +52,7 @@ let package = Package( ], dependencies: [ // .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.12.0"), - .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "f4786bf573ce30f85107b422590d7633d17fb87a"), + .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "97f2662bcfa8dff6983fe19320c85611047ab73d"), // .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", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"), diff --git a/Library/Sources/AppDataProviders/Domain/CDProviderV3.swift b/Library/Sources/AppDataProviders/Domain/CDProviderV3.swift index dd117248..4b6d5319 100644 --- a/Library/Sources/AppDataProviders/Domain/CDProviderV3.swift +++ b/Library/Sources/AppDataProviders/Domain/CDProviderV3.swift @@ -35,6 +35,6 @@ final class CDProviderV3: NSManagedObject { @NSManaged var providerId: String? @NSManaged var fullName: String? @NSManaged var supportedConfigurationIds: String? - @NSManaged var encodedCustomizations: Data? // [String: ProviderMetadata.Customization] + @NSManaged var encodedMetadata: Data? // [String: Provider.Metadata] @NSManaged var lastUpdate: Date? } diff --git a/Library/Sources/AppDataProviders/Domain/CoreDataMapper.swift b/Library/Sources/AppDataProviders/Domain/CoreDataMapper.swift index 093f0628..5bbdfdcc 100644 --- a/Library/Sources/AppDataProviders/Domain/CoreDataMapper.swift +++ b/Library/Sources/AppDataProviders/Domain/CoreDataMapper.swift @@ -31,13 +31,13 @@ struct CoreDataMapper { let context: NSManagedObjectContext @discardableResult - func cdProvider(from metadata: ProviderMetadata, lastUpdate: Date?) throws -> CDProviderV3 { + func cdProvider(from provider: Provider, lastUpdate: Date?) throws -> CDProviderV3 { let entity = CDProviderV3(context: context) - entity.providerId = metadata.id.rawValue - entity.fullName = metadata.description + entity.providerId = provider.id.rawValue + entity.fullName = provider.description entity.lastUpdate = lastUpdate - entity.supportedConfigurationIds = metadata.customizations.map(\.key).joined(separator: ",") - entity.encodedCustomizations = try JSONEncoder().encode(metadata.customizations) + entity.supportedConfigurationIds = provider.metadata.map(\.key).joined(separator: ",") + entity.encodedMetadata = try JSONEncoder().encode(provider.metadata) return entity } diff --git a/Library/Sources/AppDataProviders/Domain/DomainMapper.swift b/Library/Sources/AppDataProviders/Domain/DomainMapper.swift index 27110f3b..9475fdc6 100644 --- a/Library/Sources/AppDataProviders/Domain/DomainMapper.swift +++ b/Library/Sources/AppDataProviders/Domain/DomainMapper.swift @@ -28,28 +28,28 @@ import Foundation import PassepartoutKit struct DomainMapper { - func provider(from entity: CDProviderV3) -> ProviderMetadata? { + func provider(from entity: CDProviderV3) -> Provider? { guard let id = entity.providerId, let fullName = entity.fullName else { return nil } - let customizations: [String: ProviderMetadata.Customization] - if let encodedCustomizations = entity.encodedCustomizations { + let metadata: [String: Provider.Metadata] + if let encodedMetadata = entity.encodedMetadata { do { - customizations = try JSONDecoder().decode([String: ProviderMetadata.Customization].self, from: encodedCustomizations) + metadata = try JSONDecoder().decode([String: Provider.Metadata].self, from: encodedMetadata) } catch { return nil } } else if let supportedConfigurationIds = entity.supportedConfigurationIds?.components(separatedBy: ",") { - customizations = supportedConfigurationIds.reduce(into: [:]) { + metadata = supportedConfigurationIds.reduce(into: [:]) { $0[$1] = .init() } } else { - customizations = [:] + metadata = [:] } - return ProviderMetadata( + return Provider( id, description: fullName, - customizations: customizations + metadata: metadata ) } diff --git a/Library/Sources/AppDataProviders/Providers.xcdatamodeld/Providers.xcdatamodel/contents b/Library/Sources/AppDataProviders/Providers.xcdatamodeld/Providers.xcdatamodel/contents index 64e5550c..65bedb3d 100644 --- a/Library/Sources/AppDataProviders/Providers.xcdatamodeld/Providers.xcdatamodel/contents +++ b/Library/Sources/AppDataProviders/Providers.xcdatamodeld/Providers.xcdatamodel/contents @@ -1,7 +1,7 @@ - + diff --git a/Library/Sources/AppDataProviders/Strategy/CDProviderRepositoryV3.swift b/Library/Sources/AppDataProviders/Strategy/CDProviderRepositoryV3.swift index c6a9e197..ef237453 100644 --- a/Library/Sources/AppDataProviders/Strategy/CDProviderRepositoryV3.swift +++ b/Library/Sources/AppDataProviders/Strategy/CDProviderRepositoryV3.swift @@ -39,7 +39,7 @@ extension AppData { actor CDProviderRepositoryV3: NSObject, ProviderRepository { private nonisolated let context: NSManagedObjectContext - private nonisolated let providersSubject: CurrentValueSubject<[ProviderMetadata], Never> + private nonisolated let providersSubject: CurrentValueSubject<[Provider], Never> private nonisolated let lastUpdateSubject: CurrentValueSubject<[ProviderID: Date], Never> @@ -71,7 +71,7 @@ actor CDProviderRepositoryV3: NSObject, ProviderRepository { } } - nonisolated var indexPublisher: AnyPublisher<[ProviderMetadata], Never> { + nonisolated var indexPublisher: AnyPublisher<[Provider], Never> { providersSubject .removeDuplicates() .eraseToAnyPublisher() @@ -83,7 +83,7 @@ actor CDProviderRepositoryV3: NSObject, ProviderRepository { .eraseToAnyPublisher() } - func store(_ index: [ProviderMetadata]) async throws { + func store(_ index: [Provider]) async throws { try await context.perform { [weak self] in guard let self else { return diff --git a/Library/Sources/AppUIMain/Views/App/AddProfileMenu.swift b/Library/Sources/AppUIMain/Views/App/AddProfileMenu.swift index e5f5e6ef..7df48870 100644 --- a/Library/Sources/AppUIMain/Views/App/AddProfileMenu.swift +++ b/Library/Sources/AppUIMain/Views/App/AddProfileMenu.swift @@ -130,7 +130,7 @@ private struct ProvidersSubmenu: View { } } - func profileButton(for provider: ProviderMetadata) -> some View { + func profileButton(for provider: Provider) -> some View { Button(provider.description) { var editable = EditableProfile() editable.name = provider.description diff --git a/Library/Sources/AppUIMain/Views/Providers/ProviderContentModifier.swift b/Library/Sources/AppUIMain/Views/Providers/ProviderContentModifier.swift index ea804452..f2d3ee94 100644 --- a/Library/Sources/AppUIMain/Views/Providers/ProviderContentModifier.swift +++ b/Library/Sources/AppUIMain/Views/Providers/ProviderContentModifier.swift @@ -118,7 +118,7 @@ private extension ProviderContentModifier { ) } - var supportedProviders: [ProviderMetadata] { + var supportedProviders: [Provider] { providerManager .providers .filter { diff --git a/Library/Sources/AppUIMain/Views/Providers/ProviderPicker.swift b/Library/Sources/AppUIMain/Views/Providers/ProviderPicker.swift index dc8031a4..0ef22a66 100644 --- a/Library/Sources/AppUIMain/Views/Providers/ProviderPicker.swift +++ b/Library/Sources/AppUIMain/Views/Providers/ProviderPicker.swift @@ -28,7 +28,7 @@ import PassepartoutKit import SwiftUI struct ProviderPicker: View { - let providers: [ProviderMetadata] + let providers: [Provider] @Binding var providerId: ProviderID? diff --git a/Library/Sources/AppUITV/Views/Profile/ActiveProfileView.swift b/Library/Sources/AppUITV/Views/Profile/ActiveProfileView.swift index c13fb072..9e13b4b3 100644 --- a/Library/Sources/AppUITV/Views/Profile/ActiveProfileView.swift +++ b/Library/Sources/AppUITV/Views/Profile/ActiveProfileView.swift @@ -104,9 +104,9 @@ private extension ActiveProfileView { } } if let pair = profile.selectedProvider { - if let metadata = providerManager.provider(withId: pair.selection.id) { + if let provider = providerManager.provider(withId: pair.selection.id) { ListRowView(title: Strings.Global.Nouns.provider) { - Text(metadata.description) + Text(provider.description) } } if let entity = pair.selection.entity { diff --git a/Library/Sources/UILibrary/Views/Modules/OpenVPNView+Credentials.swift b/Library/Sources/UILibrary/Views/Modules/OpenVPNView+Credentials.swift index 01e5d47a..13962c72 100644 --- a/Library/Sources/UILibrary/Views/Modules/OpenVPNView+Credentials.swift +++ b/Library/Sources/UILibrary/Views/Modules/OpenVPNView+Credentials.swift @@ -219,8 +219,8 @@ private extension OpenVPNCredentialsView { } func onLoad() { - if let providerId, let metadata = providerManager.provider(withId: providerId) { - providerCustomization = metadata.customization(for: OpenVPN.Configuration.self) + if let providerId, let provider = providerManager.provider(withId: providerId) { + providerCustomization = provider.customization(for: OpenVPN.Configuration.self) } builder = credentials?.builder() ?? OpenVPN.Credentials.Builder() if ignoresPassword {