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,
|
RefreshEpisodesViewBGR,
|
||||||
HeaderBarShowTile(String),
|
HeaderBarShowTile(String),
|
||||||
HeaderBarNormal,
|
HeaderBarNormal,
|
||||||
|
HeaderBarHideUpdateIndicator,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -146,6 +147,9 @@ impl App {
|
|||||||
Ok(Action::HeaderBarNormal) => {
|
Ok(Action::HeaderBarNormal) => {
|
||||||
headerbar.switch_to_normal()
|
headerbar.switch_to_normal()
|
||||||
}
|
}
|
||||||
|
Ok(Action::HeaderBarHideUpdateIndicator) => {
|
||||||
|
headerbar.hide_update_notification()
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
use send_cell::SendCell;
|
use send_cell::SendCell;
|
||||||
use glib;
|
|
||||||
use gdk_pixbuf::Pixbuf;
|
use gdk_pixbuf::Pixbuf;
|
||||||
|
|
||||||
use hammond_data::feed;
|
use hammond_data::feed;
|
||||||
@ -7,8 +6,7 @@ use hammond_data::{PodcastCoverQuery, Source};
|
|||||||
use hammond_downloader::downloader;
|
use hammond_downloader::downloader;
|
||||||
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::cell::RefCell;
|
use std::sync::mpsc::Sender;
|
||||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@ -16,59 +14,27 @@ use std::collections::HashMap;
|
|||||||
use headerbar::Header;
|
use headerbar::Header;
|
||||||
use app::Action;
|
use app::Action;
|
||||||
|
|
||||||
type Foo = RefCell<Option<(Rc<Header>, Receiver<bool>)>>;
|
/// Update the rss feed(s) originating from `source`.
|
||||||
|
|
||||||
// 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`.
|
|
||||||
/// If `source` is None, Fetches all the `Source` entries in the database and updates them.
|
/// 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 `RefreshViews` action.
|
||||||
/// When It's done,it queues up a `podcast_view` refresh.
|
pub fn refresh_feed(headerbar: Rc<Header>, source: Option<Vec<Source>>, sender: Sender<Action>) {
|
||||||
pub fn refresh_feed(
|
|
||||||
headerbar: Rc<Header>,
|
|
||||||
source: Option<Vec<Source>>,
|
|
||||||
app_sender: Sender<Action>,
|
|
||||||
) {
|
|
||||||
headerbar.show_update_notification();
|
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 || {
|
thread::spawn(move || {
|
||||||
if let Some(s) = source {
|
if let Some(s) = source {
|
||||||
feed::index_loop(s);
|
feed::index_loop(s);
|
||||||
} else {
|
} else {
|
||||||
let e = feed::index_all();
|
if let Err(err) = feed::index_all() {
|
||||||
if let Err(err) = e {
|
|
||||||
error!("Error While trying to update the database.");
|
error!("Error While trying to update the database.");
|
||||||
error!("Error msg: {}", err);
|
error!("Error msg: {}", err);
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
app_sender.send(Action::RefreshViews).unwrap();
|
sender.send(Action::HeaderBarHideUpdateIndicator).unwrap();
|
||||||
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
glib::Continue(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref CACHED_PIXBUFS: Mutex<HashMap<(i32, u32), Mutex<SendCell<Pixbuf>>>> = {
|
static ref CACHED_PIXBUFS: Mutex<HashMap<(i32, u32), Mutex<SendCell<Pixbuf>>>> = {
|
||||||
Mutex::new(HashMap::new())
|
Mutex::new(HashMap::new())
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user