File tree 5 files changed +19
-4
lines changed
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 {
78
78
func configureTunnelProviderProtocol( proto _: NETunnelProviderProtocol? ) {
79
79
state = . connecting
80
80
}
81
+
82
+ var startWhenReady: Bool = false
81
83
}
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ protocol VPNService: ObservableObject {
10
10
func start( ) async
11
11
func stop( ) async
12
12
func configureTunnelProviderProtocol( proto: NETunnelProviderProtocol ? )
13
+ var startWhenReady : Bool { get set }
13
14
}
14
15
15
16
enum VPNServiceState : Equatable {
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ struct VPNMenu<VPN: VPNService>: View {
4
4
@EnvironmentObject var vpn : VPN
5
5
@EnvironmentObject var state : AppState
6
6
@Environment ( \. openSettings) private var openSettings
7
+ @Environment ( \. openWindow) private var openWindow
7
8
8
9
let inspection = Inspection < Self > ( )
9
10
@@ -16,7 +17,18 @@ struct VPNMenu<VPN: VPNService>: View {
16
17
Toggle ( isOn: Binding (
17
18
get: { vpn. state == . connected || vpn. state == . connecting } ,
18
19
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
+ }
20
32
}
21
33
}
22
34
) ) {
@@ -86,8 +98,7 @@ struct VPNMenu<VPN: VPNService>: View {
86
98
}
87
99
88
100
private var vpnDisabled : Bool {
89
- !state. hasSession ||
90
- vpn. state == . connecting ||
101
+ vpn. state == . connecting ||
91
102
vpn. state == . disconnecting ||
92
103
// Prevent starting the VPN before the user has approved the system extension.
93
104
vpn. state == . failed( . systemExtensionError( . needsUserApproval) )
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ class MockVPNService: VPNService, ObservableObject {
23
23
}
24
24
25
25
func configureTunnelProviderProtocol( proto _: NETunnelProviderProtocol ? ) { }
26
+ var startWhenReady : Bool = false
26
27
}
27
28
28
29
extension Inspection : @unchecked Sendable , @retroactive InspectionEmissary { }
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ struct VPNMenuTests {
23
23
try await ViewHosting . host ( view) {
24
24
try await sut. inspection. inspect { view in
25
25
let toggle = try view. find ( ViewType . Toggle. self)
26
- #expect( toggle. isDisabled ( ) )
26
+ #expect( ! toggle. isDisabled ( ) )
27
27
#expect( throws: Never . self) { try view. find ( text: " Sign in to use Coder Desktop " ) }
28
28
#expect( throws: Never . self) { try view. find ( button: " Sign in " ) }
29
29
}
You can’t perform that action at this time.
0 commit comments