Commit f873278a authored by Jordan Petridis's avatar Jordan Petridis 🌱

hammond_gtk: Move the gtk callback to an Application channel action.

parent f30c6455
......@@ -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()
}
_ => (),
}
......
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,57 +14,25 @@ use std::collections::HashMap;
use headerbar::Header;
use app::Action;
type Foo = RefCell<Option<(Rc<Header>, Receiver<bool>)>>;
// 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<Header>,
source: Option<Vec<Source>>,
app_sender: Sender<Action>,
) {
/// When It's done,it queues up a `RefreshViews` action.
pub fn refresh_feed(headerbar: Rc<Header>, source: Option<Vec<Source>>, sender: Sender<Action>) {
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);
});
}
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();
}
}
sender.send(Action::HeaderBarHideUpdateIndicator).unwrap();
sender.send(Action::RefreshViews).unwrap();
});
glib::Continue(false)
}
lazy_static! {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment