Small fixes
This commit is contained in:
parent
5d94131ad6
commit
934bcb9d9e
@ -14,7 +14,6 @@ use crate::sync::AppEvent;
|
||||
pub struct DownloadProgress {
|
||||
pub progress_percentage: String,
|
||||
pub progress_total: String,
|
||||
pub speed: String,
|
||||
pub eta: String,
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::component::table::SmartTable;
|
||||
use crate::sync::AppEvent;
|
||||
use crate::{screen::AppScreen, theme::Theme, AppState};
|
||||
use crate::{screen::AppScreen, AppState};
|
||||
use chrono::{DateTime, Utc};
|
||||
use crossterm::event::KeyCode;
|
||||
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
|
||||
.chars()
|
||||
.enumerate()
|
||||
.filter(|(i, c)| *c == '.')
|
||||
.map(|(i, c)| i)
|
||||
.filter(|(_i, c)| *c == '.')
|
||||
.map(|(i, _c)| i)
|
||||
.last();
|
||||
if let Some(index) = index {
|
||||
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()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
|
@ -6,7 +6,7 @@ use ratatui::{
|
||||
Frame,
|
||||
};
|
||||
|
||||
use crate::{dlp::DownloadProgress, screen::AppScreen, theme::Theme};
|
||||
use crate::{dlp::DownloadProgress, screen::AppScreen};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct LoadingScreen {
|
||||
@ -16,9 +16,9 @@ pub struct 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()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
|
@ -1,5 +1,4 @@
|
||||
use crate::file_system::FileSystem;
|
||||
use crate::theme::Theme;
|
||||
use color_eyre::Result;
|
||||
use crossterm::{
|
||||
event::{
|
||||
@ -33,7 +32,6 @@ mod loading_screen;
|
||||
mod main_screen;
|
||||
mod screen;
|
||||
mod sync;
|
||||
mod theme;
|
||||
mod util;
|
||||
mod wait_screen;
|
||||
|
||||
@ -51,7 +49,6 @@ pub struct App {
|
||||
receiver: Receiver<AppEvent>,
|
||||
sender: UnboundedSender<AppEvent>,
|
||||
token: CancellationToken,
|
||||
theme: Theme,
|
||||
}
|
||||
|
||||
impl Default for App {
|
||||
@ -76,7 +73,6 @@ impl Default for App {
|
||||
token,
|
||||
state: AppState::IPodWait,
|
||||
screens,
|
||||
theme: Theme::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,10 +88,7 @@ impl App {
|
||||
}
|
||||
|
||||
fn draw(&mut self, frame: &mut Frame) {
|
||||
self.screens
|
||||
.get(&self.state)
|
||||
.unwrap()
|
||||
.render(frame, &self.theme);
|
||||
self.screens.get(&self.state).unwrap().render(frame);
|
||||
}
|
||||
|
||||
async fn handle_events(&mut self, reader: &mut EventStream) {
|
||||
|
@ -12,7 +12,7 @@ use tokio::sync::mpsc::UnboundedSender;
|
||||
|
||||
use crate::component::table::SmartTable;
|
||||
use crate::sync::{DBPlaylist, YTPlaylist};
|
||||
use crate::{screen::AppScreen, sync::AppEvent, theme::Theme, AppState};
|
||||
use crate::{screen::AppScreen, sync::AppEvent, AppState};
|
||||
|
||||
pub struct MainScreen {
|
||||
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()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
|
@ -3,12 +3,10 @@ use std::any::Any;
|
||||
use crossterm::event::KeyEvent;
|
||||
use ratatui::Frame;
|
||||
|
||||
use crate::theme::Theme;
|
||||
|
||||
pub trait AppScreen {
|
||||
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;
|
||||
}
|
||||
|
98
src/sync.rs
98
src/sync.rs
@ -352,7 +352,7 @@ async fn remove_playlist(
|
||||
let pl = pl.unwrap();
|
||||
let max = pl.elems.len();
|
||||
let mut i = 1;
|
||||
for (item, args) in pl.elems.iter() {
|
||||
for (item, _args) in pl.elems.iter() {
|
||||
let _ = sender
|
||||
.send(AppEvent::OverallProgress((i, max as u32, Color::Red)))
|
||||
.await;
|
||||
@ -622,7 +622,7 @@ fn get_artwork_db(ipod_path: &str) -> ADatabase {
|
||||
Ok(n) => {
|
||||
return itunesdb::artworkdb::deserializer::parse_bytes(&buf[..n]);
|
||||
}
|
||||
Err(e) => {}
|
||||
Err(_e) => {}
|
||||
}
|
||||
}
|
||||
itunesdb::artworkdb::deserializer::new_db()
|
||||
@ -912,60 +912,66 @@ async fn parse_itunes(sender: &Sender<AppEvent>, path: String) -> XDatabase {
|
||||
file.read_to_string(&mut content).await.unwrap();
|
||||
let config: LyricaConfiguration = toml::from_str(&content).unwrap();
|
||||
|
||||
let yt_sender = sender.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())
|
||||
.await
|
||||
.unwrap();
|
||||
let pls = youtube_api::get_playlists(yt_channel_id, rid)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let rid = youtube_api::get_channel(yt_channel_id.clone())
|
||||
.await
|
||||
.unwrap();
|
||||
let pls = youtube_api::get_playlists(yt_channel_id, rid)
|
||||
.await
|
||||
.unwrap();
|
||||
let mut yt_v = Vec::new();
|
||||
|
||||
let mut yt_v = Vec::new();
|
||||
for pl in pls {
|
||||
let videos = youtube_api::get_playlist(pl.browse_id).await.unwrap();
|
||||
yt_v.push(YTPlaylist {
|
||||
title: pl.title,
|
||||
url: pl.pl_url,
|
||||
videos,
|
||||
});
|
||||
}
|
||||
|
||||
for pl in pls {
|
||||
let videos = youtube_api::get_playlist(pl.browse_id).await.unwrap();
|
||||
yt_v.push(YTPlaylist {
|
||||
title: pl.title,
|
||||
url: pl.pl_url,
|
||||
videos,
|
||||
});
|
||||
}
|
||||
let _ = yt_sender.send(AppEvent::YoutubeGot(yt_v)).await;
|
||||
});
|
||||
|
||||
let _ = 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 client_id = soundcloud::get_client_id().await.unwrap().unwrap();
|
||||
let playlists =
|
||||
soundcloud::get_playlists(soundcloud_user_id, client_id.clone(), app_version.clone())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let app_version = soundcloud::get_app().await.unwrap().unwrap();
|
||||
let client_id = soundcloud::get_client_id().await.unwrap().unwrap();
|
||||
let playlists = soundcloud::get_playlists(
|
||||
config.get_soundcloud().user_id,
|
||||
client_id.clone(),
|
||||
app_version.clone(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let mut playlists = playlists.collection;
|
||||
|
||||
let mut playlists = playlists.collection;
|
||||
|
||||
for playlist in playlists.iter_mut() {
|
||||
let trr = playlist.tracks.clone();
|
||||
playlist.tracks = Vec::new();
|
||||
for pl_tracks in trr.clone().chunks(45) {
|
||||
if let Ok(tracks) =
|
||||
soundcloud::get_tracks(pl_tracks.to_vec(), client_id.clone(), app_version.clone())
|
||||
.await
|
||||
{
|
||||
let mut tracks = tracks;
|
||||
tracks.retain(|t| t.title.is_some());
|
||||
playlist.tracks.append(&mut tracks);
|
||||
for playlist in playlists.iter_mut() {
|
||||
let trr = playlist.tracks.clone();
|
||||
playlist.tracks = Vec::new();
|
||||
for pl_tracks in trr.clone().chunks(45) {
|
||||
if let Ok(tracks) = soundcloud::get_tracks(
|
||||
pl_tracks.to_vec(),
|
||||
client_id.clone(),
|
||||
app_version.clone(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
let mut tracks = tracks;
|
||||
tracks.retain(|t| t.title.is_some());
|
||||
playlist.tracks.append(&mut tracks);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let _ = sender
|
||||
.send(AppEvent::SoundcloudGot(CloudPlaylists {
|
||||
collection: playlists,
|
||||
}))
|
||||
.await;
|
||||
let _ = soundcloud_sender
|
||||
.send(AppEvent::SoundcloudGot(CloudPlaylists {
|
||||
collection: playlists,
|
||||
}))
|
||||
.await;
|
||||
});
|
||||
|
||||
database
|
||||
}
|
||||
|
29
src/theme.rs
29
src/theme.rs
@ -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() {}
|
@ -1,4 +1,4 @@
|
||||
use crate::{screen::AppScreen, theme::Theme};
|
||||
use crate::screen::AppScreen;
|
||||
use color_eyre::owo_colors::OwoColorize;
|
||||
use ratatui::layout::{Constraint, Direction, Flex, Layout};
|
||||
use ratatui::widgets::Paragraph;
|
||||
@ -14,9 +14,9 @@ use tui_big_text::{BigText, PixelSize};
|
||||
pub struct 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()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([Constraint::Percentage(33); 3])
|
||||
|
Loading…
x
Reference in New Issue
Block a user