-
Notifications
You must be signed in to change notification settings - Fork 2
Migrate file tree creation to Rust backend #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Keshav-writes-code
merged 20 commits into
dev
from
migrate-filetree-to-rust-7043552137559722624
Dec 19, 2025
Merged
Changes from 6 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] 9e0502e
perf: optimize file tree building and sorting in Rust
google-labs-jules[bot] bc12921
feat(filetree): move generation and sorting to Rust backend
google-labs-jules[bot] f86735f
fix: don't use rust sort function for subsequent sorts bcuz of latenc…
Keshav-writes-code cca74c8
refac: remove unwanted legacy functions
Keshav-writes-code f6f0a33
fix(error): show a toast error if file tree building fails
Keshav-writes-code c5b6a5c
Update apps/app/src-tauri/src/lib.rs
Keshav-writes-code ebce40c
Update apps/app/src-tauri/src/lib.rs
Keshav-writes-code 91ebfeb
Update apps/app/src-tauri/src/lib.rs
Keshav-writes-code 1a18293
fix: use inline type modifier for FileNode import for consistency
Copilot 1238767
feat: implement natural/numeric sorting using natord crate
Copilot 6120081
fix: add aria label to icon based buttons
Keshav-writes-code 5a7c7fc
fix(performace): make subtree sorting happen only on rename operation…
Keshav-writes-code cfe2efc
fix: add sorting when new element gets inserted
Keshav-writes-code 6d8ebd7
refac: remove debugging statementsa
Keshav-writes-code 93e6a5a
refac: remove unwanted vairables
Keshav-writes-code b11e3c8
chore: update deps
Keshav-writes-code dbb3fcf
chore: update deps
Keshav-writes-code 342a9df
fix(ui_webkit): fix strange behaviour where a previously selected ite…
Keshav-writes-code 02f93b5
perf(filetree): optimize Android file tree building in Rust
google-labs-jules[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,85 +1,25 @@ | ||
| import { readDir, type DirEntry } from '@tauri-apps/plugin-fs'; | ||
| import { type FileNode, type GenericPath } from '@/types'; | ||
| import { | ||
| AndroidFs, | ||
| type AndroidEntryMetadataWithUri, | ||
| } from 'tauri-plugin-android-fs-api'; | ||
| import { join } from '@tauri-apps/api/path'; | ||
| import { current_platform } from './utils'; | ||
| import { invoke } from '@tauri-apps/api/core'; | ||
| import { toast } from 'svelte-sonner'; | ||
|
|
||
| export async function build_file_tree_from_fs({ | ||
| path, | ||
| document_top_tree_uri, | ||
| }: GenericPath): Promise<FileNode[]> { | ||
| let entries: DirEntry[] | AndroidEntryMetadataWithUri[] | undefined; | ||
| let base_nodes: FileNode[] | undefined; | ||
|
|
||
| if (current_platform == 'android') { | ||
| if (!document_top_tree_uri) | ||
| throw new Error('Document top tree URI is not set'); | ||
| entries = await AndroidFs.readDir({ | ||
| uri: path, | ||
| documentTopTreeUri: document_top_tree_uri, | ||
| try { | ||
| return await invoke('build_file_tree', { | ||
| path, | ||
| documentTopTreeUri: document_top_tree_uri || null, | ||
| }); | ||
| base_nodes = await transform_android_entries_to_filenode(entries, path); | ||
| } else { | ||
| entries = await readDir(path); | ||
| base_nodes = await transform_entries_to_filenode(entries, path); | ||
| } catch (error) { | ||
| console.error('Failed to build file tree:', error); | ||
| const description = | ||
| error instanceof Error | ||
| ? error.message | ||
| : typeof error === 'string' | ||
| ? error | ||
| : JSON.stringify(error); | ||
| toast.error('Failed to build file tree', { description }); | ||
| throw error; | ||
| } | ||
|
|
||
| const nodes = await Promise.all( | ||
| base_nodes.map(async (n) => { | ||
| if (!n.is_directory) return n; | ||
| const children = await build_file_tree_from_fs({ | ||
| path: n.path, | ||
| document_top_tree_uri, | ||
| }); | ||
| return { | ||
| ...n, | ||
| children, | ||
| }; | ||
| }) | ||
| ); | ||
|
|
||
| return nodes; | ||
| } | ||
| export async function transform_entries_to_filenode( | ||
| entries: DirEntry[], | ||
| base_dir_path: string | ||
| ): Promise<FileNode[]> { | ||
| const nodes = await Promise.all( | ||
| entries | ||
| .filter( | ||
| (entry) => | ||
| (entry.isDirectory && !entry.name.startsWith('.')) || | ||
| entry.name.endsWith('.md') | ||
| ) | ||
| .map(async (entry) => ({ | ||
| name: entry.name.replace(/\.md$/, ''), | ||
| path: await join(base_dir_path, entry.name), | ||
| is_directory: entry.isDirectory, | ||
| children: [], | ||
| })) | ||
| ); | ||
| return nodes; | ||
| } | ||
| export async function transform_android_entries_to_filenode( | ||
| entries: AndroidEntryMetadataWithUri[], | ||
| base_dir_path: string | ||
| ): Promise<FileNode[]> { | ||
| const nodes = await Promise.all( | ||
| entries | ||
| .filter( | ||
| (entry) => | ||
| (entry.type === 'Dir' && !entry.name.startsWith('.')) || | ||
| entry.name.endsWith('.md') | ||
| ) | ||
| .map(async (entry) => ({ | ||
| name: entry.name.replace(/\.md$/, ''), | ||
| path: `${base_dir_path}%2F${encodeURIComponent(entry.name)}`, | ||
| is_directory: entry.type === 'Dir', | ||
| children: [], | ||
| })) | ||
| ); | ||
| return nodes; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.