From c7bba033fea68fe10d685a57199c7967088eb91a Mon Sep 17 00:00:00 2001 From: Davide Date: Tue, 10 Dec 2024 14:45:07 +0100 Subject: [PATCH] Fix incorrect selection of VPN preset (#996) Drop "Any" to rather make the preset filter an explicit preset selection. Regardless of `filtersWithSelection`, _always_ enforce the preset filter to: - The preset of the currently selected entity - The first among available presets (normally non-empty) Fixes #995 --- .../AppUIMain/Views/VPN/VPNFiltersView.swift | 2 -- .../Views/VPN/VPNProviderServerView.swift | 24 +++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Library/Sources/AppUIMain/Views/VPN/VPNFiltersView.swift b/Library/Sources/AppUIMain/Views/VPN/VPNFiltersView.swift index bb018a72..66e42a6f 100644 --- a/Library/Sources/AppUIMain/Views/VPN/VPNFiltersView.swift +++ b/Library/Sources/AppUIMain/Views/VPN/VPNFiltersView.swift @@ -93,8 +93,6 @@ private extension VPNFiltersView { var presetPicker: some View { Picker(Strings.Views.Vpn.preset, selection: $model.filters.presetId) { - Text(Strings.Global.Nouns.any) - .tag(nil as String?) ForEach(model.presets, id: \.presetId) { Text($0.description) .tag($0.presetId as String?) diff --git a/Library/Sources/AppUIMain/Views/VPN/VPNProviderServerView.swift b/Library/Sources/AppUIMain/Views/VPN/VPNProviderServerView.swift index dad52cf5..ac834623 100644 --- a/Library/Sources/AppUIMain/Views/VPN/VPNProviderServerView.swift +++ b/Library/Sources/AppUIMain/Views/VPN/VPNProviderServerView.swift @@ -132,25 +132,29 @@ private extension VPNProviderServerView { return servers } - var initialFilters: VPNFilters? { - guard let selectedEntity, filtersWithSelection else { - return nil - } + var initialFilters: VPNFilters { var filters = VPNFilters() - filters.categoryName = selectedEntity.server.provider.categoryName + + // force initial preset filter + filters.presetId = vpnManager.options.presets.first?.presetId + + if let selectedEntity { + filters.presetId = selectedEntity.preset.presetId + if filtersWithSelection { + filters.categoryName = selectedEntity.server.provider.categoryName #if os(macOS) - filters.countryCode = selectedEntity.server.provider.countryCode + filters.countryCode = selectedEntity.server.provider.countryCode #endif + } + } return filters } func compatiblePreset(with server: VPNServer) -> VPNPreset? { vpnManager .presets - .filter { preset in - filtersViewModel.presets.contains { - preset.presetId == $0.presetId - } + .filter { + $0.presetId == filtersViewModel.filters.presetId } .first { if let supportedIds = server.provider.supportedPresetIds {