fix: incorrect deprecation warning when the plugin doesn't exist (#2418)

Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
hankertrix 2025-03-01 23:11:11 +08:00 committed by sxyazi
parent 84d71bfa39
commit 57ef8f9ebd
No known key found for this signature in database
2 changed files with 25 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 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.
`

View file

@ -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:?}"))?,
};