Add notification

This commit is contained in:
sxyazi 2024-05-09 02:56:18 +08:00
parent 723bacac9b
commit 07a93bfcc6
No known key found for this signature in database
2 changed files with 20 additions and 4 deletions

View file

@ -5,7 +5,7 @@ use tokio::pin;
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt}; use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
use yazi_config::popup::InputCfg; use yazi_config::popup::InputCfg;
use yazi_plugin::external; use yazi_plugin::external;
use yazi_proxy::{InputProxy, ManagerProxy, TabProxy}; use yazi_proxy::{AppProxy, InputProxy, ManagerProxy, TabProxy};
use yazi_shared::{event::Cmd, fs::FilesOp, render}; use yazi_shared::{event::Cmd, fs::FilesOp, render};
use crate::tab::Tab; use crate::tab::Tab;
@ -43,19 +43,22 @@ pub struct Opt {
} }
impl TryFrom<Cmd> for Opt { impl TryFrom<Cmd> for Opt {
type Error = anyhow::Error; type Error = ();
fn try_from(mut c: Cmd) -> Result<Self, Self::Error> { fn try_from(mut c: Cmd) -> Result<Self, Self::Error> {
Ok(Self { Ok(Self {
type_: c.take_first_str().unwrap_or_default().into(), type_: c.take_first_str().unwrap_or_default().into(),
args: shell_words::split(c.str("args").unwrap_or_default())?, args: shell_words::split(c.str("args").unwrap_or_default()).map_err(|_| ())?,
}) })
} }
} }
impl Tab { impl Tab {
pub fn search(&mut self, opt: impl TryInto<Opt>) { pub fn search(&mut self, opt: impl TryInto<Opt>) {
let Ok(opt) = opt.try_into() else { return }; let Ok(opt) = opt.try_into() else {
return AppProxy::notify_error("Invalid `search` option", "Failed to parse search option");
};
if opt.type_ == OptType::None { if opt.type_ == OptType::None {
return self.search_stop(); return self.search_stop();
} }

View file

@ -37,4 +37,17 @@ impl AppProxy {
Layer::App Layer::App
)); ));
} }
#[inline]
pub fn notify_error(title: &str, content: &str) {
emit!(Call(
Cmd::new("notify").with_any("option", NotifyOpt {
title: title.to_owned(),
content: content.to_owned(),
level: NotifyLevel::Error,
timeout: Duration::from_secs(10),
}),
Layer::App
));
}
} }