Application State

Overview

AppState manages global application configuration, including directory paths and metadata. It must be initialized once at application startup before using any LightyLauncher functionality.

Initialization

use lighty_core::AppState;

const QUALIFIER: &str = "com";
const ORGANIZATION: &str = "MyLauncher";
const APPLICATION: &str = "";

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Initialize with your application details
    let _app = AppState::new(
        QUALIFIER.to_string(),
        ORGANIZATION.to_string(),
        APPLICATION.to_string(),
    )?;

    // Now you can use other LightyLauncher functions
    Ok(())
}

Architecture

spinner

API Reference

Initialization

AppState::new(qualifier, organization, application)

Initializes the global application state.

Parameters:

  • qualifier: Reverse domain notation (e.g., "com", "fr")

  • organization: Organization/launcher name (e.g., ".LightyLauncher")

  • application: Application name (optional, can be empty)

Returns: Result<AppState, AppStateError>

Errors:

  • AppStateError::ProjectDirsCreation - Failed to create project directories

  • AppStateError::NotInitialized - AppState already initialized

Example:

Directory Access

AppState::get_project_dirs()

Returns the platform-specific project directories.

Returns: &'static Lazy<ProjectDirs>

Directories include:

  • data_dir() - Application data directory

  • config_dir() - Configuration directory

  • cache_dir() - Cache directory

Example:

Metadata Access

AppState::get_app_name()

Returns the application name derived from organization.

Returns: String

Behavior:

  • Strips leading . from organization name

  • Falls back to "LightyLauncher" if not initialized

Example:

AppState::get_app_version()

Returns the crate version from Cargo.toml.

Returns: String

Example:

AppState::get_organization()

Returns the organization name if initialized.

Returns: Option<&'static String>

AppState::get_qualifier()

Returns the qualifier if initialized.

Returns: Option<&'static String>

AppState::get_application()

Returns the application name if initialized.

Returns: Option<&'static String>

Platform-Specific Paths

Windows

macOS

Linux

Thread Safety

AppState uses OnceCell for thread-safe initialization:

Best Practices

1. Initialize Early

2. Handle Initialization Errors

3. Organization Naming Convention

Integration with Other Crates

lighty-version

lighty-launch

Error Reference

See Also

Last updated