@@ -29,16 +29,7 @@ protocol SystemExtensionAsyncRecorder: Sendable {
2929extension CoderVPNService : SystemExtensionAsyncRecorder {
3030 func recordSystemExtensionState( _ state: SystemExtensionState ) async {
3131 sysExtnState = state
32- if state == . uninstalled {
33- installSystemExtension ( )
34- }
3532 if state == . installed {
36- do {
37- try await getTunnelManager ( )
38- neState = . disabled
39- } catch {
40- neState = . unconfigured
41- }
4233 // system extension was successfully installed, so we don't need the delegate any more
4334 systemExtnDelegate = nil
4435 }
@@ -73,21 +64,7 @@ extension CoderVPNService: SystemExtensionAsyncRecorder {
7364 return extensionBundle
7465 }
7566
76- func attemptSystemExtensionInstall( ) {
77- logger. info ( " checking SystemExtension status " )
78- guard let bundleID = extensionBundle. bundleIdentifier else {
79- logger. error ( " Bundle has no identifier " )
80- return
81- }
82- let request = OSSystemExtensionRequest . propertiesRequest ( forExtensionWithIdentifier: bundleID, queue: . main)
83- let delegate = SystemExtensionDelegate ( asyncDelegate: self )
84- request. delegate = delegate
85- systemExtnDelegate = delegate
86- OSSystemExtensionManager . shared. submitRequest ( request)
87- logger. info ( " submitted SystemExtension properties request with bundleID: \( bundleID) " )
88- }
89-
90- private func installSystemExtension( ) {
67+ func installSystemExtension( ) {
9168 logger. info ( " activating SystemExtension " )
9269 guard let bundleID = extensionBundle. bundleIdentifier else {
9370 logger. error ( " Bundle has no identifier " )
@@ -97,9 +74,11 @@ extension CoderVPNService: SystemExtensionAsyncRecorder {
9774 forExtensionWithIdentifier: bundleID,
9875 queue: . main
9976 )
100- request. delegate = systemExtnDelegate
77+ let delegate = SystemExtensionDelegate ( asyncDelegate: self )
78+ systemExtnDelegate = delegate
79+ request. delegate = delegate
10180 OSSystemExtensionManager . shared. submitRequest ( request)
102- logger. info ( " submitted SystemExtension activate request with bundleID: \( bundleID) " )
81+ logger. info ( " submitted SystemExtension request with bundleID: \( bundleID) " )
10382 }
10483}
10584
@@ -109,8 +88,6 @@ class SystemExtensionDelegate<AsyncDelegate: SystemExtensionAsyncRecorder>:
10988 NSObject , OSSystemExtensionRequestDelegate
11089{
11190 private var logger = Logger ( subsystem: Bundle . main. bundleIdentifier!, category: " vpn-installer " )
112- // TODO: Refactor this to use a continuation, so the result of a request can be
113- // 'await'd for the determined state
11491 private var asyncDelegate : AsyncDelegate
11592
11693 init ( asyncDelegate: AsyncDelegate ) {
@@ -161,38 +138,4 @@ class SystemExtensionDelegate<AsyncDelegate: SystemExtensionAsyncRecorder>:
161138 logger. info ( " Replacing \( request. identifier) v \( existing. bundleShortVersion) with v \( `extension`. bundleShortVersion) " )
162139 return . replace
163140 }
164-
165- public func request(
166- _: OSSystemExtensionRequest ,
167- foundProperties properties: [ OSSystemExtensionProperties ]
168- ) {
169- // In debug builds we always replace the SE to test
170- // changes made without bumping the version
171- #if DEBUG
172- Task { [ asyncDelegate] in
173- await asyncDelegate. recordSystemExtensionState ( . uninstalled)
174- }
175- return
176- #else
177- let version = Bundle . main. object ( forInfoDictionaryKey: " CFBundleVersion " ) as? String
178- let shortVersion = Bundle . main. object ( forInfoDictionaryKey: " CFBundleShortVersionString " ) as? String
179-
180- let versionMatches = properties. contains { sysex in
181- sysex. isEnabled
182- && sysex. bundleVersion == version
183- && sysex. bundleShortVersion == shortVersion
184- }
185- if versionMatches {
186- Task { [ asyncDelegate] in
187- await asyncDelegate. recordSystemExtensionState ( . installed)
188- }
189- return
190- }
191-
192- // Either uninstalled or needs replacing
193- Task { [ asyncDelegate] in
194- await asyncDelegate. recordSystemExtensionState ( . uninstalled)
195- }
196- #endif
197- }
198141}
0 commit comments