From 4b4fca8344ea11b8cbdf4fcfc7d4d07f76d39fb3 Mon Sep 17 00:00:00 2001 From: Davide Date: Fri, 22 Nov 2024 12:52:51 +0100 Subject: [PATCH] Replace active modules count with a description (#915) To get access to modules, try to avoid full Profile objects. Instead, replace the coupled ProfileHeader occurrences with a new intermediary ProfilePreview everywhere. This way, a ProfileProcessor can inject the localized modules descriptions from above with the preview() method. --- .../Views/App/InstalledProfileView.swift | 4 +- .../AppUIMain/Views/App/ProfileCardView.swift | 14 ++--- .../Views/App/ProfileContainerView.swift | 2 +- .../Views/App/ProfileContextMenu.swift | 12 ++-- .../Views/App/ProfileDuplicateButton.swift | 7 +-- .../AppUIMain/Views/App/ProfileFlow.swift | 2 +- .../AppUIMain/Views/App/ProfileGridView.swift | 18 +++--- .../Views/App/ProfileInfoButton.swift | 8 +-- .../AppUIMain/Views/App/ProfileListView.swift | 16 ++--- .../Views/App/ProfileRemoveButton.swift | 5 +- .../AppUIMain/Views/App/ProfileRowView.swift | 28 +++++---- .../Views/AppMenu/macOS/AppMenu.swift | 14 ++--- .../Views/Migration/MigrateView.swift | 2 +- .../Views/Profile/ActiveProfileView.swift | 30 ++-------- .../Views/Profile/ProfileListView.swift | 20 +++---- .../Business/ProfileManager.swift | 4 +- .../CommonLibrary/Domain/ProfilePreview.swift | 47 +++++++++++++++ .../Domain/TunnelInstallation.swift | 7 +-- .../Strategy/InAppProcessor.swift | 8 +++ .../Strategy/ProfileProcessor.swift | 2 + .../Extensions/ProfileManager+Editing.swift | 2 +- ...nnelInstallationProviding+Extensions.swift | 4 +- .../UILibrary/L10n/PassepartoutKit+L10n.swift | 36 ++++++++++++ .../UILibrary/L10n/SwiftGen+Strings.swift | 6 +- .../UILibrary/Mock/AppContext+Mock.swift | 3 + .../Resources/en.lproj/Localizable.strings | 2 +- .../AppUIMainTests/ProfileImporterTests.swift | 2 +- .../Mock/MockProfileProcessor.swift | 4 ++ .../ProfileManagerTests.swift | 58 +++++++++---------- Passepartout/Shared/Shared+App.swift | 7 +++ 30 files changed, 229 insertions(+), 145 deletions(-) create mode 100644 Passepartout/Library/Sources/CommonLibrary/Domain/ProfilePreview.swift diff --git a/Passepartout/Library/Sources/AppUIMain/Views/App/InstalledProfileView.swift b/Passepartout/Library/Sources/AppUIMain/Views/App/InstalledProfileView.swift index 68390ba14..5bf55898d 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/App/InstalledProfileView.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/App/InstalledProfileView.swift @@ -124,7 +124,7 @@ private extension InstalledProfileView { ProfileContextMenu( profileManager: profileManager, tunnel: tunnel, - header: (profile ?? .mock).header(), + preview: .init(profile ?? .mock), interactiveManager: interactiveManager, errorHandler: errorHandler, isInstalledProfile: true, @@ -324,7 +324,7 @@ private struct ContentView: View { style: .full, profileManager: .mock, tunnel: .mock, - header: Profile.mock.header(), + preview: .init(.mock), interactiveManager: InteractiveManager(), errorHandler: .default(), nextProfileId: .constant(nil), diff --git a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileCardView.swift b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileCardView.swift index 434508fed..6a7239ea9 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileCardView.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileCardView.swift @@ -24,7 +24,6 @@ // import CommonLibrary -import PassepartoutKit import SwiftUI struct ProfileCardView: View { @@ -36,21 +35,22 @@ struct ProfileCardView: View { let style: Style - let header: ProfileHeader + let preview: ProfilePreview var body: some View { switch style { case .compact: - Text(header.name) + Text(preview.name) .themeTruncating() .frame(maxWidth: .infinity, alignment: .leading) case .full: VStack(alignment: .leading) { - Text(header.name) + Text(preview.name) .font(.headline) .themeTruncating() - Text(Strings.Views.Profiles.Rows.modules(header.modules.count)) + + Text(preview.subtitle ?? Strings.Views.Profiles.Rows.noModules) .font(.subheadline) .foregroundStyle(.secondary) } @@ -66,13 +66,13 @@ struct ProfileCardView: View { Section { ProfileCardView( style: .compact, - header: Profile.mock.header() + preview: .init(.mock) ) } Section { ProfileCardView( style: .full, - header: Profile.mock.header() + preview: .init(.mock) ) } } diff --git a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContainerView.swift b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContainerView.swift index 2f0b5749c..8ccc6ca63 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContainerView.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContainerView.swift @@ -136,7 +136,7 @@ private struct ContainerModifier: ViewModifier { profileManager.search(byName: $0) } .themeAnimation(on: profileManager.isReady, category: .profiles) - .themeAnimation(on: profileManager.headers, category: .profiles) + .themeAnimation(on: profileManager.previews, category: .profiles) } } diff --git a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContextMenu.swift b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContextMenu.swift index 995ff0ea3..d069aeda2 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContextMenu.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContextMenu.swift @@ -33,7 +33,7 @@ struct ProfileContextMenu: View, Routable { let tunnel: ExtendedTunnel - let header: ProfileHeader + let preview: ProfilePreview let interactiveManager: InteractiveManager @@ -60,7 +60,7 @@ struct ProfileContextMenu: View, Routable { @MainActor private extension ProfileContextMenu { var profile: Profile? { - profileManager.profile(withId: header.id) + profileManager.profile(withId: preview.id) } var tunnelToggleButton: some View { @@ -111,7 +111,7 @@ private extension ProfileContextMenu { var profileEditButton: some View { Button { - flow?.onEditProfile(header) + flow?.onEditProfile(preview) } label: { ThemeImageLabel(Strings.Global.edit.withTrailingDots, .profileEdit) } @@ -120,7 +120,7 @@ private extension ProfileContextMenu { var profileDuplicateButton: some View { ProfileDuplicateButton( profileManager: profileManager, - header: header, + preview: preview, errorHandler: errorHandler ) { ThemeImageLabel(Strings.Global.duplicate, .contextDuplicate) @@ -130,7 +130,7 @@ private extension ProfileContextMenu { var profileRemoveButton: some View { ProfileRemoveButton( profileManager: profileManager, - header: header + preview: preview ) { ThemeImageLabel(Strings.Global.remove, .contextRemove) } @@ -143,7 +143,7 @@ private extension ProfileContextMenu { ProfileContextMenu( profileManager: .mock, tunnel: .mock, - header: Profile.mock.header(), + preview: .init(.mock), interactiveManager: InteractiveManager(), errorHandler: .default(), isInstalledProfile: true diff --git a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileDuplicateButton.swift b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileDuplicateButton.swift index 800252387..002c4cf04 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileDuplicateButton.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileDuplicateButton.swift @@ -25,13 +25,12 @@ import CommonLibrary import CommonUtils -import PassepartoutKit import SwiftUI struct ProfileDuplicateButton