Skip to content

Commit

Permalink
feat: try reconnect on connection loss (#177)
Browse files Browse the repository at this point in the history
refactored main into a core module
fixed preview in artists/album artists
  • Loading branch information
mierak authored Dec 16, 2024
1 parent 69297b3 commit 1129c0e
Show file tree
Hide file tree
Showing 29 changed files with 1,352 additions and 1,023 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file.
- InvertSelection action
- Show album date in the `Artists` and `AlbumArtists` panes
- Config options to sort albums by date or name and to hide or show album date in in the `Artists` and `AlbumArtists` panes
- Rmpc will now try to reconnect and reinitialize on losing connection to mpd

### Changed

Expand Down
215 changes: 0 additions & 215 deletions src/cli.rs

This file was deleted.

8 changes: 6 additions & 2 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
mpd_client::MpdClient,
},
shared::{
events::ClientRequest,
lrc::{Lrc, LrcIndex},
macros::status_warn,
},
Expand All @@ -24,6 +25,7 @@ pub struct AppContext {
pub supported_commands: HashSet<String>,
pub app_event_sender: Sender<AppEvent>,
pub work_sender: Sender<WorkRequest>,
pub client_request_sender: Sender<ClientRequest>,
pub needs_render: Cell<bool>,
pub lrc_index: LrcIndex,
}
Expand All @@ -35,6 +37,7 @@ impl AppContext {
mut config: Config,
app_event_sender: Sender<AppEvent>,
work_sender: Sender<WorkRequest>,
client_request_sender: Sender<ClientRequest>,
) -> Result<Self> {
let status = client.get_status()?;
let queue = client.playlist_info()?.unwrap_or_default();
Expand All @@ -57,6 +60,7 @@ impl AppContext {
supported_commands,
app_event_sender,
work_sender,
client_request_sender,
needs_render: Cell::new(false),
})
}
Expand Down Expand Up @@ -88,13 +92,13 @@ impl AppContext {
replace_id,
callback: Box::new(on_done),
};
if let Err(err) = self.work_sender.send(WorkRequest::MpdQuery(query)) {
if let Err(err) = self.client_request_sender.send(ClientRequest::MpdQuery(query)) {
log::error!(error:? = err; "Failed to send query request");
}
}

pub fn command(&self, callback: impl FnOnce(&mut Client<'_>) -> Result<()> + Send + 'static) {
if let Err(err) = self.work_sender.send(WorkRequest::MpdCommand(MpdCommand {
if let Err(err) = self.client_request_sender.send(ClientRequest::MpdCommand(MpdCommand {
callback: Box::new(callback),
})) {
log::error!(error:? = err; "Failed to send command request");
Expand Down
Loading

0 comments on commit 1129c0e

Please sign in to comment.