Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 25 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: 0 additions & 2 deletions apps/app/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ tauri-plugin-fs = "2"
tauri-plugin-store = "2"
tauri-plugin-dialog = "2"
tauri-plugin-os = "2"
urlencoding = "2"
futures = "0.3.31"
192 changes: 0 additions & 192 deletions apps/app/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,194 +1,3 @@
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,
});
}
}
}
}
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 @@ -197,7 +6,6 @@ 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: 0 additions & 1 deletion apps/app/src/components/sidebar/file_manager/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
$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' : ''}

Copilot AI Dec 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line has trailing whitespace at the end. Please remove the trailing space after the closing double quote on this line.

Suggested change
class="{opened_filenode?.path === node.path ? 'bg-base-content/10' : ''}
class="{opened_filenode?.path === node.path ? 'bg-base-content/10' : ''}

Copilot uses AI. Check for mistakes.
{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