Skip to content

Refactor: Implement non-blocking async file operations and UI loading states - #19

Open
BradMoyetones wants to merge 1 commit into
starc007:mainfrom
BradMoyetones:refactor/async-file-ops
Open

Refactor: Implement non-blocking async file operations and UI loading states#19
BradMoyetones wants to merge 1 commit into
starc007:mainfrom
BradMoyetones:refactor/async-file-ops

Conversation

@BradMoyetones

Copy link
Copy Markdown

Description

This PR refactors the file system commands to prevent blocking the Tauri IPC threads, aligning with Tauri's best practices for I/O operations. It also introduces seamless loading states on the frontend to improve the UX during large file operations, without cluttering the global store.

Changes Made

  • Backend (src-tauri/src/commands.rs): Converted synchronous I/O commands (delete_entry, rename_entry, move_entry, create_note, etc.) to async fn. Wrapped the underlying filesystem calls using tauri::async_runtime::spawn_blocking to offload them to a background thread pool, preventing any potential UI or IPC freezes.
  • Frontend (src/stores/vault.ts): Wrapped the corresponding ipc calls in promises and implemented toast.promise from Sonner. This natively provides loading, success, and error toast notifications immediately when interacting with the vault (e.g. moving to trash, renaming) without the need to introduce additional loading state variables into the UI components.

Motivation

To ensure the application remains highly responsive and doesn't limit performance on modern hardware when handling large vaults or heavy OS-level operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant