Redo VPN toggle properly

- Use local @State for appearance

- On binding set, control VPNManager
This commit is contained in:
Davide De Rosa 2022-04-25 16:24:53 +02:00
parent 6434008ebd
commit efb9760d6b
1 changed files with 18 additions and 7 deletions

View File

@ -42,6 +42,17 @@ extension ProfileView {
@ObservedObject private var currentProfile: ObservableProfile
@State private var isLocallyEnabled = false
private var isEnabled: Binding<Bool> {
.init {
isLocallyEnabled
} set: {
isLocallyEnabled = $0
toggleVPNAndDonateIntents()
}
}
private let isLoading: Bool
private var isActiveProfile: Bool {
@ -85,13 +96,13 @@ extension ProfileView {
footer: Text(L10n.Profile.Sections.Vpn.footer)
.xxxThemeTruncation()
) {
HStack {
Button(vpnToggleString, action: toggleVPNAndDonateIntents)
.disabled(vpnManager.isRateLimiting)
Spacer()
Toggle("", isOn: .constant(currentVPNState.isEnabled))
.disabled(true)
}
Toggle(vpnToggleString, isOn: isEnabled)
.onAppear {
isLocallyEnabled = currentVPNState.isEnabled
}.onChange(of: currentVPNState.isEnabled) {
isLocallyEnabled = $0
}.disabled(vpnManager.isRateLimiting)
Text(L10n.Profile.Items.ConnectionStatus.caption)
.withTrailingText(currentVPNState.localizedStatusDescription(
withErrors: true,