diff --git a/hammond-gtk/src/headerbar.rs b/hammond-gtk/src/headerbar.rs index 057957e..4eb1a6d 100644 --- a/hammond-gtk/src/headerbar.rs +++ b/hammond-gtk/src/headerbar.rs @@ -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, 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()); diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index dbe6c3a..9e197e1 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -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(); diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index 56cdc56..c2f484d 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -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, Receiver)>>; // 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, source: Option>, delay: Option) { +pub fn refresh_feed(content: Rc, source: Option>) { // Create a async channel. let (sender, receiver) = channel(); @@ -32,11 +31,6 @@ pub fn refresh_feed(content: Rc, source: Option>, 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))