tauri-plugin-preferences 0.1.0

A Tauri plugin that provides cross-platform preferences storage using native system APIs
Documentation
# tauri-plugin-preferences

[![Crates.io Version](https://img.shields.io/crates/v/tauri-plugin-preferences)](https://crates.io/crates/tauri-plugin-preferences)
[![npm Version](https://img.shields.io/npm/v/tauri-plugin-preferences-api)](https://www.npmjs.com/package/tauri-plugin-preferences-api)
[![License](https://img.shields.io/crates/l/tauri-plugin-preferences)](LICENSE)

A Tauri plugin that provides cross-platform preferences storage using native system APIs.

## Features

- Native preferences storage (`NSUserDefaults` on 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

```toml
# src-tauri/Cargo.toml
[dependencies]
tauri-plugin-preferences = "0.1"
```

```bash
npm install tauri-plugin-preferences-api
```

### 2. Register plugin

```rust
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`:

```json
{
  "permissions": ["preferences:default"]
}
```

## Basic Usage

### TypeScript

```ts
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

```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