fix: linting

This commit is contained in:
Michel de Graaf
2025-11-19 08:40:41 +01:00
parent bb86e50b4f
commit 9f174c4c5e
9 changed files with 93 additions and 57 deletions
+13 -4
View File
@@ -384,7 +384,7 @@ impl Client {
username: String,
size: u64,
download_directory: String,
) -> Result<Receiver<DownloadStatus>> {
) -> Result<(Download, Receiver<DownloadStatus>)> {
info!("[client] Downloading {} from {}", filename, username);
let hash = md5::md5(&filename);
@@ -421,10 +421,13 @@ impl Client {
if !download_initiated {
let _ = download.sender.send(DownloadStatus::Failed);
self.context.write().unwrap().update_download_with_status(token, DownloadStatus::Failed);
self.context
.write()
.unwrap()
.update_download_with_status(token, DownloadStatus::Failed);
}
Ok(download_receiver)
Ok((download, download_receiver))
}
fn process_failed_uploads(
@@ -811,7 +814,13 @@ impl Client {
download.size
);
let _ = download.sender.send(DownloadStatus::Completed);
client_context.write().unwrap().update_download_with_status(download.token, DownloadStatus::Completed);
client_context
.write()
.unwrap()
.update_download_with_status(
download.token,
DownloadStatus::Completed,
);
}
Err(e) => {
trace!("[client] failed to download: {}", e);
+1 -3
View File
@@ -22,6 +22,4 @@ pub mod prelude {
pub use actor::server_actor::PeerAddress;
pub use client::{Client, ClientSettings};
pub use error::{Result, SoulseekRs};
pub use types::{
DownloadStatus, File, Search, SearchResult, Transfer,
};
pub use types::{DownloadStatus, File, Search, SearchResult, Transfer};
+10 -3
View File
@@ -242,7 +242,8 @@ impl DownloadPeer {
let client_guard = client_context
.read()
.map_err(|_| DownloadError::LockPoisoned)?;
let download_info = client_guard.get_download_by_token(token_u32).cloned();
let download_info =
client_guard.get_download_by_token(token_u32).cloned();
drop(client_guard);
download_info.ok_or(DownloadError::TokenNotFound(token_u32))
@@ -323,7 +324,10 @@ impl DownloadPeer {
speed_bytes_per_sec: speed,
};
let _ = dl.sender.send(status.clone());
client_context.write().unwrap().update_download_with_status(dl.token, status);
client_context
.write()
.unwrap()
.update_download_with_status(dl.token, status);
last_update_time = Instant::now();
}
@@ -421,7 +425,10 @@ impl DownloadPeer {
if let Some(ref dl) = download {
let _ = dl.sender.send(DownloadStatus::Queued);
client_context.write().unwrap().update_download_with_status(dl.token, DownloadStatus::Queued);
client_context
.write()
.unwrap()
.update_download_with_status(dl.token, DownloadStatus::Queued);
}
let mut stream = match stream {
+8 -1
View File
@@ -157,7 +157,14 @@ fn handle_file_connection(
) {
Ok((download, filename)) => {
let _ = download.sender.send(DownloadStatus::Completed);
context.client_context.write().unwrap().update_download_with_status(download.token, DownloadStatus::Completed);
context
.client_context
.write()
.unwrap()
.update_download_with_status(
download.token,
DownloadStatus::Completed,
);
info!(
"Successfully downloaded {} bytes to {}",
download.size, filename
+10 -3
View File
@@ -102,13 +102,17 @@ impl Download {
pub fn is_finished(&self) -> bool {
matches!(
self.status,
DownloadStatus::Completed | DownloadStatus::Failed | DownloadStatus::TimedOut
DownloadStatus::Completed
| DownloadStatus::Failed
| DownloadStatus::TimedOut
)
}
pub fn bytes_downloaded(&self) -> u64 {
match &self.status {
DownloadStatus::InProgress { bytes_downloaded, .. } => *bytes_downloaded,
DownloadStatus::InProgress {
bytes_downloaded, ..
} => *bytes_downloaded,
DownloadStatus::Completed => self.size,
_ => 0,
}
@@ -116,7 +120,10 @@ impl Download {
pub fn speed_bytes_per_sec(&self) -> f64 {
match &self.status {
DownloadStatus::InProgress { speed_bytes_per_sec, .. } => *speed_bytes_per_sec,
DownloadStatus::InProgress {
speed_bytes_per_sec,
..
} => *speed_bytes_per_sec,
_ => 0.0,
}
}
+4 -1
View File
@@ -54,7 +54,10 @@ pub fn init() {
}
}
Err(e) => {
eprintln!("Failed to open log file '{}': {}", log_file_path, e);
eprintln!(
"Failed to open log file '{}': {}",
log_file_path, e
);
}
}
}
+5 -1
View File
@@ -33,7 +33,11 @@ pub struct Cli {
#[arg(short, long, global = true, action = clap::ArgAction::Count)]
pub verbose: u8,
#[arg(long, env = "LOG_FILE", help = "Write logs to file instead of stderr")]
#[arg(
long,
env = "LOG_FILE",
help = "Write logs to file instead of stderr"
)]
pub log_file: Option<PathBuf>,
#[command(subcommand)]
+26 -18
View File
@@ -28,7 +28,8 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
pub struct MultiDownloadProgress {
downloads: Vec<DownloadEntry>,
receiver_channel: Receiver<(soulseek_rs::types::Download, Receiver<DownloadStatus>)>,
receiver_channel:
Receiver<(soulseek_rs::types::Download, Receiver<DownloadStatus>)>,
list_state: TableState,
max_concurrent: usize,
active_count: usize,
@@ -38,7 +39,10 @@ pub struct MultiDownloadProgress {
impl MultiDownloadProgress {
pub fn new(
receiver_channel: Receiver<(soulseek_rs::types::Download, Receiver<DownloadStatus>)>,
receiver_channel: Receiver<(
soulseek_rs::types::Download,
Receiver<DownloadStatus>,
)>,
max_concurrent: usize,
) -> Self {
let mut list_state = TableState::default();
@@ -63,12 +67,15 @@ impl MultiDownloadProgress {
terminal.draw(|frame| self.render(frame))?;
// Check for incoming downloads from background thread
while let Ok((download, receiver)) = self.receiver_channel.try_recv() {
while let Ok((download, receiver)) =
self.receiver_channel.try_recv()
{
self.downloads.push(DownloadEntry {
download,
receiver: Some(receiver),
});
self.queuing_status = format!("{} downloads queued", self.downloads.len());
self.queuing_status =
format!("{} downloads queued", self.downloads.len());
}
// Poll all receivers for status updates
@@ -229,8 +236,7 @@ impl MultiDownloadProgress {
};
let progress = if download.size > 0 {
download.bytes_downloaded() as f64
/ download.size as f64
download.bytes_downloaded() as f64 / download.size as f64
} else {
0.0
};
@@ -348,8 +354,10 @@ pub fn render_download_stats(
.filter(|d| matches!(d.download.status, DownloadStatus::Queued))
.count();
let total_downloaded: u64 =
downloads.iter().map(|d| d.download.bytes_downloaded()).sum();
let total_downloaded: u64 = downloads
.iter()
.map(|d| d.download.bytes_downloaded())
.sum();
let total_size: u64 = downloads.iter().map(|d| d.download.size).sum();
let overall_progress = if total_size > 0 {
(total_downloaded as f64 / total_size as f64 * 100.0) as u8
@@ -363,7 +371,9 @@ pub fn render_download_stats(
};
let total_speed: f64 = downloads
.iter()
.filter(|d| matches!(d.download.status, DownloadStatus::InProgress { .. }))
.filter(|d| {
matches!(d.download.status, DownloadStatus::InProgress { .. })
})
.map(|d| d.download.speed_bytes_per_sec())
.sum();
let speed_mb = (total_speed / 1_048_576.0 * 100.0).round() / 100.0;
@@ -461,7 +471,6 @@ pub fn show_multi_download_progress(
) -> Result<()> {
soulseek_rs::utils::logger::enable_buffering();
// Create channel for sending downloads and receivers from background thread
let (tx, rx) = mpsc::channel();
// Spawn background thread to initialize downloads
@@ -475,21 +484,20 @@ pub fn show_multi_download_progress(
size,
download_dir.clone(),
) {
Ok(receiver) => {
// Get the download from client
if let Some(download) = init_client.get_all_downloads().iter().find(|d| d.filename == filename && d.username == username).cloned() {
let _ = tx.send((download, receiver));
}
Ok((download, receiver)) => {
let _ = tx.send((download, receiver));
}
Err(e) => {
eprintln!("Failed to start download for {}: {}", filename, e);
eprintln!(
"Failed to start download for {}: {}",
filename, e
);
}
}
}
});
let mut progress =
MultiDownloadProgress::new(rx, max_concurrent);
let mut progress = MultiDownloadProgress::new(rx, max_concurrent);
let result = progress.run(terminal);
ratatui::restore();
+16 -23
View File
@@ -777,33 +777,26 @@ impl MainTui {
let sender = self.state.downloads_sender_channel.clone().unwrap();
thread::spawn(move || {
for (filename, username, size) in selected_files.into_iter() {
match client.download(
filename.clone(),
username.clone(),
size,
download_dir.clone(),
) {
Ok(rx) => {
if let Some(download) = client
.get_all_downloads()
.iter()
.find(|d| {
d.filename == filename && d.username == username
})
.cloned()
{
thread::spawn(move || {
for (filename, username, size) in selected_files.into_iter() {
match client.download(
filename.clone(),
username.clone(),
size,
download_dir.clone(),
) {
Ok((download, rx)) => {
let _ = sender.send((download, rx));
}
}
Err(e) => {
eprintln!(
"Failed to start download for {}: {}",
filename, e
);
Err(e) => {
eprintln!(
"Failed to start download for {}: {}",
filename, e
);
}
}
}
}
});
});
// Clear selection