use std::time::Duration; use mlua::{FromLua, IntoLua, Lua, LuaSerdeExt, Value}; use serde::{Deserialize, Serialize}; use serde_with::{DurationSecondsWithFrac, serde_as}; use yazi_binding::SER_OPT; use yazi_shared::{data::Data, event::ActionCow}; use crate::notify::MessageLevel; #[serde_as] #[derive(Clone, Debug, Deserialize, Serialize)] pub struct MessageOpt { pub title: String, pub content: String, #[serde(default)] pub level: MessageLevel, #[serde_as(as = "DurationSecondsWithFrac")] pub timeout: Duration, } impl TryFrom for MessageOpt { type Error = anyhow::Error; fn try_from(mut a: ActionCow) -> Result { Ok(Self { title: a.take_second()?, content: a.take_first()?, level: <_>::deserialize(a.get::<&Data>("level")?)?, timeout: <_>::deserialize(a.get::<&Data>("timeout")?)?, }) } } impl FromLua for MessageOpt { fn from_lua(value: Value, lua: &Lua) -> mlua::Result { lua.from_value(value) } } impl IntoLua for MessageOpt { fn into_lua(self, lua: &Lua) -> mlua::Result { lua.to_value_with(&self, SER_OPT) } }