More logging to find issue, remove loop from disconnect timer
parent
78962772e7
commit
3deb9be06f
|
@ -11,7 +11,7 @@ use librespot::{
|
|||
player::{Player, PlayerEvent},
|
||||
},
|
||||
};
|
||||
use log::{debug, error, warn};
|
||||
use log::{debug, error, trace, warn};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::{
|
||||
|
@ -56,10 +56,14 @@ impl SpoticordPlayer {
|
|||
session.shutdown();
|
||||
}
|
||||
|
||||
trace!("Creating Spotify session...");
|
||||
|
||||
// Connect the session
|
||||
let (session, _) = match Session::connect(session_config, credentials, None, false).await {
|
||||
Ok((session, credentials)) => (session, credentials),
|
||||
Err(why) => {
|
||||
error!("Failed to create Spotify session: {}", why);
|
||||
|
||||
self
|
||||
.client
|
||||
.send(IpcPacket::ConnectError(why.to_string()))
|
||||
|
@ -102,10 +106,14 @@ impl SpoticordPlayer {
|
|||
let device_id = session.device_id().to_owned();
|
||||
let ipc = self.client.clone();
|
||||
|
||||
trace!("Successfully created Spotify session");
|
||||
|
||||
// IPC Handler
|
||||
tokio::spawn(async move {
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
let mut retries = 10;
|
||||
|
||||
// Try to switch to the device
|
||||
loop {
|
||||
match client
|
||||
|
@ -121,10 +129,25 @@ impl SpoticordPlayer {
|
|||
if resp.status() == 202 {
|
||||
debug!("Successfully switched to device");
|
||||
break;
|
||||
} else {
|
||||
trace!("Device switch failed with status {}", resp.status());
|
||||
}
|
||||
|
||||
retries -= 1;
|
||||
|
||||
if retries == 0 {
|
||||
error!("Failed to switch to device");
|
||||
ipc
|
||||
.send(IpcPacket::ConnectError(
|
||||
"Switch to Spoticord device timed out".to_string(),
|
||||
))
|
||||
.unwrap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
Err(why) => {
|
||||
error!("Failed to set device: {}", why);
|
||||
ipc.send(IpcPacket::ConnectError(why.to_string())).unwrap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -583,8 +583,6 @@ impl SpoticordSession {
|
|||
|
||||
// Ignore first (immediate) tick
|
||||
timer.tick().await;
|
||||
|
||||
loop {
|
||||
timer.tick().await;
|
||||
|
||||
// Make sure this task has not been aborted, if it has this will automatically stop execution.
|
||||
|
@ -607,8 +605,6 @@ impl SpoticordSession {
|
|||
"The player has been inactive for too long, and has been disconnected.",
|
||||
)
|
||||
.await;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue