Fix sync mpris thread

And remove userinterface
This commit is contained in:
2026-03-16 17:36:18 +01:00
parent ef0c33ace5
commit be75066549

View File

@@ -1,9 +1,8 @@
mod database; mod database;
mod http_server; mod http_server;
mod player; 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}; 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, mut mpris_rx) = watch::channel((String::new(), String::new()));
let mpris_tx_http = mpris_tx.clone(); 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"); let player = player::MprisPlayer::new().expect("Could not create player");
loop { loop {
if let Ok((interpret, track)) = player.get_interpret_and_track() { 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. // 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 { //loop {
let (usernumber, userrating) = userinterface::get_user_rating(&db) // let (usernumber, userrating) = userinterface::get_user_rating(&db)
.await // .await
.expect("Can not get user input"); // .expect("Can not get user input");
let (interpret, track) = (*mpris_rx.borrow_and_update()).clone(); // let (interpret, track) = (*mpris_rx.borrow_and_update()).clone();
if let Err(e) = db // if let Err(e) = db
.user_add_rating(usernumber, &interpret, &track, userrating) // .user_add_rating(usernumber, &interpret, &track, userrating)
.await // .await
{ // {
eprintln!("{e}"); // eprintln!("{e}");
} // }
} //}
} }