Small fixes

This commit is contained in:
Michael Wain 2025-03-06 01:35:39 +03:00
parent 5d94131ad6
commit 934bcb9d9e
9 changed files with 66 additions and 99 deletions

View File

@ -14,7 +14,6 @@ use crate::sync::AppEvent;
pub struct DownloadProgress { pub struct DownloadProgress {
pub progress_percentage: String, pub progress_percentage: String,
pub progress_total: String, pub progress_total: String,
pub speed: String,
pub eta: String, pub eta: String,
} }

View File

@ -1,6 +1,6 @@
use crate::component::table::SmartTable; use crate::component::table::SmartTable;
use crate::sync::AppEvent; use crate::sync::AppEvent;
use crate::{screen::AppScreen, theme::Theme, AppState}; use crate::{screen::AppScreen, AppState};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use crossterm::event::KeyCode; use crossterm::event::KeyCode;
use ratatui::layout::{Constraint, Direction, Layout, Rect}; use ratatui::layout::{Constraint, Direction, Layout, Rect};
@ -34,8 +34,8 @@ fn get_extension_from_filename(file_name: Option<&OsStr>) -> String {
let index = file_name let index = file_name
.chars() .chars()
.enumerate() .enumerate()
.filter(|(i, c)| *c == '.') .filter(|(_i, c)| *c == '.')
.map(|(i, c)| i) .map(|(i, _c)| i)
.last(); .last();
if let Some(index) = index { if let Some(index) = index {
let extension: String = file_name.chars().skip(index).collect(); let extension: String = file_name.chars().skip(index).collect();
@ -91,7 +91,7 @@ impl AppScreen for FileSystem {
} }
} }
fn render(&self, frame: &mut Frame, _theme: &Theme) { fn render(&self, frame: &mut Frame) {
let chunks = Layout::default() let chunks = Layout::default()
.direction(Direction::Vertical) .direction(Direction::Vertical)
.constraints([ .constraints([

View File

@ -6,7 +6,7 @@ use ratatui::{
Frame, Frame,
}; };
use crate::{dlp::DownloadProgress, screen::AppScreen, theme::Theme}; use crate::{dlp::DownloadProgress, screen::AppScreen};
#[derive(Default)] #[derive(Default)]
pub struct LoadingScreen { pub struct LoadingScreen {
@ -16,9 +16,9 @@ pub struct LoadingScreen {
} }
impl AppScreen for LoadingScreen { impl AppScreen for LoadingScreen {
fn handle_key_event(&mut self, key_event: crossterm::event::KeyEvent) {} fn handle_key_event(&mut self, _key_event: crossterm::event::KeyEvent) {}
fn render(&self, frame: &mut ratatui::Frame, theme: &Theme) { fn render(&self, frame: &mut ratatui::Frame) {
let chunks = Layout::default() let chunks = Layout::default()
.direction(Direction::Vertical) .direction(Direction::Vertical)
.constraints([ .constraints([

View File

@ -1,5 +1,4 @@
use crate::file_system::FileSystem; use crate::file_system::FileSystem;
use crate::theme::Theme;
use color_eyre::Result; use color_eyre::Result;
use crossterm::{ use crossterm::{
event::{ event::{
@ -33,7 +32,6 @@ mod loading_screen;
mod main_screen; mod main_screen;
mod screen; mod screen;
mod sync; mod sync;
mod theme;
mod util; mod util;
mod wait_screen; mod wait_screen;
@ -51,7 +49,6 @@ pub struct App {
receiver: Receiver<AppEvent>, receiver: Receiver<AppEvent>,
sender: UnboundedSender<AppEvent>, sender: UnboundedSender<AppEvent>,
token: CancellationToken, token: CancellationToken,
theme: Theme,
} }
impl Default for App { impl Default for App {
@ -76,7 +73,6 @@ impl Default for App {
token, token,
state: AppState::IPodWait, state: AppState::IPodWait,
screens, screens,
theme: Theme::default(),
} }
} }
} }
@ -92,10 +88,7 @@ impl App {
} }
fn draw(&mut self, frame: &mut Frame) { fn draw(&mut self, frame: &mut Frame) {
self.screens self.screens.get(&self.state).unwrap().render(frame);
.get(&self.state)
.unwrap()
.render(frame, &self.theme);
} }
async fn handle_events(&mut self, reader: &mut EventStream) { async fn handle_events(&mut self, reader: &mut EventStream) {

View File

@ -12,7 +12,7 @@ use tokio::sync::mpsc::UnboundedSender;
use crate::component::table::SmartTable; use crate::component::table::SmartTable;
use crate::sync::{DBPlaylist, YTPlaylist}; use crate::sync::{DBPlaylist, YTPlaylist};
use crate::{screen::AppScreen, sync::AppEvent, theme::Theme, AppState}; use crate::{screen::AppScreen, sync::AppEvent, AppState};
pub struct MainScreen { pub struct MainScreen {
mode: bool, mode: bool,
@ -46,7 +46,7 @@ impl AppScreen for MainScreen {
} }
} }
fn render(&self, frame: &mut Frame, _theme: &Theme) { fn render(&self, frame: &mut Frame) {
let chunks = Layout::default() let chunks = Layout::default()
.direction(Direction::Vertical) .direction(Direction::Vertical)
.constraints([ .constraints([

View File

@ -3,12 +3,10 @@ use std::any::Any;
use crossterm::event::KeyEvent; use crossterm::event::KeyEvent;
use ratatui::Frame; use ratatui::Frame;
use crate::theme::Theme;
pub trait AppScreen { pub trait AppScreen {
fn handle_key_event(&mut self, key_event: KeyEvent); fn handle_key_event(&mut self, key_event: KeyEvent);
fn render(&self, frame: &mut Frame, theme: &Theme); fn render(&self, frame: &mut Frame);
fn as_any(&mut self) -> &mut dyn Any; fn as_any(&mut self) -> &mut dyn Any;
} }

View File

@ -352,7 +352,7 @@ async fn remove_playlist(
let pl = pl.unwrap(); let pl = pl.unwrap();
let max = pl.elems.len(); let max = pl.elems.len();
let mut i = 1; let mut i = 1;
for (item, args) in pl.elems.iter() { for (item, _args) in pl.elems.iter() {
let _ = sender let _ = sender
.send(AppEvent::OverallProgress((i, max as u32, Color::Red))) .send(AppEvent::OverallProgress((i, max as u32, Color::Red)))
.await; .await;
@ -622,7 +622,7 @@ fn get_artwork_db(ipod_path: &str) -> ADatabase {
Ok(n) => { Ok(n) => {
return itunesdb::artworkdb::deserializer::parse_bytes(&buf[..n]); return itunesdb::artworkdb::deserializer::parse_bytes(&buf[..n]);
} }
Err(e) => {} Err(_e) => {}
} }
} }
itunesdb::artworkdb::deserializer::new_db() itunesdb::artworkdb::deserializer::new_db()
@ -912,8 +912,9 @@ async fn parse_itunes(sender: &Sender<AppEvent>, path: String) -> XDatabase {
file.read_to_string(&mut content).await.unwrap(); file.read_to_string(&mut content).await.unwrap();
let config: LyricaConfiguration = toml::from_str(&content).unwrap(); let config: LyricaConfiguration = toml::from_str(&content).unwrap();
let yt_sender = sender.clone();
let yt_channel_id = config.get_youtube().user_id.clone(); let yt_channel_id = config.get_youtube().user_id.clone();
tokio::spawn(async move {
let rid = youtube_api::get_channel(yt_channel_id.clone()) let rid = youtube_api::get_channel(yt_channel_id.clone())
.await .await
.unwrap(); .unwrap();
@ -932,15 +933,16 @@ async fn parse_itunes(sender: &Sender<AppEvent>, path: String) -> XDatabase {
}); });
} }
let _ = sender.send(AppEvent::YoutubeGot(yt_v)).await; let _ = yt_sender.send(AppEvent::YoutubeGot(yt_v)).await;
});
let soundcloud_user_id = config.get_soundcloud().user_id;
let soundcloud_sender = sender.clone();
tokio::spawn(async move {
let app_version = soundcloud::get_app().await.unwrap().unwrap(); let app_version = soundcloud::get_app().await.unwrap().unwrap();
let client_id = soundcloud::get_client_id().await.unwrap().unwrap(); let client_id = soundcloud::get_client_id().await.unwrap().unwrap();
let playlists = soundcloud::get_playlists( let playlists =
config.get_soundcloud().user_id, soundcloud::get_playlists(soundcloud_user_id, client_id.clone(), app_version.clone())
client_id.clone(),
app_version.clone(),
)
.await .await
.unwrap(); .unwrap();
@ -950,8 +952,11 @@ async fn parse_itunes(sender: &Sender<AppEvent>, path: String) -> XDatabase {
let trr = playlist.tracks.clone(); let trr = playlist.tracks.clone();
playlist.tracks = Vec::new(); playlist.tracks = Vec::new();
for pl_tracks in trr.clone().chunks(45) { for pl_tracks in trr.clone().chunks(45) {
if let Ok(tracks) = if let Ok(tracks) = soundcloud::get_tracks(
soundcloud::get_tracks(pl_tracks.to_vec(), client_id.clone(), app_version.clone()) pl_tracks.to_vec(),
client_id.clone(),
app_version.clone(),
)
.await .await
{ {
let mut tracks = tracks; let mut tracks = tracks;
@ -961,11 +966,12 @@ async fn parse_itunes(sender: &Sender<AppEvent>, path: String) -> XDatabase {
} }
} }
let _ = sender let _ = soundcloud_sender
.send(AppEvent::SoundcloudGot(CloudPlaylists { .send(AppEvent::SoundcloudGot(CloudPlaylists {
collection: playlists, collection: playlists,
})) }))
.await; .await;
});
database database
} }

View File

@ -1,29 +0,0 @@
use ratatui::style::Color;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct Theme {
background: u32,
foreground: u32,
}
impl Theme {
pub fn background(&self) -> Color {
Color::from_u32(self.background)
}
pub fn foreground(&self) -> Color {
Color::from_u32(self.foreground)
}
}
impl Default for Theme {
fn default() -> Self {
Self {
background: 0x00D75FAF,
foreground: u32::MAX,
}
}
}
fn load_theme() {}

View File

@ -1,4 +1,4 @@
use crate::{screen::AppScreen, theme::Theme}; use crate::screen::AppScreen;
use color_eyre::owo_colors::OwoColorize; use color_eyre::owo_colors::OwoColorize;
use ratatui::layout::{Constraint, Direction, Flex, Layout}; use ratatui::layout::{Constraint, Direction, Flex, Layout};
use ratatui::widgets::Paragraph; use ratatui::widgets::Paragraph;
@ -14,9 +14,9 @@ use tui_big_text::{BigText, PixelSize};
pub struct WaitScreen {} pub struct WaitScreen {}
impl AppScreen for WaitScreen { impl AppScreen for WaitScreen {
fn handle_key_event(&mut self, key_event: crossterm::event::KeyEvent) {} fn handle_key_event(&mut self, _key_event: crossterm::event::KeyEvent) {}
fn render(&self, frame: &mut Frame, theme: &Theme) { fn render(&self, frame: &mut Frame) {
let chunks = Layout::default() let chunks = Layout::default()
.direction(Direction::Vertical) .direction(Direction::Vertical)
.constraints([Constraint::Percentage(33); 3]) .constraints([Constraint::Percentage(33); 3])