Added an auto-updater that runs each hour.
This commit is contained in:
parent
75fe0f8ff5
commit
35009e2574
@ -75,7 +75,7 @@ impl Header {
|
||||
|
||||
// FIXME: There appears to be a memmory leak here.
|
||||
self.refresh.connect_clicked(clone!(content => move |_| {
|
||||
utils::refresh_feed(content.clone(), None, None);
|
||||
utils::refresh_feed(content.clone(), None);
|
||||
}));
|
||||
|
||||
let switch = &self.switch;
|
||||
@ -120,7 +120,7 @@ fn on_add_bttn_clicked(content: Rc<Content>, entry: >k::Entry) {
|
||||
if let Ok(s) = source {
|
||||
info!("{:?} feed added", url);
|
||||
// update the db
|
||||
utils::refresh_feed(content, Some(vec![s]), None);
|
||||
utils::refresh_feed(content, Some(vec![s]));
|
||||
} else {
|
||||
error!("Feed probably already exists.");
|
||||
error!("Error: {:?}", source.unwrap_err());
|
||||
|
||||
@ -90,11 +90,25 @@ fn build_ui(app: >k::Application) {
|
||||
});
|
||||
app.add_action(&check);
|
||||
|
||||
// queue a db update 1 minute after the startup.
|
||||
gtk::idle_add(clone!(ct => move || {
|
||||
utils::refresh_feed(ct.clone(), None, Some(60));
|
||||
// Update on startup
|
||||
gtk::timeout_add_seconds(
|
||||
30,
|
||||
clone!(ct => move || {
|
||||
utils::refresh_feed(ct.clone(), None);
|
||||
glib::Continue(false)
|
||||
}));
|
||||
}),
|
||||
);
|
||||
|
||||
// Auto-updater, runs every hour.
|
||||
// TODO: expose the interval in which it run to a user setting.
|
||||
// TODO: show notifications.
|
||||
gtk::timeout_add_seconds(
|
||||
3600,
|
||||
clone!(ct => move || {
|
||||
utils::refresh_feed(ct.clone(), None);
|
||||
glib::Continue(true)
|
||||
}),
|
||||
);
|
||||
|
||||
gtk::idle_add(move || {
|
||||
let _ = checkup();
|
||||
|
||||
@ -5,14 +5,13 @@ use hammond_data::feed;
|
||||
use hammond_data::{Podcast, Source};
|
||||
use hammond_downloader::downloader;
|
||||
|
||||
use std::{thread, time};
|
||||
use std::thread;
|
||||
use std::cell::RefCell;
|
||||
use std::sync::mpsc::{channel, Receiver};
|
||||
use std::rc::Rc;
|
||||
|
||||
use content::Content;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
type Foo = RefCell<Option<(Rc<Content>, Receiver<bool>)>>;
|
||||
|
||||
// Create a thread local storage that will store the arguments to be transfered.
|
||||
@ -22,7 +21,7 @@ thread_local!(static GLOBAL: Foo = RefCell::new(None));
|
||||
/// 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(content: Rc<Content>, source: Option<Vec<Source>>, delay: Option<u64>) {
|
||||
pub fn refresh_feed(content: Rc<Content>, source: Option<Vec<Source>>) {
|
||||
// Create a async channel.
|
||||
let (sender, receiver) = channel();
|
||||
|
||||
@ -32,11 +31,6 @@ pub fn refresh_feed(content: Rc<Content>, source: Option<Vec<Source>>, delay: Op
|
||||
}));
|
||||
|
||||
thread::spawn(move || {
|
||||
if let Some(s) = delay {
|
||||
let t = time::Duration::from_secs(s);
|
||||
thread::sleep(t);
|
||||
}
|
||||
|
||||
let feeds = {
|
||||
if let Some(vec) = source {
|
||||
Ok(feed::fetch(vec))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user