diff --git a/Passepartout/Library/Sources/AppLibrary/Business/NEProfileRepository.swift b/Passepartout/Library/Sources/AppLibrary/Business/NEProfileRepository.swift index d15d296a..a9e71764 100644 --- a/Passepartout/Library/Sources/AppLibrary/Business/NEProfileRepository.swift +++ b/Passepartout/Library/Sources/AppLibrary/Business/NEProfileRepository.swift @@ -31,12 +31,15 @@ import PassepartoutKit public final class NEProfileRepository: ProfileRepository { private let repository: NETunnelManagerRepository + private let title: (Profile) -> String + private let profilesSubject: CurrentValueSubject<[Profile], Never> private var subscription: AnyCancellable? - public init(repository: NETunnelManagerRepository) { + public init(repository: NETunnelManagerRepository, title: @escaping (Profile) -> String) { self.repository = repository + self.title = title profilesSubject = CurrentValueSubject([]) subscription = repository @@ -62,7 +65,7 @@ public final class NEProfileRepository: ProfileRepository { } public func saveProfile(_ profile: Profile) async throws { - try await repository.save(profile, connect: false, title: \.name) + try await repository.save(profile, connect: false, title: title) } public func removeProfiles(withIds profileIds: [Profile.ID]) async throws { diff --git a/Passepartout/Library/Sources/AppUI/Business/ProfileProcessor.swift b/Passepartout/Library/Sources/AppUI/Business/ProfileProcessor.swift index 75c594ab..b0d7ee3d 100644 --- a/Passepartout/Library/Sources/AppUI/Business/ProfileProcessor.swift +++ b/Passepartout/Library/Sources/AppUI/Business/ProfileProcessor.swift @@ -28,9 +28,15 @@ import PassepartoutKit @MainActor public final class ProfileProcessor: ObservableObject { - public let process: (Profile) throws -> Profile + public let title: (Profile) -> String - public init(process: @escaping (Profile) throws -> Profile) { - self.process = process + public let processed: (Profile) throws -> Profile + + public init( + title: @escaping (Profile) -> String, + processed: @escaping (Profile) throws -> Profile + ) { + self.title = title + self.processed = processed } } diff --git a/Passepartout/Library/Sources/AppUI/Business/Tunnel+Extensions.swift b/Passepartout/Library/Sources/AppUI/Business/Tunnel+Extensions.swift index 1951fe90..0be17aeb 100644 --- a/Passepartout/Library/Sources/AppUI/Business/Tunnel+Extensions.swift +++ b/Passepartout/Library/Sources/AppUI/Business/Tunnel+Extensions.swift @@ -30,13 +30,13 @@ import PassepartoutKit @MainActor extension Tunnel { func install(_ profile: Profile, processor: ProfileProcessor) async throws { - let newProfile = try processor.process(profile) - try await install(newProfile, connect: false, title: \.name) + let newProfile = try processor.processed(profile) + try await install(newProfile, connect: false, title: processor.title) } func connect(with profile: Profile, processor: ProfileProcessor) async throws { - let newProfile = try processor.process(profile) - try await install(newProfile, connect: true, title: \.name) + let newProfile = try processor.processed(profile) + try await install(newProfile, connect: true, title: processor.title) } func currentLog(parameters: Constants.Log) async -> [String] { diff --git a/Passepartout/Library/Sources/AppUI/Mock/Mock.swift b/Passepartout/Library/Sources/AppUI/Mock/Mock.swift index 82ca4e99..6316c93e 100644 --- a/Passepartout/Library/Sources/AppUI/Mock/Mock.swift +++ b/Passepartout/Library/Sources/AppUI/Mock/Mock.swift @@ -55,6 +55,8 @@ extension AppContext { return ProfileManager(profiles: profiles) }(), profileProcessor: ProfileProcessor { + "Passepartout.Mock: \($0.name)" + } processed: { try $0.withProviderModules() }, tunnel: Tunnel(strategy: FakeTunnelStrategy(environment: env)), diff --git a/Passepartout/Shared/Shared+App.swift b/Passepartout/Shared/Shared+App.swift index d720506f..9a16cc1f 100644 --- a/Passepartout/Shared/Shared+App.swift +++ b/Passepartout/Shared/Shared+App.swift @@ -118,7 +118,9 @@ extension IAPManager { } extension ProfileProcessor { - static let shared = ProfileProcessor { profile in + static let shared = ProfileProcessor { + sharedProfileTitle($0) + } processed: { profile in var builder = profile.builder() // suppress on-demand rules if not eligible @@ -155,7 +157,7 @@ extension Tunnel { ) } -private var localProfileRepository: any ProfileRepository { +private var localProfileRepository: ProfileRepository { let store = CoreDataPersistentStore( logger: .default, containerName: Constants.shared.containers.local, @@ -182,8 +184,10 @@ extension Tunnel { ) } -private var localProfileRepository: any ProfileRepository { - NEProfileRepository(repository: neRepository) +private var localProfileRepository: ProfileRepository { + NEProfileRepository(repository: neRepository) { + sharedProfileTitle($0) + } } private var neRepository: NETunnelManagerRepository { @@ -208,6 +212,10 @@ extension ProviderFactory { // MARK: - +private let sharedProfileTitle: (Profile) -> String = { + "Passepartout: \($0.name)" +} + extension CoreDataPersistentStoreLogger where Self == DefaultCoreDataPersistentStoreLogger { static var `default`: CoreDataPersistentStoreLogger { DefaultCoreDataPersistentStoreLogger()