treewide: fix various UI bugs; optimize crypto dependencies & format
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: If8fe8b38c1d9c4fecd40ff71f88d2ae06a6a6964
This commit is contained in:
parent
764aafa88d
commit
3ccddce7fd
178 changed files with 58342 additions and 54241 deletions
|
|
@ -5,68 +5,68 @@ use tokio::sync::mpsc;
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum AppEvent {
|
||||
Key(KeyEvent),
|
||||
Tick,
|
||||
ApiResult(ApiResult),
|
||||
Key(KeyEvent),
|
||||
Tick,
|
||||
ApiResult(ApiResult),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ApiResult {
|
||||
MediaList(Vec<crate::client::MediaResponse>),
|
||||
SearchResults(crate::client::SearchResponse),
|
||||
AllTags(Vec<crate::client::TagResponse>),
|
||||
Collections(Vec<crate::client::CollectionResponse>),
|
||||
ImportDone(crate::client::ImportResponse),
|
||||
ScanDone(Vec<crate::client::ScanResponse>),
|
||||
AuditLog(Vec<crate::client::AuditEntryResponse>),
|
||||
Duplicates(Vec<crate::client::DuplicateGroupResponse>),
|
||||
DatabaseStats(crate::client::DatabaseStatsResponse),
|
||||
Statistics(crate::client::LibraryStatisticsResponse),
|
||||
ScheduledTasks(Vec<crate::client::ScheduledTaskResponse>),
|
||||
MediaUpdated,
|
||||
Error(String),
|
||||
MediaList(Vec<crate::client::MediaResponse>),
|
||||
SearchResults(crate::client::SearchResponse),
|
||||
AllTags(Vec<crate::client::TagResponse>),
|
||||
Collections(Vec<crate::client::CollectionResponse>),
|
||||
ImportDone(crate::client::ImportResponse),
|
||||
ScanDone(Vec<crate::client::ScanResponse>),
|
||||
AuditLog(Vec<crate::client::AuditEntryResponse>),
|
||||
Duplicates(Vec<crate::client::DuplicateGroupResponse>),
|
||||
DatabaseStats(crate::client::DatabaseStatsResponse),
|
||||
Statistics(crate::client::LibraryStatisticsResponse),
|
||||
ScheduledTasks(Vec<crate::client::ScheduledTaskResponse>),
|
||||
MediaUpdated,
|
||||
Error(String),
|
||||
}
|
||||
|
||||
pub struct EventHandler {
|
||||
tx: mpsc::UnboundedSender<AppEvent>,
|
||||
rx: mpsc::UnboundedReceiver<AppEvent>,
|
||||
tx: mpsc::UnboundedSender<AppEvent>,
|
||||
rx: mpsc::UnboundedReceiver<AppEvent>,
|
||||
}
|
||||
|
||||
impl EventHandler {
|
||||
pub fn new(tick_rate: Duration) -> Self {
|
||||
let (tx, rx) = mpsc::unbounded_channel();
|
||||
let event_tx = tx.clone();
|
||||
pub fn new(tick_rate: Duration) -> Self {
|
||||
let (tx, rx) = mpsc::unbounded_channel();
|
||||
let event_tx = tx.clone();
|
||||
|
||||
std::thread::spawn(move || {
|
||||
loop {
|
||||
match event::poll(tick_rate) {
|
||||
Ok(true) => {
|
||||
if let Ok(CrosstermEvent::Key(key)) = event::read()
|
||||
&& event_tx.send(AppEvent::Key(key)).is_err()
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(false) => {
|
||||
if event_tx.send(AppEvent::Tick).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!(error = %e, "event poll failed");
|
||||
}
|
||||
}
|
||||
std::thread::spawn(move || {
|
||||
loop {
|
||||
match event::poll(tick_rate) {
|
||||
Ok(true) => {
|
||||
if let Ok(CrosstermEvent::Key(key)) = event::read()
|
||||
&& event_tx.send(AppEvent::Key(key)).is_err()
|
||||
{
|
||||
break;
|
||||
}
|
||||
});
|
||||
},
|
||||
Ok(false) => {
|
||||
if event_tx.send(AppEvent::Tick).is_err() {
|
||||
break;
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
tracing::warn!(error = %e, "event poll failed");
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Self { tx, rx }
|
||||
}
|
||||
Self { tx, rx }
|
||||
}
|
||||
|
||||
pub fn sender(&self) -> mpsc::UnboundedSender<AppEvent> {
|
||||
self.tx.clone()
|
||||
}
|
||||
pub fn sender(&self) -> mpsc::UnboundedSender<AppEvent> {
|
||||
self.tx.clone()
|
||||
}
|
||||
|
||||
pub async fn next(&mut self) -> Option<AppEvent> {
|
||||
self.rx.recv().await
|
||||
}
|
||||
pub async fn next(&mut self) -> Option<AppEvent> {
|
||||
self.rx.recv().await
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue