spotify_launcher/
progress.rs1use crate::errors::*;
2use crate::ui::Zenity;
3use tokio::io::AsyncWriteExt;
4
5pub struct ProgressBar {
6 ui: Zenity,
7}
8
9impl ProgressBar {
10 pub fn spawn() -> Result<ProgressBar> {
11 let ui = Zenity::spawn(&[
12 "--progress",
13 "--title",
14 "Downloading spotify",
15 "--text=Downloading...",
16 "--no-cancel",
17 "--ok-label",
18 "😺",
19 ])?;
20 Ok(ProgressBar { ui })
21 }
22
23 pub async fn update(&mut self, progress: u64) -> Result<()> {
24 if let Some(stdin) = &mut self.ui.child.stdin {
25 let buf = format!("{}\n", progress);
26 stdin.write_all(buf.as_bytes()).await?;
27 stdin.flush().await?;
28 }
29 Ok(())
30 }
31
32 pub async fn close(&mut self) -> Result<()> {
33 self.ui.child.kill().await?;
34 Ok(())
35 }
36}