diff --git a/hammond-gtk/src/app.rs b/hammond-gtk/src/app.rs index ef03f7a..8148c01 100644 --- a/hammond-gtk/src/app.rs +++ b/hammond-gtk/src/app.rs @@ -195,6 +195,7 @@ impl App { Ok(Action::HeaderBarShowUpdateIndicator) => headerbar.show_update_notification(), Ok(Action::HeaderBarHideUpdateIndicator) => headerbar.hide_update_notification(), Ok(Action::MarkAllPlayerNotification(pd)) => { + let id = pd.id(); let callback = clone!(sender => move || { if let Err(err) = mark_all_watched(&pd, sender.clone()) { error!("Something went horribly wrong with the notif callback: {}", err); @@ -202,8 +203,12 @@ impl App { glib::Continue(false) }); + let undo_callback = clone!(sender => move || { + sender.send(Action::RefreshWidgetIfSame(id)).expect("Action channel blow up"); + }); + let text = "Marked all episodes as listened".into(); - let notif = InAppNotification::new(text, callback, || {}, sender.clone()); + let notif = InAppNotification::new(text, callback, undo_callback); notif.show(&overlay); } Ok(Action::RemoveShow(pd)) => { @@ -244,8 +249,7 @@ impl App { } }; - let sender_ = sender.clone(); - let notif = InAppNotification::new(text, callback, undo_callback, sender_); + let notif = InAppNotification::new(text, callback, undo_callback); notif.show(&overlay); } Err(_) => (), diff --git a/hammond-gtk/src/appnotif.rs b/hammond-gtk/src/appnotif.rs index 19284fe..e4b9ec2 100644 --- a/hammond-gtk/src/appnotif.rs +++ b/hammond-gtk/src/appnotif.rs @@ -2,11 +2,8 @@ use glib; use gtk; use gtk::prelude::*; -use app::Action; - use std::cell::RefCell; use std::rc::Rc; -use std::sync::mpsc::Sender; #[derive(Debug, Clone)] pub struct InAppNotification { @@ -39,7 +36,6 @@ impl InAppNotification { text: String, mut callback: F, undo_callback: U, - sender: Sender, ) -> Self where F: FnMut() -> glib::Continue + 'static, @@ -67,10 +63,6 @@ impl InAppNotification { // Hide the notification revealer.set_reveal_child(false); - // Refresh the widget if visible - if let Err(err) = sender.send(Action::RefreshWidgetIfVis) { - error!("Action channel blew up: {}", err) - } }); // Hide the revealer when the close button is clicked diff --git a/hammond-gtk/src/widgets/show.rs b/hammond-gtk/src/widgets/show.rs index c02e652..135ff17 100644 --- a/hammond-gtk/src/widgets/show.rs +++ b/hammond-gtk/src/widgets/show.rs @@ -156,9 +156,10 @@ fn on_played_button_clicked(pd: Arc, episodes: >k::Frame, sender: Sen pub fn mark_all_watched(pd: &Podcast, sender: Sender) -> Result<(), Error> { dbqueries::update_none_to_played_now(pd)?; - sender.send(Action::RefreshWidgetIfVis)?; - sender.send(Action::RefreshEpisodesView)?; - Ok(()) + // Not all widgets migth have been loaded when the mark_all is hit + // So we will need to refresh again after it's done. + sender.send(Action::RefreshWidgetIfSame(pd.id()))?; + sender.send(Action::RefreshEpisodesView).map_err(From::from) } // Ideally if we had a custom widget this would have been as simple as: