1 unstable release
| 0.1.0 | Dec 24, 2025 |
|---|
#1279 in GUI
44KB
400 lines
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
[dependencies]
tauri-plugin-preferences = "0.1"
npm install tauri-plugin-preferences-api
2. Register plugin
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_preferences::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
3. Configure permissions
Add to src-tauri/capabilities/default.json:
{
"permissions": ["preferences:default"]
}
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 tauri_plugin_preferences::PreferencesExt;
fn example(app: &tauri::AppHandle) {
let prefs = app.preferences();
// Get a value
let result = prefs.get(GetRequest { key: "user".into() });
// Set a value
prefs.set(SetRequest {
key: "user".into(),
value: r#"{"name":"John"}"#.into(),
});
}
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
Dependencies
~16–63MB
~877K SLoC