More logging to find issue, remove loop from disconnect timer

main
DaXcess 2022-11-11 09:55:38 +01:00
parent 78962772e7
commit 3deb9be06f
2 changed files with 42 additions and 23 deletions

View File

@ -11,7 +11,7 @@ use librespot::{
player::{Player, PlayerEvent}, player::{Player, PlayerEvent},
}, },
}; };
use log::{debug, error, warn}; use log::{debug, error, trace, warn};
use serde_json::json; use serde_json::json;
use crate::{ use crate::{
@ -56,10 +56,14 @@ impl SpoticordPlayer {
session.shutdown(); session.shutdown();
} }
trace!("Creating Spotify session...");
// Connect the session // Connect the session
let (session, _) = match Session::connect(session_config, credentials, None, false).await { let (session, _) = match Session::connect(session_config, credentials, None, false).await {
Ok((session, credentials)) => (session, credentials), Ok((session, credentials)) => (session, credentials),
Err(why) => { Err(why) => {
error!("Failed to create Spotify session: {}", why);
self self
.client .client
.send(IpcPacket::ConnectError(why.to_string())) .send(IpcPacket::ConnectError(why.to_string()))
@ -102,10 +106,14 @@ impl SpoticordPlayer {
let device_id = session.device_id().to_owned(); let device_id = session.device_id().to_owned();
let ipc = self.client.clone(); let ipc = self.client.clone();
trace!("Successfully created Spotify session");
// IPC Handler // IPC Handler
tokio::spawn(async move { tokio::spawn(async move {
let client = reqwest::Client::new(); let client = reqwest::Client::new();
let mut retries = 10;
// Try to switch to the device // Try to switch to the device
loop { loop {
match client match client
@ -121,10 +129,25 @@ impl SpoticordPlayer {
if resp.status() == 202 { if resp.status() == 202 {
debug!("Successfully switched to device"); debug!("Successfully switched to device");
break; 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) => { Err(why) => {
error!("Failed to set device: {}", why); error!("Failed to set device: {}", why);
ipc.send(IpcPacket::ConnectError(why.to_string())).unwrap();
break; break;
} }
} }

View File

@ -583,8 +583,6 @@ impl SpoticordSession {
// Ignore first (immediate) tick // Ignore first (immediate) tick
timer.tick().await; timer.tick().await;
loop {
timer.tick().await; timer.tick().await;
// Make sure this task has not been aborted, if it has this will automatically stop execution. // 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.", "The player has been inactive for too long, and has been disconnected.",
) )
.await; .await;
break;
}
} }
})); }));
} }