Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4de427c
feat(filetree): move file tree generation logic to Rust backend
google-labs-jules[bot] Dec 10, 2025
9e0502e
perf: optimize file tree building and sorting in Rust
google-labs-jules[bot] Dec 10, 2025
bc12921
feat(filetree): move generation and sorting to Rust backend
google-labs-jules[bot] Dec 10, 2025
f86735f
fix: don't use rust sort function for subsequent sorts bcuz of latenc…
Keshav-writes-code Dec 10, 2025
cca74c8
refac: remove unwanted legacy functions
Keshav-writes-code Dec 10, 2025
f6f0a33
fix(error): show a toast error if file tree building fails
Keshav-writes-code Dec 10, 2025
c5b6a5c
Update apps/app/src-tauri/src/lib.rs
Keshav-writes-code Dec 10, 2025
ebce40c
Update apps/app/src-tauri/src/lib.rs
Keshav-writes-code Dec 10, 2025
91ebfeb
Update apps/app/src-tauri/src/lib.rs
Keshav-writes-code Dec 10, 2025
1a18293
fix: use inline type modifier for FileNode import for consistency
Copilot Dec 10, 2025
1238767
feat: implement natural/numeric sorting using natord crate
Copilot Dec 10, 2025
6120081
fix: add aria label to icon based buttons
Keshav-writes-code Dec 12, 2025
5a7c7fc
fix(performace): make subtree sorting happen only on rename operation…
Keshav-writes-code Dec 18, 2025
cfe2efc
fix: add sorting when new element gets inserted
Keshav-writes-code Dec 18, 2025
6d8ebd7
refac: remove debugging statementsa
Keshav-writes-code Dec 18, 2025
93e6a5a
refac: remove unwanted vairables
Keshav-writes-code Dec 18, 2025
b11e3c8
chore: update deps
Keshav-writes-code Dec 18, 2025
dbb3fcf
chore: update deps
Keshav-writes-code Dec 19, 2025
342a9df
fix(ui_webkit): fix strange behaviour where a previously selected ite…
Keshav-writes-code Dec 19, 2025
02f93b5
perf(filetree): optimize Android file tree building in Rust
google-labs-jules[bot] Dec 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions apps/app/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apps/app/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ tauri-plugin-fs = "2"
tauri-plugin-store = "2"
tauri-plugin-dialog = "2"
tauri-plugin-os = "2"
urlencoding = "2"
futures = "0.3.31"
192 changes: 192 additions & 0 deletions apps/app/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,194 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone)]
pub struct FileNode {
pub name: String,
pub path: String,
pub is_directory: bool,
pub children: Vec<FileNode>,
}

fn sort_nodes(nodes: &mut Vec<FileNode>) {
nodes.sort_by(|a, b| {
if a.is_directory != b.is_directory {
return if a.is_directory {
std::cmp::Ordering::Less
} else {
std::cmp::Ordering::Greater
};
}
a.name.to_lowercase().cmp(&b.name.to_lowercase())
});

for node in nodes {
if !node.children.is_empty() {
sort_nodes(&mut node.children);
}
}
}

#[cfg(not(target_os = "android"))]
fn build_tree_recursive_desktop(path_str: &str) -> std::io::Result<Vec<FileNode>> {
use std::fs;
let mut nodes = Vec::new();
let entries = fs::read_dir(path_str)?;

for entry in entries {
if let Ok(entry) = entry {
if let Ok(metadata) = entry.metadata() {
let file_name = entry.file_name().to_string_lossy().to_string();

let is_directory = metadata.is_dir();
let starts_with_dot = file_name.starts_with('.');
let ends_with_md = file_name.ends_with(".md");

if (is_directory && !starts_with_dot) || ends_with_md {
let path = entry.path().to_string_lossy().to_string();
let mut children = Vec::new();

if is_directory {
if let Ok(sub_children) = build_tree_recursive_desktop(&path) {
children = sub_children;
}
}

nodes.push(FileNode {
name: file_name.trim_end_matches(".md").to_string(),
path,
is_directory,
children,
});
}
}
}
Comment thread
Keshav-writes-code marked this conversation as resolved.
}
Ok(nodes)
}

#[cfg(target_os = "android")]
fn build_tree_recursive_android(
app: tauri::AppHandle,
path: String,
document_top_tree_uri: Option<String>,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<Vec<FileNode>, String>> + Send>> {
Box::pin(async move {
use tauri_plugin_android_fs::AndroidFsExt;
use tauri_plugin_android_fs::FileUri;
use tauri_plugin_android_fs::EntryOptions;
use futures::future::join_all;

let api = app.android_fs();

let json_obj = serde_json::json!({
"uri": path,
"documentTopTreeUri": document_top_tree_uri
});
let file_uri = FileUri::from_json_str(&json_obj.to_string())
.map_err(|e| format!("Failed to create FileUri: {}", e))?;

let options = EntryOptions {
uri: false,
name: true,
last_modified: false,
len: false,
mime_type: false,
};

let entries = api.read_dir_with_options(&file_uri, options)
.map_err(|e| e.to_string())?;

let mut futures = Vec::new();
let mut nodes = Vec::new();

for entry in entries {
let is_directory = entry.is_dir();
let name_opt = entry.name();

if let Some(name_str) = name_opt {
let name = name_str.to_string();
let starts_with_dot = name.starts_with('.');
let ends_with_md = name.ends_with(".md");

if (is_directory && !starts_with_dot) || ends_with_md {
let path_uri = format!("{}%2F{}", path, urlencoding::encode(&name));

if is_directory {
let app_clone = app.clone();
let path_clone = path_uri.clone();
let doc_uri_clone = document_top_tree_uri.clone();
let name_clone = name.clone();

futures.push(async move {
let children_res = build_tree_recursive_android(
app_clone,
path_clone.clone(),
doc_uri_clone
).await;

match children_res {
Ok(children) => Some(FileNode {
name: name_clone.trim_end_matches(".md").to_string(),
path: path_clone,
is_directory: true,
children,
}),
Err(_) => None
}
});
} else {
nodes.push(FileNode {
name: name.trim_end_matches(".md").to_string(),
path: path_uri,
is_directory: false,
children: vec![],
});
}
}
}
}

let results = join_all(futures).await;
for res in results {
if let Some(node) = res {
nodes.push(node);
}
}

Ok(nodes)
})
}

#[tauri::command]
async fn build_file_tree(
app: tauri::AppHandle,
path: String,
document_top_tree_uri: Option<String>,
) -> Result<Vec<FileNode>, String> {
let nodes;

#[cfg(target_os = "android")]
{
let mut unsorted_nodes = build_tree_recursive_android(app, path, document_top_tree_uri).await?;
sort_nodes(&mut unsorted_nodes);
nodes = unsorted_nodes;
}

#[cfg(not(target_os = "android"))]
{
// Suppress unused variable warnings on desktop
let _ = app;
let _ = document_top_tree_uri;
nodes = tauri::async_runtime::spawn_blocking(move || {
let mut n = build_tree_recursive_desktop(&path)?;
sort_nodes(&mut n);
Ok(n)
}).await.map_err(|e| e.to_string())?
.map_err(|e: std::io::Error| e.to_string())?;
}

Ok(nodes)
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
Expand All @@ -6,6 +197,7 @@ pub fn run() {
.plugin(tauri_plugin_store::Builder::new().build())
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_android_fs::init())
.invoke_handler(tauri::generate_handler![build_file_tree])
.setup(|app| {
if cfg!(debug_assertions) {
app.handle().plugin(
Expand Down
1 change: 1 addition & 0 deletions apps/app/src/components/sidebar/file_manager/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
$effect(() => {
if (file_tree) sort_file_tree(file_tree);
});

let collapsed_state: boolean = $state(true);
$effect(() => {
if (!root_path) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
ondragstart={(e) => handle_drag_start(e, node)}
ondragend={reset_dnd}
oncontextmenu={(e) => handle_node_right_click(e, node)}
class="{opened_filenode?.path === node.path ? 'bg-base-content/10' : ''}
class="{opened_filenode?.path === node.path ? 'bg-base-content/10' : ''}
{dragged_node?.path === node.path ? 'opacity-50' : ''}
py-0.75 w-full hover:text-[color-mix(in_srgb,var(--color-base-content)_85%,black)] truncate block"
onclick={(e) => {
Expand Down
Loading