Implemented updater_on_startup and refresh_feed sleep.
This commit is contained in:
parent
a9dec8dbe8
commit
ab5802cca7
3
TODO.md
3
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.
|
||||
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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: >k::Stack, source: Option<Vec<Source>>) {
|
||||
pub fn refresh_feed(
|
||||
db: &Database,
|
||||
stack: >k::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: >k::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))
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user