[fix/improve] Sleep for a 300ms before make the first query

This commit is contained in:
Anas Elgarhy 2023-04-18 22:06:17 +02:00
parent 019ade5303
commit b2d2f7a347
No known key found for this signature in database
GPG key ID: 0501802A1D496528

View file

@ -54,13 +54,16 @@ fn main() {
// Initialize the buffer to store the response from cmus, to compare it with the next one. // Initialize the buffer to store the response from cmus, to compare it with the next one.
let mut previous_response = CmusQueryResponse::default(); let mut previous_response = CmusQueryResponse::default();
// Sleep for a 300ms before make the first query, 'cause if the demon linked with `cmus`
// and the demon is started before `cmus` with the suggested alias, the demon 'll start and exit before `cmus`
sleep!(300);
loop { loop {
// Get the response from cmus. // Get the response from cmus.
let Ok(response) = cmus::ping_cmus(&mut query_command) else { let Ok(response) = cmus::ping_cmus(&mut query_command) else {
if link { if link {
std::process::exit(0) std::process::exit(0)
} else { } else {
// If the track info is the same as the previous one, just sleep for a while and try again. // If there is no response and the `link` mode is not active, just sleep and try again
sleep!(interval); sleep!(interval);
continue; continue;
} }
@ -83,6 +86,7 @@ fn main() {
} }
} }
} }
// If the track info is the same as the previous one, just sleep for a while.
sleep!(interval); sleep!(interval);
} }
} }