Skip to content

Commit febf414

Browse files
committed
fix: temporarily disable vpn toggle after toggling off
1 parent ddf21a7 commit febf414

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Coder Desktop/Coder Desktop/Views/VPNMenu.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ struct VPNMenu<VPN: VPNService, S: Session>: View {
55
@EnvironmentObject var session: S
66
@Environment(\.openSettings) private var openSettings
77

8+
// There appears to be a race between the VPN service reporting itself as disconnected,
9+
// and the system extension process exiting. When the VPN is toggled off and on quickly,
10+
// an error is shown: "The VPN session failed because an internal error occurred".
11+
// This forces the user to wait a few seconds before they can toggle the VPN back on.
12+
@State private var waitCleanup = false
13+
private var waitCleanupDuration: Duration = .seconds(4)
14+
815
let inspection = Inspection<Self>()
916

1017
var body: some View {
@@ -16,7 +23,7 @@ struct VPNMenu<VPN: VPNService, S: Session>: View {
1623
Toggle(isOn: Binding(
1724
get: { vpn.state == .connected || vpn.state == .connecting },
1825
set: { isOn in Task {
19-
if isOn { await vpn.start() } else { await vpn.stop() }
26+
if isOn { await vpn.start() } else { await stop() }
2027
}
2128
}
2229
)) {
@@ -86,11 +93,21 @@ struct VPNMenu<VPN: VPNService, S: Session>: View {
8693
}
8794

8895
private var vpnDisabled: Bool {
96+
waitCleanup ||
8997
!session.hasSession ||
9098
vpn.state == .connecting ||
9199
vpn.state == .disconnecting ||
92100
vpn.state == .failed(.systemExtensionError(.needsUserApproval))
93101
}
102+
103+
private func stop() async {
104+
await vpn.stop()
105+
waitCleanup = true
106+
Task {
107+
try await Task.sleep(for: waitCleanupDuration)
108+
waitCleanup = false
109+
}
110+
}
94111
}
95112

96113
func openSystemExtensionSettings() {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy