Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: temporarily disable vpn toggle after toggling off#43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ethanndickson merged 3 commits intomainfromethan/toggle-wait-cleanup
Feb 12, 2025
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletionsCoder Desktop/Coder Desktop/Views/VPNMenu.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,13 @@ struct VPNMenu<VPN: VPNService, S: Session>: View {
@EnvironmentObject var session: S
@Environment(\.openSettings) private var openSettings

// There appears to be a race between the VPN service reporting itself as disconnected,
// and the system extension process exiting. When the VPN is toggled off and on quickly,
// an error is shown: "The VPN session failed because an internal error occurred".
// This forces the user to wait a few seconds before they can toggle the VPN back on.
@State private var waitCleanup = false
private var waitCleanupDuration: Duration = .seconds(6)

let inspection = Inspection<Self>()

var body: some View {
Expand All@@ -16,7 +23,7 @@ struct VPNMenu<VPN: VPNService, S: Session>: View {
Toggle(isOn: Binding(
get: { vpn.state == .connected || vpn.state == .connecting },
set: { isOn in Task {
if isOn { await vpn.start() } else { awaitvpn.stop() }
if isOn { await vpn.start() } else { await stop() }
}
}
)) {
Expand DownExpand Up@@ -86,11 +93,21 @@ struct VPNMenu<VPN: VPNService, S: Session>: View {
}

private var vpnDisabled: Bool {
!session.hasSession ||
waitCleanup ||
!session.hasSession ||
vpn.state == .connecting ||
vpn.state == .disconnecting ||
vpn.state == .failed(.systemExtensionError(.needsUserApproval))
}

private func stop() async {
await vpn.stop()
waitCleanup = true
Task {
try? await Task.sleep(for: waitCleanupDuration)
waitCleanup = false
}
}
}

func openSystemExtensionSettings() {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp