diff --git a/library/src/network.rs b/library/src/network.rs index 2248bd3..1504bc8 100644 --- a/library/src/network.rs +++ b/library/src/network.rs @@ -247,12 +247,22 @@ pub struct PatchCheckRequest { /// The unique ID of this device. This is a random UUID generated by Shorebird and _not_ the /// device's UUID or any other identifier that has meaning outside of Shorebird. pub client_id: String, - // We specifically do not send a patch number as part of this request because we always want to - // know what the latest available patch is. + /// The number of the patch currently running on the device, if any. + /// + /// Supersedes the legacy `patch_number` field. `patch_number` is + /// retained server-side for compatibility with older clients that still + /// rely on its short-circuit response path; newer updaters populate + /// this field instead. + #[serde(skip_serializing_if = "Option::is_none")] + pub current_patch_number: Option, } impl PatchCheckRequest { - pub fn new(config: &UpdateConfig, client_id: &str) -> PatchCheckRequest { + pub fn new( + config: &UpdateConfig, + client_id: &str, + current_patch_number: Option, + ) -> PatchCheckRequest { PatchCheckRequest { app_id: config.app_id.clone(), channel: config.channel.clone(), @@ -260,6 +270,7 @@ impl PatchCheckRequest { platform: current_platform().to_string(), arch: current_arch().to_string(), client_id: client_id.to_string(), + current_patch_number, } } } @@ -404,6 +415,7 @@ mod tests { platform: "".to_string(), arch: "".to_string(), client_id: "".to_string(), + current_patch_number: None, }, ); assert!(result.is_err()); diff --git a/library/src/updater.rs b/library/src/updater.rs index bcde590..e7c5aa8 100644 --- a/library/src/updater.rs +++ b/library/src/updater.rs @@ -273,7 +273,12 @@ pub fn should_auto_update() -> anyhow::Result { /// Returns true if an update is available for download. Will return false if the update is already /// downloaded and ready to install. pub fn check_for_downloadable_update(channel: Option<&str>) -> anyhow::Result { - let client_id = with_state(|state| Ok(state.client_id()))?; + let (client_id, current_patch_number) = with_state(|state| { + Ok(( + state.client_id().to_string(), + state.currently_booting_patch().map(|p| p.number), + )) + })?; let (request, url, request_fn) = with_config(|config| { let mut config = config.clone(); @@ -283,7 +288,7 @@ pub fn check_for_downloadable_update(channel: Option<&str>) -> anyhow::Result) -> anyhow::Resul shorebird_error!("Failed to clear events: {:?}", err); } // Update our outer state with the new state. - Ok(PatchCheckRequest::new(&config, &state.client_id())) + Ok(PatchCheckRequest::new( + &config, + &state.client_id(), + state.currently_booting_patch().map(|p| p.number), + )) })?; // Check for update.