tauri-csv-explorer is a cross-platform desktop application for viewing and exploring CSV files. It's a demonstration of building a modern desktop app using Tauri, with a robust separation of concerns between a Rust backend and a SvelteKit frontend.
The application has been tested on macOS and Linux (Ubuntu).
This application follows a clear separation of concerns pattern.
- The backend, written in Rust, handles all the business logic, including file I/O and CSV data processing. This logic is contained in a separate, reusable library (
src-csv). We use Polars to read CSV files. While it may be oversized for this simple use case, it showcases the potential of Rust for Data Science applications. - The frontend, built with SvelteKit and TypeScript, provides the user interface. Svelte's speed and simplicity, combined with TypeScript's strong typing, create a fast and reliable user experience. The frontend communicates with the Rust backend via Tauri's
invokeAPI.
The application is built to fulfill the following requirements:
- REQ-002 Open CSV File: A user-friendly button to open and display a CSV file.
- REQ-004 Drag & Drop: Users can drag and drop a CSV file onto the application window to open it.
- REQ-003 CLI Argument: The app can be launched from the command line with a specified CSV file path.
- REQ-005 Menu: A standard application menu with relevant options.
- REQ-006 Dynamic Title: The application window title updates to reflect the currently viewed file.
- REQ-007 File Association: The app is registered to open
.csvfiles by default. - Automatic Updates: The app includes an updater to manage releases and provide seamless updates.
Search for REQ-xxx in the codebase to locate the corresponding code snippets.
The core logic for processing CSV files, including metadata extraction (e.g., delimiter detection), resides in its own Rust crate. This demonstrates how to build a UI for an existing library. A CLI version of this library can be used independently to confirm functionality.
For visualizing the CSV data, the Svelte Datagrid is used. The chosen component is ideal for handling and displaying tabular data efficiently.
To change the application icon, use the Tauri CLI:
pnpm tauri icon path/to/your/icon.pngAfter changing the icon in the src-tauri directory, a cargo clean is required to ensure the changes are reflected in the build.
The application leverages Tauri's built-in error propagation. Errors from the Rust backend are automatically sent to the frontend, allowing for unified error handling.
Add and Configure Dialog plugin
pnpm tauri add dialogset permissions in ./src-tauri/capabilities/default.json: "dialog:allow-open"
pnpm install wx-svelte-gridIf no defaultPath is set, the Path is set first on $HOME/Documents and after one selection to the latest used directory.
When the Tauri app is started from the CLI, the first positional parameter is the CSV filename. Since we already use existing Clap logic in src-csv, the Tauri CLI plugin is not needed !
The menu is implemented in TypeScript, as it belongs to the frontend.
To set the application title, the following permission must be added:
pnpm tauri permission add "core:window:allow-set-title"Otherwise, the title will not update, and only an error will appear in the browser console:
Unhandled Promise Rejection: window.set_title not allowed. Permissions associated with this command: core:window:allow-set-title
For visualization the Svelte Datagrid is used.
Alternative: https://github.com/joaquimnetocel/svelte-datatables-net
Error Handling https://v2.tauri.app/develop/calling-rust/#error-handling Errors from the Rust backend are propagated to the Frontend.
Demo to use a new icon
pnpm tauri icon taurirc/assets/icon_csv_text.pngAfter changing the icon in src-tauri a cargo clean is needed to reflect the changes.
Files with Extension .csv should opened with the application.
Implementation:
In ./src-tauri/tauri.conf.json add fileAssociations:
"bundle": {
"fileAssociations": [
{
"ext": [
"csv"
],
"name": "CSV File",
"role": "Editor",
"mimeType": "text/csv",
"description": "A comma-separated values file."
}
],
Releases are automated using GitHub Actions. The workflow for publishing the app is defined in .github/workflows/publish-tauri-app.yml
When a new release is available it should be installed automatically. This currently only works for demonstration purposes with an AppImage on Ubuntu ARM.
To support this on macOS Apple the app must be signed (an Apple Developer account is needed). For Windows a signed release must be created.
Add the plugin
cargo tauri add updaterTauri updater signs the apps. So create Tauri Keys
pnpm tauri signer generate -w ~/.tauri/myapp.keyThis Keys have to be added to your ./src-tauri/tauri.conf.json:
createUpdaterArtifacts true
"bundle": {
...
"createUpdaterArtifacts": true
},
"plugins": {
...
"updater": {
"pubkey": "TODO: insert",
"endpoints": [
"https://github.com/TODO:user/TODO:repo/releases/latest/download/latest.json"
]
}
more: https://v2.tauri.app/plugin/updater/#tauri-configuration
In Github TAURI_SIGNING_PRIVATE_KEY and TAURI_SIGNING_PRIVATE_KEY_PASSWORD have to be configured as secrets to sign a update release, e.g.:
echo $TAURI_SIGNING_PRIVATE_KEY | gh secret set TAURI_SIGNING_PRIVATE_KEY
echo $TAURI_SIGNING_PRIVATE_KEY_PASSWORD | gh secret set TAURI_SIGNING_PRIVATE_KEY_PASSWORDVS Code + Svelte + Tauri + rust-analyzer.
