From ab5802cca777ae223207b4fa9d8bb689bdfd8336 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Sat, 4 Nov 2017 14:40:36 +0200 Subject: [PATCH] Implemented updater_on_startup and refresh_feed sleep. --- TODO.md | 3 ++- hammond-gtk/src/headerbar.rs | 4 ++-- hammond-gtk/src/main.rs | 6 ++++++ hammond-gtk/src/utils.rs | 22 ++++++++++++++++------ hammond-gtk/src/widgets/episode.rs | 7 +++---- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/TODO.md b/TODO.md index c6f9265..50224ee 100644 --- a/TODO.md +++ b/TODO.md @@ -18,6 +18,7 @@ - [ ] Headerbar back button and stack switching - [x] New episode notifier on podcast_flowbox_child, like the one vocal has - [ ] Polish the flowbox_child banner. +- [x] Update on startup **Unhack stuff:** @@ -50,7 +51,7 @@ - [ ] Discuss and decide when to schedule the download cleaner. [#3](https://gitlab.gnome.org/alatiera/Hammond/issues/3) - [ ] Unplayed Only and Downloaded only view. -- [ ] Auto-updater, update on startup +- [ ] Auto-updater - [ ] Make use of file metadas, [This](https://github.com/GuillaumeGomez/audio-video-metadata) might be helpfull. - [ ] OPML import/export // Probably need to create a crate. diff --git a/hammond-gtk/src/headerbar.rs b/hammond-gtk/src/headerbar.rs index 7ac1d69..3ec1930 100644 --- a/hammond-gtk/src/headerbar.rs +++ b/hammond-gtk/src/headerbar.rs @@ -49,7 +49,7 @@ pub fn get_headerbar(db: &Database, stack: >k::Stack) -> gtk::HeaderBar { // FIXME: There appears to be a memmory leak here. refresh_button.connect_clicked(clone!(stack, db => move |_| { - utils::refresh_feed(&db, &stack, None); + utils::refresh_feed(&db, &stack, None, None); })); header @@ -64,7 +64,7 @@ fn on_add_bttn_clicked(db: &Database, stack: >k::Stack, url: &str) { if let Ok(s) = source { // update the db - utils::refresh_feed(db, stack, Some(vec![s])); + utils::refresh_feed(db, stack, Some(vec![s]), None); } else { error!("Expected Error, feed probably already exists."); error!("Error: {:?}", source.unwrap_err()); diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index a12acb0..f21b854 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -89,6 +89,12 @@ fn build_ui(app: >k::Application) { })); app.add_action(&check); + // queue a db update 1 minute after the startup. + gtk::idle_add(clone!(db, stack => move || { + utils::refresh_feed(&db, &stack, None, Some(60)); + glib::Continue(false) + })); + // Get the headerbar let header = headerbar::get_headerbar(&db, &stack); diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index d3631fb..c06f505 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -5,22 +5,27 @@ use hammond_data::index_feed; use hammond_data::models::Source; use hammond_data::index_feed::Database; -use std::thread; +use std::{thread, time}; use std::cell::RefCell; use std::sync::mpsc::{channel, Receiver}; use views::podcasts_view; +type Foo = RefCell)>>; + // Create a thread local storage that will store the arguments to be transfered. -thread_local!( - static GLOBAL: RefCell)>> = RefCell::new(None)); +thread_local!(static GLOBAL: Foo = RefCell::new(None)); /// Update the rss feed(s) originating from `Source`. /// If `source` is None, Fetches all the `Source` entries in the database and updates them. +/// `delay` represents the desired time in seconds for the thread to sleep before executing. /// When It's done,it queues up a `podcast_view` refresh. -pub fn refresh_feed(db: &Database, stack: >k::Stack, source: Option>) { +pub fn refresh_feed( + db: &Database, + stack: >k::Stack, + source: Option>, + delay: Option, +) { // Create a async channel. let (sender, receiver) = channel(); @@ -30,6 +35,11 @@ pub fn refresh_feed(db: &Database, stack: >k::Stack, source: Option move || { + if let Some(s) = delay{ + let t = time::Duration::from_secs(s); + thread::sleep(t); + } + let feeds = { if let Some(mut vec) = source { Ok(index_feed::fetch_feeds(&db, &mut vec)) diff --git a/hammond-gtk/src/widgets/episode.rs b/hammond-gtk/src/widgets/episode.rs index 7882b02..00eb3c5 100644 --- a/hammond-gtk/src/widgets/episode.rs +++ b/hammond-gtk/src/widgets/episode.rs @@ -19,10 +19,9 @@ use gtk; use gtk::prelude::*; use gtk::{ContainerExt, TextBufferExt}; -thread_local!( - static GLOBAL: RefCell, - ))>> = RefCell::new(None)); +type Foo = RefCell)>>; + +thread_local!(static GLOBAL: Foo = RefCell::new(None)); fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk::Box { // This is just a prototype and will be reworked probably.