gntp 0.1.11

Production-ready GNTP (Growl Notification Transport Protocol) client with Windows/Android compatibility and multiple icon delivery modes. Includes sendgrowl CLI tool.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# GNTP - Growl Notification Transport Protocol Client


[![Crates.io](https://img.shields.io/crates/v/gntp.svg)](https://crates.io/crates/gntp)
[![Documentation](https://docs.rs/gntp/badge.svg)](https://docs.rs/gntp)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

A robust, production-ready Rust implementation of the **Growl Notification Transport Protocol (GNTP)** for sending desktop notifications to Growl-compatible clients across multiple platforms.

## ✨ Features


- **Full GNTP 1.0 protocol implementation**
-**Multiple icon delivery modes** (Binary, File URL, Data URL/Base64)
-**Windows Growl compatibility** with automatic workarounds
-**Cross-platform support** (Windows, macOS, Linux, Android)
-**Binary resource deduplication** to prevent protocol errors
-**Comprehensive error handling** with detailed error types
-**Production-ready** with extensive documentation
-**Zero external dependencies** (except `uuid` for unique identifiers)
- ✅ Multiple notification types per application
- ✅ Priority levels (-2 to 2)
- ✅ Sticky notifications

## 📦 Installation


Add to your `Cargo.toml`:

```toml
[dependencies]
gntp = "0.1.5"
```

## Requirements


You need a GNTP-compatible notification client:

- **Windows**: [Growl for Windows]https://github.com/briandunnington/growl-for-windows/releases
- **macOS**: Growl for Mac (legacy) or compatible client
- **Linux**: Snarl or compatible GNTP daemon
- **Android**: Googling :)

Default server: `localhost:23053`

## 🚀 Quick Start


```bash

# Build library only (no CLI) `sendgrowl`

cargo build --release

# Build dengan CLI tool (sendgrowl)

cargo build --release --features cli --bin sendgrowl

# Test sendgrowl

cargo run --features cli --bin sendgrowl -- TEST APP "Title" "Message" -i growl.png -v

# more options

sendgrowl --help
```

```rust
use gntp::{GntpClient, NotificationType, Resource, IconMode};

fn main() -> Result<(), gntp::GntpError> {
    // Create client with DataUrl mode (safest, most compatible)
    let mut client = GntpClient::new("My App")
        .with_icon_mode(IconMode::DataUrl);

    // Load icon from file
    let icon = Resource::from_file("icon.png")?;

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

    // Register (must be called first!)
    client.register(vec![notification])?;

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

    Ok(())
}
```

## 🎯 Icon Delivery Modes


### DataUrl Mode (Recommended - Default)


Embeds icons as base64-encoded data URLs. **Most compatible** across all platforms, especially Windows.

```rust
let client = GntpClient::new("App")
    .with_icon_mode(IconMode::DataUrl);
```

**Pros:**
- ✅ Works on all platforms
- ✅ No external files required
- ✅ Bypasses Growl for Windows binary resource bug

**Cons:**
- ⚠️ Larger packet size (~33% increase due to base64)

### Binary Mode (GNTP Spec Compliant)

Sends icons as binary resources according to GNTP specification.

```rust
let client = GntpClient::new("App")
    .with_icon_mode(IconMode::Binary);
```

**Pros:**
- ✅ Smallest packet size
- ✅ Fastest transmission
- ✅ GNTP spec compliant

**Cons:**
- ❌ Broken on Growl for Windows (causes timeout)

### FileUrl Mode


References icons via `file://` URLs. Requires icon files to exist on disk.

```rust
let client = GntpClient::new("App")
    .with_icon_mode(IconMode::FileUrl);
```

**Pros:**
- ✅ No data in packet
- ✅ Good for shared icons

**Cons:**
- ⚠️ Requires files on disk
- ⚠️ Path must be accessible to Growl server

## 🖼️ Working with Icons


### From File


```rust
let icon = Resource::from_file("icon.png")?;
```

### From Memory


```rust
let image_data: Vec<u8> = load_icon_from_memory();
let icon = Resource::from_bytes(image_data, "image/png");
```

### Supported Formats


- PNG (`.png`) - Recommended
- JPEG (`.jpg`, `.jpeg`)
- GIF (`.gif`)
- BMP (`.bmp`)
- ICO (`.ico`)
- SVG (`.svg`)
- WebP (`.webp`)

## 📋 Advanced Usage


### Multiple Notification Types


```rust
let info = NotificationType::new("info")
    .with_display_name("Information");
let warning = NotificationType::new("warning")
    .with_display_name("Warning");
let error = NotificationType::new("error")
    .with_display_name("Error");

client.register(vec![info, warning, error])?;

client.notify("info", "Info", "Something happened")?;
client.notify("warning", "Warning", "Be careful!")?;
client.notify("error", "Error", "Something went wrong!")?;
```

### Notification Options


```rust
use gntp::NotifyOptions;

let options = NotifyOptions::new()
    .with_sticky(true)        // Stays on screen until dismissed
    .with_priority(2);        // Emergency priority

client.notify_with_options(
    "alert",
    "Important",
    "This stays on screen",
    options
)?;
```

### Remote Notifications


```rust
let client = GntpClient::new("Remote App")
    .with_host("192.168.1.100")
    .with_port(23053);
```

### Android Notifications with Retry


Android devices may have network delays. Use retry mechanism:

```bash
# sendgrowl with retry

sendgrowl.exe MyApp Event "Title" "Message" \
  -H 192.168.1.50 \
  -r 3 \              # Retry 3 times on failure
  --retry-delay 2000  # Wait 2 seconds between retries
```

Or in Rust code with manual retry:

```rust
let mut client = GntpClient::new("Android App")
    .with_host("192.168.1.50")
    .with_icon_mode(IconMode::DataUrl);

for attempt in 1..=3 {
    match client.register(vec![notification.clone()]) {
        Ok(_) => break,
        Err(e) if attempt < 3 => {
            eprintln!("Retry {}/3...", attempt);
            std::thread::sleep(Duration::from_secs(2));
        }
        Err(e) => return Err(e),
    }
}
```

### Debug Mode


```rust
let client = GntpClient::new("Debug App")
    .with_debug(true); // Prints detailed packet information
```

## 🐛 Windows Compatibility Notes


Growl for Windows has a known bug where it doesn't properly handle binary resources according to the GNTP specification. When the server receives binary data, it may not respond, causing timeout errors (error code 10060).

**Solution:** Use `IconMode::DataUrl` (default) which embeds icons as base64 strings. This bypasses the binary resource issue entirely.

## 📊 Platform Compatibility


| Platform | Binary Mode | File URL | Data URL | Recommended |
|----------|-------------|----------|----------|-------------|
| Windows (Growl for Windows) | ⚠️ Buggy | ✅ Works |**Best** | `DataUrl` |
| macOS (Growl) | ✅ Works | ✅ Works | ✅ Works | `Binary` |
| Linux (Growl-compatible) | ✅ Works | ✅ Works | ✅ Works | `Binary` |

`Buggy`: most tests pass

## 🔧 Error Handling


```rust
match client.register(vec![notification]) {
    Ok(_) => println!("Registered successfully"),
    Err(gntp::GntpError::ConnectionError(msg)) => {
        eprintln!("Connection failed: {}", msg);
    }
    Err(gntp::GntpError::IoError(msg)) => {
        eprintln!("I/O error: {}", msg);
    }
    Err(gntp::GntpError::ProtocolError(msg)) => {
        eprintln!("Protocol error: {}", msg);
    }
}
```

## 📚 Examples


Run examples with:

```bash
# Basic notification

cargo run --example basic

# Notification with icon

cargo run --example with_icon

# Notification with full path icon

cargo run --example with_icon_binary

# Multiple notification types

cargo run --example multiple_types

# Remote notifications

GROWL_HOST=192.168.1.100 cargo run --example remote

# Android notifications with retry

ANDROID_HOST=192.168.1.50 cargo run --example android

# Error handling patterns

cargo run --example error_handling
```

### Basic Notification


```rust
use gntp::{GntpClient, NotificationType};

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

```

### With Icon


```rust
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)


```rust
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


```rust
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


```rust
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


```bash
# 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:

- Apache License, Version 2.0 ([LICENSE-APACHE]LICENSE-APACHE)
- MIT license ([LICENSE-MIT]LICENSE-MIT)

at your option.

## 🤝 Contributing


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

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## Resources


- [GNTP Protocol Specification]http://www.growlforwindows.com/gfw/help/gntp.aspx
- [Growl for Windows]https://github.com/briandunnington/growl-for-windows
- [Documentation]https://docs.rs/gntp

## 👤 Author


[Hadi Cahyadi](mailto:cumulus13@gmail.com)
    

[![Buy Me a Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/cumulus13)

[![Donate via Ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/cumulus13)
 
[Support me on Patreon](https://www.patreon.com/cumulus13)

## 🙏 Acknowledgments


- Based on the GNTP specification by The Growl Project
- Inspired by various GNTP client implementations

## 📖 Resources


- [GNTP Protocol Specification]http://www.growlforwindows.com/gfw/help/gntp.aspx
- [Growl Project]http://growl.info/
- [Growl for Windows]http://www.growlforwindows.com/

---

**Note:** This is a production-ready library with comprehensive Windows compatibility. If you encounter any issues, please open an issue on GitHub.