libobs_bootstrapper/
status_handler.rs1use std::{convert::Infallible, fmt::Debug};
2
3pub trait ObsBootstrapStatusHandler: Debug + Send + Sync {
5 type Error: std::error::Error + Send + Sync + 'static;
6
7 fn handle_downloading(&mut self, progress: f32, message: String) -> Result<(), Self::Error>;
11
12 fn handle_extraction(&mut self, progress: f32, message: String) -> Result<(), Self::Error>;
16}
17
18#[derive(Debug)]
19pub struct ObsBootstrapConsoleHandler {
20 last_download_percentage: f32,
21 last_extract_percentage: f32,
22}
23
24#[cfg_attr(coverage_nightly, coverage(off))]
25impl Default for ObsBootstrapConsoleHandler {
26 fn default() -> Self {
27 Self {
28 last_download_percentage: 0.0,
29 last_extract_percentage: 0.0,
30 }
31 }
32}
33
34#[cfg_attr(coverage_nightly, coverage(off))]
35impl ObsBootstrapStatusHandler for ObsBootstrapConsoleHandler {
36 type Error = Infallible;
37
38 fn handle_downloading(&mut self, progress: f32, message: String) -> Result<(), Infallible> {
39 if progress - self.last_download_percentage >= 0.05 || progress == 1.0 {
40 self.last_download_percentage = progress;
41 println!("Downloading: {}% - {}", progress * 100.0, message);
42 }
43 Ok(())
44 }
45
46 fn handle_extraction(&mut self, progress: f32, message: String) -> Result<(), Infallible> {
47 if progress - self.last_extract_percentage >= 0.05 || progress == 1.0 {
48 self.last_extract_percentage = progress;
49 println!("Extracting: {}% - {}", progress * 100.0, message);
50 }
51 Ok(())
52 }
53}