rustify-licensing 0.1.0

Framework-agnostic in-app licensing (validate / machine-activate / offline-grace) for native Rust apps. Keygen provider + Bevy / egui / headless adapters.
Documentation
//! # rustify-licensing
//!
//! Framework-agnostic in-app licensing for native Rust desktop apps: validate a key,
//! node-lock the machine, cache the result, and stay unlocked through a bounded
//! **offline grace** window — failing **closed** on an authoritative denial.
//!
//! A framework-agnostic core plus thin adapters, so the same logic drives a Bevy app,
//! a headless CLI, an egui/immediate-mode GUI, or tests.
//!
//! ## Shape
//! - [`core`] — pure, runtime-agnostic: [`LicenseState`] persistence + fingerprint,
//!   [`LicenseStatus`], [`CheckErr`] (the load-bearing `Denied` vs `Offline` split),
//!   and the [`core::engine`] that folds a check result into a status.
//! - [`provider`] — the [`LicenseProvider`] trait and the [`KeygenProvider`] impl
//!   (the exact Keygen validate/activate/node-lock dance). Swap in Polar later.
//! - [`adapters`] — `headless` (a blocking driver) and, behind the `bevy` feature,
//!   a [`adapters::bevy`] plugin with resources, systems, and an event API.
//!
//! ## Quick start (headless)
//! ```no_run
//! use rustify_licensing::{KeygenProvider, LicenseConfig, LicenseState, StorageConfig};
//! use rustify_licensing::adapters::headless::check_blocking;
//!
//! let config = LicenseConfig {
//!     account_id: "your-keygen-account-uuid".into(),
//!     api_base: "https://api.keygen.sh/v1".into(),
//!     grace_secs: 14 * 24 * 60 * 60,
//!     storage: StorageConfig::app_data("MyApp", "license.env", None, Some("MYAPP_LICENSE_KEY")),
//!     buy_url: "https://myapp.example/#pricing".into(),
//! };
//! let provider = KeygenProvider::from_config(&config);
//! let mut state = LicenseState::load(&config.storage);
//! let status = check_blocking(&config, &provider, &mut state, |line| println!("… {line}"));
//! println!("status: {status:?}");
//! ```

pub mod adapters;
pub mod core;
pub mod provider;

pub use crate::core::config::{LicenseConfig, StorageConfig};
pub use crate::core::error::CheckErr;
pub use crate::core::state::{now_secs, LicenseState};
pub use crate::core::status::LicenseStatus;
pub use crate::provider::{KeygenProvider, LicenseProvider};

/// Framework-agnostic threaded driver for immediate-mode GUIs / CLIs.
pub use crate::adapters::worker::LicenseWorker;

#[cfg(feature = "bevy")]
pub use crate::adapters::bevy;

/// Open a URL in the user's default browser (for a "Buy" button → `config.buy_url`).
pub fn open_url(url: &str) {
    #[cfg(target_os = "macos")]
    let _ = std::process::Command::new("open").arg(url).spawn();
    #[cfg(target_os = "windows")]
    let _ = std::process::Command::new("cmd")
        .args(["/C", "start", "", url])
        .spawn();
    #[cfg(all(unix, not(target_os = "macos")))]
    let _ = std::process::Command::new("xdg-open").arg(url).spawn();
}