mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
fix: directory loading status (#1439)
This commit is contained in:
parent
6e94776781
commit
0954f9c58c
4 changed files with 27 additions and 37 deletions
|
|
@ -15,12 +15,12 @@ pub struct Preview {
|
|||
pub skip: usize,
|
||||
|
||||
previewer_ct: Option<CancellationToken>,
|
||||
folder_loader: Option<(Url, JoinHandle<()>)>,
|
||||
folder_loader: Option<JoinHandle<()>>,
|
||||
}
|
||||
|
||||
impl Preview {
|
||||
pub fn go(&mut self, file: File, mime: &str, force: bool) {
|
||||
if !force && self.content_unchanged(&file.url, &file.cha) {
|
||||
if !force && self.content_unchanged(&file.url, file.cha) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -37,34 +37,31 @@ impl Preview {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn go_folder(&mut self, file: File, check: Option<Cha>, force: bool) {
|
||||
if !force && self.content_unchanged(&file.url, &file.cha) {
|
||||
pub fn go_folder(&mut self, file: File, dir: Option<Cha>, force: bool) {
|
||||
let (cha, url) = (file.cha, file.url());
|
||||
self.go(file, MIME_DIR, force);
|
||||
|
||||
if self.content_unchanged(&url, cha) {
|
||||
return;
|
||||
}
|
||||
|
||||
let url = file.url();
|
||||
self.go(file, MIME_DIR, force);
|
||||
self.folder_loader.take().map(|h| h.abort());
|
||||
self.folder_loader = Some(tokio::spawn(async move {
|
||||
let Some(new) = Files::assert_stale(&url, dir.unwrap_or(Cha::dummy())).await else {
|
||||
return;
|
||||
};
|
||||
let Ok(rx) = Files::from_dir(&url).await else { return };
|
||||
|
||||
self.folder_loader.take().map(|(_, h)| h.abort());
|
||||
self.folder_loader = Some((
|
||||
url.clone(),
|
||||
tokio::spawn(async move {
|
||||
let Some(cha) = Files::assert_stale(&url, check.unwrap_or(Cha::dummy())).await else {
|
||||
return;
|
||||
};
|
||||
let Ok(rx) = Files::from_dir(&url).await else { return };
|
||||
let stream =
|
||||
UnboundedReceiverStream::new(rx).chunks_timeout(50000, Duration::from_millis(500));
|
||||
pin!(stream);
|
||||
|
||||
let stream =
|
||||
UnboundedReceiverStream::new(rx).chunks_timeout(50000, Duration::from_millis(500));
|
||||
pin!(stream);
|
||||
|
||||
let ticket = FilesOp::prepare(&url);
|
||||
while let Some(chunk) = stream.next().await {
|
||||
FilesOp::Part(url.clone(), chunk, ticket).emit();
|
||||
}
|
||||
FilesOp::Done(url, cha, ticket).emit();
|
||||
}),
|
||||
));
|
||||
let ticket = FilesOp::prepare(&url);
|
||||
while let Some(chunk) = stream.next().await {
|
||||
FilesOp::Part(url.clone(), chunk, ticket).emit();
|
||||
}
|
||||
FilesOp::Done(url, new, ticket).emit();
|
||||
}));
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -92,7 +89,7 @@ impl Preview {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn content_unchanged(&self, url: &Url, cha: &Cha) -> bool {
|
||||
fn content_unchanged(&self, url: &Url, cha: Cha) -> bool {
|
||||
match &self.lock {
|
||||
Some(l) => *url == l.url && self.skip == l.skip && cha.hits(l.cha),
|
||||
None => false,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::ops::{Deref, Range};
|
||||
|
||||
use mlua::{AnyUserData, Lua, MetaMethod, UserDataFields, UserDataMethods};
|
||||
use mlua::{AnyUserData, Lua, UserDataFields};
|
||||
use yazi_config::LAYOUT;
|
||||
use yazi_plugin::{bindings::Cast, url::Url};
|
||||
|
||||
|
|
@ -51,14 +51,7 @@ impl Folder {
|
|||
})?;
|
||||
|
||||
lua.register_userdata_type::<yazi_fs::FolderStage>(|reg| {
|
||||
reg.add_meta_method(MetaMethod::ToString, |lua, me, ()| {
|
||||
use yazi_fs::FolderStage::{Failed, Loaded, Loading};
|
||||
lua.create_string(match me {
|
||||
Loading => "loading",
|
||||
Loaded => "loaded",
|
||||
Failed(_) => "failed",
|
||||
})
|
||||
});
|
||||
reg.add_field_method_get("is_loading", |_, me| Ok(*me == yazi_fs::FolderStage::Loading));
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ function Current:empty()
|
|||
if self._folder.files.filter then
|
||||
line = ui.Line("No filter results")
|
||||
else
|
||||
line = ui.Line(self._folder.stage == "loading" and "Loading..." or "No items")
|
||||
line = ui.Line(self._folder.stage.is_loading and "Loading..." or "No items")
|
||||
end
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ function M:peek()
|
|||
|
||||
if #folder.files == 0 then
|
||||
return ya.preview_widgets(self, {
|
||||
ui.Paragraph(self.area, { ui.Line(folder.stage == "loading" and "Loading..." or "No items") })
|
||||
ui.Paragraph(self.area, { ui.Line(folder.stage.is_loading and "Loading..." or "No items") })
|
||||
:align(ui.Paragraph.CENTER),
|
||||
})
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue