mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
41 lines
1.1 KiB
Rust
41 lines
1.1 KiB
Rust
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<f64>")]
|
|
pub timeout: Duration,
|
|
}
|
|
|
|
impl TryFrom<ActionCow> for MessageOpt {
|
|
type Error = anyhow::Error;
|
|
|
|
fn try_from(mut a: ActionCow) -> Result<Self, Self::Error> {
|
|
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<Self> { lua.from_value(value) }
|
|
}
|
|
|
|
impl IntoLua for MessageOpt {
|
|
fn into_lua(self, lua: &Lua) -> mlua::Result<Value> { lua.to_value_with(&self, SER_OPT) }
|
|
}
|