@@ -40,12 +40,13 @@ actor Manager {
4040 dest: dest,
4141 urlSession: URLSession ( configuration: sessionConfig)
4242 ) { progress in
43- pushProgress ( msg: " Downloading library... \n \( progress. description) " )
43+ // TODO: Debounce, somehow
44+ pushProgress ( stage: . downloading, downloadProgress: progress)
4445 }
4546 } catch {
4647 throw . download( error)
4748 }
48- pushProgress ( msg : " Fetching server version... " )
49+ pushProgress ( stage : . validating )
4950 let client = Client ( url: cfg. serverUrl)
5051 let buildInfo : BuildInfoResponse
5152 do {
@@ -56,7 +57,6 @@ actor Manager {
5657 guard let semver = buildInfo. semver else {
5758 throw . serverInfo( " invalid version: \( buildInfo. version) " )
5859 }
59- pushProgress ( msg: " Validating library... " )
6060 do {
6161 try SignatureValidator . validate ( path: dest, expectedVersion: semver)
6262 } catch {
@@ -67,13 +67,13 @@ actor Manager {
6767 // so it's safe to execute. However, the SE must be sandboxed, so we defer to the app.
6868 try await removeQuarantine ( dest)
6969
70- pushProgress ( msg : " Opening library... " )
70+ pushProgress ( stage : . opening )
7171 do {
7272 try tunnelHandle = TunnelHandle ( dylibPath: dest)
7373 } catch {
7474 throw . tunnelSetup( error)
7575 }
76- pushProgress ( msg : " Setting up tunnel... " )
76+ pushProgress ( stage : . settingUpTunnel )
7777 speaker = await Speaker < Vpn_ManagerMessage , Vpn_TunnelMessage > (
7878 writeFD: tunnelHandle. writeHandle,
7979 readFD: tunnelHandle. readHandle
@@ -168,8 +168,7 @@ actor Manager {
168168 }
169169
170170 func startVPN( ) async throws ( ManagerError) {
171- // Clear progress message
172- pushProgress ( msg: nil )
171+ pushProgress ( stage: . startingTunnel)
173172 logger. info ( " sending start rpc " )
174173 guard let tunFd = ptp. tunnelFileDescriptor else {
175174 logger. error ( " no fd " )
@@ -246,13 +245,13 @@ actor Manager {
246245 }
247246}
248247
249- func pushProgress( msg : String ? ) {
248+ func pushProgress( stage : ProgressStage , downloadProgress : DownloadProgress ? = nil ) {
250249 guard let conn = globalXPCListenerDelegate. conn else {
251250 logger. warning ( " couldn't send progress message to app: no connection " )
252251 return
253252 }
254- logger. debug ( " sending progress message to app: \( msg ?? " nil " ) " )
255- conn. onProgress ( msg : msg )
253+ logger. debug ( " sending progress message to app " )
254+ conn. onProgress ( stage : stage , downloadProgress : downloadProgress )
256255}
257256
258257struct ManagerConfig {
@@ -333,7 +332,7 @@ private func removeQuarantine(_ dest: URL) async throws(ManagerError) {
333332 let file = NSURL ( fileURLWithPath: dest. path)
334333 try ? file. getResourceValue ( & flag, forKey: kCFURLQuarantinePropertiesKey as URLResourceKey )
335334 if flag != nil {
336- pushProgress ( msg : " Unquarantining download... " )
335+ pushProgress ( stage : . removingQuarantine )
337336 // Try the privileged helper first (it may not even be registered)
338337 if await globalHelperXPCSpeaker. tryRemoveQuarantine ( path: dest. path) {
339338 // Success!
0 commit comments