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

Commit2603ace

Browse files
chore: prompt for sign in when turning VPN on if signed out (#114)
Closes#106.
1 parent111b30c commit2603ace

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

‎Coder-Desktop/Coder-Desktop/Preview Content/PreviewVPN.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

‎Coder-Desktop/Coder-Desktop/VPN/VPNService.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ protocol VPNService: ObservableObject {
1010
func start()async
1111
func stop()async
1212
func configureTunnelProviderProtocol(proto:NETunnelProviderProtocol?)
13+
varstartWhenReady:Bool{getset}
1314
}
1415

1516
enumVPNServiceState:Equatable{

‎Coder-Desktop/Coder-Desktop/Views/VPNMenu.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ struct VPNMenu<VPN: VPNService>: View {
44
@EnvironmentObjectvarvpn:VPN
55
@EnvironmentObjectvarstate:AppState
66
@Environment(\.openSettings)privatevaropenSettings
7+
@Environment(\.openWindow)privatevaropenWindow
78

89
letinspection=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:{ isOninTask{
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
privatevarvpnDisabled: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))

‎Coder-Desktop/Coder-DesktopTests/Util.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class MockVPNService: VPNService, ObservableObject {
2323
}
2424

2525
func configureTunnelProviderProtocol(proto _:NETunnelProviderProtocol?){}
26+
varstartWhenReady:Bool=false
2627
}
2728

2829
extensionInspection:@uncheckedSendable,@retroactiveInspectionEmissary{}

‎Coder-Desktop/Coder-DesktopTests/VPNMenuTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct VPNMenuTests {
2323
tryawaitViewHosting.host(view){
2424
tryawait sut.inspection.inspect{ viewin
2525
lettoggle=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
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp