Skip to content

Commit

Permalink
Fix incorrect selection of VPN preset (#996)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
keeshux authored Dec 10, 2024
1 parent 6f9c78b commit c7bba03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 0 additions & 2 deletions Library/Sources/AppUIMain/Views/VPN/VPNFiltersView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down
24 changes: 14 additions & 10 deletions Library/Sources/AppUIMain/Views/VPN/VPNProviderServerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Configuration>? {
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 {
Expand Down

0 comments on commit c7bba03

Please sign in to comment.