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
This commit is contained in:
Davide 2024-12-10 14:45:07 +01:00 committed by GitHub
parent 6f9c78b257
commit c7bba033fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 12 deletions

View File

@ -93,8 +93,6 @@ private extension VPNFiltersView {
var presetPicker: some View { var presetPicker: some View {
Picker(Strings.Views.Vpn.preset, selection: $model.filters.presetId) { Picker(Strings.Views.Vpn.preset, selection: $model.filters.presetId) {
Text(Strings.Global.Nouns.any)
.tag(nil as String?)
ForEach(model.presets, id: \.presetId) { ForEach(model.presets, id: \.presetId) {
Text($0.description) Text($0.description)
.tag($0.presetId as String?) .tag($0.presetId as String?)

View File

@ -132,25 +132,29 @@ private extension VPNProviderServerView {
return servers return servers
} }
var initialFilters: VPNFilters? { var initialFilters: VPNFilters {
guard let selectedEntity, filtersWithSelection else {
return nil
}
var filters = 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) #if os(macOS)
filters.countryCode = selectedEntity.server.provider.countryCode filters.countryCode = selectedEntity.server.provider.countryCode
#endif #endif
}
}
return filters return filters
} }
func compatiblePreset(with server: VPNServer) -> VPNPreset<Configuration>? { func compatiblePreset(with server: VPNServer) -> VPNPreset<Configuration>? {
vpnManager vpnManager
.presets .presets
.filter { preset in .filter {
filtersViewModel.presets.contains { $0.presetId == filtersViewModel.filters.presetId
preset.presetId == $0.presetId
}
} }
.first { .first {
if let supportedIds = server.provider.supportedPresetIds { if let supportedIds = server.provider.supportedPresetIds {