gntp 0.1.4

A complete Growl Notification Transport Protocol (GNTP) client library for Rust
Documentation

GNTP - Growl Notification Transport Protocol Client

Crates.io Documentation License

A complete Rust implementation of the Growl Notification Transport Protocol (GNTP) for sending desktop notifications.

Features

  • ✅ Full GNTP 1.0 protocol implementation
  • ✅ Binary icon support (PNG, JPG, etc.)
  • ✅ Multiple notification types per application
  • ✅ Priority levels (-2 to 2)
  • ✅ Sticky notifications
  • ✅ Comprehensive error handling
  • ✅ No external dependencies (except uuid)
  • ✅ Cross-platform (Windows, macOS, Linux)

Installation

Add this to your Cargo.toml:

[dependencies]

gntp = "0.1"

Requirements

You need a GNTP-compatible notification client:

  • Windows: Growl for Windows
  • macOS: Growl for Mac (legacy) or compatible client
  • Linux: Snarl or compatible GNTP daemon

Default server: localhost:23053

Quick Start

use gntp::{GntpClient, NotificationType};

fn main() -> Result<(), gntp::GntpError> {
    // Create client
    let mut client = GntpClient::new("My App");

    // Define notification type
    let notification = NotificationType::new("alert")
        .with_display_name("Alert Notification");

    // Step 1: Register (MUST be called first!)
    client.register(vec![notification])?;

    // Step 2: Send notification
    client.notify("alert", "Hello", "This is a test notification")?;

    Ok(())
}

Examples

Basic Notification

use gntp::{GntpClient, NotificationType};

let mut client = GntpClient::new("Example App");
let notification = NotificationType::new("message");
client.register(vec![notification])?;
client.notify("message", "Hello", "Basic notification")?;

With Icon

use gntp::{GntpClient, NotificationType, Resource};

let mut client = GntpClient::new("Icon Example");

// Load application icon
if let Ok(icon) = Resource::from_file("app_icon.png") {
    client = client.with_icon(icon);
}

let notification = NotificationType::new("alert");
client.register(vec![notification])?;
client.notify("alert", "Alert", "With icon")?;

With Options (Priority & Sticky)

use gntp::{GntpClient, NotificationType, NotifyOptions};

let mut client = GntpClient::new("Options Example");
let notification = NotificationType::new("important");
client.register(vec![notification])?;

let options = NotifyOptions::new()
    .with_sticky(true)
    .with_priority(2);

client.notify_with_options(
    "important",
    "Critical",
    "High priority sticky notification",
    options
)?;

Multiple Notification Types

let mut client = GntpClient::new("Multi App");

let notifications = vec![
    NotificationType::new("info"),
    NotificationType::new("warning"),
    NotificationType::new("error"),
];

client.register(notifications)?;

client.notify("info", "Info", "Information")?;
client.notify("warning", "Warning", "Warning message")?;
client.notify("error", "Error", "Error occurred")?;

Protocol Details

GNTP requires two separate steps:

  1. REGISTER - Register your application and notification types (once at startup)
  2. NOTIFY - Send notifications (multiple times)

Icons are sent as binary resources with unique identifiers, not as file paths.

Error Handling

match client.register(vec![notification]) {
    Ok(_) => println!("Registered successfully"),
    Err(e) => {
        eprintln!("Registration failed: {}", e);
        // Handle error (Growl not running, network issue, etc.)
    }
}

Running Examples

# Basic example

cargo run --example basic


# With icon

cargo run --example with_icon


# Multiple notification types

cargo run --example multiple_types


# With options (priority, sticky)

cargo run --example with_options


# Error handling

cargo run --example error_handling

License

Licensed under either of:

at your option.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Resources

Author

Hadi Cahyadi

Buy Me a Coffee

Donate via Ko-fi

Support me on Patreon