fix: put call to report launch success on bg thread. (#72)
* fix: use non-blocking http client when reporting launch success * Make patch install report request on bg thread * Pass client_id instead of state * Convert client_id from &str to String
This commit is contained in:
@@ -71,6 +71,10 @@ impl UpdaterState {
|
||||
slots: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn client_id_or_default(&self) -> String {
|
||||
self.client_id.clone().unwrap_or("".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
fn is_file_not_found(error: &anyhow::Error) -> bool {
|
||||
|
||||
@@ -291,19 +291,13 @@ pub fn send_patch_check_request(
|
||||
|
||||
pub fn report_successful_patch_install(
|
||||
config: &UpdateConfig,
|
||||
state: &UpdaterState,
|
||||
client_id: String,
|
||||
patch_number: usize,
|
||||
) -> anyhow::Result<()> {
|
||||
let client_id = state
|
||||
.client_id
|
||||
.clone()
|
||||
.unwrap_or("".to_string())
|
||||
.to_string();
|
||||
|
||||
let event = PatchInstallEvent::new(
|
||||
config.app_id.clone(),
|
||||
current_arch().to_string(),
|
||||
client_id.to_string(),
|
||||
client_id,
|
||||
patch_number,
|
||||
current_platform().to_string(),
|
||||
config.release_version.clone(),
|
||||
|
||||
@@ -384,11 +384,15 @@ pub fn report_launch_success() -> anyhow::Result<()> {
|
||||
// Ignore the error here, we'll try to activate the next best patch
|
||||
// even if we fail to mark this one as good.
|
||||
if state.mark_patch_as_good(patch.number).is_ok() {
|
||||
let report_result =
|
||||
report_successful_patch_install(&config, &state, patch.number);
|
||||
if let Err(err) = report_result {
|
||||
error!("Failed to report successful patch install: {:?}", err);
|
||||
}
|
||||
let config_copy = config.clone();
|
||||
let client_id = state.client_id_or_default();
|
||||
std::thread::spawn(move || {
|
||||
let report_result =
|
||||
report_successful_patch_install(&config_copy, client_id, patch.number);
|
||||
if let Err(err) = report_result {
|
||||
error!("Failed to report successful patch install: {:?}", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user