From f3d13d0cdfd2fefc51cfe13ab306b6c1221f073e Mon Sep 17 00:00:00 2001 From: Davide Date: Mon, 4 Nov 2024 23:34:22 +0100 Subject: [PATCH] Refactor AppContext creation and profile processing (#810) Streamline initialization of AppContext objects without singletons, especially because some are interconnected. Rethink ProfileProcessor to be the only gateway of profile processing for: - Include - Save - Connect Provide closures with access to the IAPManager for eligibility checks. Finally, take a ProfileProcessor parameter in: - ProfileManager (for isIncluded and willSave) - ExtendedTunnel (for willConnect) so that it's used implicitly without having to put it into the SwiftUI environment. Other than that: - Move AppError to CommonLibrary - Skip decoding of attributes from Core Data because they are already part of the profile --- Passepartout/App/Platforms/App+macOS.swift | 1 - .../CDProfileRepositoryV3.swift | 8 +- .../AppUIMain/Views/About/CreditsView.swift | 1 + .../Views/App/ProviderEntitySelector.swift | 3 - .../Views/App/TunnelRestartButton.swift | 5 +- .../Views/AppMenu/macOS/AppMenu.swift | 8 +- .../Views/Profile/ProfileSaveButton.swift | 1 + .../Business/ExtendedTunnel.swift | 32 +- .../Business/ProfileManager.swift | 15 +- .../Business/ProfileProcessor.swift | 31 +- .../Domain/AppError.swift | 2 +- .../Domain/ProfileAttributes.swift | 2 + .../CommonUtils/Business/BuildProducts.swift | 2 +- .../UILibrary/Business/AppContext.swift | 24 +- .../Extensions/View+Environment.swift | 1 - .../UILibrary/L10n/AppError+L10n.swift | 51 +-- .../UILibrary/L10n/ErrorHandler+Default.swift | 1 + .../UILibrary/Mock/AppContext+Mock.swift | 114 ++++++ .../Mock/{Mock.swift => Profile+Mock.swift} | 80 +---- .../Views/UI/ConnectionStatusText.swift | 12 +- .../Views/UI/TunnelToggleButton.swift | 7 +- Passepartout/Shared/Shared+App.swift | 326 +++++++++--------- 22 files changed, 403 insertions(+), 324 deletions(-) rename Passepartout/Library/Sources/{UILibrary => CommonLibrary}/Domain/AppError.swift (97%) create mode 100644 Passepartout/Library/Sources/UILibrary/Mock/AppContext+Mock.swift rename Passepartout/Library/Sources/UILibrary/Mock/{Mock.swift => Profile+Mock.swift} (53%) diff --git a/Passepartout/App/Platforms/App+macOS.swift b/Passepartout/App/Platforms/App+macOS.swift index aac81c80..33989c36 100644 --- a/Passepartout/App/Platforms/App+macOS.swift +++ b/Passepartout/App/Platforms/App+macOS.swift @@ -85,7 +85,6 @@ extension PassepartoutApp { MenuBarExtra { AppMenu( profileManager: context.profileManager, - profileProcessor: context.profileProcessor, tunnel: context.tunnel ) .withEnvironment(from: context, theme: theme) diff --git a/Passepartout/Library/Sources/AppDataProfiles/CDProfileRepositoryV3.swift b/Passepartout/Library/Sources/AppDataProfiles/CDProfileRepositoryV3.swift index c8b4a564..3bbffa22 100644 --- a/Passepartout/Library/Sources/AppDataProfiles/CDProfileRepositoryV3.swift +++ b/Passepartout/Library/Sources/AppDataProfiles/CDProfileRepositoryV3.swift @@ -68,13 +68,7 @@ private extension AppData { return nil } let profile = try registry.decodedProfile(from: encoded, with: coder) - var builder = profile.builder() - builder.attributes = ProfileAttributes( - isAvailableForTV: cdEntity.isAvailableForTV?.boolValue ?? false, - lastUpdate: cdEntity.lastUpdate, - fingerprint: cdEntity.fingerprint - ) - return try builder.tryBuild() + return profile } static func toMapper( diff --git a/Passepartout/Library/Sources/AppUIMain/Views/About/CreditsView.swift b/Passepartout/Library/Sources/AppUIMain/Views/About/CreditsView.swift index 941d1025..4710e857 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/About/CreditsView.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/About/CreditsView.swift @@ -23,6 +23,7 @@ // along with Passepartout. If not, see . // +import CommonLibrary import CommonUtils import SwiftUI diff --git a/Passepartout/Library/Sources/AppUIMain/Views/App/ProviderEntitySelector.swift b/Passepartout/Library/Sources/AppUIMain/Views/App/ProviderEntitySelector.swift index fd971681..54de04ff 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/App/ProviderEntitySelector.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/App/ProviderEntitySelector.swift @@ -30,9 +30,6 @@ import SwiftUI struct ProviderEntitySelector: View { - @EnvironmentObject - private var profileProcessor: ProfileProcessor - @ObservedObject var profileManager: ProfileManager diff --git a/Passepartout/Library/Sources/AppUIMain/Views/App/TunnelRestartButton.swift b/Passepartout/Library/Sources/AppUIMain/Views/App/TunnelRestartButton.swift index bfa5477a..2b27f3a5 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/App/TunnelRestartButton.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/App/TunnelRestartButton.swift @@ -30,9 +30,6 @@ import SwiftUI struct TunnelRestartButton