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

Commitddf21a7

Browse files
fix: connect to xpc on vpn start (#40)
1 parent47d0464 commitddf21a7

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

‎Coder Desktop/Coder Desktop/VPNService.swift

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ final class CoderVPNService: NSObject, VPNService {
7070
Task{
7171
awaitloadNetworkExtensionConfig()
7272
}
73-
xpc.connect()
74-
xpc.getPeerState()
7573
NotificationCenter.default.addObserver(
7674
self,
7775
selector: #selector(vpnDidUpdate(_:)),
@@ -93,8 +91,6 @@ final class CoderVPNService: NSObject, VPNService {
9391
}
9492

9593
awaitstartTunnel()
96-
xpc.connect()
97-
xpc.ping()
9894
logger.debug("network extension enabled")
9995
}
10096

@@ -162,28 +158,47 @@ final class CoderVPNService: NSObject, VPNService {
162158
}
163159

164160
extensionCoderVPNService{
161+
// The number of NETunnelProviderSession states makes the excessive branching
162+
// necessary.
163+
// swiftlint:disable:next cyclomatic_complexity
165164
@objcprivatefunc vpnDidUpdate(_ notification:Notification){
166165
guardlet connection= notification.objectas?NETunnelProviderSessionelse{
167166
return
168167
}
169-
switch connection.status{
170-
case.disconnected:
168+
switch(tunnelState, connection.status){
169+
// Any -> Disconnected: Update UI w/ error if present
170+
case(_,.disconnected):
171171
connection.fetchLastDisconnectError{ errin
172172
self.tunnelState=iflet err{
173173
.failed(.internalError(err.localizedDescription))
174174
}else{
175175
.disabled
176176
}
177177
}
178-
case.connecting:
178+
// Connecting -> Connecting: no-op
179+
case(.connecting,.connecting):
180+
break
181+
// Connected -> Connected: no-op
182+
case(.connected,.connected):
183+
break
184+
// Non-connecting -> Connecting: Establish XPC
185+
case(_,.connecting):
186+
xpc.connect()
187+
xpc.ping()
179188
tunnelState=.connecting
180-
case.connected:
189+
// Non-connected -> Connected: Retrieve Peers
190+
case(_,.connected):
191+
xpc.connect()
192+
xpc.getPeerState()
181193
tunnelState=.connected
182-
case.reasserting:
194+
// Any -> Reasserting
195+
case(_,.reasserting):
183196
tunnelState=.connecting
184-
case.disconnecting:
197+
// Any -> Disconnecting
198+
case(_,.disconnecting):
185199
tunnelState=.disconnecting
186-
case.invalid:
200+
// Any -> Invalid
201+
case(_,.invalid):
187202
tunnelState=.failed(.networkExtensionError(.unconfigured))
188203
@unknowndefault:
189204
tunnelState=.disabled

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp