diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bf6a4a5..8b6b7cd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/): ### Added - Allow using `ps.sub()` in `init.lua` directly without a plugin ([#3638]) +- New `relay-notify-push` DDS event to allow custom notification handlers ([#3642]) - New `cx.which` API to access the which component state ([#3617]) - New `ind-which-activate` DDS event to change the which component behavior ([#3608]) @@ -1636,3 +1637,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/): [#3633]: https://github.com/sxyazi/yazi/pull/3633 [#3634]: https://github.com/sxyazi/yazi/pull/3634 [#3638]: https://github.com/sxyazi/yazi/pull/3638 +[#3642]: https://github.com/sxyazi/yazi/pull/3642 diff --git a/Cargo.lock b/Cargo.lock index 8bfbf28f..6a5c18dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5538,6 +5538,7 @@ version = "26.1.22" dependencies = [ "anyhow", "crossterm 0.29.0", + "either", "futures", "hashbrown 0.16.1", "libc", @@ -5765,6 +5766,7 @@ version = "26.1.22" dependencies = [ "anyhow", "crossterm 0.29.0", + "either", "scopeguard", "tokio", "tracing", @@ -5835,6 +5837,7 @@ dependencies = [ "bitflags 2.10.0", "core-foundation-sys", "dirs", + "either", "foldhash", "hashbrown 0.16.1", "libc", @@ -6056,6 +6059,7 @@ version = "26.1.22" dependencies = [ "anyhow", "deadpool", + "either", "futures", "hashbrown 0.16.1", "parking_lot", diff --git a/Cargo.toml b/Cargo.toml index f9ff91d9..74662127 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ core-foundation-sys = "0.8.7" crossterm = { version = "0.29.0", features = [ "event-stream" ] } dirs = "6.0.0" dyn-clone = "1.0.20" +either = { version = "1.15.0" } foldhash = "0.2.0" futures = "0.3.31" globset = "0.4.18" diff --git a/yazi-actor/Cargo.toml b/yazi-actor/Cargo.toml index 1c7f31a8..9e75f99d 100644 --- a/yazi-actor/Cargo.toml +++ b/yazi-actor/Cargo.toml @@ -38,6 +38,7 @@ yazi-widgets = { path = "../yazi-widgets", version = "26.1.22" } # External dependencies anyhow = { workspace = true } crossterm = { workspace = true } +either = { workspace = true } futures = { workspace = true } hashbrown = { workspace = true } mlua = { workspace = true } diff --git a/yazi-actor/src/app/accept_payload.rs b/yazi-actor/src/app/accept_payload.rs index 2f548ec0..1384fabc 100644 --- a/yazi-actor/src/app/accept_payload.rs +++ b/yazi-actor/src/app/accept_payload.rs @@ -2,7 +2,7 @@ use anyhow::Result; use mlua::IntoLua; use tracing::error; use yazi_actor::lives::Lives; -use yazi_binding::runtime_mut; +use yazi_binding::runtime_scope; use yazi_dds::{LOCAL, Payload, REMOTE}; use yazi_macro::succ; use yazi_plugin::LUA; @@ -31,11 +31,9 @@ impl Actor for AcceptPayload { succ!(Lives::scope(&cx.core, || { let body = payload.body.into_lua(&LUA)?; for (id, cb) in handlers { - let blocking = runtime_mut!(LUA)?.critical_push(&id, true); - if let Err(e) = cb.call::<()>(body.clone()) { + if let Err(e) = runtime_scope!(LUA, &id, cb.call::<()>(body.clone())) { error!("Failed to run `{kind}` event handler in your `{id}` plugin: {e}"); } - runtime_mut!(LUA)?.critical_pop(blocking)?; } Ok(()) })?); diff --git a/yazi-actor/src/app/mouse.rs b/yazi-actor/src/app/mouse.rs index 7a00ee46..6db836d2 100644 --- a/yazi-actor/src/app/mouse.rs +++ b/yazi-actor/src/app/mouse.rs @@ -3,6 +3,7 @@ use crossterm::event::MouseEventKind; use mlua::{ObjectLike, Table}; use tracing::error; use yazi_actor::lives::Lives; +use yazi_binding::runtime_scope; use yazi_config::YAZI; use yazi_macro::succ; use yazi_parser::app::MouseOpt; @@ -20,11 +21,14 @@ impl Actor for Mouse { fn act(cx: &mut Ctx, opt: Self::Options) -> Result { let event = yazi_binding::MouseEvent::from(opt.event); + let Some(size) = cx.term.as_ref().and_then(|t| t.size().ok()) else { succ!() }; + let area = yazi_binding::elements::Rect::from(size); let result = Lives::scope(&cx.core, move || { - let area = yazi_binding::elements::Rect::from(size); - let root = LUA.globals().raw_get::("Root")?.call_method::
("new", area)?; + let root = runtime_scope!(LUA, "root", { + LUA.globals().raw_get::
("Root")?.call_method::
("new", area) + })?; if matches!(event.kind, MouseEventKind::Down(_) if YAZI.mgr.mouse_events.get().draggable()) { root.raw_set("_drag_start", event)?; diff --git a/yazi-actor/src/core/preflight.rs b/yazi-actor/src/core/preflight.rs index 843941b2..b020bed9 100644 --- a/yazi-actor/src/core/preflight.rs +++ b/yazi-actor/src/core/preflight.rs @@ -1,6 +1,6 @@ use anyhow::Result; use mlua::{ErrorContext, ExternalError, IntoLua, Value}; -use yazi_binding::runtime_mut; +use yazi_binding::runtime_scope; use yazi_dds::{LOCAL, spark::{Spark, SparkKind}}; use yazi_plugin::LUA; @@ -18,11 +18,7 @@ impl Preflight { Ok(Lives::scope(cx.core, || { let mut body = opt.1.into_lua(&LUA)?; for (id, cb) in handlers { - let blocking = runtime_mut!(LUA)?.critical_push(&id, true); - let result = cb.call::(&body); - runtime_mut!(LUA)?.critical_pop(blocking)?; - - match result { + match runtime_scope!(LUA, &id, cb.call::(&body)) { Ok(Value::Nil) => { Err(format!("`{kind}` event cancelled by `{id}` plugin on preflight").into_lua_err())? } diff --git a/yazi-actor/src/lives/lives.rs b/yazi-actor/src/lives/lives.rs index 37e3bbff..1a2b5fff 100644 --- a/yazi-actor/src/lives/lives.rs +++ b/yazi-actor/src/lives/lives.rs @@ -16,7 +16,10 @@ pub(super) static FILE_CACHE: RoCell, Any pub struct Lives; impl Lives { - pub fn scope(core: &yazi_core::Core, f: impl FnOnce() -> mlua::Result) -> mlua::Result { + pub fn scope(core: &yazi_core::Core, f: F) -> mlua::Result + where + F: FnOnce() -> mlua::Result, + { FILE_CACHE.init(Default::default()); defer! { FILE_CACHE.drop(); } diff --git a/yazi-actor/src/mgr/toggle_all.rs b/yazi-actor/src/mgr/toggle_all.rs index 79b0e9f5..70b968cc 100644 --- a/yazi-actor/src/mgr/toggle_all.rs +++ b/yazi-actor/src/mgr/toggle_all.rs @@ -14,7 +14,7 @@ impl Actor for ToggleAll { const NAME: &str = "toggle_all"; fn act(cx: &mut Ctx, opt: Self::Options) -> Result { - use yazi_shared::Either::*; + use either::Either::*; let tab = cx.tab_mut(); let it = tab.current.files.iter().map(|f| &f.url); diff --git a/yazi-actor/src/notify/push.rs b/yazi-actor/src/notify/push.rs index defe333a..568ac9b2 100644 --- a/yazi-actor/src/notify/push.rs +++ b/yazi-actor/src/notify/push.rs @@ -1,11 +1,11 @@ -use std::time::{Duration, Instant}; +use std::time::Instant; use anyhow::Result; use yazi_core::notify::Message; -use yazi_macro::succ; +use yazi_dds::spark::SparkKind; +use yazi_macro::{act, succ}; use yazi_parser::notify::PushOpt; -use yazi_proxy::NotifyProxy; -use yazi_shared::data::Data; +use yazi_shared::{Source, data::Data}; use crate::{Actor, Ctx}; @@ -24,8 +24,15 @@ impl Actor for Push { if cx.notify.messages.iter().all(|m| m != &msg) { cx.notify.messages.push(msg); - NotifyProxy::tick(Duration::ZERO); + act!(notify:tick, cx)?; } succ!(); } + + fn hook(cx: &Ctx, _: &Self::Options) -> Option { + match cx.source() { + Source::Relay => Some(SparkKind::RelayNotifyPush), + _ => None, + } + } } diff --git a/yazi-actor/src/notify/tick.rs b/yazi-actor/src/notify/tick.rs index 67964f91..ccf40299 100644 --- a/yazi-actor/src/notify/tick.rs +++ b/yazi-actor/src/notify/tick.rs @@ -4,7 +4,7 @@ use anyhow::Result; use ratatui::layout::Rect; use yazi_core::notify::Notify; use yazi_emulator::Dimension; -use yazi_macro::succ; +use yazi_macro::{render, render_partial, succ}; use yazi_parser::notify::TickOpt; use yazi_proxy::NotifyProxy; use yazi_shared::data::Data; @@ -52,13 +52,13 @@ impl Actor for Tick { } else if let Some(min) = timeouts.iter().min() { *min } else { - succ!(); + succ!(render!()); }; cx.notify.tick_handle = Some(tokio::spawn(async move { tokio::time::sleep(interval).await; NotifyProxy::tick(interval); })); - succ!(); + succ!(render_partial!()); } } diff --git a/yazi-adapter/src/adapters.rs b/yazi-adapter/src/adapters.rs index d5a5510a..36b50e71 100644 --- a/yazi-adapter/src/adapters.rs +++ b/yazi-adapter/src/adapters.rs @@ -1,7 +1,5 @@ use std::ops::{Deref, DerefMut}; -use yazi_shared::Either; - use crate::Adapter; pub(super) struct Adapters(Vec); @@ -17,12 +15,7 @@ impl DerefMut for Adapters { } impl From<&yazi_emulator::Emulator> for Adapters { - fn from(value: &yazi_emulator::Emulator) -> Self { - match value.kind { - Either::Left(b) => b.into(), - Either::Right(u) => u.into(), - } - } + fn from(value: &yazi_emulator::Emulator) -> Self { value.kind.either_into() } } impl From for Adapters { diff --git a/yazi-adapter/src/lib.rs b/yazi-adapter/src/lib.rs index 4cb03b2c..e6cc408a 100644 --- a/yazi-adapter/src/lib.rs +++ b/yazi-adapter/src/lib.rs @@ -19,7 +19,7 @@ pub fn init() -> anyhow::Result<()> { // Emulator detection let mut emulator = Emulator::detect().unwrap_or_default(); - TMUX.set(emulator.kind.is_left_and(|&b| b == Brand::Tmux)); + TMUX.set(emulator.kind.left() == Some(Brand::Tmux)); // Tmux support if TMUX.get() { diff --git a/yazi-binding/src/macros.rs b/yazi-binding/src/macros.rs index 1e467186..6c1cfef8 100644 --- a/yazi-binding/src/macros.rs +++ b/yazi-binding/src/macros.rs @@ -14,6 +14,19 @@ macro_rules! runtime_mut { }}; } +#[macro_export] +macro_rules! runtime_scope { + ($lua:ident, $id:expr, $block:expr) => {{ + let mut f = || { + let blocking = $crate::runtime_mut!($lua)?.critical_push($id, true); + let result = (|| $block)(); + $crate::runtime_mut!($lua)?.critical_pop(blocking)?; + result + }; + f() + }}; +} + #[macro_export] macro_rules! deprecate { ($lua:ident, $tt:tt) => {{ diff --git a/yazi-boot/src/actions/debug.rs b/yazi-boot/src/actions/debug.rs index 681e51ab..bd9d3a38 100644 --- a/yazi-boot/src/actions/debug.rs +++ b/yazi-boot/src/actions/debug.rs @@ -164,7 +164,7 @@ impl Actions { fn file1_output() -> String { use std::io::Write; - let p = env::temp_dir().join(format!("yazi-debug-{}", timestamp_us())); + let p = env::temp_dir().join(format!(".yazi-debug-{}.tmp", timestamp_us())); std::fs::File::create_new(&p).map(|mut f| f.write_all(b"Hello, World!")).ok(); let cmd = env::var_os("YAZI_FILE_ONE").unwrap_or("file".into()); diff --git a/yazi-cli/Cargo.toml b/yazi-cli/Cargo.toml index c51010ef..a6ac05e9 100644 --- a/yazi-cli/Cargo.toml +++ b/yazi-cli/Cargo.toml @@ -48,6 +48,7 @@ clap = { workspace = true } clap_complete = "4.5.65" clap_complete_fig = "4.5.2" clap_complete_nushell = "4.5.10" +serde = { workspace = true } serde_json = { workspace = true } vergen-gitcl = { version = "9.1.0", features = [ "build" ] } diff --git a/yazi-cli/src/args.rs b/yazi-cli/src/args.rs index 273a4447..86ebac67 100644 --- a/yazi-cli/src/args.rs +++ b/yazi-cli/src/args.rs @@ -2,7 +2,7 @@ use std::{borrow::Cow, ffi::OsString}; use anyhow::{Result, bail}; use clap::{Parser, Subcommand}; -use yazi_shared::{Either, Id}; +use yazi_shared::Id; #[derive(Parser)] #[command(name = "Ya", about, long_about = None)] @@ -139,9 +139,16 @@ macro_rules! impl_emit_body { impl $name { #[allow(dead_code)] pub(super) fn body(self) -> Result { - let cmd: Vec<_> = [Either::Left(self.name)] + #[derive(serde::Serialize)] + #[serde(untagged)] + enum Elem { + Name(String), + Arg(Vec), + } + + let cmd: Vec<_> = [Elem::Name(self.name)] .into_iter() - .chain(self.args.into_iter().map(|s| Either::Right(s.into_encoded_bytes()))) + .chain(self.args.into_iter().map(|s| Elem::Arg(s.into_encoded_bytes()))) .collect(); Ok(serde_json::to_string(&cmd)?) } diff --git a/yazi-dds/src/spark/kind.rs b/yazi-dds/src/spark/kind.rs index 5ee1e3dc..a6f155d4 100644 --- a/yazi-dds/src/spark/kind.rs +++ b/yazi-dds/src/spark/kind.rs @@ -12,6 +12,8 @@ pub enum SparkKind { KeyQuit, // which:activate IndWhichActivate, + // notify:push + RelayNotifyPush, } impl AsRef for SparkKind { @@ -27,6 +29,8 @@ impl AsRef for SparkKind { Self::KeyQuit => "key-quit", // which:activate Self::IndWhichActivate => "ind-which-activate", + // notify:push + Self::RelayNotifyPush => "relay-notify-push", } } } diff --git a/yazi-dds/src/spark/spark.rs b/yazi-dds/src/spark/spark.rs index 0e47539d..e83e455c 100644 --- a/yazi-dds/src/spark/spark.rs +++ b/yazi-dds/src/spark/spark.rs @@ -166,6 +166,8 @@ impl<'a> Spark<'a> { KeyQuit => Self::Quit(<_>::from_lua(value, lua)?), // which:activate IndWhichActivate => Self::WhichActivate(<_>::from_lua(value, lua)?), + // notify:push + RelayNotifyPush => Self::NotifyPush(<_>::from_lua(value, lua)?), }) } } diff --git a/yazi-emulator/Cargo.toml b/yazi-emulator/Cargo.toml index 36fb8169..4c6c28fe 100644 --- a/yazi-emulator/Cargo.toml +++ b/yazi-emulator/Cargo.toml @@ -19,6 +19,7 @@ yazi-tty = { path = "../yazi-tty", version = "26.1.22" } # External dependencies anyhow = { workspace = true } crossterm = { workspace = true } +either = { workspace = true } scopeguard = { workspace = true } tokio = { workspace = true } tracing = { workspace = true } diff --git a/yazi-emulator/src/emulator.rs b/yazi-emulator/src/emulator.rs index d2947dc7..72d45aeb 100644 --- a/yazi-emulator/src/emulator.rs +++ b/yazi-emulator/src/emulator.rs @@ -2,10 +2,11 @@ use std::{io::BufWriter, time::Duration}; use anyhow::Result; use crossterm::{cursor::{RestorePosition, SavePosition}, execute, style::Print, terminal::{disable_raw_mode, enable_raw_mode}}; +use either::Either; use scopeguard::defer; use tokio::time::sleep; use tracing::{debug, error, warn}; -use yazi_shared::{Either, RoCell}; +use yazi_shared::RoCell; use yazi_tty::{Handle, TTY}; use crate::{Brand, Dimension, Mux, TMUX, Unknown}; diff --git a/yazi-fm/src/app/render.rs b/yazi-fm/src/app/render.rs index 75c6958e..0db64eef 100644 --- a/yazi-fm/src/app/render.rs +++ b/yazi-fm/src/app/render.rs @@ -4,7 +4,9 @@ use anyhow::Result; use crossterm::{cursor::{MoveTo, SetCursorStyle, Show}, execute, queue, terminal::{BeginSynchronizedUpdate, EndSynchronizedUpdate}}; use ratatui::{CompletedFrame, backend::{Backend, CrosstermBackend}, buffer::Buffer, layout::Position}; use yazi_actor::{Ctx, lives::Lives}; +use yazi_binding::runtime_scope; use yazi_macro::{act, succ}; +use yazi_plugin::LUA; use yazi_shared::{data::Data, event::NEED_RENDER}; use yazi_tty::TTY; use yazi_widgets::COLLISION; @@ -26,7 +28,9 @@ impl App { let collision = COLLISION.swap(false, Ordering::Relaxed); let frame = term .draw(|f| { - _ = Lives::scope(&self.core, || Ok(f.render_widget(Root::new(&self.core), f.area()))); + _ = Lives::scope(&self.core, || { + runtime_scope!(LUA, "root", Ok(f.render_widget(Root::new(&self.core), f.area()))) + }); }) .unwrap(); @@ -57,9 +61,11 @@ impl App { let frame = term .draw_partial(|f| { _ = Lives::scope(&self.core, || { - f.render_widget(crate::tasks::Progress::new(&self.core), f.area()); - f.render_widget(crate::notify::Notify::new(&self.core), f.area()); - Ok(()) + runtime_scope!(LUA, "root", { + f.render_widget(crate::tasks::Progress::new(&self.core), f.area()); + f.render_widget(crate::notify::Notify::new(&self.core), f.area()); + Ok(()) + }) }); }) .unwrap(); diff --git a/yazi-fs/Cargo.toml b/yazi-fs/Cargo.toml index d994e942..e45f61da 100644 --- a/yazi-fs/Cargo.toml +++ b/yazi-fs/Cargo.toml @@ -22,6 +22,7 @@ anyhow = { workspace = true } arc-swap = "1.8.0" bitflags = { workspace = true } dirs = { workspace = true } +either = { workspace = true } foldhash = { workspace = true } hashbrown = { workspace = true } parking_lot = { workspace = true } diff --git a/yazi-fs/src/provider/local/calculator.rs b/yazi-fs/src/provider/local/calculator.rs index 9aaa89fa..328c61a8 100644 --- a/yazi-fs/src/provider/local/calculator.rs +++ b/yazi-fs/src/provider/local/calculator.rs @@ -1,7 +1,7 @@ use std::{collections::VecDeque, future::poll_fn, io, mem, path::{Path, PathBuf}, pin::Pin, task::{Poll, ready}, time::{Duration, Instant}}; +use either::Either; use tokio::task::JoinHandle; -use yazi_shared::Either; type Task = Either; @@ -84,7 +84,7 @@ impl SizeCalculator { }; } - let Some(next) = front.right_mut()?.next() else { + let Some(next) = front.as_mut().right()?.next() else { pop_and_continue!(); }; diff --git a/yazi-fs/src/provider/local/casefold.rs b/yazi-fs/src/provider/local/casefold.rs index 8dcad1f0..cae9877f 100644 --- a/yazi-fs/src/provider/local/casefold.rs +++ b/yazi-fs/src/provider/local/casefold.rs @@ -182,8 +182,8 @@ fn final_path(path: &Path) -> io::Result { fn final_path(path: &Path) -> io::Result { use std::{ffi::OsString, fs::File, os::windows::{ffi::OsStringExt, fs::OpenOptionsExt, io::AsRawHandle}}; + use either::Either; use windows_sys::Win32::{Foundation::HANDLE, Storage::FileSystem::{FILE_FLAG_BACKUP_SEMANTICS, FILE_FLAG_OPEN_REPARSE_POINT, GetFinalPathNameByHandleW, VOLUME_NAME_DOS}}; - use yazi_shared::Either; let file = std::fs::OpenOptions::new() .access_mode(0) @@ -214,7 +214,8 @@ fn final_path(path: &Path) -> io::Result { match inner(&file, &mut [0u16; 512])? { Either::Left(path) => Ok(path), Either::Right(len) => inner(&file, &mut vec![0u16; len as usize])? - .left_or_err(|| io::Error::new(io::ErrorKind::InvalidData, "path too long")), + .left() + .ok_or_else(|| io::Error::new(io::ErrorKind::InvalidData, "path too long")), } } diff --git a/yazi-parser/src/notify/push.rs b/yazi-parser/src/notify/push.rs index 7056db38..75160845 100644 --- a/yazi-parser/src/notify/push.rs +++ b/yazi-parser/src/notify/push.rs @@ -3,7 +3,7 @@ use std::{str::FromStr, time::Duration}; use anyhow::anyhow; use mlua::{FromLua, IntoLua, Lua, LuaSerdeExt, Value}; use serde::{Deserialize, Serialize}; -use serde_with::{DurationSeconds, serde_as}; +use serde_with::{DurationSecondsWithFrac, serde_as}; use yazi_config::{Style, THEME}; use yazi_shared::event::CmdCow; @@ -13,7 +13,7 @@ pub struct PushOpt { pub title: String, pub content: String, pub level: PushLevel, - #[serde_as(as = "DurationSeconds")] // FIXME + #[serde_as(as = "DurationSecondsWithFrac")] pub timeout: Duration, } diff --git a/yazi-parser/src/notify/tick.rs b/yazi-parser/src/notify/tick.rs index 491bc958..6a0a5593 100644 --- a/yazi-parser/src/notify/tick.rs +++ b/yazi-parser/src/notify/tick.rs @@ -4,7 +4,7 @@ use anyhow::bail; use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; use yazi_shared::event::CmdCow; -#[derive(Debug)] +#[derive(Debug, Default)] pub struct TickOpt { pub interval: Duration, } diff --git a/yazi-plugin/src/loader/loader.rs b/yazi-plugin/src/loader/loader.rs index 4287508e..944cf69c 100644 --- a/yazi-plugin/src/loader/loader.rs +++ b/yazi-plugin/src/loader/loader.rs @@ -26,6 +26,7 @@ impl Deref for Loader { impl Default for Loader { fn default() -> Self { let cache = HashMap::from_iter([ + // Plugins ("archive".to_owned(), preset!("plugins/archive").into()), ("code".to_owned(), preset!("plugins/code").into()), ("dds".to_owned(), preset!("plugins/dds").into()), @@ -51,6 +52,22 @@ impl Default for Loader { ("vfs".to_owned(), preset!("plugins/vfs").into()), ("video".to_owned(), preset!("plugins/video").into()), ("zoxide".to_owned(), preset!("plugins/zoxide").into()), + // Components + ("current".to_owned(), [][..].into()), + ("entity".to_owned(), [][..].into()), + ("header".to_owned(), [][..].into()), + ("linemode".to_owned(), [][..].into()), + ("marker".to_owned(), [][..].into()), + ("modal".to_owned(), [][..].into()), + ("parent".to_owned(), [][..].into()), + ("preview".to_owned(), [][..].into()), + ("progress".to_owned(), [][..].into()), + ("rail".to_owned(), [][..].into()), + ("root".to_owned(), [][..].into()), + ("status".to_owned(), [][..].into()), + ("tab".to_owned(), [][..].into()), + ("tabs".to_owned(), [][..].into()), + ("tasks".to_owned(), [][..].into()), ]); Self { cache: RwLock::new(cache) } } diff --git a/yazi-plugin/src/lua.rs b/yazi-plugin/src/lua.rs index dca05068..00840a82 100644 --- a/yazi-plugin/src/lua.rs +++ b/yazi-plugin/src/lua.rs @@ -1,7 +1,7 @@ use anyhow::{Context, Result}; use futures::executor::block_on; use mlua::Lua; -use yazi_binding::{Runtime, runtime_mut}; +use yazi_binding::{Runtime, runtime_scope}; use yazi_boot::BOOT; use yazi_macro::plugin_preset as preset; use yazi_shared::RoCell; @@ -65,9 +65,7 @@ fn stage_2(lua: &'static Lua) -> mlua::Result<()> { lua.load(preset!("compat")).set_name("compat.lua").exec()?; if let Ok(b) = std::fs::read(BOOT.config_dir.join("init.lua")) { - let blocking = runtime_mut!(lua)?.critical_push("init", true); - block_on(lua.load(b).set_name("init.lua").exec_async())?; - runtime_mut!(lua)?.critical_pop(blocking)?; + runtime_scope!(lua, "init", block_on(lua.load(b).set_name("init.lua").exec_async()))?; } Ok(()) diff --git a/yazi-shared/src/either.rs b/yazi-shared/src/either.rs deleted file mode 100644 index edc2c7d8..00000000 --- a/yazi-shared/src/either.rs +++ /dev/null @@ -1,89 +0,0 @@ -use serde::Serialize; - -#[derive(Clone, Copy, Debug)] -pub enum Either { - Left(L), - Right(R), -} - -impl Either { - pub fn left(&self) -> Option<&L> { - match self { - Self::Left(l) => Some(l), - _ => None, - } - } - - pub fn right(&self) -> Option<&R> { - match self { - Self::Right(r) => Some(r), - _ => None, - } - } - - pub fn left_mut(&mut self) -> Option<&mut L> { - match self { - Self::Left(l) => Some(l), - _ => None, - } - } - - pub fn right_mut(&mut self) -> Option<&mut R> { - match self { - Self::Right(r) => Some(r), - _ => None, - } - } - - pub fn is_left_and bool>(&self, f: F) -> bool { - self.left().map(f).unwrap_or(false) - } - - pub fn is_right_and bool>(&self, f: F) -> bool { - self.right().map(f).unwrap_or(false) - } - - pub fn into_left(self) -> Option { - match self { - Self::Left(l) => Some(l), - _ => None, - } - } - - pub fn into_right(self) -> Option { - match self { - Self::Right(r) => Some(r), - _ => None, - } - } - - pub fn left_or_err E>(self, f: F) -> Result { - match self { - Self::Left(l) => Ok(l), - _ => Err(f()), - } - } - - pub fn right_or_err E>(self, f: F) -> Result { - match self { - Self::Right(r) => Ok(r), - _ => Err(f()), - } - } -} - -impl Serialize for Either -where - L: Serialize, - R: Serialize, -{ - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - match self { - Self::Left(l) => l.serialize(serializer), - Self::Right(r) => r.serialize(serializer), - } - } -} diff --git a/yazi-shared/src/lib.rs b/yazi-shared/src/lib.rs index c51318fb..642c9244 100644 --- a/yazi-shared/src/lib.rs +++ b/yazi-shared/src/lib.rs @@ -1,6 +1,6 @@ yazi_macro::mod_pub!(data errors event loc path pool scheme shell strand translit url wtf8); -yazi_macro::mod_flat!(alias bytes chars completion_token condition debounce either env id layer localset natsort os predictor ro_cell source sync_cell terminal tests throttle time utf8); +yazi_macro::mod_flat!(alias bytes chars completion_token condition debounce env id layer localset natsort os predictor ro_cell source sync_cell terminal tests throttle time utf8); pub fn init() { LOCAL_SET.with(tokio::task::LocalSet::new); diff --git a/yazi-vfs/Cargo.toml b/yazi-vfs/Cargo.toml index b7812837..04acbefb 100644 --- a/yazi-vfs/Cargo.toml +++ b/yazi-vfs/Cargo.toml @@ -21,6 +21,7 @@ yazi-shared = { path = "../yazi-shared", version = "26.1.22" } # External dependencies anyhow = { workspace = true } deadpool = { version = "0.12.3", default-features = false, features = [ "managed", "rt_tokio_1" ] } +either = { workspace = true } futures = { workspace = true } hashbrown = { workspace = true } parking_lot = { workspace = true } diff --git a/yazi-vfs/src/provider/calculator.rs b/yazi-vfs/src/provider/calculator.rs index db103d13..b055ad96 100644 --- a/yazi-vfs/src/provider/calculator.rs +++ b/yazi-vfs/src/provider/calculator.rs @@ -1,7 +1,8 @@ use std::{collections::VecDeque, io, time::{Duration, Instant}}; +use either::Either; use yazi_fs::provider::{DirReader, FileHolder}; -use yazi_shared::{Either, url::{AsUrl, UrlBuf}}; +use yazi_shared::url::{AsUrl, UrlBuf}; use super::ReadDir; @@ -66,7 +67,7 @@ impl SizeCalculator { }; } - let Ok(Some(ent)) = front.right_mut()?.next().await else { + let Ok(Some(ent)) = front.as_mut().right()?.next().await else { pop_and_continue!(); };