From 5e1d1e557fecaa32867f2081fbf978760406d7f4 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Fri, 26 Jan 2018 19:15:07 +0200 Subject: [PATCH] GtkApplication: Add an action for showing the headerbar_update_indicator. --- hammond-gtk/src/app.rs | 12 ++++++------ hammond-gtk/src/utils.rs | 10 +++------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/hammond-gtk/src/app.rs b/hammond-gtk/src/app.rs index 5bd083c..ae2c224 100644 --- a/hammond-gtk/src/app.rs +++ b/hammond-gtk/src/app.rs @@ -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(_) => (), } diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index 13437ce..70b641b 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -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
, source: Option>, sender: Sender) { - // TODO: make it an application channel action. - // I missed it before apparently. - headerbar.show_update_notification(); +pub fn refresh_feed(source: Option>, sender: Sender) { + 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.");