Implemented updater_on_startup and refresh_feed sleep.

This commit is contained in:
Jordan Petridis 2017-11-04 14:40:36 +02:00
parent a9dec8dbe8
commit ab5802cca7
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
5 changed files with 29 additions and 13 deletions

View File

@ -18,6 +18,7 @@
- [ ] Headerbar back button and stack switching - [ ] Headerbar back button and stack switching
- [x] New episode notifier on podcast_flowbox_child, like the one vocal has - [x] New episode notifier on podcast_flowbox_child, like the one vocal has
- [ ] Polish the flowbox_child banner. - [ ] Polish the flowbox_child banner.
- [x] Update on startup
**Unhack stuff:** **Unhack stuff:**
@ -50,7 +51,7 @@
- [ ] Discuss and decide when to schedule the download cleaner. [#3](https://gitlab.gnome.org/alatiera/Hammond/issues/3) - [ ] Discuss and decide when to schedule the download cleaner. [#3](https://gitlab.gnome.org/alatiera/Hammond/issues/3)
- [ ] Unplayed Only and Downloaded only view. - [ ] 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. - [ ] 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. - [ ] OPML import/export // Probably need to create a crate.

View File

@ -49,7 +49,7 @@ pub fn get_headerbar(db: &Database, stack: &gtk::Stack) -> gtk::HeaderBar {
// FIXME: There appears to be a memmory leak here. // FIXME: There appears to be a memmory leak here.
refresh_button.connect_clicked(clone!(stack, db => move |_| { refresh_button.connect_clicked(clone!(stack, db => move |_| {
utils::refresh_feed(&db, &stack, None); utils::refresh_feed(&db, &stack, None, None);
})); }));
header header
@ -64,7 +64,7 @@ fn on_add_bttn_clicked(db: &Database, stack: &gtk::Stack, url: &str) {
if let Ok(s) = source { if let Ok(s) = source {
// update the db // update the db
utils::refresh_feed(db, stack, Some(vec![s])); utils::refresh_feed(db, stack, Some(vec![s]), None);
} else { } else {
error!("Expected Error, feed probably already exists."); error!("Expected Error, feed probably already exists.");
error!("Error: {:?}", source.unwrap_err()); error!("Error: {:?}", source.unwrap_err());

View File

@ -89,6 +89,12 @@ fn build_ui(app: &gtk::Application) {
})); }));
app.add_action(&check); 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 // Get the headerbar
let header = headerbar::get_headerbar(&db, &stack); let header = headerbar::get_headerbar(&db, &stack);

View File

@ -5,22 +5,27 @@ use hammond_data::index_feed;
use hammond_data::models::Source; use hammond_data::models::Source;
use hammond_data::index_feed::Database; use hammond_data::index_feed::Database;
use std::thread; use std::{thread, time};
use std::cell::RefCell; use std::cell::RefCell;
use std::sync::mpsc::{channel, Receiver}; use std::sync::mpsc::{channel, Receiver};
use views::podcasts_view; use views::podcasts_view;
type Foo = RefCell<Option<(Database, gtk::Stack, Receiver<bool>)>>;
// Create a thread local storage that will store the arguments to be transfered. // Create a thread local storage that will store the arguments to be transfered.
thread_local!( thread_local!(static GLOBAL: Foo = RefCell::new(None));
static GLOBAL: RefCell<Option<(Database,
gtk::Stack,
Receiver<bool>)>> = RefCell::new(None));
/// 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.
/// `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. /// When It's done,it queues up a `podcast_view` refresh.
pub fn refresh_feed(db: &Database, stack: &gtk::Stack, source: Option<Vec<Source>>) { pub fn refresh_feed(
db: &Database,
stack: &gtk::Stack,
source: Option<Vec<Source>>,
delay: Option<u64>,
) {
// Create a async channel. // Create a async channel.
let (sender, receiver) = channel(); let (sender, receiver) = channel();
@ -30,6 +35,11 @@ pub fn refresh_feed(db: &Database, stack: &gtk::Stack, source: Option<Vec<Source
})); }));
thread::spawn(clone!(db => move || { thread::spawn(clone!(db => move || {
if let Some(s) = delay{
let t = time::Duration::from_secs(s);
thread::sleep(t);
}
let feeds = { let feeds = {
if let Some(mut vec) = source { if let Some(mut vec) = source {
Ok(index_feed::fetch_feeds(&db, &mut vec)) Ok(index_feed::fetch_feeds(&db, &mut vec))

View File

@ -19,10 +19,9 @@ use gtk;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::{ContainerExt, TextBufferExt}; use gtk::{ContainerExt, TextBufferExt};
thread_local!( type Foo = RefCell<Option<(gtk::Button, gtk::Button, gtk::Button, Receiver<bool>)>>;
static GLOBAL: RefCell<Option<((
gtk::Button, gtk::Button, gtk::Button, Receiver<bool>, thread_local!(static GLOBAL: Foo = RefCell::new(None));
))>> = RefCell::new(None));
fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk::Box { fn epidose_widget(db: &Database, episode: &mut Episode, pd_title: &str) -> gtk::Box {
// This is just a prototype and will be reworked probably. // This is just a prototype and will be reworked probably.