diff --git a/Passepartout/App/Extensions/ProviderProfileAvailability.swift b/Passepartout/App/Extensions/ProviderProfileAvailability.swift index 4e278364..ea723a5f 100644 --- a/Passepartout/App/Extensions/ProviderProfileAvailability.swift +++ b/Passepartout/App/Extensions/ProviderProfileAvailability.swift @@ -29,7 +29,7 @@ import PassepartoutLibrary protocol ProviderProfileAvailability { var profile: Profile { get } - var providerManager: Impl.ProviderManager { get } + var providerManager: ProviderManager { get } } extension ProviderProfileAvailability { diff --git a/Passepartout/App/Mac/Models/DefaultLightProfileManager.swift b/Passepartout/App/Mac/Models/DefaultLightProfileManager.swift index fede6a7c..87a88d73 100644 --- a/Passepartout/App/Mac/Models/DefaultLightProfileManager.swift +++ b/Passepartout/App/Mac/Models/DefaultLightProfileManager.swift @@ -51,9 +51,9 @@ class DefaultLightProfile: LightProfile { } class DefaultLightProfileManager: LightProfileManager { - private let profileManager = Impl.ProfileManager.shared + private let profileManager = ProfileManager.shared - private let providerManager = Impl.ProviderManager.shared + private let providerManager = ProviderManager.shared private var subscriptions: Set = [] diff --git a/Passepartout/App/Mac/Models/DefaultLightProviderManager.swift b/Passepartout/App/Mac/Models/DefaultLightProviderManager.swift index d857ae50..c5f1992d 100644 --- a/Passepartout/App/Mac/Models/DefaultLightProviderManager.swift +++ b/Passepartout/App/Mac/Models/DefaultLightProviderManager.swift @@ -77,7 +77,7 @@ class DefaultLightProviderServer: LightProviderServer { } class DefaultLightProviderManager: LightProviderManager { - private let providerManager = Impl.ProviderManager.shared + private let providerManager = ProviderManager.shared private var subscriptions: Set = [] diff --git a/Passepartout/App/Mac/Models/DefaultLightVPNManager.swift b/Passepartout/App/Mac/Models/DefaultLightVPNManager.swift index fb0371e9..5d8ef958 100644 --- a/Passepartout/App/Mac/Models/DefaultLightVPNManager.swift +++ b/Passepartout/App/Mac/Models/DefaultLightVPNManager.swift @@ -28,7 +28,7 @@ import PassepartoutLibrary import Combine class DefaultLightVPNManager: LightVPNManager { - private let vpnManager = Impl.VPNManager.shared + private let vpnManager = VPNManager.shared private var subscriptions: Set = [] diff --git a/Passepartout/App/Views/AccountView.swift b/Passepartout/App/Views/AccountView.swift index 5bff80fb..60b19b17 100644 --- a/Passepartout/App/Views/AccountView.swift +++ b/Passepartout/App/Views/AccountView.swift @@ -27,7 +27,7 @@ import SwiftUI import PassepartoutLibrary struct AccountView: View { - @ObservedObject private var providerManager: Impl.ProviderManager + @ObservedObject private var providerManager: ProviderManager private let providerName: ProviderName? diff --git a/Passepartout/App/Views/AddHostView+Name.swift b/Passepartout/App/Views/AddHostView+Name.swift index c5deec1f..7e713b79 100644 --- a/Passepartout/App/Views/AddHostView+Name.swift +++ b/Passepartout/App/Views/AddHostView+Name.swift @@ -30,7 +30,7 @@ import TunnelKitWireGuard extension AddHostView { struct NameView: View { - @ObservedObject private var profileManager: Impl.ProfileManager + @ObservedObject private var profileManager: ProfileManager private let url: URL diff --git a/Passepartout/App/Views/AddProfileView.swift b/Passepartout/App/Views/AddProfileView.swift index 1afd3db2..dfda6a1e 100644 --- a/Passepartout/App/Views/AddProfileView.swift +++ b/Passepartout/App/Views/AddProfileView.swift @@ -71,7 +71,7 @@ enum AddProfileView { } struct AccountWrapperView: View { - @ObservedObject private var profileManager: Impl.ProfileManager + @ObservedObject private var profileManager: ProfileManager @Binding private var profile: Profile diff --git a/Passepartout/App/Views/AddProviderView+Name.swift b/Passepartout/App/Views/AddProviderView+Name.swift index af4c1359..7d3f72df 100644 --- a/Passepartout/App/Views/AddProviderView+Name.swift +++ b/Passepartout/App/Views/AddProviderView+Name.swift @@ -28,7 +28,7 @@ import PassepartoutLibrary extension AddProviderView { struct NameView: View { - @ObservedObject private var profileManager: Impl.ProfileManager + @ObservedObject private var profileManager: ProfileManager @Binding private var profile: Profile diff --git a/Passepartout/App/Views/AddProviderView.swift b/Passepartout/App/Views/AddProviderView.swift index 0ea18efa..1087be14 100644 --- a/Passepartout/App/Views/AddProviderView.swift +++ b/Passepartout/App/Views/AddProviderView.swift @@ -27,7 +27,7 @@ import SwiftUI import PassepartoutLibrary struct AddProviderView: View { - @ObservedObject private var providerManager: Impl.ProviderManager + @ObservedObject private var providerManager: ProviderManager @ObservedObject private var productManager: ProductManager diff --git a/Passepartout/App/Views/DiagnosticsView+OpenVPN.swift b/Passepartout/App/Views/DiagnosticsView+OpenVPN.swift index cd8cb484..57471edc 100644 --- a/Passepartout/App/Views/DiagnosticsView+OpenVPN.swift +++ b/Passepartout/App/Views/DiagnosticsView+OpenVPN.swift @@ -37,9 +37,9 @@ extension DiagnosticsView { } } - @ObservedObject private var providerManager: Impl.ProviderManager + @ObservedObject private var providerManager: ProviderManager - @ObservedObject private var vpnManager: Impl.VPNManager + @ObservedObject private var vpnManager: VPNManager @ObservedObject private var currentVPNState: ObservableVPNState diff --git a/Passepartout/App/Views/DiagnosticsView+WireGuard.swift b/Passepartout/App/Views/DiagnosticsView+WireGuard.swift index 6c8d0814..63734e12 100644 --- a/Passepartout/App/Views/DiagnosticsView+WireGuard.swift +++ b/Passepartout/App/Views/DiagnosticsView+WireGuard.swift @@ -29,7 +29,7 @@ import TunnelKitWireGuard extension DiagnosticsView { struct WireGuardView: View { - @ObservedObject private var vpnManager: Impl.VPNManager + @ObservedObject private var vpnManager: VPNManager private let providerName: ProviderName? diff --git a/Passepartout/App/Views/EndpointView+OpenVPN.swift b/Passepartout/App/Views/EndpointView+OpenVPN.swift index 0f98a21a..16338c41 100644 --- a/Passepartout/App/Views/EndpointView+OpenVPN.swift +++ b/Passepartout/App/Views/EndpointView+OpenVPN.swift @@ -31,7 +31,7 @@ extension EndpointView { struct OpenVPNView: View { @Environment(\.presentationMode) private var presentationMode - @ObservedObject private var providerManager: Impl.ProviderManager + @ObservedObject private var providerManager: ProviderManager @ObservedObject private var currentProfile: ObservableProfile @@ -53,7 +53,7 @@ extension EndpointView { // XXX: do not escape mutating 'self', use constant providerManager init(currentProfile: ObservableProfile) { - let providerManager: Impl.ProviderManager = .shared + let providerManager: ProviderManager = .shared self.providerManager = providerManager self.currentProfile = currentProfile diff --git a/Passepartout/App/Views/EndpointView+WireGuard.swift b/Passepartout/App/Views/EndpointView+WireGuard.swift index 38b50547..10aa7183 100644 --- a/Passepartout/App/Views/EndpointView+WireGuard.swift +++ b/Passepartout/App/Views/EndpointView+WireGuard.swift @@ -29,7 +29,7 @@ import TunnelKitWireGuard extension EndpointView { struct WireGuardView: View { - @ObservedObject private var providerManager: Impl.ProviderManager + @ObservedObject private var providerManager: ProviderManager @ObservedObject private var currentProfile: ObservableProfile @@ -41,7 +41,7 @@ extension EndpointView { // XXX: do not escape mutating 'self', use constant providerManager init(currentProfile: ObservableProfile, isReadonly: Bool) { - let providerManager: Impl.ProviderManager = .shared + let providerManager: ProviderManager = .shared self.providerManager = providerManager self.currentProfile = currentProfile diff --git a/Passepartout/App/Views/OrganizerView+Profiles.swift b/Passepartout/App/Views/OrganizerView+Profiles.swift index 50a7cda5..610753e5 100644 --- a/Passepartout/App/Views/OrganizerView+Profiles.swift +++ b/Passepartout/App/Views/OrganizerView+Profiles.swift @@ -28,7 +28,7 @@ import PassepartoutLibrary extension OrganizerView { struct ProfilesList: View { - @ObservedObject private var profileManager: Impl.ProfileManager + @ObservedObject private var profileManager: ProfileManager init() { profileManager = .shared diff --git a/Passepartout/App/Views/OrganizerView+Scene.swift b/Passepartout/App/Views/OrganizerView+Scene.swift index 6a7c6ad9..aec43e19 100644 --- a/Passepartout/App/Views/OrganizerView+Scene.swift +++ b/Passepartout/App/Views/OrganizerView+Scene.swift @@ -30,9 +30,9 @@ extension OrganizerView { struct SceneView: View { @Environment(\.scenePhase) private var scenePhase - @ObservedObject private var profileManager: Impl.ProfileManager + @ObservedObject private var profileManager: ProfileManager - @ObservedObject private var vpnManager: Impl.VPNManager + @ObservedObject private var vpnManager: VPNManager @ObservedObject private var productManager: ProductManager diff --git a/Passepartout/App/Views/OrganizerView.swift b/Passepartout/App/Views/OrganizerView.swift index d54e201d..909d4156 100644 --- a/Passepartout/App/Views/OrganizerView.swift +++ b/Passepartout/App/Views/OrganizerView.swift @@ -81,7 +81,7 @@ struct OrganizerView: View { .themePrimaryView() // VPN configuration error publisher (no need to observe VPNManager) - .onReceive(Impl.VPNManager.shared.configurationError) { + .onReceive(VPNManager.shared.configurationError) { alertType = .error($0.profile.header.name, $0.error.localizedAppDescription) } } diff --git a/Passepartout/App/Views/ProfileView+Diagnostics.swift b/Passepartout/App/Views/ProfileView+Diagnostics.swift index 7b086423..c67bbeac 100644 --- a/Passepartout/App/Views/ProfileView+Diagnostics.swift +++ b/Passepartout/App/Views/ProfileView+Diagnostics.swift @@ -28,7 +28,7 @@ import PassepartoutLibrary extension ProfileView { struct DiagnosticsSection: View { - @ObservedObject private var profileManager: Impl.ProfileManager + @ObservedObject private var profileManager: ProfileManager @ObservedObject private var currentProfile: ObservableProfile diff --git a/Passepartout/App/Views/ProfileView+MainMenu.swift b/Passepartout/App/Views/ProfileView+MainMenu.swift index aa61efd0..b3266a38 100644 --- a/Passepartout/App/Views/ProfileView+MainMenu.swift +++ b/Passepartout/App/Views/ProfileView+MainMenu.swift @@ -38,9 +38,9 @@ extension ProfileView { } } - @ObservedObject private var profileManager: Impl.ProfileManager + @ObservedObject private var profileManager: ProfileManager - @ObservedObject private var vpnManager: Impl.VPNManager + @ObservedObject private var vpnManager: VPNManager @ObservedObject private var currentProfile: ObservableProfile @@ -200,7 +200,7 @@ extension ProfileView { } struct DuplicateButton: View { - @ObservedObject private var profileManager: Impl.ProfileManager + @ObservedObject private var profileManager: ProfileManager private let header: Profile.Header diff --git a/Passepartout/App/Views/ProfileView+Provider.swift b/Passepartout/App/Views/ProfileView+Provider.swift index b23acdc4..7f5fbd6a 100644 --- a/Passepartout/App/Views/ProfileView+Provider.swift +++ b/Passepartout/App/Views/ProfileView+Provider.swift @@ -28,7 +28,7 @@ import PassepartoutLibrary extension ProfileView { struct ProviderSection: View, ProviderProfileAvailability { - @ObservedObject var providerManager: Impl.ProviderManager + @ObservedObject var providerManager: ProviderManager @ObservedObject private var currentProfile: ObservableProfile diff --git a/Passepartout/App/Views/ProfileView+Rename.swift b/Passepartout/App/Views/ProfileView+Rename.swift index 65873078..16b653eb 100644 --- a/Passepartout/App/Views/ProfileView+Rename.swift +++ b/Passepartout/App/Views/ProfileView+Rename.swift @@ -30,7 +30,7 @@ extension ProfileView { struct RenameView: View { @Environment(\.presentationMode) private var presentationMode - @ObservedObject private var profileManager: Impl.ProfileManager + @ObservedObject private var profileManager: ProfileManager @ObservedObject private var currentProfile: ObservableProfile diff --git a/Passepartout/App/Views/ProfileView+VPN.swift b/Passepartout/App/Views/ProfileView+VPN.swift index 1ca4d09c..48ae3fbb 100644 --- a/Passepartout/App/Views/ProfileView+VPN.swift +++ b/Passepartout/App/Views/ProfileView+VPN.swift @@ -28,7 +28,7 @@ import PassepartoutLibrary extension ProfileView { struct VPNSection: View { - @ObservedObject private var profileManager: Impl.ProfileManager + @ObservedObject private var profileManager: ProfileManager private let profileId: UUID diff --git a/Passepartout/App/Views/ProfileView.swift b/Passepartout/App/Views/ProfileView.swift index 05736ae7..13e1b628 100644 --- a/Passepartout/App/Views/ProfileView.swift +++ b/Passepartout/App/Views/ProfileView.swift @@ -56,7 +56,7 @@ struct ProfileView: View { @State private var modalType: ModalType? init() { - currentProfile = Impl.ProfileManager.shared.currentProfile + currentProfile = ProfileManager.shared.currentProfile } var body: some View { diff --git a/Passepartout/App/Views/ProviderLocationView.swift b/Passepartout/App/Views/ProviderLocationView.swift index 59956f5c..efa12635 100644 --- a/Passepartout/App/Views/ProviderLocationView.swift +++ b/Passepartout/App/Views/ProviderLocationView.swift @@ -27,7 +27,7 @@ import SwiftUI import PassepartoutLibrary struct ProviderLocationView: View, ProviderProfileAvailability { - @ObservedObject var providerManager: Impl.ProviderManager + @ObservedObject var providerManager: ProviderManager @ObservedObject private var currentProfile: ObservableProfile @@ -64,7 +64,7 @@ struct ProviderLocationView: View, ProviderProfileAvailability { // XXX: do not escape mutating 'self', use constant providerManager init(currentProfile: ObservableProfile, isEditable: Bool, isPresented: Binding) { - let providerManager: Impl.ProviderManager = .shared + let providerManager: ProviderManager = .shared self.providerManager = providerManager self.currentProfile = currentProfile @@ -268,7 +268,7 @@ extension ProviderLocationView { } struct ServerListView: View { - @ObservedObject private var providerManager: Impl.ProviderManager + @ObservedObject private var providerManager: ProviderManager private let location: ProviderLocation diff --git a/Passepartout/App/Views/ProviderPresetView.swift b/Passepartout/App/Views/ProviderPresetView.swift index 4bc7b8bc..8bb3edd7 100644 --- a/Passepartout/App/Views/ProviderPresetView.swift +++ b/Passepartout/App/Views/ProviderPresetView.swift @@ -29,7 +29,7 @@ import PassepartoutLibrary struct ProviderPresetView: View { @Environment(\.presentationMode) private var presentationMode - @ObservedObject private var providerManager: Impl.ProviderManager + @ObservedObject private var providerManager: ProviderManager @ObservedObject private var currentProfile: ObservableProfile @@ -39,7 +39,7 @@ struct ProviderPresetView: View { // XXX: do not escape mutating 'self', use constant providerManager init(currentProfile: ObservableProfile) { - let providerManager: Impl.ProviderManager = .shared + let providerManager: ProviderManager = .shared self.providerManager = providerManager self.currentProfile = currentProfile diff --git a/Passepartout/App/Views/ShortcutsView+Add.swift b/Passepartout/App/Views/ShortcutsView+Add.swift index e8fbf0a7..36196bbb 100644 --- a/Passepartout/App/Views/ShortcutsView+Add.swift +++ b/Passepartout/App/Views/ShortcutsView+Add.swift @@ -29,7 +29,7 @@ import PassepartoutLibrary extension ShortcutsView { struct AddView: View { - @ObservedObject private var providerManager: Impl.ProviderManager + @ObservedObject private var providerManager: ProviderManager @StateObject private var pendingProfile = ObservableProfile() diff --git a/Passepartout/App/Views/VPNToggle.swift b/Passepartout/App/Views/VPNToggle.swift index 47bbc012..286ed5e5 100644 --- a/Passepartout/App/Views/VPNToggle.swift +++ b/Passepartout/App/Views/VPNToggle.swift @@ -27,9 +27,9 @@ import SwiftUI import PassepartoutLibrary struct VPNToggle: View { - @ObservedObject private var profileManager: Impl.ProfileManager + @ObservedObject private var profileManager: ProfileManager - @ObservedObject private var vpnManager: Impl.VPNManager + @ObservedObject private var vpnManager: VPNManager @ObservedObject private var currentVPNState: ObservableVPNState @@ -113,7 +113,7 @@ struct VPNToggle: View { IntentDispatcher.donateDisableVPN() IntentDispatcher.donateConnection( with: profile, - providerManager: Impl.ProviderManager.shared + providerManager: ProviderManager.shared ) } } diff --git a/Passepartout/AppShared/Context/CoreContext+Shared.swift b/Passepartout/AppShared/Context/CoreContext+Shared.swift index 5f41ed78..46e244e9 100644 --- a/Passepartout/AppShared/Context/CoreContext+Shared.swift +++ b/Passepartout/AppShared/Context/CoreContext+Shared.swift @@ -36,15 +36,15 @@ extension UpgradeManager { static let shared = CoreContext.shared.upgradeManager } -extension Impl.ProfileManager { +extension ProfileManager { static let shared = CoreContext.shared.profileManager } -extension Impl.ProviderManager { +extension ProviderManager { static let shared = CoreContext.shared.providerManager } -extension Impl.VPNManager { +extension VPNManager { static let shared = CoreContext.shared.vpnManager } diff --git a/Passepartout/AppShared/Context/CoreContext.swift b/Passepartout/AppShared/Context/CoreContext.swift index 481f7e49..d821fde7 100644 --- a/Passepartout/AppShared/Context/CoreContext.swift +++ b/Passepartout/AppShared/Context/CoreContext.swift @@ -27,14 +27,6 @@ import Foundation import Combine import PassepartoutLibrary -enum Impl { - typealias ProfileManager = DefaultProfileManager - - typealias ProviderManager = DefaultProviderManager - - typealias VPNManager = DefaultVPNManager -} - class CoreContext { let store: KeyValueStore @@ -52,11 +44,11 @@ class CoreContext { let upgradeManager: UpgradeManager - let providerManager: Impl.ProviderManager + let providerManager: ProviderManager - let profileManager: Impl.ProfileManager + let profileManager: ProfileManager - let vpnManager: Impl.VPNManager + let vpnManager: VPNManager private var cancellables: Set = [] @@ -74,7 +66,7 @@ class CoreContext { upgradeManager = UpgradeManager(store: store) - providerManager = DefaultProviderManager( + providerManager = ProviderManager( appBuild: Constants.Global.appBuildNumber, bundleServices: DefaultWebServices.bundledServices( withVersion: Constants.Services.version @@ -87,7 +79,7 @@ class CoreContext { persistence: providersPersistence ) - profileManager = DefaultProfileManager( + profileManager = ProfileManager( store: store, providerManager: providerManager, appGroup: Constants.App.appGroupId, @@ -105,7 +97,7 @@ class CoreContext { tunnelBundleIdentifier: Constants.App.tunnelBundleId ) #endif - vpnManager = DefaultVPNManager( + vpnManager = VPNManager( appGroup: Constants.App.appGroupId, store: store, profileManager: profileManager, diff --git a/PassepartoutLibrary/Sources/PassepartoutCore/Extensions/Provider+Extensions.swift b/PassepartoutLibrary/Sources/PassepartoutCore/Extensions/Provider+Extensions.swift index 20ad1e4d..a8628dd9 100644 --- a/PassepartoutLibrary/Sources/PassepartoutCore/Extensions/Provider+Extensions.swift +++ b/PassepartoutLibrary/Sources/PassepartoutCore/Extensions/Provider+Extensions.swift @@ -45,13 +45,6 @@ extension Profile { provider?.name } - public func providerServer(_ providerManager: ProviderManager) -> ProviderServer? { - guard let serverId = provider?.vpnSettings[currentVPNProtocol]?.serverId else { - return nil - } - return providerManager.server(withId: serverId) - } - public func providerServerId() -> String? { return provider?.vpnSettings[currentVPNProtocol]?.serverId } diff --git a/PassepartoutLibrary/Sources/PassepartoutCore/Managers/CurrentProfileProviding.swift b/PassepartoutLibrary/Sources/PassepartoutCore/Managers/CurrentProfileProviding.swift deleted file mode 100644 index 5d1bd070..00000000 --- a/PassepartoutLibrary/Sources/PassepartoutCore/Managers/CurrentProfileProviding.swift +++ /dev/null @@ -1,32 +0,0 @@ -// -// CurrentProfileProviding.swift -// Passepartout -// -// Created by Davide De Rosa on 6/22/22. -// Copyright (c) 2022 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 . -// - -import Foundation - -public protocol CurrentProfileProviding { - associatedtype WrappedType: WrappedProfile - - var currentProfile: WrappedType { get } -} diff --git a/PassepartoutLibrary/Sources/PassepartoutCore/Managers/CurrentVPNStateProviding.swift b/PassepartoutLibrary/Sources/PassepartoutCore/Managers/CurrentVPNStateProviding.swift deleted file mode 100644 index 2bc2ceaf..00000000 --- a/PassepartoutLibrary/Sources/PassepartoutCore/Managers/CurrentVPNStateProviding.swift +++ /dev/null @@ -1,32 +0,0 @@ -// -// CurrentVPNStateProviding.swift -// Passepartout -// -// Created by Davide De Rosa on 6/22/22. -// Copyright (c) 2022 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 . -// - -import Foundation - -public protocol CurrentVPNStateProviding { - associatedtype WrappedType: WrappedVPNState - - var currentState: WrappedType { get } -} diff --git a/PassepartoutLibrary/Sources/PassepartoutCore/Managers/ProfileManager.swift b/PassepartoutLibrary/Sources/PassepartoutCore/Managers/ProfileManager.swift deleted file mode 100644 index 11674aac..00000000 --- a/PassepartoutLibrary/Sources/PassepartoutCore/Managers/ProfileManager.swift +++ /dev/null @@ -1,72 +0,0 @@ -// -// ProfileManager.swift -// Passepartout -// -// Created by Davide De Rosa on 6/20/22. -// Copyright (c) 2022 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 . -// - -import Foundation -import Combine - -public protocol ProfileManager { - typealias ProfileEx = (profile: Profile, isReady: Bool) - - var activeProfileId: UUID? { get } - - var currentProfileId: UUID? { get set } - - var didUpdateProfiles: PassthroughSubject { get } - - var didUpdateActiveProfile: PassthroughSubject { get } - - var didCreateProfile: PassthroughSubject { get } - - var headers: [Profile.Header] { get } - - var profiles: [Profile] { get } - - func isExistingProfile(withId id: UUID) -> Bool - - func isExistingProfile(withName name: String) -> Bool - - func liveProfileEx(withId id: UUID) throws -> ProfileEx - - func makeProfileReady(_ profile: Profile) async throws - - func saveProfile(_ profile: Profile, isActive: Bool?, updateIfCurrent: Bool) - - func savePassword(forProfile profile: Profile) - - func passwordReference(forProfile profile: Profile) -> Data? - - func removeProfiles(withIds ids: [UUID]) - - @available(*, deprecated, message: "only use for testing") - func removeAllProfiles() - - func duplicateProfile(withId id: UUID, setAsCurrent: Bool) - - func profile(withHeader header: Profile.Header, fromContents contents: String, originalURL: URL?, passphrase: String?) throws -> Profile - - func persist() - - func observeUpdates() -} diff --git a/PassepartoutLibrary/Sources/PassepartoutCore/Managers/ProfileManagerWithCurrentProfile.swift b/PassepartoutLibrary/Sources/PassepartoutCore/Managers/ProfileManagerWithCurrentProfile.swift deleted file mode 100644 index 76dc8f95..00000000 --- a/PassepartoutLibrary/Sources/PassepartoutCore/Managers/ProfileManagerWithCurrentProfile.swift +++ /dev/null @@ -1,29 +0,0 @@ -// -// ProfileManagerWithCurrentProfile.swift -// Passepartout -// -// Created by Davide De Rosa on 6/22/22. -// Copyright (c) 2022 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 . -// - -import Foundation - -public protocol ProfileManagerWithCurrentProfile: ProfileManager, CurrentProfileProviding { -} diff --git a/PassepartoutLibrary/Sources/PassepartoutCore/Managers/ProviderManager.swift b/PassepartoutLibrary/Sources/PassepartoutCore/Managers/ProviderManager.swift deleted file mode 100644 index d084c345..00000000 --- a/PassepartoutLibrary/Sources/PassepartoutCore/Managers/ProviderManager.swift +++ /dev/null @@ -1,61 +0,0 @@ -// -// ProviderManager.swift -// Passepartout -// -// Created by Davide De Rosa on 6/19/22. -// Copyright (c) 2022 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 . -// - -import Foundation -import Combine - -public protocol ProviderManager { - var didUpdateProviders: PassthroughSubject { get } - - func allProviders() -> [ProviderMetadata] - - func provider(withName name: ProviderName) -> ProviderMetadata? - - func isAvailable(_ name: ProviderName, vpnProtocol: VPNProtocolType) -> Bool - - func defaultUsername(_ name: ProviderName, vpnProtocol: VPNProtocolType) -> String? - - func lastUpdate(_ name: ProviderName, vpnProtocol: VPNProtocolType) -> Date? - - func categories(_ name: ProviderName, vpnProtocol: VPNProtocolType) -> [ProviderCategory] - - func servers(forLocation location: ProviderLocation) -> [ProviderServer] - - func server(_ name: ProviderName, vpnProtocol: VPNProtocolType, apiId: String) -> ProviderServer? - - func anyDefaultServer(_ name: ProviderName, vpnProtocol: VPNProtocolType) -> ProviderServer? - - func server(withId id: String) -> ProviderServer? - - func fetchProvidersIndexPublisher(priority: ProviderManagerFetchPriority) -> AnyPublisher - - func fetchProviderPublisher( - withName providerName: ProviderName, - vpnProtocol: VPNProtocolType, - priority: ProviderManagerFetchPriority - ) -> AnyPublisher - - func reset() -} diff --git a/PassepartoutLibrary/Sources/PassepartoutCore/Managers/VPNManager.swift b/PassepartoutLibrary/Sources/PassepartoutCore/Managers/VPNManager.swift deleted file mode 100644 index 3112ba6b..00000000 --- a/PassepartoutLibrary/Sources/PassepartoutCore/Managers/VPNManager.swift +++ /dev/null @@ -1,61 +0,0 @@ -// -// VPNManager.swift -// Passepartout -// -// Created by Davide De Rosa on 6/22/22. -// Copyright (c) 2022 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 . -// - -import Foundation -import Combine - -public protocol VPNManager { - var lastError: Error? { get } - - var configurationError: PassthroughSubject { get } - - var tunnelLogPath: String? { get set } - - var tunnelLogFormat: String? { get set } - - var masksPrivateData: Bool { get set } - - func connectWithActiveProfile(toServer newServerId: String?) async throws - - @discardableResult - func connect(with profileId: UUID) async throws -> Profile - - @discardableResult - func connect(with profileId: UUID, toServer newServerId: String) async throws -> Profile - - func reconnect() async - - func modifyActiveProfile(_ block: (inout Profile) -> Void) async throws - - func disable() async - - func uninstall() async - - func serverConfiguration(forProtocol vpnProtocol: VPNProtocolType) -> Any? - - func debugLogURL(forProtocol vpnProtocol: VPNProtocolType) -> URL? - - func observeUpdates() -} diff --git a/PassepartoutLibrary/Sources/PassepartoutCore/Managers/VPNManagerWithCurrentState.swift b/PassepartoutLibrary/Sources/PassepartoutCore/Managers/VPNManagerWithCurrentState.swift deleted file mode 100644 index 009f64ac..00000000 --- a/PassepartoutLibrary/Sources/PassepartoutCore/Managers/VPNManagerWithCurrentState.swift +++ /dev/null @@ -1,29 +0,0 @@ -// -// VPNManagerWithCurrentState.swift -// Passepartout -// -// Created by Davide De Rosa on 6/22/22. -// Copyright (c) 2022 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 . -// - -import Foundation - -public protocol VPNManagerWithCurrentState: VPNManager, CurrentVPNStateProviding { -} diff --git a/PassepartoutLibrary/Sources/PassepartoutLibrary/Managers/UpgradeManager.swift b/PassepartoutLibrary/Sources/PassepartoutLibrary/Managers/UpgradeManager.swift index d54ed835..6cc33366 100644 --- a/PassepartoutLibrary/Sources/PassepartoutLibrary/Managers/UpgradeManager.swift +++ b/PassepartoutLibrary/Sources/PassepartoutLibrary/Managers/UpgradeManager.swift @@ -29,7 +29,7 @@ import SwiftyBeaver import PassepartoutCore import PassepartoutUtils -public class UpgradeManager: ObservableObject { +public final class UpgradeManager: ObservableObject { // MARK: Initialization diff --git a/PassepartoutLibrary/Sources/PassepartoutProfiles/Extensions/PassepartoutProfiles+Subtype.swift b/PassepartoutLibrary/Sources/PassepartoutProfiles/Extensions/PassepartoutProfiles+Subtype.swift index 26a87a4e..81da7d3f 100644 --- a/PassepartoutLibrary/Sources/PassepartoutProfiles/Extensions/PassepartoutProfiles+Subtype.swift +++ b/PassepartoutLibrary/Sources/PassepartoutProfiles/Extensions/PassepartoutProfiles+Subtype.swift @@ -39,6 +39,13 @@ extension Profile { } extension Profile { + public func providerServer(_ providerManager: ProviderManager) -> ProviderServer? { + guard let serverId = providerServerId() else { + return nil + } + return providerManager.server(withId: serverId) + } + public func providerOpenVPNSettings(withManager providerManager: ProviderManager) throws -> Profile.OpenVPNSettings { guard isProvider else { fatalError("Not a provider") diff --git a/PassepartoutLibrary/Sources/PassepartoutProfiles/Extensions/ProfileManager+Extensions.swift b/PassepartoutLibrary/Sources/PassepartoutProfiles/Extensions/ProfileManager+Extensions.swift index faee21d0..abcba144 100644 --- a/PassepartoutLibrary/Sources/PassepartoutProfiles/Extensions/ProfileManager+Extensions.swift +++ b/PassepartoutLibrary/Sources/PassepartoutProfiles/Extensions/ProfileManager+Extensions.swift @@ -60,7 +60,7 @@ extension ProfileManager { } } -extension ProfileManagerWithCurrentProfile { +extension ProfileManager { public func isCurrentProfileActive() -> Bool { currentProfile.value.id == activeProfileId } diff --git a/PassepartoutLibrary/Sources/PassepartoutProfiles/Extensions/ProviderManager+Extensions.swift b/PassepartoutLibrary/Sources/PassepartoutProfiles/Extensions/ProviderManager+Extensions.swift index bb2e3114..21e9b243 100644 --- a/PassepartoutLibrary/Sources/PassepartoutProfiles/Extensions/ProviderManager+Extensions.swift +++ b/PassepartoutLibrary/Sources/PassepartoutProfiles/Extensions/ProviderManager+Extensions.swift @@ -26,6 +26,7 @@ import Foundation import Combine import PassepartoutCore +import PassepartoutProviders extension ProviderManager { public func fetchRemoteProviderPublisher(forProfile profile: Profile) -> AnyPublisher { diff --git a/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/PersistenceManager.swift b/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/PersistenceManager.swift index 37908c4a..980df76e 100644 --- a/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/PersistenceManager.swift +++ b/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/PersistenceManager.swift @@ -28,7 +28,7 @@ import CoreData import PassepartoutCore import PassepartoutUtils -public class PersistenceManager { +public final class PersistenceManager { private let store: KeyValueStore public init(store: KeyValueStore) { diff --git a/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/DefaultProfileManager+Keychain.swift b/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/ProfileManager+Keychain.swift similarity index 98% rename from PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/DefaultProfileManager+Keychain.swift rename to PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/ProfileManager+Keychain.swift index ffe7bbd4..b72e064e 100644 --- a/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/DefaultProfileManager+Keychain.swift +++ b/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/ProfileManager+Keychain.swift @@ -1,5 +1,5 @@ // -// DefaultProfileManager+Keychain.swift +// ProfileManager+Keychain.swift // Passepartout // // Created by Davide De Rosa on 4/8/22. @@ -28,7 +28,7 @@ import TunnelKitManager import PassepartoutCore import PassepartoutUtils -extension DefaultProfileManager { +extension ProfileManager { public func savePassword(forProfile profile: Profile) { guard !profile.isPlaceholder else { assertionFailure("Placeholder") diff --git a/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/DefaultProfileManager+Processing.swift b/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/ProfileManager+Processing.swift similarity index 95% rename from PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/DefaultProfileManager+Processing.swift rename to PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/ProfileManager+Processing.swift index 86edf2a7..ec65db91 100644 --- a/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/DefaultProfileManager+Processing.swift +++ b/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/ProfileManager+Processing.swift @@ -1,5 +1,5 @@ // -// DefaultProfileManager+Processing.swift +// ProfileManager+Processing.swift // Passepartout // // Created by Davide De Rosa on 4/7/22. @@ -28,7 +28,7 @@ import TunnelKitOpenVPN import TunnelKitWireGuard import PassepartoutCore -extension DefaultProfileManager { +extension ProfileManager { public func profile(withHeader header: Profile.Header, fromContents contents: String, originalURL: URL?, passphrase: String?) throws -> Profile { do { let ovpn = try OpenVPN.ConfigurationParser.parsed(fromContents: contents, passphrase: passphrase, originalURL: originalURL) diff --git a/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/DefaultProfileManager.swift b/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/ProfileManager.swift similarity index 97% rename from PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/DefaultProfileManager.swift rename to PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/ProfileManager.swift index 85aa53b4..650c7ec1 100644 --- a/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/DefaultProfileManager.swift +++ b/PassepartoutLibrary/Sources/PassepartoutProfiles/Managers/ProfileManager.swift @@ -1,5 +1,5 @@ // -// DefaultProfileManager.swift +// ProfileManager.swift // Passepartout // // Created by Davide De Rosa on 2/25/22. @@ -27,11 +27,12 @@ import Foundation import Combine import TunnelKitManager import PassepartoutCore -import PassepartoutCore import PassepartoutUtils +import PassepartoutProviders + +public final class ProfileManager: ObservableObject { + public typealias ProfileEx = (profile: Profile, isReady: Bool) -public class DefaultProfileManager: ProfileManagerWithCurrentProfile, ObservableObject { - // MARK: Initialization private let store: KeyValueStore @@ -46,7 +47,7 @@ public class DefaultProfileManager: ProfileManagerWithCurrentProfile, Observable private let strategy: ProfileManagerStrategy - // MARK: Observables + // MARK: State @Published private var internalActiveProfileId: UUID? { willSet { @@ -110,7 +111,7 @@ public class DefaultProfileManager: ProfileManagerWithCurrentProfile, Observable // MARK: Index -extension DefaultProfileManager { +extension ProfileManager { private var allHeaders: [UUID: Profile.Header] { strategy.allHeaders } @@ -136,7 +137,7 @@ extension DefaultProfileManager { // MARK: Profiles -extension DefaultProfileManager { +extension ProfileManager { public func liveProfileEx(withId id: UUID) throws -> ProfileEx { guard let profile = liveProfile(withId: id) else { pp_log.error("Profile not found: \(id)") @@ -249,7 +250,7 @@ extension DefaultProfileManager { // MARK: Observation -extension DefaultProfileManager { +extension ProfileManager { private func setCurrentProfile(_ profile: Profile) { guard !currentProfile.isLoading else { pp_log.warning("Already loading another profile") @@ -300,7 +301,7 @@ extension DefaultProfileManager { } } -extension DefaultProfileManager { +extension ProfileManager { public func observeUpdates() { $internalActiveProfileId .sink { @@ -393,7 +394,7 @@ extension DefaultProfileManager { // MARK: Readiness -extension DefaultProfileManager { +extension ProfileManager { private func isProfileReady(_ profile: Profile) -> Bool { isProfileProviderAvailable(profile) } @@ -433,7 +434,7 @@ extension DefaultProfileManager { // MARK: KeyValueStore -extension DefaultProfileManager { +extension ProfileManager { public private(set) var activeProfileId: UUID? { get { guard let idString: String = store.value(forLocation: StoreKey.activeProfileId) else { @@ -459,7 +460,7 @@ extension DefaultProfileManager { } } -private extension DefaultProfileManager { +private extension ProfileManager { private enum StoreKey: String, KeyStoreDomainLocation { case activeProfileId diff --git a/PassepartoutLibrary/Sources/PassepartoutProviders/Managers/DefaultProviderManager.swift b/PassepartoutLibrary/Sources/PassepartoutProviders/Managers/ProviderManager.swift similarity index 99% rename from PassepartoutLibrary/Sources/PassepartoutProviders/Managers/DefaultProviderManager.swift rename to PassepartoutLibrary/Sources/PassepartoutProviders/Managers/ProviderManager.swift index 9d054f6d..3723789f 100644 --- a/PassepartoutLibrary/Sources/PassepartoutProviders/Managers/DefaultProviderManager.swift +++ b/PassepartoutLibrary/Sources/PassepartoutProviders/Managers/ProviderManager.swift @@ -29,7 +29,7 @@ import PassepartoutCore import PassepartoutServices import PassepartoutUtils -public class DefaultProviderManager: ProviderManager, ObservableObject, RateLimited { +public final class ProviderManager: ObservableObject, RateLimited { private let appBuild: Int private let bundleServices: WebServices diff --git a/PassepartoutLibrary/Sources/PassepartoutCore/Managers/ProviderManagerFetchPriority.swift b/PassepartoutLibrary/Sources/PassepartoutProviders/Managers/ProviderManagerFetchPriority.swift similarity index 100% rename from PassepartoutLibrary/Sources/PassepartoutCore/Managers/ProviderManagerFetchPriority.swift rename to PassepartoutLibrary/Sources/PassepartoutProviders/Managers/ProviderManagerFetchPriority.swift diff --git a/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/DefaultVPNManager+Actions.swift b/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/VPNManager+Actions.swift similarity index 98% rename from PassepartoutLibrary/Sources/PassepartoutVPN/Managers/DefaultVPNManager+Actions.swift rename to PassepartoutLibrary/Sources/PassepartoutVPN/Managers/VPNManager+Actions.swift index 87374e35..1c908019 100644 --- a/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/DefaultVPNManager+Actions.swift +++ b/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/VPNManager+Actions.swift @@ -1,5 +1,5 @@ // -// DefaultVPNManager+Actions.swift +// VPNManager+Actions.swift // Passepartout // // Created by Davide De Rosa on 3/30/22. @@ -31,7 +31,7 @@ import PassepartoutUtils // current profile, this must be updated too. this is done in // ProfileManager.activateProfile() -extension DefaultVPNManager { +extension VPNManager { public func connectWithActiveProfile(toServer newServerId: String?) async throws { guard currentState.vpnStatus != .connected else { pp_log.warning("VPN is already connected") diff --git a/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/DefaultVPNManager+Configuration.swift b/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/VPNManager+Configuration.swift similarity index 98% rename from PassepartoutLibrary/Sources/PassepartoutVPN/Managers/DefaultVPNManager+Configuration.swift rename to PassepartoutLibrary/Sources/PassepartoutVPN/Managers/VPNManager+Configuration.swift index 1cd9f889..d50ad1f8 100644 --- a/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/DefaultVPNManager+Configuration.swift +++ b/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/VPNManager+Configuration.swift @@ -1,5 +1,5 @@ // -// DefaultVPNManager+Configuration.swift +// VPNManager+Configuration.swift // Passepartout // // Created by Davide De Rosa on 3/12/22. @@ -27,7 +27,7 @@ import Foundation import PassepartoutCore import PassepartoutUtils -extension DefaultVPNManager { +extension VPNManager { private var vpnPreferences: VPNPreferences { DefaultVPNPreferences( tunnelLogPath: tunnelLogPath, diff --git a/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/DefaultVPNManager.swift b/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/VPNManager.swift similarity index 95% rename from PassepartoutLibrary/Sources/PassepartoutVPN/Managers/DefaultVPNManager.swift rename to PassepartoutLibrary/Sources/PassepartoutVPN/Managers/VPNManager.swift index 6a99d7fd..8bf51e31 100644 --- a/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/DefaultVPNManager.swift +++ b/PassepartoutLibrary/Sources/PassepartoutVPN/Managers/VPNManager.swift @@ -1,5 +1,5 @@ // -// DefaultVPNManager.swift +// VPNManager.swift // Passepartout // // Created by Davide De Rosa on 2/9/22. @@ -29,9 +29,10 @@ import TunnelKitCore import TunnelKitManager import PassepartoutCore import PassepartoutProfiles +import PassepartoutProviders import PassepartoutUtils -public class DefaultVPNManager: VPNManagerWithCurrentState, ObservableObject where ProfileManagerType.WrappedType == ObservableProfile { +public final class VPNManager: ObservableObject { // MARK: Initialization @@ -39,7 +40,7 @@ public class DefaultVPNManager