From b04e8382d0a71477bd6f839cc13eeaf33d737d13 Mon Sep 17 00:00:00 2001 From: hankertrix <91734413+hankertrix@users.noreply.github.com> Date: Fri, 28 Feb 2025 22:09:21 +0800 Subject: [PATCH] fix: fix incorrect warning when plugin doesn't exist Fixes #2415. --- yazi-plugin/src/loader/loader.rs | 37 ++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/yazi-plugin/src/loader/loader.rs b/yazi-plugin/src/loader/loader.rs index 99dcb43a..af4c9358 100644 --- a/yazi-plugin/src/loader/loader.rs +++ b/yazi-plugin/src/loader/loader.rs @@ -20,7 +20,9 @@ impl Deref for Loader { type Target = RwLock>; #[inline] - fn deref(&self) -> &Self::Target { &self.cache } + fn deref(&self) -> &Self::Target { + &self.cache + } } impl Default for Loader { @@ -61,21 +63,28 @@ impl Loader { Ok(b) => b, Err(e) if e.kind() == std::io::ErrorKind::NotFound => { static WARNED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); - if !WARNED.swap(true, std::sync::atomic::Ordering::Relaxed) { - yazi_proxy::AppProxy::notify(yazi_proxy::options::NotifyOpt { - title: "Deprecated entry file".to_owned(), - content: format!( - "The plugin's entry file `init.lua` has been deprecated in favor of the new `main.lua` (user's own `init.lua` remains unchanged). - -Please run `ya pack -m` to automatically migrate all plugins, or manually rename your `{name}.yazi/init.lua` to `{name}.yazi/main.lua`." - ), - level: yazi_proxy::options::NotifyLevel::Warn, - timeout: std::time::Duration::from_secs(25), - }); - } let p = BOOT.plugin_dir.join(format!("{name}.yazi/init.lua")); - fs::read(&p).await.with_context(|| format!("Failed to load plugin from {p:?}"))? + + match fs::read(&p).await { + Err(e) => Err(e).with_context(|| format!("Failed to load plugin from {p:?}"))?, + + Ok(b) => { + if !WARNED.swap(true, std::sync::atomic::Ordering::Relaxed) { + yazi_proxy::AppProxy::notify(yazi_proxy::options::NotifyOpt { + title: "Deprecated entry file".to_owned(), + content: format!( + "The plugin's entry file `init.lua` has been deprecated in favor of the new `main.lua` (user's own `init.lua` remains unchanged). + +Please run `ya pack -m` to automatically migrate all plugins, or manually rename your `{name}.yazi/init.lua` to `{name}.yazi/main.lua`." + ), + level: yazi_proxy::options::NotifyLevel::Warn, + timeout: std::time::Duration::from_secs(25), + }); + } + b + } + } } Err(e) => Err(e).with_context(|| format!("Failed to load plugin from {p:?}"))?, };