mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
bab7f09007
commit
a281c3f81a
9 changed files with 45 additions and 29 deletions
|
|
@ -6,7 +6,7 @@ use yazi_config::open::Opener;
|
||||||
use yazi_shared::{fs::Url, term::Term, Exec, Layer, RoCell};
|
use yazi_shared::{fs::Url, term::Term, Exec, Layer, RoCell};
|
||||||
|
|
||||||
use super::files::FilesOp;
|
use super::files::FilesOp;
|
||||||
use crate::{preview::PreviewLock, tasks::TasksProgress};
|
use crate::preview::PreviewLock;
|
||||||
|
|
||||||
static TX: RoCell<UnboundedSender<Event>> = RoCell::new();
|
static TX: RoCell<UnboundedSender<Event>> = RoCell::new();
|
||||||
|
|
||||||
|
|
@ -25,11 +25,8 @@ pub enum Event {
|
||||||
Mimetype(BTreeMap<Url, String>),
|
Mimetype(BTreeMap<Url, String>),
|
||||||
Preview(PreviewLock),
|
Preview(PreviewLock),
|
||||||
|
|
||||||
// Input(InputOpt, mpsc::UnboundedSender<Result<String, InputError>>),
|
|
||||||
|
|
||||||
// Tasks
|
// Tasks
|
||||||
Open(Vec<(OsString, String)>, Option<Opener>),
|
Open(Vec<(OsString, String)>, Option<Opener>),
|
||||||
Progress(TasksProgress),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Event {
|
impl Event {
|
||||||
|
|
@ -83,9 +80,6 @@ macro_rules! emit {
|
||||||
(Open($targets:expr, $opener:expr)) => {
|
(Open($targets:expr, $opener:expr)) => {
|
||||||
$crate::Event::Open($targets, $opener).emit();
|
$crate::Event::Open($targets, $opener).emit();
|
||||||
};
|
};
|
||||||
(Progress($progress:expr)) => {
|
|
||||||
$crate::Event::Progress($progress).emit();
|
|
||||||
};
|
|
||||||
|
|
||||||
($event:ident) => {
|
($event:ident) => {
|
||||||
$crate::Event::$event.emit();
|
$crate::Event::$event.emit();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use anyhow::bail;
|
use anyhow::anyhow;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use yazi_config::popup::InputCfg;
|
use yazi_config::popup::InputCfg;
|
||||||
use yazi_shared::{Exec, InputError, Layer};
|
use yazi_shared::{Exec, InputError, Layer};
|
||||||
|
|
@ -14,13 +14,7 @@ impl TryFrom<&Exec> for Opt {
|
||||||
type Error = anyhow::Error;
|
type Error = anyhow::Error;
|
||||||
|
|
||||||
fn try_from(e: &Exec) -> Result<Self, Self::Error> {
|
fn try_from(e: &Exec) -> Result<Self, Self::Error> {
|
||||||
let Some(data) = e.data.borrow_mut().take() else {
|
e.take_data().ok_or_else(|| anyhow!("invalid data"))
|
||||||
bail!("missing data");
|
|
||||||
};
|
|
||||||
let Ok(opt) = data.downcast::<Opt>() else {
|
|
||||||
bail!("invalid data");
|
|
||||||
};
|
|
||||||
Ok(*opt)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
use yazi_config::popup::SelectCfg;
|
use yazi_config::popup::SelectCfg;
|
||||||
use yazi_shared::{term::Term, Exec, Layer};
|
use yazi_shared::{term::Term, Exec, Layer};
|
||||||
|
|
@ -14,13 +14,7 @@ impl TryFrom<&Exec> for Opt {
|
||||||
type Error = anyhow::Error;
|
type Error = anyhow::Error;
|
||||||
|
|
||||||
fn try_from(e: &Exec) -> Result<Self, Self::Error> {
|
fn try_from(e: &Exec) -> Result<Self, Self::Error> {
|
||||||
let Some(data) = e.data.borrow_mut().take() else {
|
e.take_data().ok_or_else(|| anyhow!("invalid data"))
|
||||||
bail!("missing data");
|
|
||||||
};
|
|
||||||
let Ok(opt) = data.downcast::<Opt>() else {
|
|
||||||
bail!("invalid data");
|
|
||||||
};
|
|
||||||
Ok(*opt)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,4 @@ mod arrow;
|
||||||
mod cancel;
|
mod cancel;
|
||||||
mod inspect;
|
mod inspect;
|
||||||
mod toggle;
|
mod toggle;
|
||||||
|
mod update;
|
||||||
|
|
|
||||||
31
yazi-core/src/tasks/commands/update.rs
Normal file
31
yazi-core/src/tasks/commands/update.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
use anyhow::anyhow;
|
||||||
|
use yazi_shared::{Exec, Layer};
|
||||||
|
|
||||||
|
use crate::{emit, 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>) -> bool {
|
||||||
|
let Ok(opt) = opt.try_into() else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
self.progress = opt.progress;
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,7 +7,7 @@ use yazi_config::{open::Opener, TASKS};
|
||||||
use yazi_shared::{fs::{unique_path, Url}, Throttle};
|
use yazi_shared::{fs::{unique_path, Url}, Throttle};
|
||||||
|
|
||||||
use super::{workers::{File, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash, Precache, PrecacheOpMime, PrecacheOpSize, Process, ProcessOpOpen}, Running, TaskOp, TaskStage, TasksProgress};
|
use super::{workers::{File, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash, Precache, PrecacheOpMime, PrecacheOpSize, Process, ProcessOpOpen}, Running, TaskOp, TaskStage, TasksProgress};
|
||||||
use crate::emit;
|
use crate::tasks::Tasks;
|
||||||
|
|
||||||
pub struct Scheduler {
|
pub struct Scheduler {
|
||||||
file: Arc<File>,
|
file: Arc<File>,
|
||||||
|
|
@ -157,7 +157,7 @@ impl Scheduler {
|
||||||
let new = TasksProgress::from(&*running.read());
|
let new = TasksProgress::from(&*running.read());
|
||||||
if last != new {
|
if last != new {
|
||||||
last = new;
|
last = new;
|
||||||
emit!(Progress(new));
|
Tasks::_update(new);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -195,10 +195,6 @@ impl App {
|
||||||
tasks.file_open(&targets);
|
tasks.file_open(&targets);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Progress(progress) => {
|
|
||||||
tasks.progress = progress;
|
|
||||||
emit!(Render);
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,7 @@ impl<'a> Executor<'a> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
on!(update);
|
||||||
on!(toggle, "close");
|
on!(toggle, "close");
|
||||||
on!(arrow);
|
on!(arrow);
|
||||||
on!(inspect);
|
on!(inspect);
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,11 @@ impl Exec {
|
||||||
self.data = RefCell::new(Some(Box::new(data)));
|
self.data = RefCell::new(Some(Box::new(data)));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn take_data<T: 'static>(&self) -> Option<T> {
|
||||||
|
self.data.replace(None).and_then(|d| d.downcast::<T>().ok()).map(|d| *d)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Exec {
|
impl Display for Exec {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue