Optionally apply filters based on server selection (#754)

Restore passing selectedEntity, but add filtersWithSelection to decide
whether to filter servers based on selection.

Partially revert 91a3e42533
This commit is contained in:
Davide 2024-10-23 22:57:30 +02:00 committed by GitHub
parent 1e06c350ee
commit 1a82aea612
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 22 additions and 9 deletions

View File

@ -41,7 +41,7 @@
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source", "location" : "git@github.com:passepartoutvpn/passepartoutkit-source",
"state" : { "state" : {
"revision" : "079fb0e57cecfc2ed128ae9bf8614fcf3c2a6582" "revision" : "a0cb540f739c58d04756d15b9a7bb21fae52c95f"
} }
}, },
{ {

View File

@ -28,7 +28,7 @@ let package = Package(
], ],
dependencies: [ dependencies: [
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.9.0"), // .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.9.0"),
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "079fb0e57cecfc2ed128ae9bf8614fcf3c2a6582"), .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "a0cb540f739c58d04756d15b9a7bb21fae52c95f"),
// .package(path: "../../../passepartoutkit-source"), // .package(path: "../../../passepartoutkit-source"),
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", from: "0.9.1"), .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", from: "0.9.1"),
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"), // .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"),

View File

@ -49,8 +49,15 @@ extension OpenVPNModule: ProviderEntityViewProviding {
with provider: ModuleMetadata.Provider, with provider: ModuleMetadata.Provider,
onSelect: @escaping (any ProviderEntity & Encodable) async throws -> Void onSelect: @escaping (any ProviderEntity & Encodable) async throws -> Void
) -> some View { ) -> some View {
VPNProviderServerCoordinator<OpenVPN.Configuration>( let selectedEntity: VPNEntity<OpenVPN.Configuration>? = try? provider
.entity
.map {
try providerEntity(from: $0)
}
return VPNProviderServerCoordinator(
providerId: provider.id, providerId: provider.id,
selectedEntity: selectedEntity,
onSelect: onSelect onSelect: onSelect
) )
} }

View File

@ -131,6 +131,7 @@ private extension OpenVPNView {
providerId: $0, providerId: $0,
configurationType: OpenVPN.Configuration.self, configurationType: OpenVPN.Configuration.self,
selectedEntity: providerEntity.wrappedValue, selectedEntity: providerEntity.wrappedValue,
filtersWithSelection: true,
onSelect: onSelectServer onSelect: onSelectServer
) )
} }

View File

@ -34,6 +34,8 @@ struct VPNProviderServerCoordinator<Configuration>: View where Configuration: Pr
let providerId: ProviderID let providerId: ProviderID
let selectedEntity: VPNEntity<Configuration>?
let onSelect: (VPNEntity<Configuration>) async throws -> Void let onSelect: (VPNEntity<Configuration>) async throws -> Void
@StateObject @StateObject
@ -44,7 +46,8 @@ struct VPNProviderServerCoordinator<Configuration>: View where Configuration: Pr
VPNProviderServerView( VPNProviderServerView(
providerId: providerId, providerId: providerId,
configurationType: Configuration.self, configurationType: Configuration.self,
selectedEntity: nil, selectedEntity: selectedEntity,
filtersWithSelection: false,
onSelect: onSelect onSelect: onSelect
) )
.toolbar { .toolbar {

View File

@ -41,6 +41,8 @@ struct VPNProviderServerView<Configuration>: View where Configuration: ProviderC
let selectedEntity: VPNEntity<Configuration>? let selectedEntity: VPNEntity<Configuration>?
let filtersWithSelection: Bool
let onSelect: (_ server: VPNServer, _ preset: VPNPreset<Configuration>) -> Void let onSelect: (_ server: VPNServer, _ preset: VPNPreset<Configuration>) -> Void
@StateObject @StateObject
@ -74,7 +76,7 @@ struct VPNProviderServerView<Configuration>: View where Configuration: ProviderC
for: providerId, for: providerId,
configurationType: Configuration.self configurationType: Configuration.self
) )
if let selectedEntity { if let selectedEntity, filtersWithSelection {
filters = VPNFilters(with: selectedEntity.server.provider) filters = VPNFilters(with: selectedEntity.server.provider)
} else { } else {
filters = VPNFilters() filters = VPNFilters()
@ -122,6 +124,7 @@ extension VPNProviderServerView {
providerId: .protonvpn, providerId: .protonvpn,
configurationType: OpenVPN.Configuration.self, configurationType: OpenVPN.Configuration.self,
selectedEntity: nil, selectedEntity: nil,
filtersWithSelection: false,
onSelect: { _, _ in } onSelect: { _, _ in }
) )
} }

View File

@ -57,7 +57,7 @@ private extension VPNProviderServerView.Subview {
ThemeImage(.marked) ThemeImage(.marked)
.opacity(server.id == selectedServer?.id ? 1.0 : 0.0) .opacity(server.id == selectedServer?.id ? 1.0 : 0.0)
} }
.width(max: 20.0) .width(10.0)
TableColumn(Strings.Global.region) { server in TableColumn(Strings.Global.region) { server in
HStack { HStack {
@ -65,7 +65,6 @@ private extension VPNProviderServerView.Subview {
Text(server.region) Text(server.region)
} }
} }
.width(max: 200.0)
TableColumn(Strings.Global.address, value: \.address) TableColumn(Strings.Global.address, value: \.address)
@ -76,7 +75,6 @@ private extension VPNProviderServerView.Subview {
Text(Strings.Views.Provider.selectServer) Text(Strings.Views.Provider.selectServer)
} }
} }
.width(min: 100.0, max: 100.0)
} }
.disabled(manager.isFiltering) .disabled(manager.isFiltering)
} }
@ -99,6 +97,7 @@ private extension VPNProviderServerView.Subview {
providerId: .tunnelbear, providerId: .tunnelbear,
configurationType: OpenVPN.Configuration.self, configurationType: OpenVPN.Configuration.self,
selectedEntity: nil, selectedEntity: nil,
filtersWithSelection: false,
onSelect: { _, _ in } onSelect: { _, _ in }
) )
} }

View File

@ -159,7 +159,7 @@ private struct ProviderCountryFlag: View {
var body: some View { var body: some View {
ThemeCountryFlag( ThemeCountryFlag(
code: provider.entity?.countryCode, code: provider.entity?.header.countryCode,
placeholderTip: Strings.Errors.App.Provider.missingEntity, placeholderTip: Strings.Errors.App.Provider.missingEntity,
countryTip: { countryTip: {
$0.localizedAsRegionCode $0.localizedAsRegionCode