1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-01 18:51:04 +02:00

fix(mpd): stops working if connection lost

The client will now attempt to reconnect when a connection loss is detected.

Fixes #21.
This commit is contained in:
Jake Stanger 2023-01-28 14:40:12 +00:00
parent 1cdfebf8db
commit 90cd078973
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
4 changed files with 67 additions and 25 deletions

View file

@ -178,30 +178,43 @@ impl Module<Button> for MusicModule {
let music_dir = self.music_dir.clone();
spawn(async move {
let mut rx = {
let client = get_client(player_type, &host, music_dir).await;
client.subscribe_change()
};
loop {
let mut rx = {
let client = get_client(player_type, &host, music_dir.clone()).await;
client.subscribe_change()
};
while let Ok((track, status)) = rx.recv().await {
match track {
Some(track) => {
let display_string =
replace_tokens(format.as_str(), &tokens, &track, &status, &icons);
while let Ok(update) = rx.recv().await {
match update {
PlayerUpdate::Update(track, status) => match *track {
Some(track) => {
let display_string = replace_tokens(
format.as_str(),
&tokens,
&track,
&status,
&icons,
);
let update = SongUpdate {
song: track,
status,
display_string,
};
let update = SongUpdate {
song: track,
status,
display_string,
};
tx.send(ModuleUpdateEvent::Update(Some(update))).await?;
tx.send(ModuleUpdateEvent::Update(Some(update)))
.await
.expect(ERR_CHANNEL_SEND);
}
None => tx
.send(ModuleUpdateEvent::Update(None))
.await
.expect(ERR_CHANNEL_SEND),
},
PlayerUpdate::Disconnect => break,
}
None => tx.send(ModuleUpdateEvent::Update(None)).await?,
}
}
Ok::<(), mpsc::error::SendError<ModuleUpdateEvent<Self::SendMessage>>>(())
});
}