comply with clippy
This commit is contained in:
parent
3862d5d324
commit
e1dc925ecc
28
src/app.rs
28
src/app.rs
|
|
@ -29,7 +29,7 @@ pub struct App {
|
||||||
pub pl_newname_input: String, // Stores the new name of the playlist
|
pub pl_newname_input: String, // Stores the new name of the playlist
|
||||||
pub pl_cursor_pos: usize, // Stores the cursor position for renaming playlist
|
pub pl_cursor_pos: usize, // Stores the cursor position for renaming playlist
|
||||||
|
|
||||||
pub pl_new_pl_input: String, // Stores the name of new playlist to be created
|
pub pl_new_pl_input: String, // Stores the name of new playlist to be created
|
||||||
pub pl_new_pl_cursor_pos: usize, // Stores the cursor position of new playlist to be created
|
pub pl_new_pl_cursor_pos: usize, // Stores the cursor position of new playlist to be created
|
||||||
pub pl_new_pl_songs_buffer: Vec<Song>, // Buffer for songs that need to be added to the newly created playlist
|
pub pl_new_pl_songs_buffer: Vec<Song>, // Buffer for songs that need to be added to the newly created playlist
|
||||||
|
|
||||||
|
|
@ -101,8 +101,7 @@ impl App {
|
||||||
self.update_queue();
|
self.update_queue();
|
||||||
|
|
||||||
// Deals with database update
|
// Deals with database update
|
||||||
if self.should_update_song_list {
|
if self.should_update_song_list && self.conn.status.updating_db.is_none() {
|
||||||
if let None = self.conn.status.updating_db {
|
|
||||||
// Update the songs list
|
// Update the songs list
|
||||||
self.conn.songs_filenames = self
|
self.conn.songs_filenames = self
|
||||||
.conn
|
.conn
|
||||||
|
|
@ -115,7 +114,6 @@ impl App {
|
||||||
self.browser.update_directory(&mut self.conn)?;
|
self.browser.update_directory(&mut self.conn)?;
|
||||||
|
|
||||||
self.should_update_song_list = false;
|
self.should_update_song_list = false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -163,22 +161,22 @@ impl App {
|
||||||
let file = format!("{}/{}", self.browser.path, content);
|
let file = format!("{}/{}", self.browser.path, content);
|
||||||
let songs = self.conn.conn.listfiles(&file).unwrap_or_default();
|
let songs = self.conn.conn.listfiles(&file).unwrap_or_default();
|
||||||
for (t, f) in songs.iter() {
|
for (t, f) in songs.iter() {
|
||||||
if t == "file" {
|
if t == "file"
|
||||||
if Path::new(&f).has_extension(&[
|
&& Path::new(&f).has_extension(&[
|
||||||
"mp3", "ogg", "flac", "m4a", "wav", "aac", "opus", "ape", "wma",
|
"mp3", "ogg", "flac", "m4a", "wav", "aac", "opus", "ape", "wma",
|
||||||
"mpc", "aiff", "dff", "mp2", "mka",
|
"mpc", "aiff", "dff", "mp2", "mka",
|
||||||
]) {
|
])
|
||||||
let path = file.clone() + "/" + f;
|
{
|
||||||
let full_path = path.strip_prefix("./").unwrap_or_else(|| "");
|
let path = file.clone() + "/" + f;
|
||||||
let song = self.conn.get_song_with_only_filename(&full_path);
|
let full_path = path.strip_prefix("./").unwrap_or("");
|
||||||
self.conn.conn.push(&song)?;
|
let song = self.conn.get_song_with_only_filename(full_path);
|
||||||
}
|
self.conn.conn.push(&song)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if content_type == "file" {
|
} else if content_type == "file" {
|
||||||
let mut status = false;
|
let mut status = false;
|
||||||
for (i, song) in self.queue_list.list.clone().iter().enumerate() {
|
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) {
|
if song_path.eq(content) {
|
||||||
self.conn.conn.delete(i as u32).unwrap();
|
self.conn.conn.delete(i as u32).unwrap();
|
||||||
status = true;
|
status = true;
|
||||||
|
|
@ -253,7 +251,7 @@ impl App {
|
||||||
let (t, path) = browser.filetree.get(browser.selected).unwrap();
|
let (t, path) = browser.filetree.get(browser.selected).unwrap();
|
||||||
if t == "directory" {
|
if t == "directory" {
|
||||||
if path != "." {
|
if path != "." {
|
||||||
browser.prev_path = browser.path.clone();
|
browser.prev_path.clone_from(&browser.path);
|
||||||
browser.path = browser.prev_path.clone() + "/" + path;
|
browser.path = browser.prev_path.clone() + "/" + path;
|
||||||
browser.update_directory(&mut self.conn)?;
|
browser.update_directory(&mut self.conn)?;
|
||||||
browser.prev_selected = browser.selected;
|
browser.prev_selected = browser.selected;
|
||||||
|
|
@ -261,7 +259,7 @@ impl App {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let index = self.queue_list.list.iter().position(|x| {
|
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)
|
file.eq(path)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ impl FileBrowser {
|
||||||
let mut file_vec: Vec<(String, String)> = vec![];
|
let mut file_vec: Vec<(String, String)> = vec![];
|
||||||
let mut dir_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() {
|
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));
|
dir_vec.push((t, f));
|
||||||
} else if t == "file"
|
} else if t == "file"
|
||||||
&& Path::new(&f).has_extension(&[
|
&& Path::new(&f).has_extension(&[
|
||||||
|
|
@ -73,7 +73,7 @@ impl FileBrowser {
|
||||||
.lsinfo(Song {
|
.lsinfo(Song {
|
||||||
file: (self.path.clone() + "/" + song)
|
file: (self.path.clone() + "/" + song)
|
||||||
.strip_prefix("./")
|
.strip_prefix("./")
|
||||||
.unwrap_or_else(|| "")
|
.unwrap_or("")
|
||||||
.to_string(),
|
.to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
|
|
@ -121,7 +121,7 @@ impl FileBrowser {
|
||||||
self.update_directory(conn)?;
|
self.update_directory(conn)?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.path = self.prev_path.clone();
|
self.path.clone_from(&self.prev_path);
|
||||||
self.update_directory(conn)?;
|
self.update_directory(conn)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use crate::{
|
||||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
|
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
|
||||||
use std::time::Duration;
|
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<()> {
|
pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
||||||
// searching, playlist renaming, playlist appending
|
// 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::ScrollDown => app.handle_scroll_down(),
|
||||||
MouseEventKind::Down(button) => {
|
MouseEventKind::Down(button) => {
|
||||||
let (x, y) = (mouse_event.column, mouse_event.row);
|
let (x, y) = (mouse_event.column, mouse_event.row);
|
||||||
match button {
|
if button == crossterm::event::MouseButton::Left {
|
||||||
crossterm::event::MouseButton::Left => app.handle_mouse_left_click(x, y)?,
|
app.handle_mouse_left_click(x, y)?;
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,14 @@ pub fn hande_pl_append_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()>
|
||||||
let option_song = songs.first();
|
let option_song = songs.first();
|
||||||
if let Some(song) = option_song {
|
if let Some(song) = option_song {
|
||||||
if *pl_name == "Current Playlist" {
|
if *pl_name == "Current Playlist" {
|
||||||
app.conn.conn.push(&song)?;
|
app.conn.conn.push(song)?;
|
||||||
app.update_queue();
|
app.update_queue();
|
||||||
} else if *pl_name == "New Playlist" {
|
} else if *pl_name == "New Playlist" {
|
||||||
app.pl_new_pl_songs_buffer.clear();
|
app.pl_new_pl_songs_buffer.clear();
|
||||||
app.pl_new_pl_songs_buffer.push(song.clone());
|
app.pl_new_pl_songs_buffer.push(song.clone());
|
||||||
app.inputmode = InputMode::NewPlaylist;
|
app.inputmode = InputMode::NewPlaylist;
|
||||||
} else {
|
} 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" {
|
if t == "file" {
|
||||||
let short_path = f;
|
let short_path = f;
|
||||||
if let Some(full_path) = app.conn.get_full_path(short_path) {
|
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" {
|
if *pl_name == "Current Playlist" {
|
||||||
app.conn.conn.push(&song)?;
|
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 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" {
|
if *pl_name == "Current Playlist" {
|
||||||
app.conn.conn.push(&song)?;
|
app.conn.conn.push(&song)?;
|
||||||
} else if *pl_name == "New Playlist" {
|
} 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 {
|
for song in songs {
|
||||||
// We ignore the Err() since there could be songs in playlists, which do not exist in the db anymore.
|
// 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
|
// So instead of panicking, we just ignore if the song does not exists
|
||||||
app.conn
|
app.conn.add_to_playlist(pl_name, &song).unwrap_or(());
|
||||||
.add_to_playlist(*pl_name, &song)
|
|
||||||
.unwrap_or_else(|_| {});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
|
||||||
|
|
||||||
let mut status: bool = false;
|
let mut status: bool = false;
|
||||||
for sn in app.queue_list.list.iter() {
|
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) {
|
if file.eq(s) {
|
||||||
status = true;
|
status = true;
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +137,7 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
|
||||||
.alignment(Alignment::Right)
|
.alignment(Alignment::Right)
|
||||||
}
|
}
|
||||||
VolumeStatus::Muted(_v) => {
|
VolumeStatus::Muted(_v) => {
|
||||||
Title::from(format!("Muted").red()).alignment(Alignment::Right)
|
Title::from("Muted".red()).alignment(Alignment::Right)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.borders(Borders::ALL),
|
.borders(Borders::ALL),
|
||||||
|
|
@ -235,7 +235,7 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) {
|
||||||
.alignment(Alignment::Right)
|
.alignment(Alignment::Right)
|
||||||
}
|
}
|
||||||
VolumeStatus::Muted(_v) => {
|
VolumeStatus::Muted(_v) => {
|
||||||
Title::from(format!("Muted").red()).alignment(Alignment::Right)
|
Title::from("Muted".red()).alignment(Alignment::Right)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.borders(Borders::ALL),
|
.borders(Borders::ALL),
|
||||||
|
|
@ -288,7 +288,7 @@ fn draw_progress_bar(frame: &mut Frame, app: &mut App, size: Rect) {
|
||||||
// Get the current playing state
|
// Get the current playing state
|
||||||
let mut state: String = String::new();
|
let mut state: String = String::new();
|
||||||
if !app.queue_list.list.is_empty() {
|
if !app.queue_list.list.is_empty() {
|
||||||
state = app.conn.state.clone();
|
state.clone_from(&app.conn.state);
|
||||||
state.push(':');
|
state.push(':');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Reference in New Issue