Remove Empty Folder From View

This commit is contained in:
2026-02-17 00:55:05 -06:00
parent 1242999b35
commit a909a16f57

View File

@@ -3536,12 +3536,18 @@ fn offline_list_dir(dir: &std::path::Path) -> Vec<OfflineEntry> {
None => continue, None => continue,
}; };
// Hide download marker files + aria2 artifacts // Hide sidecar files
if name.ends_with(".cj-jftui.json") || name.ends_with(".aria2") || name.ends_with(".part") { if !path.is_dir() && is_hidden_sidecar(&name) {
continue; continue;
} }
let is_dir = path.is_dir(); 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 }); out.push(OfflineEntry { name, path, is_dir });
} }
@@ -3557,6 +3563,44 @@ fn offline_list_dir(dir: &std::path::Path) -> Vec<OfflineEntry> {
out 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( fn render_offline_library_dir(
frame: &mut Frame, frame: &mut Frame,
title: &str, title: &str,