Simplify the code

This commit is contained in:
sxyazi 2024-06-19 17:11:34 +08:00
parent 3fc1c86fcf
commit dab892e77c
No known key found for this signature in database
4 changed files with 5 additions and 7 deletions

View file

@ -1,4 +1,3 @@
use anyhow::anyhow;
use yazi_shared::{event::Cmd, render};
use crate::confirm::Confirm;
@ -18,7 +17,7 @@ impl Confirm {
pub fn close(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt;
if let Some(cb) = self.callback.take() {
_ = cb.send(if opt.submit { Ok(true) } else { Err(anyhow!("canceled")) });
_ = cb.send(opt.submit);
}
self.visible = false;

View file

@ -6,7 +6,7 @@ use crate::confirm::Confirm;
pub struct Opt {
cfg: ConfirmCfg,
tx: oneshot::Sender<anyhow::Result<bool>>,
tx: oneshot::Sender<bool>,
}
impl TryFrom<Cmd> for Opt {

View file

@ -1,4 +1,3 @@
use anyhow::Result;
use tokio::sync::oneshot::Sender;
use yazi_config::popup::Position;
@ -11,6 +10,6 @@ pub struct Confirm {
pub offset: usize,
pub position: Position,
pub(super) callback: Option<Sender<Result<bool>>>,
pub(super) callback: Option<Sender<bool>>,
pub visible: bool,
}

View file

@ -6,9 +6,9 @@ pub struct ConfirmProxy;
impl ConfirmProxy {
#[inline]
pub async fn show(cfg: ConfirmCfg) -> anyhow::Result<bool> {
pub async fn show(cfg: ConfirmCfg) -> bool {
let (tx, rx) = oneshot::channel();
emit!(Call(Cmd::new("show").with_any("tx", tx).with_any("cfg", cfg), Layer::Confirm));
rx.await?
rx.await.unwrap_or(false)
}
}