chore: update to Rust 2024 edition
This commit is contained in:
+1
-1
@@ -5,6 +5,6 @@ resolver = "2"
|
||||
[workspace.package]
|
||||
version = "0.3.0"
|
||||
authors = ["Michel de Graaf"]
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
repository = "https://github.com/michel/soulseek-rs"
|
||||
|
||||
@@ -156,13 +156,12 @@ impl PeerActor {
|
||||
let transfer_response =
|
||||
MessageFactory::build_transfer_response_message(transfer);
|
||||
|
||||
if let Some(ref handle) = self.self_handle {
|
||||
if let Err(e) =
|
||||
if let Some(ref handle) = self.self_handle
|
||||
&& let Err(e) =
|
||||
handle.send(PeerMessage::SendMessage(transfer_response))
|
||||
{
|
||||
error!("[peer:{}] Failed to send TransferResponse message: {}", username, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
PeerMessage::TransferResponse {
|
||||
token,
|
||||
|
||||
@@ -285,11 +285,10 @@ impl Client {
|
||||
#[allow(dead_code)]
|
||||
pub fn remove_peer(&self, username: &str) {
|
||||
let context = self.context.read().unwrap();
|
||||
if let Some(ref registry) = context.peer_registry {
|
||||
if let Some(handle) = registry.remove_peer(username) {
|
||||
if let Some(ref registry) = context.peer_registry
|
||||
&& let Some(handle) = registry.remove_peer(username) {
|
||||
let _ = handle.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn search(
|
||||
@@ -334,12 +333,11 @@ impl Client {
|
||||
sleep(Duration::from_millis(100));
|
||||
|
||||
// Check if cancelled
|
||||
if let Some(ref flag) = cancel_flag {
|
||||
if flag.load(Ordering::Relaxed) {
|
||||
if let Some(ref flag) = cancel_flag
|
||||
&& flag.load(Ordering::Relaxed) {
|
||||
info!("Search cancelled by user");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if timeout reached
|
||||
if start.elapsed() >= timeout {
|
||||
@@ -504,13 +502,12 @@ impl Client {
|
||||
}
|
||||
ClientOperation::PeerDisconnected(username, error) => {
|
||||
let context = client_context.read().unwrap();
|
||||
if let Some(ref registry) = context.peer_registry {
|
||||
if let Some(handle) =
|
||||
if let Some(ref registry) = context.peer_registry
|
||||
&& let Some(handle) =
|
||||
registry.remove_peer(&username)
|
||||
{
|
||||
let _ = handle.stop();
|
||||
}
|
||||
}
|
||||
if let Some(error) = error {
|
||||
warn!(
|
||||
"[client] Peer {} disconnected with error: {:?}",
|
||||
|
||||
@@ -306,8 +306,8 @@ impl DownloadPeer {
|
||||
processor.process_data_chunk(data);
|
||||
chunk_counter += 1;
|
||||
|
||||
if let Some(ref dl) = download {
|
||||
if chunk_counter % PROGRESS_UPDATE_CHUNKS == 0 {
|
||||
if let Some(ref dl) = download
|
||||
&& chunk_counter % PROGRESS_UPDATE_CHUNKS == 0 {
|
||||
let elapsed =
|
||||
last_update_time.elapsed().as_secs_f64();
|
||||
let bytes_since_last_update =
|
||||
@@ -331,7 +331,6 @@ impl DownloadPeer {
|
||||
|
||||
last_update_time = Instant::now();
|
||||
}
|
||||
}
|
||||
|
||||
let expected_size = download
|
||||
.as_ref()
|
||||
|
||||
@@ -167,12 +167,11 @@ pub fn log(level: LogLevel, message: &str) {
|
||||
buffer.push(formatted_message.clone());
|
||||
}
|
||||
// But ALSO write to file if configured (file logging bypasses buffering)
|
||||
if let Ok(mut log_file) = LOG_FILE.lock() {
|
||||
if let Some(file) = log_file.as_mut() {
|
||||
if let Ok(mut log_file) = LOG_FILE.lock()
|
||||
&& let Some(file) = log_file.as_mut() {
|
||||
let _ = writeln!(file, "{}", formatted_message_plain);
|
||||
let _ = file.flush();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Write to file if configured, otherwise to stderr
|
||||
if let Ok(mut log_file) = LOG_FILE.lock() {
|
||||
|
||||
@@ -27,11 +27,13 @@ fn main() -> Result<()> {
|
||||
3 => "DEBUG",
|
||||
_ => "TRACE",
|
||||
};
|
||||
env::set_var("LOG_LEVEL", log_level);
|
||||
// SAFETY: Called before any threads are spawned
|
||||
unsafe { env::set_var("LOG_LEVEL", log_level) };
|
||||
|
||||
// Set LOG_FILE env var if provided via CLI
|
||||
if let Some(log_file) = &cli.log_file {
|
||||
env::set_var("LOG_FILE", log_file.to_string_lossy().to_string());
|
||||
// SAFETY: Called before any threads are spawned
|
||||
unsafe { env::set_var("LOG_FILE", log_file.to_string_lossy().to_string()) };
|
||||
}
|
||||
|
||||
let username = cli.username
|
||||
|
||||
@@ -113,11 +113,10 @@ impl FileSelector {
|
||||
Duration::from_millis(100)
|
||||
};
|
||||
|
||||
if poll(timeout)? {
|
||||
if let Event::Key(key) = event::read()? {
|
||||
if poll(timeout)?
|
||||
&& let Event::Key(key) = event::read()? {
|
||||
self.handle_key(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok((terminal, self.selected_indices.iter().copied().collect()))
|
||||
@@ -157,8 +156,8 @@ impl FileSelector {
|
||||
}
|
||||
|
||||
fn toggle_selection(&mut self) {
|
||||
if let Some(filtered_idx) = self.state.selected() {
|
||||
if let Some(&original_idx) = self.filtered_indices.get(filtered_idx)
|
||||
if let Some(filtered_idx) = self.state.selected()
|
||||
&& let Some(&original_idx) = self.filtered_indices.get(filtered_idx)
|
||||
{
|
||||
if self.selected_indices.contains(&original_idx) {
|
||||
self.selected_indices.remove(&original_idx);
|
||||
@@ -166,7 +165,6 @@ impl FileSelector {
|
||||
self.selected_indices.insert(original_idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_key(&mut self, key: KeyEvent) {
|
||||
@@ -194,15 +192,13 @@ impl FileSelector {
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
// If nothing selected, select the current item under cursor
|
||||
if self.selected_indices.is_empty() {
|
||||
if let Some(filtered_idx) = self.state.selected() {
|
||||
if let Some(&original_idx) =
|
||||
if self.selected_indices.is_empty()
|
||||
&& let Some(filtered_idx) = self.state.selected()
|
||||
&& let Some(&original_idx) =
|
||||
self.filtered_indices.get(filtered_idx)
|
||||
{
|
||||
self.selected_indices.insert(original_idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.should_exit = true;
|
||||
}
|
||||
KeyCode::Up | KeyCode::Down => {
|
||||
@@ -238,15 +234,13 @@ impl FileSelector {
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
// If nothing selected, select the current item under cursor
|
||||
if self.selected_indices.is_empty() {
|
||||
if let Some(filtered_idx) = self.state.selected() {
|
||||
if let Some(&original_idx) =
|
||||
if self.selected_indices.is_empty()
|
||||
&& let Some(filtered_idx) = self.state.selected()
|
||||
&& let Some(&original_idx) =
|
||||
self.filtered_indices.get(filtered_idx)
|
||||
{
|
||||
self.selected_indices.insert(original_idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.should_exit = true;
|
||||
}
|
||||
KeyCode::Esc | KeyCode::Char('q') => {
|
||||
|
||||
@@ -81,8 +81,8 @@ impl MultiDownloadProgress {
|
||||
// Poll all receivers for status updates
|
||||
let mut need_start_next = false;
|
||||
for download_entry in &mut self.downloads {
|
||||
if let Some(receiver) = &download_entry.receiver {
|
||||
if let Ok(status) = receiver.try_recv() {
|
||||
if let Some(receiver) = &download_entry.receiver
|
||||
&& let Ok(status) = receiver.try_recv() {
|
||||
let was_active = !download_entry.download.is_finished();
|
||||
download_entry.download.status = status;
|
||||
let is_finished = download_entry.download.is_finished();
|
||||
@@ -94,7 +94,6 @@ impl MultiDownloadProgress {
|
||||
need_start_next = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start next batch after iteration completes
|
||||
@@ -103,11 +102,10 @@ impl MultiDownloadProgress {
|
||||
}
|
||||
|
||||
// Handle keyboard input
|
||||
if poll(Duration::from_millis(100))? {
|
||||
if let Event::Key(key) = event::read()? {
|
||||
if poll(Duration::from_millis(100))?
|
||||
&& let Event::Key(key) = event::read()? {
|
||||
self.handle_key(key);
|
||||
}
|
||||
}
|
||||
|
||||
// Exit when user cancels or all downloads finished
|
||||
if self.should_exit || self.all_finished() {
|
||||
|
||||
@@ -519,8 +519,8 @@ impl MainTui {
|
||||
let (col, row) = (mouse.column, mouse.row);
|
||||
|
||||
// Check if click is within searches pane
|
||||
if let Some(area) = self.state.searches_pane_area {
|
||||
if col >= area.x
|
||||
if let Some(area) = self.state.searches_pane_area
|
||||
&& col >= area.x
|
||||
&& col < area.x + area.width
|
||||
&& row >= area.y
|
||||
&& row < area.y + area.height
|
||||
@@ -528,11 +528,10 @@ impl MainTui {
|
||||
self.state.focused_pane = FocusedPane::Searches;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
// Check if click is within results pane
|
||||
if let Some(area) = self.state.results_pane_area {
|
||||
if col >= area.x
|
||||
if let Some(area) = self.state.results_pane_area
|
||||
&& col >= area.x
|
||||
&& col < area.x + area.width
|
||||
&& row >= area.y
|
||||
&& row < area.y + area.height
|
||||
@@ -540,11 +539,10 @@ impl MainTui {
|
||||
self.state.focused_pane = FocusedPane::Results;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
// Check if click is within downloads pane
|
||||
if let Some(area) = self.state.downloads_pane_area {
|
||||
if col >= area.x
|
||||
if let Some(area) = self.state.downloads_pane_area
|
||||
&& col >= area.x
|
||||
&& col < area.x + area.width
|
||||
&& row >= area.y
|
||||
&& row < area.y + area.height
|
||||
@@ -552,7 +550,6 @@ impl MainTui {
|
||||
self.state.focused_pane = FocusedPane::Downloads;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -749,15 +746,14 @@ impl MainTui {
|
||||
}
|
||||
|
||||
// Update selected search if this is the active one
|
||||
if let Some(selected_idx) = selected_search_index {
|
||||
if selected_idx == idx {
|
||||
if let Some(selected_idx) = selected_search_index
|
||||
&& selected_idx == idx {
|
||||
self.state.results_items = search.results.clone();
|
||||
self.state.results_filtered_items =
|
||||
search.results.clone();
|
||||
self.state.results_filtered_indices =
|
||||
(0..search.results.len()).collect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mark as completed after timeout
|
||||
|
||||
Reference in New Issue
Block a user