omaha_client/state_machine/
observer.rsuse crate::{
common::{ProtocolState, UpdateCheckSchedule},
installer::ProgressObserver,
protocol::response::Response,
state_machine::{update_check, State, UpdateCheckError},
};
use futures::{channel::mpsc, future::BoxFuture, prelude::*};
#[derive(Debug)]
pub enum StateMachineEvent {
StateChange(State),
ScheduleChange(UpdateCheckSchedule),
ProtocolStateChange(ProtocolState),
UpdateCheckResult(Result<update_check::Response, UpdateCheckError>),
InstallProgressChange(InstallProgress),
OmahaServerResponse(Response),
InstallerError(Option<Box<dyn std::error::Error + Send + 'static>>),
}
#[derive(Debug)]
pub struct InstallProgress {
pub progress: f32,
}
pub(super) struct StateMachineProgressObserver(pub(super) mpsc::Sender<InstallProgress>);
impl ProgressObserver for StateMachineProgressObserver {
fn receive_progress(
&self,
_operation: Option<&str>,
progress: f32,
_total_size: Option<u64>,
_size_so_far: Option<u64>,
) -> BoxFuture<'_, ()> {
async move {
let _ = self.0.clone().send(InstallProgress { progress }).await;
}
.boxed()
}
}