From 7ede841346780e0335e561ca17cc87de714ae46f Mon Sep 17 00:00:00 2001 From: Davide Date: Mon, 28 Oct 2024 20:30:22 +0100 Subject: [PATCH] Present error alert on missing provider (#766) --- .../xcshareddata/swiftpm/Package.resolved | 2 +- Passepartout/Library/Package.swift | 2 +- .../Library/Sources/AppUI/L10n/AppError+L10n.swift | 6 +++--- .../Sources/AppUI/L10n/SwiftGen+Strings.swift | 8 ++++++-- .../AppUI/Resources/en.lproj/Localizable.strings | 6 ++++-- .../AppUI/Views/UI/InstalledProfileView.swift | 2 +- .../Sources/AppUI/Views/UI/TunnelToggleButton.swift | 13 ++++++++++++- 7 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 72ba4a43..7d80fade 100644 --- a/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -41,7 +41,7 @@ "kind" : "remoteSourceControl", "location" : "git@github.com:passepartoutvpn/passepartoutkit-source", "state" : { - "revision" : "d21f1b362dfe667c36483e18b2dbb494bba54660" + "revision" : "db0f5258fdbd5192dd2b87dedc46494494bc7ffb" } }, { diff --git a/Passepartout/Library/Package.swift b/Passepartout/Library/Package.swift index 6985d19f..ca79dfd6 100644 --- a/Passepartout/Library/Package.swift +++ b/Passepartout/Library/Package.swift @@ -28,7 +28,7 @@ let package = Package( ], dependencies: [ // .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.9.0"), - .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "d21f1b362dfe667c36483e18b2dbb494bba54660"), + .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "db0f5258fdbd5192dd2b87dedc46494494bc7ffb"), // .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", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"), diff --git a/Passepartout/Library/Sources/AppUI/L10n/AppError+L10n.swift b/Passepartout/Library/Sources/AppUI/L10n/AppError+L10n.swift index 857a07ef..d1513dc6 100644 --- a/Passepartout/Library/Sources/AppUI/L10n/AppError+L10n.swift +++ b/Passepartout/Library/Sources/AppUI/L10n/AppError+L10n.swift @@ -56,9 +56,6 @@ extension PassepartoutError: LocalizedError { return Strings.Errors.App.Passepartout.connectionModuleRequired case .corruptProviderModule: - if let ppReason = reason as? PassepartoutError, ppReason.code == .notFound { - return Strings.Errors.App.Provider.missingEntity - } return Strings.Errors.App.Passepartout.corruptProviderModule(reason?.localizedDescription ?? "") case .incompatibleModules: @@ -84,6 +81,9 @@ extension PassepartoutError: LocalizedError { .compactMap { $0 } .joined(separator: " ") + case .providerRequired: + return Strings.Errors.App.Passepartout.providerRequired + case .unhandled: return reason?.localizedDescription diff --git a/Passepartout/Library/Sources/AppUI/L10n/SwiftGen+Strings.swift b/Passepartout/Library/Sources/AppUI/L10n/SwiftGen+Strings.swift index 6c931a8b..36b5571b 100644 --- a/Passepartout/Library/Sources/AppUI/L10n/SwiftGen+Strings.swift +++ b/Passepartout/Library/Sources/AppUI/L10n/SwiftGen+Strings.swift @@ -133,12 +133,16 @@ public enum Strings { public static let incompatibleModules = Strings.tr("Localizable", "errors.app.passepartout.incompatible_modules", fallback: "Some active modules are incompatible, try to only activate one of them.") /// Invalid fields. public static let invalidFields = Strings.tr("Localizable", "errors.app.passepartout.invalid_fields", fallback: "Invalid fields.") + /// No provider server selected. + public static let missingProviderEntity = Strings.tr("Localizable", "errors.app.passepartout.missing_provider_entity", fallback: "No provider server selected.") /// Unable to parse file. public static let parsing = Strings.tr("Localizable", "errors.app.passepartout.parsing", fallback: "Unable to parse file.") + /// No provider selected. + public static let providerRequired = Strings.tr("Localizable", "errors.app.passepartout.provider_required", fallback: "No provider selected.") } public enum Provider { - /// No provider server selected. - public static let missingEntity = Strings.tr("Localizable", "errors.app.provider.missing_entity", fallback: "No provider server selected.") + /// No provider selected. + public static let `required` = Strings.tr("Localizable", "errors.app.provider.required", fallback: "No provider selected.") } } public enum Tunnel { diff --git a/Passepartout/Library/Sources/AppUI/Resources/en.lproj/Localizable.strings b/Passepartout/Library/Sources/AppUI/Resources/en.lproj/Localizable.strings index f3879e1c..c0c3819b 100644 --- a/Passepartout/Library/Sources/AppUI/Resources/en.lproj/Localizable.strings +++ b/Passepartout/Library/Sources/AppUI/Resources/en.lproj/Localizable.strings @@ -260,13 +260,15 @@ "errors.app.empty_profile_name" = "Profile name is empty."; "errors.app.malformed_module" = "Module %@ is malformed. %@"; -"errors.app.provider.missing_entity" = "No provider server selected."; +"errors.app.provider.required" = "No provider selected."; "errors.app.default" = "Unable to complete operation."; "errors.app.passepartout.connection_module_required" = "Routing module can only be enabled together with a connection."; "errors.app.passepartout.corrupt_provider_module" = "Unable to connect to provider server (reason=%@)."; -"errors.app.passepartout.invalid_fields" = "Invalid fields."; "errors.app.passepartout.incompatible_modules" = "Some active modules are incompatible, try to only activate one of them."; +"errors.app.passepartout.invalid_fields" = "Invalid fields."; +"errors.app.passepartout.missing_provider_entity" = "No provider server selected."; "errors.app.passepartout.parsing" = "Unable to parse file."; +"errors.app.passepartout.provider_required" = "No provider selected."; "errors.app.passepartout.default" = "Unable to complete operation (code=%@)."; "errors.tunnel.auth" = "Auth failed"; diff --git a/Passepartout/Library/Sources/AppUI/Views/UI/InstalledProfileView.swift b/Passepartout/Library/Sources/AppUI/Views/UI/InstalledProfileView.swift index 19f1ad2d..fde16e26 100644 --- a/Passepartout/Library/Sources/AppUI/Views/UI/InstalledProfileView.swift +++ b/Passepartout/Library/Sources/AppUI/Views/UI/InstalledProfileView.swift @@ -160,7 +160,7 @@ private struct ProviderCountryFlag: View { var body: some View { ThemeCountryFlag( code: provider.entity?.header.countryCode, - placeholderTip: Strings.Errors.App.Provider.missingEntity, + placeholderTip: Strings.Errors.App.Passepartout.missingProviderEntity, countryTip: { $0.localizedAsRegionCode } diff --git a/Passepartout/Library/Sources/AppUI/Views/UI/TunnelToggleButton.swift b/Passepartout/Library/Sources/AppUI/Views/UI/TunnelToggleButton.swift index 63e5b7c8..64c2333d 100644 --- a/Passepartout/Library/Sources/AppUI/Views/UI/TunnelToggleButton.swift +++ b/Passepartout/Library/Sources/AppUI/Views/UI/TunnelToggleButton.swift @@ -140,9 +140,20 @@ private extension TunnelToggleButton { } catch is CancellationError { // } catch { - if (error as? PassepartoutError)?.code == .missingProviderEntity { + switch (error as? PassepartoutError)?.code { + case .missingProviderEntity: onProviderEntityRequired?(profile) return + + case .providerRequired: + errorHandler.handle( + error, + title: Strings.Global.connection + ) + return + + default: + break } errorHandler.handle( error,