Fix some on-demand behavior (#646)

Fixes #644 
Fixes #645
This commit is contained in:
Davide 2024-09-30 19:35:41 +02:00 committed by GitHub
parent 3f60dee9a2
commit 4b1f6e547b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 50 additions and 3 deletions

View File

@ -32,7 +32,7 @@
"kind" : "remoteSourceControl",
"location" : "git@github.com:passepartoutvpn/passepartoutkit",
"state" : {
"revision" : "fd4fe153c17a33d43a2e75d58512194ac3588eba"
"revision" : "1277fe7386441dd303673aa867ef9a05fe2aa9f5"
}
},
{

View File

@ -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"),

View File

@ -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

View File

@ -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";

View File

@ -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)
}

View File

@ -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 {