yazi/yazi-core/src/tasks/commands/update.rs
2024-01-02 08:38:26 +08:00

31 lines
648 B
Rust

use anyhow::anyhow;
use yazi_shared::{emit, event::Exec, render, Layer};
use crate::tasks::{Tasks, TasksProgress};
pub struct Opt {
progress: TasksProgress,
}
impl TryFrom<&Exec> for Opt {
type Error = anyhow::Error;
fn try_from(e: &Exec) -> Result<Self, Self::Error> {
e.take_data().ok_or_else(|| anyhow!("invalid data"))
}
}
impl Tasks {
pub fn _update(progress: TasksProgress) {
emit!(Call(Exec::call("update", vec![]).with_data(Opt { progress }).vec(), Layer::Tasks));
}
pub fn update(&mut self, opt: impl TryInto<Opt>) {
let Ok(opt) = opt.try_into() else {
return;
};
self.progress = opt.progress;
render!();
}
}