Simplify the code

This commit is contained in:
sxyazi 2025-03-01 23:09:14 +08:00
parent 964aa5d2d9
commit 6548a75c2a
No known key found for this signature in database
2 changed files with 18 additions and 17 deletions

View file

@ -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 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. - 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. 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 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. - 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. Issues with \`${LABEL_NAME}\` will be marked ready once edited with the proper content, or closed after 2 days of inactivity.
` `

View file

@ -56,20 +56,10 @@ impl Loader {
} }
// TODO: remove this // TODO: remove this
let p = BOOT.plugin_dir.join(format!("{name}.yazi/main.lua")); fn warn(name: &str) {
let chunk = match fs::read(&p).await { static WARNED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
Ok(b) => b, if !WARNED.swap(true, std::sync::atomic::Ordering::Relaxed) {
Err(e) if e.kind() == std::io::ErrorKind::NotFound => { yazi_proxy::AppProxy::notify(yazi_proxy::options::NotifyOpt {
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 {
title: "Deprecated entry file".to_owned(), title: "Deprecated entry file".to_owned(),
content: format!( 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). "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, level: yazi_proxy::options::NotifyLevel::Warn,
timeout: std::time::Duration::from_secs(25), 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 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:?}"))?, Err(e) => Err(e).with_context(|| format!("Failed to load plugin from {p:?}"))?,