From 42bf392fff3f5cc5bc3ed653936e4233496ea4e0 Mon Sep 17 00:00:00 2001 From: Davide Date: Fri, 20 Dec 2024 10:30:57 +0100 Subject: [PATCH] Do not connect TV profile on server selection (#1030) You may still connect manually, but iOS/macOS apps mainly serve as remote to switch servers on the TV. --- .../AppUIMain/Views/App/AppCoordinator.swift | 21 +++++++++++++++++++ .../Views/App/ProfileContextMenu.swift | 13 +++++++++--- .../Extensions/OpenVPNModule+Extensions.swift | 2 ++ .../WireGuardModule+Extensions.swift | 2 ++ .../Providers/ProviderEntitySelector.swift | 3 +++ .../VPN/VPNProviderServerCoordinator.swift | 4 +++- .../ProviderEntityViewProviding.swift | 1 + 7 files changed, 42 insertions(+), 4 deletions(-) diff --git a/Library/Sources/AppUIMain/Views/App/AppCoordinator.swift b/Library/Sources/AppUIMain/Views/App/AppCoordinator.swift index 03edd4a2..22d6c956 100644 --- a/Library/Sources/AppUIMain/Views/App/AppCoordinator.swift +++ b/Library/Sources/AppUIMain/Views/App/AppCoordinator.swift @@ -191,6 +191,7 @@ extension AppCoordinator { ProviderEntitySelector( module: module, errorHandler: errorHandler, + selectTitle: profile.providerServerSelectionTitle, onSelect: { try await onSelectProviderEntity(with: $0, in: profile, force: force) } @@ -270,6 +271,11 @@ private extension AppCoordinator { let wasConnected = newProfile.id == tunnel.currentProfile?.id && tunnel.status == .active try await profileManager.save(newProfile, isLocal: true) + + guard profile.shouldConnectToProviderServer else { + return + } + if !wasConnected { pp_log(.app, .info, "Profile \(newProfile.id) was not connected, will connect to new provider entity") await onConnect(newProfile, force: force) @@ -313,6 +319,21 @@ private extension AppCoordinator { } } +private extension Profile { + var providerServerSelectionTitle: String { + attributes.isAvailableForTV == true ? Strings.Views.Providers.selectEntity : Strings.Global.Actions.connect + } + + var shouldConnectToProviderServer: Bool { +#if os(tvOS) + true +#else + // do not connect TV profiles on server selection + attributes.isAvailableForTV != true +#endif + } +} + // MARK: - Previews #Preview { diff --git a/Library/Sources/AppUIMain/Views/App/ProfileContextMenu.swift b/Library/Sources/AppUIMain/Views/App/ProfileContextMenu.swift index 9e4d9eb9..39a1d393 100644 --- a/Library/Sources/AppUIMain/Views/App/ProfileContextMenu.swift +++ b/Library/Sources/AppUIMain/Views/App/ProfileContextMenu.swift @@ -88,14 +88,14 @@ private extension ProfileContextMenu { } var providerConnectToButton: some View { - profile.map { + profile.map { profile in ProviderConnectToButton( - profile: $0, + profile: profile, onTap: { flow?.connectionFlow?.onProviderEntityRequired($0) }, label: { - ThemeImageLabel(Strings.Views.App.ProfileContext.connectTo.withTrailingDots, .profileProvider) + ThemeImageLabel(profile.providerServerSelectionTitle, .profileProvider) } ) .uiAccessibility(.App.ProfileMenu.connectTo) @@ -143,6 +143,13 @@ private extension ProfileContextMenu { } } +private extension Profile { + var providerServerSelectionTitle: String { + (attributes.isAvailableForTV == true ? + Strings.Views.Providers.selectEntity : Strings.Views.App.ProfileContext.connectTo).withTrailingDots + } +} + #Preview { List { Menu("Menu") { diff --git a/Library/Sources/AppUIMain/Views/Modules/Extensions/OpenVPNModule+Extensions.swift b/Library/Sources/AppUIMain/Views/Modules/Extensions/OpenVPNModule+Extensions.swift index 5b510c61..7a4f3cf7 100644 --- a/Library/Sources/AppUIMain/Views/Modules/Extensions/OpenVPNModule+Extensions.swift +++ b/Library/Sources/AppUIMain/Views/Modules/Extensions/OpenVPNModule+Extensions.swift @@ -37,6 +37,7 @@ extension OpenVPNModule.Builder: ModuleViewProviding { extension OpenVPNModule: ProviderEntityViewProviding { public func providerEntityView( errorHandler: ErrorHandler, + selectTitle: String, onSelect: @escaping (Module) async throws -> Void ) -> some View { providerSelection.map { @@ -44,6 +45,7 @@ extension OpenVPNModule: ProviderEntityViewProviding { moduleId: id, providerId: $0.id, selectedEntity: $0.entity, + selectTitle: selectTitle, onSelect: { var newBuilder = builder() newBuilder.providerEntity = $0 diff --git a/Library/Sources/AppUIMain/Views/Modules/Extensions/WireGuardModule+Extensions.swift b/Library/Sources/AppUIMain/Views/Modules/Extensions/WireGuardModule+Extensions.swift index cf1d8014..d498960c 100644 --- a/Library/Sources/AppUIMain/Views/Modules/Extensions/WireGuardModule+Extensions.swift +++ b/Library/Sources/AppUIMain/Views/Modules/Extensions/WireGuardModule+Extensions.swift @@ -37,6 +37,7 @@ extension WireGuardModule.Builder: ModuleViewProviding { extension WireGuardModule: ProviderEntityViewProviding { public func providerEntityView( errorHandler: ErrorHandler, + selectTitle: String, onSelect: @escaping (Module) async throws -> Void ) -> some View { providerSelection.map { @@ -44,6 +45,7 @@ extension WireGuardModule: ProviderEntityViewProviding { moduleId: id, providerId: $0.id, selectedEntity: $0.entity, + selectTitle: selectTitle, onSelect: { var newBuilder = builder() newBuilder.providerEntity = $0 diff --git a/Library/Sources/AppUIMain/Views/Providers/ProviderEntitySelector.swift b/Library/Sources/AppUIMain/Views/Providers/ProviderEntitySelector.swift index f25ab91e..28761526 100644 --- a/Library/Sources/AppUIMain/Views/Providers/ProviderEntitySelector.swift +++ b/Library/Sources/AppUIMain/Views/Providers/ProviderEntitySelector.swift @@ -33,12 +33,15 @@ struct ProviderEntitySelector: View { let errorHandler: ErrorHandler + let selectTitle: String + let onSelect: (Module) async throws -> Void var body: some View { if let viewProvider = module as? any ProviderEntityViewProviding { AnyView(viewProvider.providerEntityView( errorHandler: errorHandler, + selectTitle: selectTitle, onSelect: onSelect )) } else { diff --git a/Library/Sources/AppUIMain/Views/VPN/VPNProviderServerCoordinator.swift b/Library/Sources/AppUIMain/Views/VPN/VPNProviderServerCoordinator.swift index ed5e9324..d285d838 100644 --- a/Library/Sources/AppUIMain/Views/VPN/VPNProviderServerCoordinator.swift +++ b/Library/Sources/AppUIMain/Views/VPN/VPNProviderServerCoordinator.swift @@ -38,6 +38,8 @@ struct VPNProviderServerCoordinator: View where Configuration: Id let selectedEntity: VPNEntity? + let selectTitle: String + let onSelect: (VPNEntity) async throws -> Void @ObservedObject @@ -49,7 +51,7 @@ struct VPNProviderServerCoordinator: View where Configuration: Id providerId: providerId, selectedEntity: selectedEntity, filtersWithSelection: false, - selectTitle: Strings.Global.Actions.connect, + selectTitle: selectTitle, onSelect: onSelect ) .themeNavigationStack(closable: true) diff --git a/Library/Sources/UILibrary/Strategy/ProviderEntityViewProviding.swift b/Library/Sources/UILibrary/Strategy/ProviderEntityViewProviding.swift index f4d40957..3acc89f6 100644 --- a/Library/Sources/UILibrary/Strategy/ProviderEntityViewProviding.swift +++ b/Library/Sources/UILibrary/Strategy/ProviderEntityViewProviding.swift @@ -33,6 +33,7 @@ public protocol ProviderEntityViewProviding { @MainActor func providerEntityView( errorHandler: ErrorHandler, + selectTitle: String, onSelect: @escaping (Module) async throws -> Void ) -> EntityContent }