GtkApplication: Add an action for showing the headerbar_update_indicator.

This commit is contained in:
Jordan Petridis 2018-01-26 19:15:07 +02:00
parent a7e3b1b99e
commit 5e1d1e557f
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 9 additions and 13 deletions

View File

@ -30,6 +30,7 @@ pub enum Action {
ShowShowsAnimated,
HeaderBarShowTile(String),
HeaderBarNormal,
HeaderBarShowUpdateIndicator,
HeaderBarHideUpdateIndicator,
}
@ -87,21 +88,19 @@ impl App {
}
pub fn setup_timed_callbacks(&self) {
let header = self.header.clone();
let sender = self.sender.clone();
// Update the feeds right after the Application is initialized.
gtk::timeout_add_seconds(2, move || {
utils::refresh_feed(header.clone(), None, sender.clone());
utils::refresh_feed(None, sender.clone());
glib::Continue(false)
});
let header = self.header.clone();
let sender = self.sender.clone();
// 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, move || {
utils::refresh_feed(header.clone(), None, sender.clone());
utils::refresh_feed(None, sender.clone());
glib::Continue(true)
});
@ -128,9 +127,9 @@ impl App {
match receiver.recv_timeout(Duration::from_millis(10)) {
Ok(Action::UpdateSources(source)) => {
if let Some(s) = source {
utils::refresh_feed(headerbar.clone(), Some(vec![s]), sender.clone())
utils::refresh_feed(Some(vec![s]), sender.clone())
} else {
utils::refresh_feed(headerbar.clone(), None, sender.clone())
utils::refresh_feed(None, sender.clone())
}
}
Ok(Action::RefreshAllViews) => content.update(),
@ -145,6 +144,7 @@ impl App {
Ok(Action::ShowShowsAnimated) => content.get_shows().switch_podcasts_animated(),
Ok(Action::HeaderBarShowTile(title)) => headerbar.switch_to_back(&title),
Ok(Action::HeaderBarNormal) => headerbar.switch_to_normal(),
Ok(Action::HeaderBarShowUpdateIndicator) => headerbar.show_update_notification(),
Ok(Action::HeaderBarHideUpdateIndicator) => headerbar.hide_update_notification(),
Err(_) => (),
}

View File

@ -8,25 +8,21 @@ use hammond_data::pipeline;
use hammond_downloader::downloader;
use std::collections::HashMap;
use std::sync::{Arc, Mutex, RwLock};
use std::sync::{Mutex, RwLock};
use std::sync::mpsc::Sender;
use std::thread;
use app::Action;
use headerbar::Header;
/// 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.
pub fn refresh_feed(headerbar: Arc<Header>, source: Option<Vec<Source>>, sender: Sender<Action>) {
// TODO: make it an application channel action.
// I missed it before apparently.
headerbar.show_update_notification();
pub fn refresh_feed(source: Option<Vec<Source>>, sender: Sender<Action>) {
sender.send(Action::HeaderBarShowUpdateIndicator).unwrap();
thread::spawn(move || {
// FIXME: This is messy at best.
if let Some(s) = source {
// feed::index_loop(s);
// TODO: determine if it needs to ignore_etags.
if let Err(err) = pipeline::run(s, true) {
error!("Error While trying to update the database.");