Tauri SDK API reference
JavaScript
import {
getFingerprint,
getLatestAllowedVersion,
getLicense,
getLicenseKey,
getLicenseKeyHint,
getOfflineState,
getPortalUrl,
getState,
isClockTampered,
LicenseError,
onStateChange,
ready,
refresh,
setLicenseKey,
watchLicense,
type LicenseErrorCode,
type LicenseSnapshot,
type LicenseState,
type OfflineState,
type UnlistenFn,
} from "@licenseman/tauri";Every function calls the plugin over Tauri’s IPC, and needs its permission.
ready(): Promise<LicenseState>
Resolves with the state on startup. With a valid stored token, right away with ACTIVE, and the online validation runs in the background. Otherwise, once the startup validation is done. Never rejects because of LicenseManager.
getState(): Promise<LicenseState>
The current state. See license states.
getLicense(): Promise<LicenseSnapshot>
The state, the offline state and the latest allowed version, in one call.
watchLicense(listener): Promise<UnlistenFn>
Subscribes to the state event, then calls listener(snapshot) with the current snapshot, then on every change. Resolves with a function that stops listening. See rendering the license.
onStateChange(listener): Promise<UnlistenFn>
Calls listener(state, snapshot) on every change of state, not with the current state. Resolves with a function that stops listening.
setLicenseKey(key: string): Promise<LicenseState>
Validates the key online, trimmed, case kept, retrying transient failures for up to 30 seconds. On success, stores it with its token, and resolves with ACTIVE. On any failure, rejects with a LicenseError and changes nothing. See activating a license.
refresh(): Promise<LicenseState>
Waits for ready(), then validates the stored key now, retrying transient failures for up to 30 seconds. Resolves with the new state. Never rejects because of LicenseManager. Without a stored key, resolves with the current state. See refresh().
getOfflineState(): Promise<OfflineState>
Whether the last validation reached LicenseManager, and how long the stored token remains valid. See offline state.
getLatestAllowedVersion(): Promise<string | null | undefined>
In VERSION_NOT_ALLOWED, refused by LicenseManager: the latest version the license allows, or null when it allows none. undefined in every other state, and when the refusal comes from the stored token offline.
getPortalUrl(): Promise<string>
The link to your product’s customer portal, like https://app.licensemanager.dev/portal/x7Kp2QaZ.
isClockTampered(): Promise<boolean>
The result of the latest clock check. See clock tampering.
getLicenseKeyHint(): Promise<string | null>
The last 5 characters of the stored key, or null when none was activated.
getLicenseKey(): Promise<string | null>
The stored key, or null. Needs licensemanager:allow-get-license-key, not in licensemanager:default.
getFingerprint(): Promise<string>
This computer’s fingerprint for your product. Needs licensemanager:allow-get-fingerprint, not in licensemanager:default. See machine fingerprint.
Types
type LicenseState =
| "LOADING"
| "MISSING_KEY"
| "ACTIVE"
| "INVALID_KEY"
| "EXPIRED"
| "VERSION_NOT_ALLOWED"
| "MACHINE_LIMIT_REACHED"
| "OFFLINE_EXPIRED"
| "CLOCK_TAMPERED";
type OfflineState =
| { mode: "online" }
| {
mode: "offline";
/** Expiration of the stored token, or null without a valid token. */
validUntil: Date | null;
/** Time left before validUntil, in milliseconds. 0 without a valid token. */
remainingMs: number;
};
interface LicenseSnapshot {
state: LicenseState;
offline: OfflineState;
latestAllowedVersion: string | null | undefined;
}LicenseError
Extends Error, with name set to "LicenseError".
| Property | Type | |
|---|---|---|
code | LicenseErrorCode | What failed. Branch on it, not on message. |
message | string | For logs. |
status | number | undefined | The HTTP status, when LicenseManager answered. |
latestAllowedVersion | string | null | undefined | For version_not_allowed only. |
isLocking | boolean | true when the license itself was refused. |
Rust
use tauri_plugin_licensemanager::{
Builder, LatestAllowedVersion, LicenseError, LicenseErrorCode, LicenseManager,
LicenseState, LicensemanagerExt, MachineFingerprint, OfflineState, Subscription,
};The full documentation of each item is on docs.rs .
Builder
| Method | Default | |
|---|---|---|
Builder::new(product_id, public_key) | Required | Your product’s id, and your organization’s Ed25519 public key, as PEM, from the Security page. |
.version(impl Into<String>) | The app’s version | Your app’s version, from tauri.conf.json or Cargo.toml. |
.machine_name(impl Into<String>) | The hostname | The machine’s name on LicenseManager. |
.platform(impl Into<String>) | macOS, Windows or Linux | The machine’s platform on LicenseManager. |
.fingerprint(impl Into<MachineFingerprint>) | The system’s machine id | The machine part of the fingerprint. |
.min_offline_duration(Duration) | Zero | The minimum validity left after a renewal. See min_offline_duration. |
.api_base_url(impl Into<String>) | https://api.licensemanager.dev | For tests. |
.build() | The TauriPlugin, for tauri::Builder::plugin. |
The app’s setup fails when the product id is empty, the public key isn’t a valid Ed25519 public key, or the app runs on iOS or Android. See setup.
LicensemanagerExt
license(&self) -> &LicenseManager, on any App, AppHandle, Window or Webview. Panics when the plugin isn’t registered.
LicenseManager
Cheap to clone: clones share the same state.
| Method | |
|---|---|
state(&self) -> LicenseState | The current state. |
async ready(&self) -> LicenseState | Like ready() above. |
async set_license_key(&self, input: &str) -> Result<LicenseState, LicenseError> | Like setLicenseKey() above. |
async refresh(&self) -> LicenseState | Like refresh() above. |
license_key(&self) -> Option<String> | The stored key. |
portal_url(&self) -> String | The link to the customer portal. |
latest_allowed_version(&self) -> LatestAllowedVersion | Like getLatestAllowedVersion() above. |
offline_state(&self) -> OfflineState | Like getOfflineState() above. |
async fingerprint(&self) -> String | This computer’s fingerprint. |
is_clock_tampered(&self) -> bool | The result of the latest clock check. |
on_state_change(&self, F) -> Subscription | Calls F(LicenseState) on every change. Removed when the Subscription is dropped. |
subscribe(&self) -> tokio::sync::watch::Receiver<LicenseState> | The current state, and every change. |
dispose(&self) | Stops the renewals, the pending retries and the clock check. Called by the plugin when the app exits. |
LicenseState
Loading, MissingKey, Active, InvalidKey, Expired, VersionNotAllowed, MachineLimitReached, OfflineExpired, ClockTampered. Serialized like in JavaScript, like "MISSING_KEY". as_str() returns the same string.
OfflineState
Online, or Offline { valid_until: Option<SystemTime>, remaining: Duration }.
LatestAllowedVersion
NotApplicable (undefined in JavaScript), NoneAllowed (null), or Version(String).
MachineFingerprint
Static(String), from a String or &str, or a function, with MachineFingerprint::from_sync_fn(|| -> String) or MachineFingerprint::from_fn(|| async -> String).
LicenseError
| Field | Type |
|---|---|
code | LicenseErrorCode |
message | String |
status | Option<u16> |
latest_allowed_version | LatestAllowedVersion |
is_locking() is true when the license itself was refused.
Commands and event
@licenseman/tauri calls these commands, as plugin:licensemanager|<command>: get_state, ready, get_license, set_license_key, refresh, get_offline_state, get_latest_allowed_version, get_portal_url, is_clock_tampered, get_license_key_hint, get_license_key, get_fingerprint. Each has an allow- and a deny- permission, like licensemanager:allow-get-state.
On every change of state, the plugin emits licensemanager://state-changed to every window, with the snapshot: { state, offline, latestAllowedVersion }, validUntil as milliseconds since 1970.
LicenseErrorCode
| Code | Rust | Locking | Source |
|---|---|---|---|
not_found | NotFound | Yes | LicenseManager, 404. |
license_expired | LicenseExpired | Yes | LicenseManager, 403. |
version_not_allowed | VersionNotAllowed | Yes | LicenseManager, 403. |
machine_limit_reached | MachineLimitReached | Yes | LicenseManager, 403. |
plan_limit_exceeded | PlanLimitExceeded | No | LicenseManager, 402. |
validation_error | ValidationError | No | LicenseManager, 422, or an empty key. |
internal_error | InternalError | No | LicenseManager, 500. |
network_error | NetworkError | No | The SDK: no answer, a timeout after 10 seconds, or an unknown error code, after the retries. |
invalid_response | InvalidResponse | No | The SDK: no token in the answer, or a token that failed verification. |
See the errors for what to show for each one.