Skip to content

fix: prompt for sign in when toggling coder connect on #204

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 9 additions & 6 deletions Coder-Desktop/Coder-Desktop/Views/VPN/VPNMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,15 @@ struct VPNMenu<VPN: VPNService, FS: FileSyncDaemon>: View {
}

private var vpnDisabled: Bool {
vpn.state == .connecting ||
vpn.state == .disconnecting ||
// Prevent starting the VPN before the user has approved the system extension.
vpn.state == .failed(.systemExtensionError(.needsUserApproval)) ||
// Prevent starting the VPN without a VPN configuration.
vpn.state == .failed(.networkExtensionError(.unconfigured))
// Always enabled if signed out, as that will open the sign in window
state.hasSession && (
vpn.state == .connecting ||
vpn.state == .disconnecting ||
// Prevent starting the VPN before the user has approved the system extension.
vpn.state == .failed(.systemExtensionError(.needsUserApproval)) ||
// Prevent starting the VPN without a VPN configuration.
vpn.state == .failed(.networkExtensionError(.unconfigured))
)
}
}

Expand Down
17 changes: 17 additions & 0 deletions Coder-Desktop/Coder-DesktopTests/VPNMenuTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ struct VPNMenuTests {
}
}

@Test
func testVPNLoggedOutUnconfigured() async throws {
vpn.state = .failed(.networkExtensionError(.unconfigured))
try await ViewHosting.host(view) {
try await sut.inspection.inspect { view in
let toggle = try view.find(ViewType.Toggle.self)
// Toggle should be enabled even with a failure that would
// normally make it disabled, because we're signed out.
#expect(!toggle.isDisabled())
#expect(throws: Never.self) { try view.find(text: "Sign in to use Coder Desktop") }
#expect(throws: Never.self) { try view.find(button: "Sign in") }
}
}
}

@Test
func testStartStopCalled() async throws {
try await ViewHosting.host(view) {
Expand Down Expand Up @@ -59,6 +74,7 @@ struct VPNMenuTests {
@Test
func testVPNDisabledWhileConnecting() async throws {
vpn.state = .disabled
state.login(baseAccessURL: URL(string: "https://coder.example.com")!, sessionToken: "fake-token")

try await ViewHosting.host(view) {
try await sut.inspection.inspect { view in
Expand All @@ -79,6 +95,7 @@ struct VPNMenuTests {
@Test
func testVPNDisabledWhileDisconnecting() async throws {
vpn.state = .disabled
state.login(baseAccessURL: URL(string: "https://coder.example.com")!, sessionToken: "fake-token")

try await ViewHosting.host(view) {
try await sut.inspection.inspect { view in
Expand Down
Loading