From 57ef8f9ebdf152dc1d41b4cde96f25df43d10ead Mon Sep 17 00:00:00 2001 From: hankertrix <91734413+hankertrix@users.noreply.github.com> Date: Sat, 1 Mar 2025 23:11:11 +0800 Subject: [PATCH] fix: incorrect deprecation warning when the plugin doesn't exist (#2418) Co-authored-by: sxyazi --- scripts/validate-form/main.js | 4 ++-- yazi-plugin/src/loader/loader.rs | 38 +++++++++++++++++++------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/scripts/validate-form/main.js b/scripts/validate-form/main.js index cd27c9e2..45362ff2 100644 --- a/scripts/validate-form/main.js +++ b/scripts/validate-form/main.js @@ -12,7 +12,7 @@ function bugReportBody(creator, content, hash) { - The bug can still be reproduced on the [newest nightly build](https://yazi-rs.github.io/docs/installation/#binaries). - The debug information (\`yazi --debug\`) is updated for the newest nightly. -- All *required* fields in the checklist have been checked. +- The *required* fields in the checklist are checked. Issues with \`${LABEL_NAME}\` will be marked ready once edited with the proper content, or closed after 2 days of inactivity. ` @@ -27,7 +27,7 @@ function featureRequestBody(creator, content) { - The requested feature does not exist in the [newest nightly build](https://yazi-rs.github.io/docs/installation/#binaries). - The debug information (\`yazi --debug\`) is updated for the newest nightly. -- All *required* fields in the checklist have been checked. +- The *required* fields in the checklist are checked. Issues with \`${LABEL_NAME}\` will be marked ready once edited with the proper content, or closed after 2 days of inactivity. ` diff --git a/yazi-plugin/src/loader/loader.rs b/yazi-plugin/src/loader/loader.rs index 99dcb43a..d4cbbaae 100644 --- a/yazi-plugin/src/loader/loader.rs +++ b/yazi-plugin/src/loader/loader.rs @@ -56,26 +56,34 @@ impl Loader { } // TODO: remove this + fn warn(name: &str) { + 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/main.lua")); let chunk = match fs::read(&p).await { 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 { + Ok(b) => { + warn(name); + b + } + Err(e) => Err(e).with_context(|| format!("Failed to load plugin from {p:?}"))?, + } } Err(e) => Err(e).with_context(|| format!("Failed to load plugin from {p:?}"))?, };