From e9742cb80935d1072fabb4bd8c52a49e2218eeaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20misaki=20masa?= Date: Sun, 21 Sep 2025 23:33:30 +0800 Subject: [PATCH] fix: check compatibility when reusing previewer bytecode cache (#3190) --- yazi-binding/src/elements/area.rs | 4 ++++ yazi-plugin/src/isolate/peek.rs | 28 ++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/yazi-binding/src/elements/area.rs b/yazi-binding/src/elements/area.rs index d1258fbe..301276fd 100644 --- a/yazi-binding/src/elements/area.rs +++ b/yazi-binding/src/elements/area.rs @@ -51,6 +51,10 @@ impl From for Area { fn from(rect: Rect) -> Self { Self::Rect(rect) } } +impl From for Area { + fn from(rect: ratatui::layout::Rect) -> Self { Self::Rect(rect.into()) } +} + impl TryFrom for Area { type Error = mlua::Error; diff --git a/yazi-plugin/src/isolate/peek.rs b/yazi-plugin/src/isolate/peek.rs index a712a2c4..9c212f90 100644 --- a/yazi-plugin/src/isolate/peek.rs +++ b/yazi-plugin/src/isolate/peek.rs @@ -2,11 +2,11 @@ use mlua::{ExternalError, HookTriggers, IntoLua, ObjectLike, VmState}; use tokio::{runtime::Handle, select}; use tokio_util::sync::CancellationToken; use tracing::error; -use yazi_binding::{File, elements::Rect}; +use yazi_binding::{Error, File, elements::{Rect, Renderable}}; use yazi_config::LAYOUT; use yazi_dds::Sendable; -use yazi_parser::app::{PluginCallback, PluginOpt}; -use yazi_proxy::AppProxy; +use yazi_parser::{app::{PluginCallback, PluginOpt}, mgr::{PreviewLock, UpdatePeekedOpt}}; +use yazi_proxy::{AppProxy, MgrProxy}; use yazi_shared::{event::Cmd, pool::Symbol}; use super::slim_lua; @@ -22,7 +22,10 @@ pub fn peek( let ct = CancellationToken::new(); if let Some(c) = LOADER.read().get(id) { - if c.sync_peek { + if let Err(e) = Loader::compatible_or_error(id, c) { + peek_error(file, mime, skip, e); + return None; + } else if c.sync_peek { peek_sync(cmd, file, mime, skip); } else { peek_async(cmd, file, mime, skip, ct.clone()); @@ -112,3 +115,20 @@ fn peek_async( } }); } + +fn peek_error(file: yazi_fs::File, mime: Symbol, skip: usize, error: anyhow::Error) { + let area = LAYOUT.get().preview; + MgrProxy::update_peeked(UpdatePeekedOpt { + lock: PreviewLock { + url: file.url, + cha: file.cha, + mime: mime.to_string(), + skip, + area: area.into(), + data: vec![ + Renderable::Clear(yazi_binding::elements::Clear { area: area.into() }), + Renderable::from(Error::custom(error.to_string())).with_area(area), + ], + }, + }); +}