@@ -29,16 +29,7 @@ protocol SystemExtensionAsyncRecorder: Sendable {
29
29
extension CoderVPNService : SystemExtensionAsyncRecorder {
30
30
func recordSystemExtensionState( _ state: SystemExtensionState ) async {
31
31
sysExtnState = state
32
- if state == . uninstalled {
33
- installSystemExtension ( )
34
- }
35
32
if state == . installed {
36
- do {
37
- try await getTunnelManager ( )
38
- neState = . disabled
39
- } catch {
40
- neState = . unconfigured
41
- }
42
33
// system extension was successfully installed, so we don't need the delegate any more
43
34
systemExtnDelegate = nil
44
35
}
@@ -73,21 +64,7 @@ extension CoderVPNService: SystemExtensionAsyncRecorder {
73
64
return extensionBundle
74
65
}
75
66
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( ) {
91
68
logger. info ( " activating SystemExtension " )
92
69
guard let bundleID = extensionBundle. bundleIdentifier else {
93
70
logger. error ( " Bundle has no identifier " )
@@ -97,9 +74,11 @@ extension CoderVPNService: SystemExtensionAsyncRecorder {
97
74
forExtensionWithIdentifier: bundleID,
98
75
queue: . main
99
76
)
100
- request. delegate = systemExtnDelegate
77
+ let delegate = SystemExtensionDelegate ( asyncDelegate: self )
78
+ systemExtnDelegate = delegate
79
+ request. delegate = delegate
101
80
OSSystemExtensionManager . shared. submitRequest ( request)
102
- logger. info ( " submitted SystemExtension activate request with bundleID: \( bundleID) " )
81
+ logger. info ( " submitted SystemExtension request with bundleID: \( bundleID) " )
103
82
}
104
83
}
105
84
@@ -109,8 +88,6 @@ class SystemExtensionDelegate<AsyncDelegate: SystemExtensionAsyncRecorder>:
109
88
NSObject , OSSystemExtensionRequestDelegate
110
89
{
111
90
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
114
91
private var asyncDelegate : AsyncDelegate
115
92
116
93
init ( asyncDelegate: AsyncDelegate ) {
@@ -161,38 +138,4 @@ class SystemExtensionDelegate<AsyncDelegate: SystemExtensionAsyncRecorder>:
161
138
logger. info ( " Replacing \( request. identifier) v \( existing. bundleShortVersion) with v \( `extension`. bundleShortVersion) " )
162
139
return . replace
163
140
}
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
- }
198
141
}
0 commit comments