@@ -35,7 +35,7 @@ const DOWNLOAD_TIMEOUT: Duration = Duration::from_secs(15);
35
35
const UPDATE_INTERVAL : Duration = Duration :: from_secs ( 60 * 60 * 24 ) ;
36
36
/// Wait this long until next try if an update failed
37
37
const UPDATE_INTERVAL_ERROR : Duration = Duration :: from_secs ( 60 * 60 * 6 ) ;
38
- /// Retry strategy for `RunVersionCheck `.
38
+ /// Retry strategy for `GetVersionInfo `.
39
39
const IMMEDIATE_RETRY_STRATEGY : ConstantInterval = ConstantInterval :: new ( Duration :: ZERO , Some ( 3 ) ) ;
40
40
41
41
#[ cfg( target_os = "linux" ) ]
@@ -104,8 +104,8 @@ pub(crate) struct VersionUpdater {
104
104
rx : Option < mpsc:: Receiver < VersionUpdaterCommand > > ,
105
105
availability_handle : ApiAvailabilityHandle ,
106
106
107
- /// Oneshot channels for responding to [VersionUpdaterCommand::RunVersionCheck ].
108
- run_version_check_responders : Vec < oneshot:: Sender < AppVersionInfo > > ,
107
+ /// Oneshot channels for responding to [VersionUpdaterCommand::GetVersionInfo ].
108
+ get_version_info_responders : Vec < oneshot:: Sender < AppVersionInfo > > ,
109
109
}
110
110
111
111
#[ derive( Clone ) ]
@@ -115,7 +115,7 @@ pub(crate) struct VersionUpdaterHandle {
115
115
116
116
enum VersionUpdaterCommand {
117
117
SetShowBetaReleases ( bool ) ,
118
- RunVersionCheck ( oneshot:: Sender < AppVersionInfo > ) ,
118
+ GetVersionInfo ( oneshot:: Sender < AppVersionInfo > ) ,
119
119
}
120
120
121
121
impl VersionUpdaterHandle {
@@ -132,11 +132,15 @@ impl VersionUpdaterHandle {
132
132
}
133
133
}
134
134
135
- pub async fn run_version_check ( & mut self ) -> Result < AppVersionInfo , Error > {
135
+ /// Get the latest cached [AppVersionInfo].
136
+ ///
137
+ /// If the cache is stale or missing, this will immediately query the API for the latest
138
+ /// version. This may take a few seconds.
139
+ pub async fn get_version_info ( & mut self ) -> Result < AppVersionInfo , Error > {
136
140
let ( done_tx, done_rx) = oneshot:: channel ( ) ;
137
141
if self
138
142
. tx
139
- . send ( VersionUpdaterCommand :: RunVersionCheck ( done_tx) )
143
+ . send ( VersionUpdaterCommand :: GetVersionInfo ( done_tx) )
140
144
. await
141
145
. is_err ( )
142
146
{
@@ -174,7 +178,7 @@ impl VersionUpdater {
174
178
show_beta_releases,
175
179
rx : Some ( rx) ,
176
180
availability_handle,
177
- run_version_check_responders : vec ! [ ] ,
181
+ get_version_info_responders : vec ! [ ] ,
178
182
} ,
179
183
VersionUpdaterHandle { tx } ,
180
184
)
@@ -186,7 +190,7 @@ impl VersionUpdater {
186
190
}
187
191
188
192
/// Immediately query the API for the latest [AppVersionInfo].
189
- fn query_app_version (
193
+ fn do_version_check (
190
194
& mut self ,
191
195
) -> Pin <
192
196
Box < dyn Future < Output = Result < mullvad_api:: AppVersionResponse , Error > > + Send + ' static > ,
@@ -226,7 +230,7 @@ impl VersionUpdater {
226
230
/// [ApiAvailability](mullvad_api::availability::ApiAvailability).
227
231
///
228
232
/// On any error, this function retries repeatedly every [UPDATE_INTERVAL_ERROR] until success.
229
- fn query_app_version_in_background (
233
+ fn do_version_check_in_background (
230
234
& self ,
231
235
) -> Pin <
232
236
Box < dyn Future < Output = Result < mullvad_api:: AppVersionResponse , Error > > + Send + ' static > ,
@@ -328,9 +332,9 @@ impl VersionUpdater {
328
332
329
333
/// Update [Self::last_app_version_info] and write it to disk cache.
330
334
///
331
- /// Also, if we are currently have a pending [RunVersionCheck ][rvc] command, respond to it.
335
+ /// Also, if we are currently have a pending [GetVersionInfo ][rvc] command, respond to it.
332
336
///
333
- /// [rvc]: VersionUpdaterCommand::RunVersionCheck
337
+ /// [rvc]: VersionUpdaterCommand::GetVersionInfo
334
338
async fn update_version_info ( & mut self , new_version_info : AppVersionInfo ) {
335
339
// if daemon can't be reached, return immediately
336
340
if self . update_sender . send ( new_version_info. clone ( ) ) . is_err ( ) {
@@ -346,7 +350,7 @@ impl VersionUpdater {
346
350
/// Get the time left until [Self::last_app_version_info] becomes stale, and should be
347
351
/// refreshed, or [Duration::ZERO] if it already is stale.
348
352
///
349
- /// This happens [UPDATE_INTERVAL] after the last version query .
353
+ /// This happens [UPDATE_INTERVAL] after the last version check .
350
354
fn time_until_version_is_stale ( & self ) -> Duration {
351
355
let now = SystemTime :: now ( ) ;
352
356
self
@@ -360,13 +364,14 @@ impl VersionUpdater {
360
364
. unwrap_or ( Duration :: ZERO )
361
365
}
362
366
367
+ /// Is [Self::last_app_version_info] stale?
363
368
fn version_is_stale ( & self ) -> bool {
364
369
self . time_until_version_is_stale ( ) . is_zero ( )
365
370
}
366
371
367
372
/// Wait until [Self::last_app_version_info] becomes stale and needs to be refreshed.
368
373
///
369
- /// This happens [UPDATE_INTERVAL] after the last version query .
374
+ /// This happens [UPDATE_INTERVAL] after the last version check .
370
375
fn wait_until_version_is_stale ( & self ) -> Pin < Box < impl FusedFuture < Output = ( ) > > > {
371
376
let time_until_stale = self . time_until_version_is_stale ( ) ;
372
377
@@ -375,21 +380,21 @@ impl VersionUpdater {
375
380
Box :: pin ( talpid_time:: sleep ( time_until_stale) . fuse ( ) )
376
381
}
377
382
378
- /// Returns true if we are currently handling one or more `RunVersionCheck ` commands.
383
+ /// Returns true if we are currently handling one or more `GetVersionInfo ` commands.
379
384
fn is_running_version_check ( & self ) -> bool {
380
- !self . run_version_check_responders . is_empty ( )
385
+ !self . get_version_info_responders . is_empty ( )
381
386
}
382
387
383
388
pub async fn run ( mut self ) {
384
- let mut rx = self . rx . take ( ) . unwrap ( ) . fuse ( ) ;
389
+ let mut rx = self . rx . take ( ) . unwrap ( ) ;
385
390
let mut version_is_stale = self . wait_until_version_is_stale ( ) ;
386
391
let mut version_check = futures:: future:: Fuse :: terminated ( ) ;
387
392
388
393
// If this is a dev build, there's no need to pester the API for version checks.
389
394
if * IS_DEV_BUILD {
390
395
log:: warn!( "Not checking for updates because this is a development build" ) ;
391
396
while let Some ( cmd) = rx. next ( ) . await {
392
- if let VersionUpdaterCommand :: RunVersionCheck ( done_tx) = cmd {
397
+ if let VersionUpdaterCommand :: GetVersionInfo ( done_tx) = cmd {
393
398
log:: info!( "Version check is disabled in dev builds" ) ;
394
399
let _ = done_tx. send ( dev_version_cache ( ) ) ;
395
400
}
@@ -423,7 +428,7 @@ impl VersionUpdater {
423
428
}
424
429
}
425
430
426
- Some ( VersionUpdaterCommand :: RunVersionCheck ( done_tx) ) => {
431
+ Some ( VersionUpdaterCommand :: GetVersionInfo ( done_tx) ) => {
427
432
if self . update_sender. is_closed( ) {
428
433
return ;
429
434
}
@@ -435,9 +440,9 @@ impl VersionUpdater {
435
440
_ => {
436
441
// otherwise, start a foreground query to get the latest version_info.
437
442
if !self . is_running_version_check( ) {
438
- version_check = self . query_app_version ( ) . fuse( ) ;
443
+ version_check = self . do_version_check ( ) . fuse( ) ;
439
444
}
440
- self . run_version_check_responders . push( done_tx) ;
445
+ self . get_version_info_responders . push( done_tx) ;
441
446
}
442
447
}
443
448
}
@@ -455,7 +460,7 @@ impl VersionUpdater {
455
460
if self . is_running_version_check( ) {
456
461
continue ;
457
462
}
458
- version_check = self . query_app_version_in_background ( ) . fuse( ) ;
463
+ version_check = self . do_version_check_in_background ( ) . fuse( ) ;
459
464
} ,
460
465
461
466
response = version_check => {
@@ -468,8 +473,8 @@ impl VersionUpdater {
468
473
let new_version_info =
469
474
self . response_to_version_info( version_info_response) ;
470
475
471
- // Respond to all pending RunVersionCheck commands
472
- for done_tx in self . run_version_check_responders . drain( ..) {
476
+ // Respond to all pending GetVersionInfo commands
477
+ for done_tx in self . get_version_info_responders . drain( ..) {
473
478
let _ = done_tx. send( new_version_info. clone( ) ) ;
474
479
}
475
480
@@ -478,7 +483,7 @@ impl VersionUpdater {
478
483
}
479
484
Err ( err) => {
480
485
log:: error!( "Failed to fetch version info: {err:#}" ) ;
481
- self . run_version_check_responders . clear( ) ;
486
+ self . get_version_info_responders . clear( ) ;
482
487
}
483
488
}
484
489
0 commit comments