File tree Expand file tree Collapse file tree 5 files changed +19
-4
lines changed Expand file tree Collapse file tree 5 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -78,4 +78,6 @@ final class PreviewVPN: Coder_Desktop.VPNService {
7878 func configureTunnelProviderProtocol( proto _: NETunnelProviderProtocol? ) {
7979 state = . connecting
8080 }
81+
82+ var startWhenReady: Bool = false
8183}
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ protocol VPNService: ObservableObject {
1010 func start( ) async
1111 func stop( ) async
1212 func configureTunnelProviderProtocol( proto: NETunnelProviderProtocol ? )
13+ var startWhenReady : Bool { get set }
1314}
1415
1516enum VPNServiceState : Equatable {
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ struct VPNMenu<VPN: VPNService>: View {
44 @EnvironmentObject var vpn : VPN
55 @EnvironmentObject var state : AppState
66 @Environment ( \. openSettings) private var openSettings
7+ @Environment ( \. openWindow) private var openWindow
78
89 let inspection = Inspection < Self > ( )
910
@@ -16,7 +17,18 @@ struct VPNMenu<VPN: VPNService>: View {
1617 Toggle ( isOn: Binding (
1718 get: { vpn. state == . connected || vpn. state == . connecting } ,
1819 set: { isOn in Task {
19- if isOn { await vpn. start ( ) } else { await vpn. stop ( ) }
20+ if isOn {
21+ // Clicking the toggle while logged out should
22+ // open the login window, then start the VPN asap
23+ if !state. hasSession {
24+ vpn. startWhenReady = true
25+ openWindow ( id: . login)
26+ } else {
27+ await vpn. start ( )
28+ }
29+ } else {
30+ await vpn. stop ( )
31+ }
2032 }
2133 }
2234 ) ) {
@@ -86,8 +98,7 @@ struct VPNMenu<VPN: VPNService>: View {
8698 }
8799
88100 private var vpnDisabled : Bool {
89- !state. hasSession ||
90- vpn. state == . connecting ||
101+ vpn. state == . connecting ||
91102 vpn. state == . disconnecting ||
92103 // Prevent starting the VPN before the user has approved the system extension.
93104 vpn. state == . failed( . systemExtensionError( . needsUserApproval) )
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ class MockVPNService: VPNService, ObservableObject {
2323 }
2424
2525 func configureTunnelProviderProtocol( proto _: NETunnelProviderProtocol ? ) { }
26+ var startWhenReady : Bool = false
2627}
2728
2829extension Inspection : @unchecked Sendable , @retroactive InspectionEmissary { }
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ struct VPNMenuTests {
2323 try await ViewHosting . host ( view) {
2424 try await sut. inspection. inspect { view in
2525 let toggle = try view. find ( ViewType . Toggle. self)
26- #expect( toggle. isDisabled ( ) )
26+ #expect( ! toggle. isDisabled ( ) )
2727 #expect( throws: Never . self) { try view. find ( text: " Sign in to use Coder Desktop " ) }
2828 #expect( throws: Never . self) { try view. find ( button: " Sign in " ) }
2929 }
You can’t perform that action at this time.
0 commit comments