Skip to main content

Crate tauri_plugin_licensemanager

Crate tauri_plugin_licensemanager 

Source
Expand description

Tauri v2 plugin for licensemanager.dev: license key activation, offline tokens, background renewal, clock tampering detection and machine fingerprinting.

Register the plugin with a Builder, then reach the LicenseManager with LicensemanagerExt::license:

use std::time::Duration;
use tauri_plugin_licensemanager::{LicenseState, LicensemanagerExt};

const PUBLIC_KEY: &str = "-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----";

#[tauri::command]
fn export_pdf(app: tauri::AppHandle) -> Result<(), String> {
    if app.license().state() != LicenseState::Active {
        return Err("A license is required".into());
    }
    Ok(())
}

// `context` is `tauri::generate_context!()` in an app.
fn run(context: tauri::Context) {
    tauri::Builder::default()
        .plugin(
            tauri_plugin_licensemanager::Builder::new("x7Kp2QaZ", PUBLIC_KEY)
                .min_offline_duration(Duration::from_secs(14 * 86_400))
                .build(),
        )
        .invoke_handler(tauri::generate_handler![export_pdf])
        .run(context)
        .expect("error while running tauri application");
}

See https://licensemanager.dev/docs/tauri.

Structs§

Builder
Configures and builds the plugin.
LicenseError
A failed license validation. Branch on code, never on message.
LicenseErrorDto
A LicenseError as JSON: { code, message, status?, latestAllowedVersion? }.
LicenseManager
The license state machine: one per app, created by the plugin and reached with LicensemanagerExt::license.
Snapshot
Everything the webview needs to render the license, in one call. Also the payload of the licensemanager://state-changed event.
Subscription
Keeps a listener registered by LicenseManager::on_state_change until dropped.

Enums§

ConfigError
Invalid plugin configuration: a developer error, reported at startup.
LatestAllowedVersion
In state VERSION_NOT_ALLOWED, the latest version the license allows.
LicenseErrorCode
Error codes returned by the validate-key endpoint, plus SDK-side codes for failures that never reached a definitive server answer.
LicenseState
The license state of the app.
MachineFingerprint
User-supplied machine fingerprint source, replacing the native machine id. The value is still hashed before use.
OfflineState
Whether the last validation reached the server.
OfflineStateDto
OfflineState as JSON: { mode: "online" } or { mode: "offline", validUntil: number | null, remainingMs: number }, times in ms since the epoch.

Constants§

SDK_NAME
Name of this SDK.
STATE_CHANGED_EVENT
Event emitted to every webview on each state change, with a Snapshot.

Traits§

LicensemanagerExt
Access to the LicenseManager from an App, AppHandle, Window…