From b2d2f7a3477c0e65681227bcb4d503d8ae8b3b4c Mon Sep 17 00:00:00 2001 From: Anas Elgarhy Date: Tue, 18 Apr 2023 22:06:17 +0200 Subject: [PATCH] [fix/improve] Sleep for a 300ms before make the first query --- src/bin/cmus-notify.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bin/cmus-notify.rs b/src/bin/cmus-notify.rs index 89e7aa0..493ce52 100644 --- a/src/bin/cmus-notify.rs +++ b/src/bin/cmus-notify.rs @@ -54,13 +54,16 @@ fn main() { // Initialize the buffer to store the response from cmus, to compare it with the next one. 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 { // Get the response from cmus. let Ok(response) = cmus::ping_cmus(&mut query_command) else { if link { std::process::exit(0) } 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); 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); } }