comply with clippy

This commit is contained in:
krolxon 2024-06-13 15:31:40 +05:30
parent 3862d5d324
commit e1dc925ecc
5 changed files with 28 additions and 33 deletions

View File

@ -101,8 +101,7 @@ impl App {
self.update_queue();
// Deals with database update
if self.should_update_song_list {
if let None = self.conn.status.updating_db {
if self.should_update_song_list && self.conn.status.updating_db.is_none() {
// Update the songs list
self.conn.songs_filenames = self
.conn
@ -116,7 +115,6 @@ impl App {
self.should_update_song_list = false;
}
}
Ok(())
}
@ -163,22 +161,22 @@ impl App {
let file = format!("{}/{}", self.browser.path, content);
let songs = self.conn.conn.listfiles(&file).unwrap_or_default();
for (t, f) in songs.iter() {
if t == "file" {
if Path::new(&f).has_extension(&[
if t == "file"
&& Path::new(&f).has_extension(&[
"mp3", "ogg", "flac", "m4a", "wav", "aac", "opus", "ape", "wma",
"mpc", "aiff", "dff", "mp2", "mka",
]) {
])
{
let path = file.clone() + "/" + f;
let full_path = path.strip_prefix("./").unwrap_or_else(|| "");
let song = self.conn.get_song_with_only_filename(&full_path);
let full_path = path.strip_prefix("./").unwrap_or("");
let song = self.conn.get_song_with_only_filename(full_path);
self.conn.conn.push(&song)?;
}
}
}
} else if content_type == "file" {
let mut status = false;
for (i, song) in self.queue_list.list.clone().iter().enumerate() {
let song_path = song.file.split("/").last().unwrap_or_default();
let song_path = song.file.split('/').last().unwrap_or_default();
if song_path.eq(content) {
self.conn.conn.delete(i as u32).unwrap();
status = true;
@ -253,7 +251,7 @@ impl App {
let (t, path) = browser.filetree.get(browser.selected).unwrap();
if t == "directory" {
if path != "." {
browser.prev_path = browser.path.clone();
browser.prev_path.clone_from(&browser.path);
browser.path = browser.prev_path.clone() + "/" + path;
browser.update_directory(&mut self.conn)?;
browser.prev_selected = browser.selected;
@ -261,7 +259,7 @@ impl App {
}
} else {
let index = self.queue_list.list.iter().position(|x| {
let file = x.file.split("/").last().unwrap_or_default();
let file = x.file.split('/').last().unwrap_or_default();
file.eq(path)
});

View File

@ -32,7 +32,7 @@ impl FileBrowser {
let mut file_vec: Vec<(String, String)> = vec![];
let mut dir_vec: Vec<(String, String)> = vec![];
for (t, f) in conn.conn.listfiles(self.path.as_str())?.into_iter() {
if t == "directory" && !f.starts_with(".") {
if t == "directory" && !f.starts_with('.') {
dir_vec.push((t, f));
} else if t == "file"
&& Path::new(&f).has_extension(&[
@ -73,7 +73,7 @@ impl FileBrowser {
.lsinfo(Song {
file: (self.path.clone() + "/" + song)
.strip_prefix("./")
.unwrap_or_else(|| "")
.unwrap_or("")
.to_string(),
..Default::default()
})
@ -121,7 +121,7 @@ impl FileBrowser {
self.update_directory(conn)?;
}
} else {
self.path = self.prev_path.clone();
self.path.clone_from(&self.prev_path);
self.update_directory(conn)?;
}

View File

@ -6,7 +6,7 @@ use crate::{
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
use std::time::Duration;
use super::{pl_append_keys, pl_rename_keys, new_pl_keys, search_keys};
use super::{new_pl_keys, pl_append_keys, pl_rename_keys, search_keys};
pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
// searching, playlist renaming, playlist appending
@ -325,9 +325,8 @@ pub fn handle_mouse_events(mouse_event: MouseEvent, app: &mut App) -> AppResult<
MouseEventKind::ScrollDown => app.handle_scroll_down(),
MouseEventKind::Down(button) => {
let (x, y) = (mouse_event.column, mouse_event.row);
match button {
crossterm::event::MouseButton::Left => app.handle_mouse_left_click(x, y)?,
_ => {}
if button == crossterm::event::MouseButton::Left {
app.handle_mouse_left_click(x, y)?;
}
}
_ => {}

View File

@ -29,14 +29,14 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()>
let option_song = songs.first();
if let Some(song) = option_song {
if *pl_name == "Current Playlist" {
app.conn.conn.push(&song)?;
app.conn.conn.push(song)?;
app.update_queue();
} else if *pl_name == "New Playlist" {
app.pl_new_pl_songs_buffer.clear();
app.pl_new_pl_songs_buffer.push(song.clone());
app.inputmode = InputMode::NewPlaylist;
} else {
app.conn.add_to_playlist(pl_name, &song)?;
app.conn.add_to_playlist(pl_name, song)?;
}
}
}
@ -47,7 +47,7 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()>
if t == "file" {
let short_path = f;
if let Some(full_path) = app.conn.get_full_path(short_path) {
let song = app.conn.get_song_with_only_filename(&full_path);
let song = app.conn.get_song_with_only_filename(full_path);
if *pl_name == "Current Playlist" {
app.conn.conn.push(&song)?;
@ -72,7 +72,7 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()>
])
{
let full_path = app.conn.get_full_path(f).unwrap_or_default();
let song = app.conn.get_song_with_only_filename(&full_path);
let song = app.conn.get_song_with_only_filename(full_path);
if *pl_name == "Current Playlist" {
app.conn.conn.push(&song)?;
} else if *pl_name == "New Playlist" {
@ -98,9 +98,7 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()>
for song in songs {
// We ignore the Err() since there could be songs in playlists, which do not exist in the db anymore.
// So instead of panicking, we just ignore if the song does not exists
app.conn
.add_to_playlist(*pl_name, &song)
.unwrap_or_else(|_| {});
app.conn.add_to_playlist(pl_name, &song).unwrap_or(());
}
}
}

View File

@ -83,7 +83,7 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
let mut status: bool = false;
for sn in app.queue_list.list.iter() {
let file = sn.file.split("/").last().unwrap_or_default();
let file = sn.file.split('/').last().unwrap_or_default();
if file.eq(s) {
status = true;
}
@ -137,7 +137,7 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
.alignment(Alignment::Right)
}
VolumeStatus::Muted(_v) => {
Title::from(format!("Muted").red()).alignment(Alignment::Right)
Title::from("Muted".red()).alignment(Alignment::Right)
}
})
.borders(Borders::ALL),
@ -235,7 +235,7 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) {
.alignment(Alignment::Right)
}
VolumeStatus::Muted(_v) => {
Title::from(format!("Muted").red()).alignment(Alignment::Right)
Title::from("Muted".red()).alignment(Alignment::Right)
}
})
.borders(Borders::ALL),
@ -288,7 +288,7 @@ fn draw_progress_bar(frame: &mut Frame, app: &mut App, size: Rect) {
// Get the current playing state
let mut state: String = String::new();
if !app.queue_list.list.is_empty() {
state = app.conn.state.clone();
state.clone_from(&app.conn.state);
state.push(':');
}