From 4b1f6e547bdf806a034605b22ef1783cd8d587d5 Mon Sep 17 00:00:00 2001 From: Davide Date: Mon, 30 Sep 2024 19:35:41 +0200 Subject: [PATCH] Fix some on-demand behavior (#646) Fixes #644 Fixes #645 --- .../xcshareddata/swiftpm/Package.resolved | 2 +- Passepartout/Library/Package.swift | 2 +- .../Sources/AppUI/L10n/SwiftGen+Strings.swift | 6 +++ .../Resources/en.lproj/Localizable.strings | 4 ++ .../AppUI/Views/UI/ConnectionStatusView.swift | 37 +++++++++++++++++++ .../AppUI/Views/UI/TunnelToggleButton.swift | 2 +- 6 files changed, 50 insertions(+), 3 deletions(-) diff --git a/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 453e7614..974a33ca 100644 --- a/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,7 +32,7 @@ "kind" : "remoteSourceControl", "location" : "git@github.com:passepartoutvpn/passepartoutkit", "state" : { - "revision" : "fd4fe153c17a33d43a2e75d58512194ac3588eba" + "revision" : "1277fe7386441dd303673aa867ef9a05fe2aa9f5" } }, { diff --git a/Passepartout/Library/Package.swift b/Passepartout/Library/Package.swift index b583c6fa..36055c67 100644 --- a/Passepartout/Library/Package.swift +++ b/Passepartout/Library/Package.swift @@ -31,7 +31,7 @@ let package = Package( ], dependencies: [ // .package(url: "git@github.com:passepartoutvpn/passepartoutkit", from: "0.7.0"), - .package(url: "git@github.com:passepartoutvpn/passepartoutkit", revision: "fd4fe153c17a33d43a2e75d58512194ac3588eba"), + .package(url: "git@github.com:passepartoutvpn/passepartoutkit", revision: "1277fe7386441dd303673aa867ef9a05fe2aa9f5"), // .package(path: "../../../passepartoutkit"), .package(url: "git@github.com:passepartoutvpn/passepartoutkit-openvpn-openssl", from: "0.6.0"), // .package(path: "../../../passepartoutkit-openvpn-openssl"), diff --git a/Passepartout/Library/Sources/AppUI/L10n/SwiftGen+Strings.swift b/Passepartout/Library/Sources/AppUI/L10n/SwiftGen+Strings.swift index be9485ec..82344877 100644 --- a/Passepartout/Library/Sources/AppUI/L10n/SwiftGen+Strings.swift +++ b/Passepartout/Library/Sources/AppUI/L10n/SwiftGen+Strings.swift @@ -410,6 +410,12 @@ public enum Strings { public static let name = Strings.tr("Localizable", "placeholders.profile.name", fallback: "My profile") } } + public enum Ui { + public enum ConnectionStatus { + /// (on-demand) + public static let onDemandSuffix = Strings.tr("Localizable", "ui.connection_status.on_demand_suffix", fallback: " (on-demand)") + } + } public enum Views { public enum About { /// About diff --git a/Passepartout/Library/Sources/AppUI/Resources/en.lproj/Localizable.strings b/Passepartout/Library/Sources/AppUI/Resources/en.lproj/Localizable.strings index e615d1c0..9fe0a722 100644 --- a/Passepartout/Library/Sources/AppUI/Resources/en.lproj/Localizable.strings +++ b/Passepartout/Library/Sources/AppUI/Resources/en.lproj/Localizable.strings @@ -204,6 +204,10 @@ "modules.wireguard.preshared_key" = "Pre-shared key"; "modules.wireguard.allowed_ips" = "Allowed IPs"; +// MARK: - Components + +"ui.connection_status.on_demand_suffix" = " (on-demand)"; + // MARK: - Alerts "alerts.iap.restricted.title" = "Restricted"; diff --git a/Passepartout/Library/Sources/AppUI/Views/UI/ConnectionStatusView.swift b/Passepartout/Library/Sources/AppUI/Views/UI/ConnectionStatusView.swift index 41be8bdf..0cbae7f5 100644 --- a/Passepartout/Library/Sources/AppUI/Views/UI/ConnectionStatusView.swift +++ b/Passepartout/Library/Sources/AppUI/Views/UI/ConnectionStatusView.swift @@ -58,9 +58,46 @@ private extension ConnectionStatusView { return "↓\(down) ↑\(up)" } + case .inactive: + var desc = status.localizedDescription + if tunnel.currentProfile?.onDemand ?? false { + desc += Strings.Ui.ConnectionStatus.onDemandSuffix + } + return desc + default: break } return status.localizedDescription } } + +#Preview("Connected") { + ConnectionStatusView(tunnel: .mock) + .task { + try? await Tunnel.mock.connect(with: .mock, processor: IAPManager.mock) + } + .frame(width: 100, height: 100) + .environmentObject(Theme()) + .environmentObject(ConnectionObserver.mock) +} + +#Preview("On-Demand") { + var builder = Profile.Builder() + var onDemand = OnDemandModule.Builder() + onDemand.isEnabled = true + builder.modules = [onDemand.tryBuild()] + let profile: Profile + do { + profile = try builder.tryBuild() + } catch { + fatalError() + } + return ConnectionStatusView(tunnel: .mock) + .task { + try? await Tunnel.mock.connect(with: profile, processor: IAPManager.mock) + } + .frame(width: 100, height: 100) + .environmentObject(Theme()) + .environmentObject(ConnectionObserver.mock) +} diff --git a/Passepartout/Library/Sources/AppUI/Views/UI/TunnelToggleButton.swift b/Passepartout/Library/Sources/AppUI/Views/UI/TunnelToggleButton.swift index a9dd0252..d95ce316 100644 --- a/Passepartout/Library/Sources/AppUI/Views/UI/TunnelToggleButton.swift +++ b/Passepartout/Library/Sources/AppUI/Views/UI/TunnelToggleButton.swift @@ -81,7 +81,7 @@ private extension TunnelToggleButton { } var canConnect: Bool { - !isInstalled || tunnel.status == .inactive + !isInstalled || (tunnel.status == .inactive && tunnel.currentProfile?.onDemand != true) } var color: Color {