Fix unselectable presets (#1004)
Revert #996 and do something midway: - When set, use preset filter as selection (disambiguate compatible presets) - Set initial preset filter with current selected server preset Server selection still picks a random preset if: - Preset filter is "Any" - More than one preset is compatible
This commit is contained in:
parent
4fb457aee2
commit
2075f109f2
|
@ -93,6 +93,8 @@ 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?)
|
||||||
|
|
|
@ -132,13 +132,11 @@ private extension VPNProviderServerView {
|
||||||
return servers
|
return servers
|
||||||
}
|
}
|
||||||
|
|
||||||
var initialFilters: VPNFilters {
|
var initialFilters: VPNFilters? {
|
||||||
|
guard let selectedEntity else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
var filters = VPNFilters()
|
var filters = VPNFilters()
|
||||||
|
|
||||||
// force initial preset filter
|
|
||||||
filters.presetId = vpnManager.options.presets.first?.presetId
|
|
||||||
|
|
||||||
if let selectedEntity {
|
|
||||||
filters.presetId = selectedEntity.preset.presetId
|
filters.presetId = selectedEntity.preset.presetId
|
||||||
if filtersWithSelection {
|
if filtersWithSelection {
|
||||||
filters.categoryName = selectedEntity.server.provider.categoryName
|
filters.categoryName = selectedEntity.server.provider.categoryName
|
||||||
|
@ -146,17 +144,19 @@ private extension VPNProviderServerView {
|
||||||
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 compatiblePresets(with server: VPNServer) -> [VPNPreset<Configuration>] {
|
||||||
vpnManager
|
vpnManager
|
||||||
.presets
|
.presets
|
||||||
.filter {
|
.filter {
|
||||||
$0.presetId == filtersViewModel.filters.presetId
|
if let selectedId = filtersViewModel.filters.presetId {
|
||||||
|
return $0.presetId == selectedId
|
||||||
}
|
}
|
||||||
.first {
|
return true
|
||||||
|
}
|
||||||
|
.filter {
|
||||||
if let supportedIds = server.provider.supportedPresetIds {
|
if let supportedIds = server.provider.supportedPresetIds {
|
||||||
return supportedIds.contains($0.presetId)
|
return supportedIds.contains($0.presetId)
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,8 @@ private extension VPNProviderServerView {
|
||||||
}
|
}
|
||||||
|
|
||||||
func onSelectServer(_ server: VPNServer) {
|
func onSelectServer(_ server: VPNServer) {
|
||||||
guard let preset = compatiblePreset(with: server) else {
|
let presets = compatiblePresets(with: server)
|
||||||
|
guard let preset = presets.first else {
|
||||||
pp_log(.app, .error, "Unable to find a compatible preset. Supported IDs: \(server.provider.supportedPresetIds ?? [])")
|
pp_log(.app, .error, "Unable to find a compatible preset. Supported IDs: \(server.provider.supportedPresetIds ?? [])")
|
||||||
assertionFailure("No compatible presets for server \(server.serverId) (provider=\(vpnManager.providerId), configuration=\(Configuration.configurationIdentifier), supported=\(server.provider.supportedPresetIds ?? []))")
|
assertionFailure("No compatible presets for server \(server.serverId) (provider=\(vpnManager.providerId), configuration=\(Configuration.configurationIdentifier), supported=\(server.provider.supportedPresetIds ?? []))")
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue