h-gtk/utils: Make refresh_feed methods generic over Source.
This commit is contained in:
parent
7b71f59d3e
commit
4db7628eed
@ -132,7 +132,8 @@ impl App {
|
|||||||
utils::cleanup(cleanup_date);
|
utils::cleanup(cleanup_date);
|
||||||
|
|
||||||
gtk::idle_add(move || {
|
gtk::idle_add(move || {
|
||||||
utils::refresh(None, sender.clone());
|
let s: Option<Vec<_>> = None;
|
||||||
|
utils::refresh(s, sender.clone());
|
||||||
glib::Continue(false)
|
glib::Continue(false)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -145,7 +146,8 @@ impl App {
|
|||||||
info!("Auto-refresh every {:?} seconds.", refresh_interval);
|
info!("Auto-refresh every {:?} seconds.", refresh_interval);
|
||||||
|
|
||||||
gtk::timeout_add_seconds(refresh_interval, move || {
|
gtk::timeout_add_seconds(refresh_interval, move || {
|
||||||
utils::refresh(None, sender.clone());
|
let s: Option<Vec<_>> = None;
|
||||||
|
utils::refresh(s, sender.clone());
|
||||||
|
|
||||||
glib::Continue(true)
|
glib::Continue(true)
|
||||||
});
|
});
|
||||||
@ -172,7 +174,8 @@ impl App {
|
|||||||
if let Some(s) = source {
|
if let Some(s) = source {
|
||||||
utils::refresh(Some(vec![s]), sender.clone());
|
utils::refresh(Some(vec![s]), sender.clone());
|
||||||
} else {
|
} else {
|
||||||
utils::refresh(None, sender.clone());
|
let s: Option<Vec<_>> = None;
|
||||||
|
utils::refresh(s, sender.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Action::RefreshAllViews) => content.update(),
|
Ok(Action::RefreshAllViews) => content.update(),
|
||||||
|
|||||||
@ -111,7 +111,10 @@ pub fn cleanup(cleanup_date: DateTime<Utc>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn refresh(source: Option<Vec<Source>>, sender: Sender<Action>) {
|
pub fn refresh<S>(source: Option<S>, sender: Sender<Action>)
|
||||||
|
where
|
||||||
|
S: IntoIterator<Item = Source> + Send + 'static,
|
||||||
|
{
|
||||||
if let Err(err) = refresh_feed(source, sender) {
|
if let Err(err) = refresh_feed(source, sender) {
|
||||||
error!("An error occured while trying to update the feeds.");
|
error!("An error occured while trying to update the feeds.");
|
||||||
error!("Error: {}", err);
|
error!("Error: {}", err);
|
||||||
@ -136,18 +139,27 @@ pub fn get_cleanup_date(settings: &Settings) -> DateTime<Utc> {
|
|||||||
/// 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.
|
/// 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.
|
/// When It's done,it queues up a `RefreshViews` action.
|
||||||
fn refresh_feed(source: Option<Vec<Source>>, sender: Sender<Action>) -> Result<(), Error> {
|
fn refresh_feed<S>(source: Option<S>, sender: Sender<Action>) -> Result<(), Error>
|
||||||
|
where
|
||||||
|
S: IntoIterator<Item = Source> + Send + 'static,
|
||||||
|
{
|
||||||
sender.send(Action::HeaderBarShowUpdateIndicator)?;
|
sender.send(Action::HeaderBarShowUpdateIndicator)?;
|
||||||
|
|
||||||
rayon::spawn(move || {
|
rayon::spawn(move || {
|
||||||
let sources = source.unwrap_or_else(|| {
|
if let Some(s) = source {
|
||||||
dbqueries::get_sources().expect("Failed to retrieve Sources from the database.")
|
// Refresh only specified feeds
|
||||||
});
|
pipeline::run(s, false)
|
||||||
|
.map_err(|err| error!("Error: {}", err))
|
||||||
if let Err(err) = pipeline::run(sources, false) {
|
.map_err(|_| error!("Error While trying to update the database."))
|
||||||
error!("Error While trying to update the database.");
|
.ok();
|
||||||
error!("Error msg: {}", err);
|
} 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
|
sender
|
||||||
.send(Action::HeaderBarHideUpdateIndicator)
|
.send(Action::HeaderBarHideUpdateIndicator)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user