InAppNotification: Remove the need to pass a sender.
This commit is contained in:
parent
1f1d4af8ba
commit
f94ccb9947
@ -195,6 +195,7 @@ impl App {
|
|||||||
Ok(Action::HeaderBarShowUpdateIndicator) => headerbar.show_update_notification(),
|
Ok(Action::HeaderBarShowUpdateIndicator) => headerbar.show_update_notification(),
|
||||||
Ok(Action::HeaderBarHideUpdateIndicator) => headerbar.hide_update_notification(),
|
Ok(Action::HeaderBarHideUpdateIndicator) => headerbar.hide_update_notification(),
|
||||||
Ok(Action::MarkAllPlayerNotification(pd)) => {
|
Ok(Action::MarkAllPlayerNotification(pd)) => {
|
||||||
|
let id = pd.id();
|
||||||
let callback = clone!(sender => move || {
|
let callback = clone!(sender => move || {
|
||||||
if let Err(err) = mark_all_watched(&pd, sender.clone()) {
|
if let Err(err) = mark_all_watched(&pd, sender.clone()) {
|
||||||
error!("Something went horribly wrong with the notif callback: {}", err);
|
error!("Something went horribly wrong with the notif callback: {}", err);
|
||||||
@ -202,8 +203,12 @@ impl App {
|
|||||||
glib::Continue(false)
|
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 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);
|
notif.show(&overlay);
|
||||||
}
|
}
|
||||||
Ok(Action::RemoveShow(pd)) => {
|
Ok(Action::RemoveShow(pd)) => {
|
||||||
@ -244,8 +249,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let sender_ = sender.clone();
|
let notif = InAppNotification::new(text, callback, undo_callback);
|
||||||
let notif = InAppNotification::new(text, callback, undo_callback, sender_);
|
|
||||||
notif.show(&overlay);
|
notif.show(&overlay);
|
||||||
}
|
}
|
||||||
Err(_) => (),
|
Err(_) => (),
|
||||||
|
|||||||
@ -2,11 +2,8 @@ use glib;
|
|||||||
use gtk;
|
use gtk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
||||||
use app::Action;
|
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::mpsc::Sender;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct InAppNotification {
|
pub struct InAppNotification {
|
||||||
@ -39,7 +36,6 @@ impl InAppNotification {
|
|||||||
text: String,
|
text: String,
|
||||||
mut callback: F,
|
mut callback: F,
|
||||||
undo_callback: U,
|
undo_callback: U,
|
||||||
sender: Sender<Action>,
|
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
F: FnMut() -> glib::Continue + 'static,
|
F: FnMut() -> glib::Continue + 'static,
|
||||||
@ -67,10 +63,6 @@ impl InAppNotification {
|
|||||||
|
|
||||||
// Hide the notification
|
// Hide the notification
|
||||||
revealer.set_reveal_child(false);
|
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
|
// Hide the revealer when the close button is clicked
|
||||||
|
|||||||
@ -156,9 +156,10 @@ fn on_played_button_clicked(pd: Arc<Podcast>, episodes: >k::Frame, sender: Sen
|
|||||||
|
|
||||||
pub fn mark_all_watched(pd: &Podcast, sender: Sender<Action>) -> Result<(), Error> {
|
pub fn mark_all_watched(pd: &Podcast, sender: Sender<Action>) -> Result<(), Error> {
|
||||||
dbqueries::update_none_to_played_now(pd)?;
|
dbqueries::update_none_to_played_now(pd)?;
|
||||||
sender.send(Action::RefreshWidgetIfVis)?;
|
// Not all widgets migth have been loaded when the mark_all is hit
|
||||||
sender.send(Action::RefreshEpisodesView)?;
|
// So we will need to refresh again after it's done.
|
||||||
Ok(())
|
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:
|
// Ideally if we had a custom widget this would have been as simple as:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user