diff --git a/podcasts-gtk/src/app.rs b/podcasts-gtk/src/app.rs index fe8051a..545b332 100644 --- a/podcasts-gtk/src/app.rs +++ b/podcasts-gtk/src/app.rs @@ -17,10 +17,11 @@ use settings::{self, WindowGeometry}; use stacks::{Content, PopulatedState}; use utils; use widgets::about_dialog; -use widgets::appnotif::InAppNotification; +use widgets::appnotif::{InAppNotification, State}; use widgets::player; use widgets::show_menu::{mark_all_notif, remove_show_notif, ShowMenu}; +use std::cell::RefCell; use std::env; use std::rc::Rc; use std::sync::Arc; @@ -60,6 +61,7 @@ pub(crate) enum Action { HeaderBarShowUpdateIndicator, HeaderBarHideUpdateIndicator, MarkAllPlayerNotification(Arc), + ShowUpdateNotif(Receiver), RemoveShow(Arc), ErrorNotification(String), InitEpisode(i32), @@ -75,6 +77,7 @@ pub(crate) struct App { content: Rc, headerbar: Rc
, player: Rc, + updater: RefCell>, sender: Sender, receiver: Receiver, } @@ -130,6 +133,8 @@ impl App { // Add the player to the main Box wrap.add(&player.action_bar); + let updater = RefCell::new(None); + window.add(&wrap); let app = App { @@ -140,6 +145,7 @@ impl App { headerbar: header, content, player, + updater, sender, receiver, }; @@ -313,6 +319,27 @@ impl App { let notif = InAppNotification::new(&err, 6, callback, undo_cb); notif.show(&self.overlay); } + Action::ShowUpdateNotif(receiver) => { + let callback = move |revealer: gtk::Revealer| { + if let Some(_) = receiver.try_recv() { + revealer.set_reveal_child(false); + return glib::Continue(false); + } + + glib::Continue(true) + }; + let txt = i18n("Fetching new episodes"); + let undo_cb: Option = None; + let updater = InAppNotification::new(&txt, 1, callback, undo_cb); + updater.set_close_state(State::Hidden); + + let old = self.updater.replace(Some(updater)); + old.map(|i| i.destroy()); + self.updater + .borrow() + .as_ref() + .map(|i| i.show(&self.overlay)); + } Action::InitEpisode(rowid) => { let res = self.player.initialize_episode(rowid); debug_assert!(res.is_ok()); diff --git a/podcasts-gtk/src/utils.rs b/podcasts-gtk/src/utils.rs index 95cf8dd..dd74ee9 100644 --- a/podcasts-gtk/src/utils.rs +++ b/podcasts-gtk/src/utils.rs @@ -8,7 +8,7 @@ use gtk::prelude::*; use gtk::{IsA, Widget}; use chrono::prelude::*; -use crossbeam_channel::{unbounded, Sender}; +use crossbeam_channel::{bounded, unbounded, Sender}; use failure::Error; use fragile::Fragile; use rayon; @@ -201,6 +201,8 @@ where S: IntoIterator + Send + 'static, { sender.send(Action::HeaderBarShowUpdateIndicator); + let (up_sender, up_receiver) = bounded(1); + sender.send(Action::ShowUpdateNotif(up_receiver)); rayon::spawn(move || { if let Some(s) = source { @@ -218,6 +220,7 @@ where .ok(); }; + up_sender.send(true); sender.send(Action::HeaderBarHideUpdateIndicator); sender.send(Action::RefreshAllViews); }); diff --git a/podcasts-gtk/src/widgets/appnotif.rs b/podcasts-gtk/src/widgets/appnotif.rs index 3b350ea..8771a75 100644 --- a/podcasts-gtk/src/widgets/appnotif.rs +++ b/podcasts-gtk/src/widgets/appnotif.rs @@ -128,4 +128,8 @@ impl InAppNotification { State::Hidden => self.close.hide(), } } + + pub(crate) fn destroy(self) { + self.revealer.destroy(); + } }