hammond_gtk: Move the gtk callback to an Application channel action.
This commit is contained in:
parent
f30c645596
commit
f873278a96
@ -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()
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
||||
@ -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<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);
|
||||
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<HashMap<(i32, u32), Mutex<SendCell<Pixbuf>>>> = {
|
||||
Mutex::new(HashMap::new())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user