InAppNotification: Remove the need to pass a sender.

This commit is contained in:
Jordan Petridis 2018-04-13 03:46:32 +03:00
parent 1f1d4af8ba
commit f94ccb9947
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
3 changed files with 11 additions and 14 deletions

View File

@ -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(_) => (),

View File

@ -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<Action>,
) -> 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

View File

@ -156,9 +156,10 @@ fn on_played_button_clicked(pd: Arc<Podcast>, episodes: &gtk::Frame, sender: Sen
pub fn mark_all_watched(pd: &Podcast, sender: Sender<Action>) -> 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: