From 6548a75c2a9201ba34bcb6ec8d50bc274dccc64f Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sat, 1 Mar 2025 23:09:14 +0800 Subject: [PATCH] Simplify the code --- scripts/validate-form/main.js | 4 ++-- yazi-plugin/src/loader/loader.rs | 31 ++++++++++++++++--------------- 2 files changed, 18 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 ae20dcff..d4cbbaae 100644 --- a/yazi-plugin/src/loader/loader.rs +++ b/yazi-plugin/src/loader/loader.rs @@ -56,20 +56,10 @@ impl Loader { } // TODO: remove this - 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); - - let p = BOOT.plugin_dir.join(format!("{name}.yazi/init.lua")); - - 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 { + 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). @@ -79,9 +69,20 @@ Please run `ya pack -m` to automatically migrate all plugins, or manually rename 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 => { + let p = BOOT.plugin_dir.join(format!("{name}.yazi/init.lua")); + 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:?}"))?,