InAppNotification: Allow to set a custom timer
This allows for a custom timer to be set before the callback will be run. Currently all the callbacks only run once and then retunr glib::Continue(false) but this would allow for setting a low timer and have a callback that would determine if it needs to be run again, Continue(true), in a relative responsive way.
This commit is contained in:
parent
336b9a126e
commit
304c92f733
@ -307,7 +307,7 @@ impl App {
|
||||
error!("An error notification was triggered: {}", err);
|
||||
let callback = || glib::Continue(false);
|
||||
let undo_cb: Option<fn()> = None;
|
||||
let notif = InAppNotification::new(&err, callback, undo_cb);
|
||||
let notif = InAppNotification::new(&err, 6, callback, undo_cb);
|
||||
notif.show(&self.overlay);
|
||||
}
|
||||
Action::InitEpisode(rowid) => {
|
||||
|
||||
@ -39,7 +39,12 @@ impl Default for InAppNotification {
|
||||
}
|
||||
|
||||
impl InAppNotification {
|
||||
pub(crate) fn new<F, U>(text: &str, mut callback: F, undo_callback: Option<U>) -> Self
|
||||
pub(crate) fn new<F, U>(
|
||||
text: &str,
|
||||
timer: u32,
|
||||
mut callback: F,
|
||||
undo_callback: Option<U>,
|
||||
) -> Self
|
||||
where
|
||||
F: FnMut() -> glib::Continue + 'static,
|
||||
U: Fn() + 'static,
|
||||
@ -48,10 +53,16 @@ impl InAppNotification {
|
||||
notif.text.set_text(&text);
|
||||
|
||||
let revealer_weak = notif.revealer.downgrade();
|
||||
let id = timeout_add_seconds(6, move || {
|
||||
let mut time = 0;
|
||||
let id = timeout_add_seconds(1, move || {
|
||||
if time < timer {
|
||||
time += 1;
|
||||
return glib::Continue(true);
|
||||
};
|
||||
|
||||
let revealer = match revealer_weak.upgrade() {
|
||||
Some(r) => r,
|
||||
None => return,
|
||||
None => return glib::Continue(false),
|
||||
};
|
||||
|
||||
revealer.set_reveal_child(false);
|
||||
|
||||
@ -145,7 +145,7 @@ pub(crate) fn mark_all_notif(pd: Arc<Show>, sender: &Sender<Action>) -> InAppNot
|
||||
|
||||
let undo_callback = clone!(sender => move || sender.send(Action::RefreshWidgetIfSame(id)));
|
||||
let text = i18n("Marked all episodes as listened");
|
||||
InAppNotification::new(&text, callback, Some(undo_callback))
|
||||
InAppNotification::new(&text, 6, callback, Some(undo_callback))
|
||||
}
|
||||
|
||||
pub(crate) fn remove_show_notif(pd: Arc<Show>, sender: Sender<Action>) -> InAppNotification {
|
||||
@ -177,5 +177,5 @@ pub(crate) fn remove_show_notif(pd: Arc<Show>, sender: Sender<Action>) -> InAppN
|
||||
sender.send(Action::RefreshEpisodesView);
|
||||
};
|
||||
|
||||
InAppNotification::new(&text, callback, Some(undo_callback))
|
||||
InAppNotification::new(&text, 6, callback, Some(undo_callback))
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user