ShowWidget: Upon unsubing spawn IO heavy tasks into a seperate thread.
This commit is contained in:
parent
299d2e8db1
commit
65a2d666a3
@ -16,6 +16,7 @@ use app::Action;
|
|||||||
|
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::thread;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -120,23 +121,28 @@ fn on_unsub_button_clicked(
|
|||||||
unsub_button: >k::Button,
|
unsub_button: >k::Button,
|
||||||
sender: Sender<Action>,
|
sender: Sender<Action>,
|
||||||
) {
|
) {
|
||||||
let res = dbqueries::remove_feed(pd);
|
|
||||||
if res.is_ok() {
|
|
||||||
info!("{} was removed succesfully.", pd.title());
|
|
||||||
// hack to get away without properly checking for none.
|
// hack to get away without properly checking for none.
|
||||||
// if pressed twice would panic.
|
// if pressed twice would panic.
|
||||||
unsub_button.hide();
|
unsub_button.hide();
|
||||||
|
// Spawn a thread so it won't block the ui.
|
||||||
|
thread::spawn(clone!(pd => move || {
|
||||||
|
let res = dbqueries::remove_feed(&pd);
|
||||||
|
if res.is_ok() {
|
||||||
|
info!("{} was removed succesfully.", pd.title());
|
||||||
|
|
||||||
let dl_fold = downloader::get_download_folder(pd.title());
|
let dl_fold = downloader::get_download_folder(pd.title());
|
||||||
if let Ok(fold) = dl_fold {
|
if let Ok(fold) = dl_fold {
|
||||||
let res3 = fs::remove_dir_all(&fold);
|
let res3 = fs::remove_dir_all(&fold);
|
||||||
|
// TODO: Show errors?
|
||||||
if res3.is_ok() {
|
if res3.is_ok() {
|
||||||
info!("All the content at, {} was removed succesfully", &fold);
|
info!("All the content at, {} was removed succesfully", &fold);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
sender.send(Action::RefreshViews).unwrap();
|
}));
|
||||||
shows.switch_podcasts_animated();
|
shows.switch_podcasts_animated();
|
||||||
|
// Queue a refresh after the switch to avoid blocking the db.
|
||||||
|
sender.send(Action::RefreshViews).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user