tauri-plugin-preferences
A Tauri plugin that provides cross-platform preferences storage using native system APIs.
Features
- Native preferences storage (
NSUserDefaultson macOS/iOS) - Simple key-value API with JSON serialization
- Type-safe TypeScript/JavaScript API
- Rust API for backend access
Platform Support
| Platform | Backend | Status |
|---|---|---|
| macOS | NSUserDefaults |
✅ Supported |
| iOS | UserDefaults |
✅ Supported |
| Windows | Registry | 🚧 Planned |
| Linux | XDG Config | 🚧 Planned |
| Android | SharedPreferences | 🚧 Planned |
Requirements
- Tauri 2.x
- macOS 10.13+ / iOS 14.0+
Quick Start
1. Install dependencies
# src-tauri/Cargo.toml
[]
= "0.1"
2. Register plugin
3. Configure permissions
Add to src-tauri/capabilities/default.json:
Basic Usage
TypeScript
import { get, set, remove, has, clear } from 'tauri-plugin-preferences-api';
// Store a value (automatically serialized to JSON)
await set('user', { name: 'John', age: 30 });
// Retrieve a value (automatically deserialized)
const user = await get<{ name: string; age: number }>('user');
// Check if key exists
const exists = await has('user');
// Remove a key
await remove('user');
// Clear all preferences
await clear();
Rust
use PreferencesExt;
API Reference
| Method | Description |
|---|---|
get<T>(key) |
Get a value, returns null if not found |
set<T>(key, value) |
Store a value (JSON serialized) |
remove(key) |
Remove a value |
has(key) |
Check if key exists |
clear() |
Clear all preferences |
License
MIT