diff --git a/hammond-gtk/src/app.rs b/hammond-gtk/src/app.rs index 15ce75f..471b92a 100644 --- a/hammond-gtk/src/app.rs +++ b/hammond-gtk/src/app.rs @@ -22,6 +22,7 @@ pub enum Action { RefreshEpisodesViewBGR, HeaderBarShowTile(String), HeaderBarNormal, + HeaderBarHideUpdateIndicator, } #[derive(Debug)] @@ -146,6 +147,9 @@ impl App { Ok(Action::HeaderBarNormal) => { headerbar.switch_to_normal() } + Ok(Action::HeaderBarHideUpdateIndicator) => { + headerbar.hide_update_notification() + } _ => (), } diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index 62f5e43..b4ff12f 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -1,5 +1,4 @@ use send_cell::SendCell; -use glib; use gdk_pixbuf::Pixbuf; use hammond_data::feed; @@ -7,8 +6,7 @@ use hammond_data::{PodcastCoverQuery, Source}; use hammond_downloader::downloader; use std::thread; -use std::cell::RefCell; -use std::sync::mpsc::{channel, Receiver, Sender}; +use std::sync::mpsc::Sender; use std::sync::Mutex; use std::rc::Rc; use std::collections::HashMap; @@ -16,59 +14,27 @@ use std::collections::HashMap; use headerbar::Header; use app::Action; -type Foo = RefCell, Receiver)>>; - -// Create a thread local storage that will store the arguments to be transfered. -thread_local!(static GLOBAL: Foo = RefCell::new(None)); - -/// Update the rss feed(s) originating from `Source`. +/// Update the rss feed(s) originating from `source`. /// If `source` is None, Fetches all the `Source` entries in the database and updates them. -/// `delay` represents the desired time in seconds for the thread to sleep before executing. -/// When It's done,it queues up a `podcast_view` refresh. -pub fn refresh_feed( - headerbar: Rc
, - source: Option>, - app_sender: Sender, -) { +/// When It's done,it queues up a `RefreshViews` action. +pub fn refresh_feed(headerbar: Rc
, source: Option>, sender: Sender) { headerbar.show_update_notification(); - // Create a async channel. - let (sender, receiver) = channel(); - - // Pass the desired arguments into the Local Thread Storage. - GLOBAL.with(clone!(headerbar => move |global| { - *global.borrow_mut() = Some((headerbar.clone(), receiver)); - })); - thread::spawn(move || { if let Some(s) = source { feed::index_loop(s); } else { - let e = feed::index_all(); - if let Err(err) = e { + if let Err(err) = feed::index_all() { error!("Error While trying to update the database."); error!("Error msg: {}", err); - }; + } }; - app_sender.send(Action::RefreshViews).unwrap(); - - let _ = sender.send(true); - glib::idle_add(hide_update_indicator); + sender.send(Action::HeaderBarHideUpdateIndicator).unwrap(); + sender.send(Action::RefreshViews).unwrap(); }); } -fn hide_update_indicator() -> glib::Continue { - GLOBAL.with(|global| { - if let Some((ref headerbar, ref reciever)) = *global.borrow() { - if reciever.try_recv().is_ok() { - headerbar.hide_update_notification(); - } - } - }); - glib::Continue(false) -} - lazy_static! { static ref CACHED_PIXBUFS: Mutex>>> = { Mutex::new(HashMap::new())