Remove Empty Folder From View
This commit is contained in:
48
src/main.rs
48
src/main.rs
@@ -3536,12 +3536,18 @@ fn offline_list_dir(dir: &std::path::Path) -> Vec<OfflineEntry> {
|
||||
None => continue,
|
||||
};
|
||||
|
||||
// Hide download marker files + aria2 artifacts
|
||||
if name.ends_with(".cj-jftui.json") || name.ends_with(".aria2") || name.ends_with(".part") {
|
||||
// Hide sidecar files
|
||||
if !path.is_dir() && is_hidden_sidecar(&name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let is_dir = path.is_dir();
|
||||
|
||||
// ✅ Hide "empty" folders (only sidecars / empty / no real files under them)
|
||||
if is_dir && !dir_has_visible_content(&path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
out.push(OfflineEntry { name, path, is_dir });
|
||||
}
|
||||
|
||||
@@ -3557,6 +3563,44 @@ fn offline_list_dir(dir: &std::path::Path) -> Vec<OfflineEntry> {
|
||||
out
|
||||
}
|
||||
|
||||
|
||||
fn is_hidden_sidecar(name: &str) -> bool {
|
||||
name.ends_with(".cj-jftui.json") || name.ends_with(".aria2") || name.ends_with(".part")
|
||||
}
|
||||
|
||||
// Returns true if this directory contains any "visible" file or any subdir that does.
|
||||
fn dir_has_visible_content(dir: &std::path::Path) -> bool {
|
||||
let rd = match std::fs::read_dir(dir) {
|
||||
Ok(r) => r,
|
||||
Err(_) => return false,
|
||||
};
|
||||
|
||||
for ent in rd.flatten() {
|
||||
let path = ent.path();
|
||||
let name = match path.file_name().and_then(|s| s.to_str()) {
|
||||
Some(s) => s,
|
||||
None => continue,
|
||||
};
|
||||
|
||||
if path.is_dir() {
|
||||
if dir_has_visible_content(&path) {
|
||||
return true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// file
|
||||
if is_hidden_sidecar(name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return true; // any other file means "visible content"
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
|
||||
fn render_offline_library_dir(
|
||||
frame: &mut Frame,
|
||||
title: &str,
|
||||
|
||||
Reference in New Issue
Block a user