mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41: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,
|
pub skip: usize,
|
||||||
|
|
||||||
previewer_ct: Option<CancellationToken>,
|
previewer_ct: Option<CancellationToken>,
|
||||||
folder_loader: Option<(Url, JoinHandle<()>)>,
|
folder_loader: Option<JoinHandle<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Preview {
|
impl Preview {
|
||||||
pub fn go(&mut self, file: File, mime: &str, force: bool) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,34 +37,31 @@ impl Preview {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn go_folder(&mut self, file: File, check: Option<Cha>, force: bool) {
|
pub fn go_folder(&mut self, file: File, dir: Option<Cha>, force: bool) {
|
||||||
if !force && self.content_unchanged(&file.url, &file.cha) {
|
let (cha, url) = (file.cha, file.url());
|
||||||
|
self.go(file, MIME_DIR, force);
|
||||||
|
|
||||||
|
if self.content_unchanged(&url, cha) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let url = file.url();
|
self.folder_loader.take().map(|h| h.abort());
|
||||||
self.go(file, MIME_DIR, force);
|
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());
|
let stream =
|
||||||
self.folder_loader = Some((
|
UnboundedReceiverStream::new(rx).chunks_timeout(50000, Duration::from_millis(500));
|
||||||
url.clone(),
|
pin!(stream);
|
||||||
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 =
|
let ticket = FilesOp::prepare(&url);
|
||||||
UnboundedReceiverStream::new(rx).chunks_timeout(50000, Duration::from_millis(500));
|
while let Some(chunk) = stream.next().await {
|
||||||
pin!(stream);
|
FilesOp::Part(url.clone(), chunk, ticket).emit();
|
||||||
|
}
|
||||||
let ticket = FilesOp::prepare(&url);
|
FilesOp::Done(url, new, ticket).emit();
|
||||||
while let Some(chunk) = stream.next().await {
|
}));
|
||||||
FilesOp::Part(url.clone(), chunk, ticket).emit();
|
|
||||||
}
|
|
||||||
FilesOp::Done(url, cha, ticket).emit();
|
|
||||||
}),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
@ -92,7 +89,7 @@ impl Preview {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn content_unchanged(&self, url: &Url, cha: &Cha) -> bool {
|
fn content_unchanged(&self, url: &Url, cha: Cha) -> bool {
|
||||||
match &self.lock {
|
match &self.lock {
|
||||||
Some(l) => *url == l.url && self.skip == l.skip && cha.hits(l.cha),
|
Some(l) => *url == l.url && self.skip == l.skip && cha.hits(l.cha),
|
||||||
None => false,
|
None => false,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::ops::{Deref, Range};
|
use std::ops::{Deref, Range};
|
||||||
|
|
||||||
use mlua::{AnyUserData, Lua, MetaMethod, UserDataFields, UserDataMethods};
|
use mlua::{AnyUserData, Lua, UserDataFields};
|
||||||
use yazi_config::LAYOUT;
|
use yazi_config::LAYOUT;
|
||||||
use yazi_plugin::{bindings::Cast, url::Url};
|
use yazi_plugin::{bindings::Cast, url::Url};
|
||||||
|
|
||||||
|
|
@ -51,14 +51,7 @@ impl Folder {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
lua.register_userdata_type::<yazi_fs::FolderStage>(|reg| {
|
lua.register_userdata_type::<yazi_fs::FolderStage>(|reg| {
|
||||||
reg.add_meta_method(MetaMethod::ToString, |lua, me, ()| {
|
reg.add_field_method_get("is_loading", |_, me| Ok(*me == yazi_fs::FolderStage::Loading));
|
||||||
use yazi_fs::FolderStage::{Failed, Loaded, Loading};
|
|
||||||
lua.create_string(match me {
|
|
||||||
Loading => "loading",
|
|
||||||
Loaded => "loaded",
|
|
||||||
Failed(_) => "failed",
|
|
||||||
})
|
|
||||||
});
|
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ function Current:empty()
|
||||||
if self._folder.files.filter then
|
if self._folder.files.filter then
|
||||||
line = ui.Line("No filter results")
|
line = ui.Line("No filter results")
|
||||||
else
|
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
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ function M:peek()
|
||||||
|
|
||||||
if #folder.files == 0 then
|
if #folder.files == 0 then
|
||||||
return ya.preview_widgets(self, {
|
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),
|
:align(ui.Paragraph.CENTER),
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue