IPC API Bridge
Relevant source files
The following files were used as context for generating this wiki page:
The IPC (Inter-Process Communication) API Bridge serves as the critical communication layer between the React-based frontend and the Rust-based Tauri backend. It provides a typed, asynchronous interface for the frontend to perform note operations, manage application state, and modify system settings.
This bridge is designed with portability in mind, featuring a dual-path execution model: a production path that utilizes Tauri's invoke command to reach the Rust backend, and a development/web path that uses a localStorage based shim for browser environments without a native backend.
Sources: src/lib/api.ts, src/lib/tauri/shim.ts, plans/migration.md:52-54
Architecture Overview
The bridge architecture follows a request-response pattern where the frontend "invokes" specific command strings that are caught and processed by either the native Tauri core or a web shim.
The diagram above illustrates the decision logic and data flow between the frontend and the different persistence layers based on the environment.
Sources: src/lib/api.ts, src/lib/tauri/shim.ts:257-270, plans/migration.md:65-68
Core API Interface
The frontend interacts with the backend through a centralized api object. This object maps semantic function calls to specific IPC command strings recognized by the Rust backend.
Note Management Commands
These commands handle the lifecycle of notes, including creation, retrieval, and persistence transitions between "draft" and "saved" states.
| Command Function | IPC String | Parameters | Returns |
|---|---|---|---|
noteCreate | note_create | None | NoteMeta |
noteGet | note_get | id: string | NoteWithContent |
noteSave | note_save | id, content | NoteMeta |
noteSaveAs | note_save_as | id, path, content | NoteMeta |
noteTrash | note_trash | id: string | NoteMeta |
noteRestore | note_restore | id: string | NoteMeta |
notePin | note_pin | id, pinned | NoteMeta |
Sources: src/lib/api.ts:4-15, src-tauri/src/notes.rs:25-50, src/test/lib/api.test.ts:15-30
Application and System Settings
These commands manage global application behavior, such as theme preferences and note expiry logic.
| Command Function | IPC String | Parameters | Description |
|---|---|---|---|
settingsSet | settings_set | key, value | Updates app settings (e.g., theme, expiry) |
appStateSet | app_state_set | key, value | Persists UI state (e.g., sidebarWidth) |
expiryRunNow | expiry_run_now | None | Triggers the auto-trash/delete logic immediately |
Sources: src/lib/api.ts:18-22, src/test/lib/api.test.ts:31-36
Execution Logic
The bridge facilitates complex state transitions, such as moving a note from the active list to the trash or converting an internal draft into an external saved file.
This sequence shows the multi-step process handled by the backend when a user promotes a draft to a saved file, involving filesystem operations and database updates.
Sources: src-tauri/src/notes.rs:40-46, src/lib/api.ts:11-12, plans/migration.md:124-126
Web Development Shim
To enable development in standard browsers or testing environments, a shim layer simulates the Tauri IPC interface. It uses localStorage under the key augenblick:webdb:v1 to persist data.
Shim Implementation Details
The shim implements the same command signatures as the native backend to ensure transparency for the frontend.
- Persistence: Data is stored as a serialized JSON object containing
notes,appState, andsettings. - ID Generation: Uses
crypto.randomUUID()for note identifiers. - Command Simulation: Includes logic for deriving titles and previews from content, which matches the Rust backend's behavior.
// src/lib/tauri/shim.ts:257-270
export function ensureTauriInternalsShim() {
if (typeof window === "undefined") return;
const w = window as Window & { __TAURI_INTERNALS__?: any };
if (w.__TAURI_INTERNALS__) return;
w.__TAURI_INTERNALS__ = {
__augenblick_web: true,
invoke: invokeWeb, // Internal dispatcher for all case-matched commands
convertFileSrc: (filePath: string) => filePath,
};
}
Sources: src/lib/tauri/shim.ts:8-10, src/lib/tauri/shim.ts:75-80, src/lib/tauri/shim.ts:257-270, src/test/lib/tauriShim.test.ts:10-25
Conclusion
The IPC API Bridge is a robust abstraction layer that decouples the Augenblick UI from its underlying OS-specific implementation. By providing a unified interface for both native Tauri and web environments, it ensures consistent behavior across platforms while maintaining strict type safety for application data and settings.