Update library with Provider.Metadata renaming

This commit is contained in:
Davide 2024-12-04 09:26:10 +01:00
parent d53a01864b
commit d4543b49ac
No known key found for this signature in database
GPG Key ID: A48836171C759F5E
12 changed files with 27 additions and 27 deletions

View File

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

View File

@ -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"),

View File

@ -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?
}

View File

@ -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
}

View File

@ -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
)
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23507" systemVersion="23H222" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier="">
<entity name="CDProviderV3" representedClassName="CDProviderV3" syncable="YES">
<attribute name="encodedCustomizations" optional="YES" attributeType="Binary"/>
<attribute name="encodedMetadata" optional="YES" attributeType="Binary"/>
<attribute name="fullName" optional="YES" attributeType="String"/>
<attribute name="lastUpdate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="providerId" optional="YES" attributeType="String"/>

View File

@ -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

View File

@ -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

View File

@ -118,7 +118,7 @@ private extension ProviderContentModifier {
)
}
var supportedProviders: [ProviderMetadata] {
var supportedProviders: [Provider] {
providerManager
.providers
.filter {

View File

@ -28,7 +28,7 @@ import PassepartoutKit
import SwiftUI
struct ProviderPicker: View {
let providers: [ProviderMetadata]
let providers: [Provider]
@Binding
var providerId: ProviderID?

View File

@ -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 {

View File

@ -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 {