Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not connect TV profile on server selection #1030

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Library/Sources/AppUIMain/Views/App/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ extension AppCoordinator {
ProviderEntitySelector(
module: module,
errorHandler: errorHandler,
selectTitle: profile.providerServerSelectionTitle,
onSelect: {
try await onSelectProviderEntity(with: $0, in: profile, force: force)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 10 additions & 3 deletions Library/Sources/AppUIMain/Views/App/ProfileContextMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ extension OpenVPNModule.Builder: ModuleViewProviding {
extension OpenVPNModule: ProviderEntityViewProviding {
public func providerEntityView(
errorHandler: ErrorHandler,
selectTitle: String,
onSelect: @escaping (Module) async throws -> Void
) -> some View {
providerSelection.map {
VPNProviderServerCoordinator(
moduleId: id,
providerId: $0.id,
selectedEntity: $0.entity,
selectTitle: selectTitle,
onSelect: {
var newBuilder = builder()
newBuilder.providerEntity = $0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ extension WireGuardModule.Builder: ModuleViewProviding {
extension WireGuardModule: ProviderEntityViewProviding {
public func providerEntityView(
errorHandler: ErrorHandler,
selectTitle: String,
onSelect: @escaping (Module) async throws -> Void
) -> some View {
providerSelection.map {
VPNProviderServerCoordinator(
moduleId: id,
providerId: $0.id,
selectedEntity: $0.entity,
selectTitle: selectTitle,
onSelect: {
var newBuilder = builder()
newBuilder.providerEntity = $0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ struct VPNProviderServerCoordinator<Configuration>: View where Configuration: Id

let selectedEntity: VPNEntity<Configuration>?

let selectTitle: String

let onSelect: (VPNEntity<Configuration>) async throws -> Void

@ObservedObject
Expand All @@ -49,7 +51,7 @@ struct VPNProviderServerCoordinator<Configuration>: View where Configuration: Id
providerId: providerId,
selectedEntity: selectedEntity,
filtersWithSelection: false,
selectTitle: Strings.Global.Actions.connect,
selectTitle: selectTitle,
onSelect: onSelect
)
.themeNavigationStack(closable: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public protocol ProviderEntityViewProviding {
@MainActor
func providerEntityView(
errorHandler: ErrorHandler,
selectTitle: String,
onSelect: @escaping (Module) async throws -> Void
) -> EntityContent
}