Fix sync mpris thread
And remove userinterface
This commit is contained in:
31
src/main.rs
31
src/main.rs
@@ -1,9 +1,8 @@
|
||||
mod database;
|
||||
mod http_server;
|
||||
mod player;
|
||||
mod userinterface;
|
||||
|
||||
use std::{env::args, sync::Arc, thread::sleep, time::Duration};
|
||||
use std::{env::args, sync::Arc, time::Duration};
|
||||
|
||||
use tokio::{join, sync::watch};
|
||||
|
||||
@@ -67,7 +66,7 @@ async fn main() {
|
||||
let (mpris_tx, mut mpris_rx) = watch::channel((String::new(), String::new()));
|
||||
|
||||
let mpris_tx_http = mpris_tx.clone();
|
||||
tokio::spawn(async move {
|
||||
std::thread::spawn(move || {
|
||||
let player = player::MprisPlayer::new().expect("Could not create player");
|
||||
loop {
|
||||
if let Ok((interpret, track)) = player.get_interpret_and_track() {
|
||||
@@ -76,7 +75,7 @@ async fn main() {
|
||||
}
|
||||
}
|
||||
// Use the std sleep here to avoid an await which will requires player to be Send.
|
||||
sleep(Duration::from_millis(10));
|
||||
std::thread::sleep(Duration::from_millis(1000));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -94,17 +93,17 @@ async fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
loop {
|
||||
let (usernumber, userrating) = userinterface::get_user_rating(&db)
|
||||
.await
|
||||
.expect("Can not get user input");
|
||||
let (interpret, track) = (*mpris_rx.borrow_and_update()).clone();
|
||||
//loop {
|
||||
// let (usernumber, userrating) = userinterface::get_user_rating(&db)
|
||||
// .await
|
||||
// .expect("Can not get user input");
|
||||
// let (interpret, track) = (*mpris_rx.borrow_and_update()).clone();
|
||||
|
||||
if let Err(e) = db
|
||||
.user_add_rating(usernumber, &interpret, &track, userrating)
|
||||
.await
|
||||
{
|
||||
eprintln!("{e}");
|
||||
}
|
||||
}
|
||||
// if let Err(e) = db
|
||||
// .user_add_rating(usernumber, &interpret, &track, userrating)
|
||||
// .await
|
||||
// {
|
||||
// eprintln!("{e}");
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user