diff --git a/hammond-gtk/src/app.rs b/hammond-gtk/src/app.rs index 47cffe0..1c0fc2f 100644 --- a/hammond-gtk/src/app.rs +++ b/hammond-gtk/src/app.rs @@ -132,7 +132,8 @@ impl App { utils::cleanup(cleanup_date); gtk::idle_add(move || { - utils::refresh(None, sender.clone()); + let s: Option> = None; + utils::refresh(s, sender.clone()); glib::Continue(false) }); } @@ -145,7 +146,8 @@ impl App { info!("Auto-refresh every {:?} seconds.", refresh_interval); gtk::timeout_add_seconds(refresh_interval, move || { - utils::refresh(None, sender.clone()); + let s: Option> = None; + utils::refresh(s, sender.clone()); glib::Continue(true) }); @@ -172,7 +174,8 @@ impl App { if let Some(s) = source { utils::refresh(Some(vec![s]), sender.clone()); } else { - utils::refresh(None, sender.clone()); + let s: Option> = None; + utils::refresh(s, sender.clone()); } } Ok(Action::RefreshAllViews) => content.update(), diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index e387773..08f90de 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -111,7 +111,10 @@ pub fn cleanup(cleanup_date: DateTime) { } } -pub fn refresh(source: Option>, sender: Sender) { +pub fn refresh(source: Option, sender: Sender) +where + S: IntoIterator + Send + 'static, +{ if let Err(err) = refresh_feed(source, sender) { error!("An error occured while trying to update the feeds."); error!("Error: {}", err); @@ -136,18 +139,27 @@ pub fn get_cleanup_date(settings: &Settings) -> DateTime { /// Update the rss feed(s) originating from `source`. /// If `source` is None, Fetches all the `Source` entries in the database and updates them. /// When It's done,it queues up a `RefreshViews` action. -fn refresh_feed(source: Option>, sender: Sender) -> Result<(), Error> { +fn refresh_feed(source: Option, sender: Sender) -> Result<(), Error> +where + S: IntoIterator + Send + 'static, +{ sender.send(Action::HeaderBarShowUpdateIndicator)?; rayon::spawn(move || { - let sources = source.unwrap_or_else(|| { - dbqueries::get_sources().expect("Failed to retrieve Sources from the database.") - }); - - if let Err(err) = pipeline::run(sources, false) { - error!("Error While trying to update the database."); - error!("Error msg: {}", err); - } + if let Some(s) = source { + // Refresh only specified feeds + pipeline::run(s, false) + .map_err(|err| error!("Error: {}", err)) + .map_err(|_| error!("Error While trying to update the database.")) + .ok(); + } else { + // Refresh all the feeds + dbqueries::get_sources() + .map(|s| s.into_iter()) + .and_then(|s| pipeline::run(s, false)) + .map_err(|err| error!("Error: {}", err)) + .ok(); + }; sender .send(Action::HeaderBarHideUpdateIndicator)