Skip to content

cumulus13/gntp.net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Gntp.Net

NuGet License: MIT

Production-ready GNTP (Growl Notification Transport Protocol) client for .NET with full Windows/Android/macOS/Linux compatibility and callback support.

✨ Features

  • βœ… Full GNTP 1.0 protocol implementation
  • βœ… Async/await support for modern .NET
  • βœ… Callback support (click, close, timeout events)
  • βœ… Multiple icon delivery modes (Binary, File URL, Data URL, HTTP URL)
  • βœ… Cross-platform (Windows, macOS, Linux, Android)
  • βœ… Multi-targeting (.NET Standard 2.0/2.1, .NET 6/7/8)
  • βœ… Zero dependencies - pure .NET implementation
  • βœ… Fully documented with XML comments

πŸ“¦ Installation

dotnet add package Gntp.Net

Or via NuGet Package Manager:

Install-Package Gntp.Net

πŸš€ Quick Start

using Gntp.Net;

// Create client
var client = new GntpClient("My Application");

// Define notification type
var notification = new NotificationType("alert")
    .WithDisplayName("Alert Notification");

// Register
await client.RegisterAsync(notification);

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

πŸ“‹ Examples

Basic Notification

var client = new GntpClient("My App");

var notification = new NotificationType("alert");
await client.RegisterAsync(notification);

await client.NotifyAsync("alert", "Title", "Message");

With Icon

var client = new GntpClient("Icon App")
    .WithIconMode(IconMode.Binary); // Best for Windows

var icon = GntpResource.FromFile("icon.png");

var notification = new NotificationType("alert")
    .WithIcon(icon);

await client.RegisterAsync(notification);
await client.NotifyAsync("alert", "With Icon!", "This has an icon");

With Callbacks (IMPORTANT!)

var client = new GntpClient("Callback App");

await client.WithCallbackAsync(info =>
{
    Console.WriteLine($"Event: {info.Type}");
    Console.WriteLine($"Context: {info.Context}");
    
    switch (info.Type)
    {
        case CallbackType.Click:
            Console.WriteLine("User clicked!");
            break;
        case CallbackType.Close:
            Console.WriteLine("User closed");
            break;
        case CallbackType.Timeout:
            Console.WriteLine("Timed out");
            break;
    }
});

var notification = new NotificationType("alert");
await client.RegisterAsync(notification);

var options = new NotifyOptions()
    .WithSticky(true)
    .WithCallbackContext("user_data_123")
    .WithCallbackTarget("https://example.com");

await client.NotifyAsync("alert", "Click Me!", "Message", options);

// Keep app running to receive callbacks
Console.ReadKey();
client.Dispose();

Multiple Notification Types

var client = new GntpClient("Multi-Type App");

var info = new NotificationType("info").WithDisplayName("Information");
var warning = new NotificationType("warning").WithDisplayName("Warning");
var error = new NotificationType("error").WithDisplayName("Error");

await client.RegisterAsync(info, warning, error);

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

Remote Notifications

var client = new GntpClient("Remote App")
    .WithHost("192.168.1.100")
    .WithPort(23053);

Notification Options

var options = new NotifyOptions()
    .WithSticky(true)               // Stays until dismissed
    .WithPriority(2)                // Emergency priority (-2 to 2)
    .WithIcon(icon)                 // Per-notification icon
    .WithCallbackContext("data")    // Custom callback data
    .WithCallbackTarget("https://example.com"); // URL to open

await client.NotifyAsync("alert", "Title", "Text", options);

🎯 Icon Delivery Modes

Binary Mode (Recommended for Windows)

var client = new GntpClient("App")
    .WithIconMode(IconMode.Binary);

Format: x-growl-resource://UUID + binary data
Best for: Windows Growl, macOS, Linux
βœ… Tested and working on all platforms

DataURL Mode

var client = new GntpClient("App")
    .WithIconMode(IconMode.DataUrl);

Format: data:image/png;base64,iVBORw0...
Best for: Android, fallback option
⚠️ May have issues with large icons

FileURL Mode

var client = new GntpClient("App")
    .WithIconMode(IconMode.FileUrl);

Format: file:///C:/full/path/to/icon.png
Best for: Shared icons on disk
⚠️ Requires absolute path

HttpURL Mode

var client = new GntpClient("App")
    .WithIconMode(IconMode.HttpUrl);

Format: http://example.com/icon.png
Best for: Web-hosted icons

🌍 Platform Compatibility

Platform Binary Mode DataURL Mode Callbacks Recommended
Windows (Growl for Windows) βœ… Works ⚠️ Issues βœ… Works Binary
macOS (Growl) βœ… Works βœ… Works βœ… Works Binary
Linux (Growl-compatible) βœ… Works βœ… Works βœ… Works Binary
Android (Growl for Android) βœ… Works βœ… Works βœ… Works Binary or DataURL

πŸ”” Callback Events

Callbacks are triggered when users interact with notifications:

  • CallbackType.Click - User clicked the notification
  • CallbackType.Close - User closed the notification
  • CallbackType.Timeout - Notification timed out
await client.WithCallbackAsync(info =>
{
    // info.Type - Event type
    // info.NotificationId - Notification ID
    // info.Context - Custom data
    // info.Timestamp - Event time
});

πŸ“š API Reference

GntpClient

// Constructor
new GntpClient(string applicationName)

// Configuration
.WithHost(string host)
.WithPort(int port)
.WithIcon(GntpResource icon)
.WithIconMode(IconMode mode)
.WithDebug(bool debug)
.WithTimeout(int timeout)
.WithCallbackAsync(Action<CallbackInfo> handler)

// Operations
await RegisterAsync(params NotificationType[] notifications)
await NotifyAsync(string name, string title, string text)
await NotifyAsync(string name, string title, string text, NotifyOptions options)

GntpResource

// Static factory methods
GntpResource.FromFile(string path)
GntpResource.FromBytes(byte[] data, string mimeType)

// Instance methods
string GetReference(IconMode mode)
string ToDataUrl()

πŸ› Troubleshooting

Icon Not Showing

Try Binary mode (most reliable):

client.WithIconMode(IconMode.Binary);

Callbacks Not Working

Ensure:

  1. Callback is set BEFORE RegisterAsync()
  2. App stays running to receive callbacks
  3. Call client.Dispose() when done
  4. Firewall allows incoming connections

Android Connection Issues

Use longer timeout:

client.WithTimeout(15000); // 15 seconds

🀝 Contributing

Contributions welcome! Please open an issue or PR.

πŸ“„ License

MIT License - See LICENSE file for details.

πŸ‘€ Author

Hadi Cahyadi

Buy Me a Coffee

Donate via Ko-fi

Support me on Patreon

πŸ™ Related Projects


Production-ready GNTP client for .NET with full cross-platform support and callback functionality!

About

Production-ready GNTP (Growl Notification Transport Protocol) client for .NET with Windows/Android/macOS/Linux compatibility, callback support, and multiple icon delivery modes

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors