From 750abb519b4a604af7e47e293ec588255584d234 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Thu, 4 Jan 2018 16:42:17 +0200 Subject: [PATCH] GtkApplication: Change the action channel polling interval. --- hammond-gtk/src/app.rs | 23 ++++++++--------------- hammond-gtk/src/views/episodes.rs | 1 + hammond-gtk/src/widgets/episode.rs | 8 ++++---- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/hammond-gtk/src/app.rs b/hammond-gtk/src/app.rs index 471b92a..18bb469 100644 --- a/hammond-gtk/src/app.rs +++ b/hammond-gtk/src/app.rs @@ -13,7 +13,6 @@ use utils; use std::rc::Rc; use std::sync::mpsc::{channel, Receiver, Sender}; -use std::time::Duration; #[derive(Clone, Debug)] pub enum Action { @@ -124,15 +123,15 @@ impl App { self.setup_timed_callbacks(); self.setup_actions(); - let receiver = self.receiver; let content = self.content.clone(); let headerbar = self.header.clone(); let sender = self.sender.clone(); - gtk::idle_add(clone!(content, headerbar => move || { - match receiver.recv_timeout(Duration::from_millis(5)) { + let receiver = self.receiver; + gtk::timeout_add(250, move || { + match receiver.try_recv() { Ok(Action::UpdateSources(source)) => { if let Some(s) = source { - utils::refresh_feed(headerbar.clone(), Some(vec!(s)), sender.clone()) + utils::refresh_feed(headerbar.clone(), Some(vec![s]), sender.clone()) } } Ok(Action::RefreshViews) => { @@ -141,20 +140,14 @@ impl App { Ok(Action::RefreshEpisodesViewBGR) => { content.update_episode_view_if_baground(); } - Ok(Action::HeaderBarShowTile(title)) => { - headerbar.switch_to_back(&title) - } - Ok(Action::HeaderBarNormal) => { - headerbar.switch_to_normal() - } - Ok(Action::HeaderBarHideUpdateIndicator) => { - headerbar.hide_update_notification() - } + Ok(Action::HeaderBarShowTile(title)) => headerbar.switch_to_back(&title), + Ok(Action::HeaderBarNormal) => headerbar.switch_to_normal(), + Ok(Action::HeaderBarHideUpdateIndicator) => headerbar.hide_update_notification(), _ => (), } Continue(true) - })); + }); ApplicationExtManual::run(&self.app_instance, &[]); } diff --git a/hammond-gtk/src/views/episodes.rs b/hammond-gtk/src/views/episodes.rs index cddde81..85d946b 100644 --- a/hammond-gtk/src/views/episodes.rs +++ b/hammond-gtk/src/views/episodes.rs @@ -70,6 +70,7 @@ impl Default for EpisodesView { } } +// TODO: REFACTOR ME impl EpisodesView { pub fn new(sender: Sender) -> Rc { let view = EpisodesView::default(); diff --git a/hammond-gtk/src/widgets/episode.rs b/hammond-gtk/src/widgets/episode.rs index aef5146..eb9eb37 100644 --- a/hammond-gtk/src/widgets/episode.rs +++ b/hammond-gtk/src/widgets/episode.rs @@ -107,7 +107,7 @@ impl EpisodeWidget { title .get_style_context() .map(|c| c.add_class("dim-label")); - sender.clone().send(Action::RefreshEpisodesViewBGR).unwrap(); + sender.send(Action::RefreshEpisodesViewBGR).unwrap(); }; })); @@ -261,12 +261,12 @@ fn on_play_bttn_clicked(episode_id: i32) { // } pub fn episodes_listbox(pd: &Podcast, sender: Sender) -> Result { - let episodes = dbqueries::get_pd_episodeswidgets(pd)?; + let mut episodes = dbqueries::get_pd_episodeswidgets(pd)?; let list = gtk::ListBox::new(); - episodes.into_iter().for_each(|mut ep| { - let widget = EpisodeWidget::new(&mut ep, sender.clone()); + episodes.iter_mut().for_each(|ep| { + let widget = EpisodeWidget::new(ep, sender.clone()); list.add(&widget.container); });