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
5 changed files with 29 additions and 13 deletions
+2 -2
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.
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: &gtk::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());
+6
View File
@@ -89,6 +89,12 @@ fn build_ui(app: &gtk::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);
+16 -6
View File
@@ -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<Option<(Database, gtk::Stack, Receiver<bool>)>>;
// Create a thread local storage that will store the arguments to be transfered.
thread_local!(
static GLOBAL: RefCell<Option<(Database,
gtk::Stack,
Receiver<bool>)>> = 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: &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.
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 || {
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))
+3 -4
View File
@@ -19,10 +19,9 @@ use gtk;
use gtk::prelude::*;
use gtk::{ContainerExt, TextBufferExt};
thread_local!(
static GLOBAL: RefCell<Option<((
gtk::Button, gtk::Button, gtk::Button, Receiver<bool>,
))>> = RefCell::new(None));
type Foo = RefCell<Option<(gtk::Button, gtk::Button, gtk::Button, Receiver<bool>)>>;
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.