diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 0000000..656e08b --- /dev/null +++ b/.cargo/config @@ -0,0 +1,2 @@ +[net] +git-fetch-with-cli = true \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 5a1b7f2..83e0c4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,7 +78,7 @@ async fn start() { ); return; } - + let spotify = match Spotify::new( &settings.username, &settings.password, @@ -143,60 +143,61 @@ async fn start() { e ) ); - } else { - let refresh = Duration::from_secs(settings.refresh_ui_seconds); - let now = Instant::now(); - let mut time_elapsed: u64; - - 'outer: loop { - print!("{esc}[2J{esc}[1;1H", esc = 27 as char); - let mut exit_flag: i8 = 1; - - for download in downloader.get_downloads().await { - let state = download.state; - - let progress: String; - - if state != DownloadState::Done { - exit_flag &= 0; - progress = match state { - DownloadState::Downloading(r, t) => { - let p = r as f32 / t as f32 * 100.0; - if p > 100.0 { - "100%".to_string() - } else { - format!("{}%", p as i8) - } - } - DownloadState::Post => "Postprocessing... ".to_string(), - DownloadState::None => "Preparing... ".to_string(), - DownloadState::Lock => "Preparing... ".to_string(), - DownloadState::Error(e) => { - exit_flag |= 1; - format!("{} ", e) - } - DownloadState::Done => { - exit_flag |= 1; - "Impossible state".to_string() - } - }; - } else { - progress = "Done.".to_string(); - } - - println!("{:<19}| {}", progress, download.title); - } - time_elapsed = now.elapsed().as_secs(); - if exit_flag == 1 { - break 'outer; - } - - println!("\nElapsed second(s): {}", time_elapsed); - task::sleep(refresh).await - } - println!("Finished download(s) in {} second(s).", time_elapsed); + return; } } + + let refresh = Duration::from_secs(settings.refresh_ui_seconds); + let now = Instant::now(); + let mut time_elapsed: u64; + + 'outer: loop { + print!("{esc}[2J{esc}[1;1H", esc = 27 as char); + let mut exit_flag: i8 = 1; + + for download in downloader.get_downloads().await { + let state = download.state; + + let progress: String; + + if state != DownloadState::Done { + exit_flag &= 0; + progress = match state { + DownloadState::Downloading(r, t) => { + let p = r as f32 / t as f32 * 100.0; + if p > 100.0 { + "100%".to_string() + } else { + format!("{}%", p as i8) + } + } + DownloadState::Post => "Postprocessing... ".to_string(), + DownloadState::None => "Preparing... ".to_string(), + DownloadState::Lock => "Preparing... ".to_string(), + DownloadState::Error(e) => { + exit_flag |= 1; + format!("{} ", e) + } + DownloadState::Done => { + exit_flag |= 1; + "Impossible state".to_string() + } + }; + } else { + progress = "Done.".to_string(); + } + + println!("{:<19}| {}", progress, download.title); + } + time_elapsed = now.elapsed().as_secs(); + if exit_flag == 1 { + break 'outer; + } + + println!("\nElapsed second(s): {}", time_elapsed); + task::sleep(refresh).await + } + println!("Finished download(s) in {} second(s).", time_elapsed); } Err(e) => { error!("{} {}", "Handling input failed:".red(), e)