API Reference | Notifications
This section of documentation describes the notification system in the OutfitTool API, implemented through the Notification class and the PopNotification method of the IModuleController interface.
Notification Class
The Notification class represents a notification that a module can send to the user through the host's notification system.
Class Definition
namespace OutfitTool.API1.Dto;
public class Notification(string title, string message, string href)
{
public readonly string Message = message;
public readonly string Title = title;
public readonly string Href = href;
}
Class Properties
- string Title
- Notification title displayed in the popup window. Should be brief and informative.
- string Message
- Main notification text containing event details. May include additional information.
- string Href
- Link that will be opened when clicking on the notification. Can be a URL, file path, or other system-supported link.
Usage in IModuleController
To send notifications, the module must implement the PopNotification method in its ModuleController class, which inherits the IModuleController interface.
PopNotification Method
Notification? PopNotification();
The method returns an instance of the Notification class or null if there are no notifications. The host calls this method periodically (every 400 ms) to check for new notifications from all loaded modules.
Notification Handling in Host Project
In the OutfitTool project, a notification system is implemented where the host periodically polls all modules for notifications:
Checking Notifications in MainWindow.xaml.cs
private void CheckNotifications()
{
var moduleManager = ServiceLocator.GetService<IModuleManager>();
var modules = moduleManager.GetModules();
foreach (Module module in modules)
{
if (module.Enabled)
{
var notification = module.ModuleController.PopNotification();
if (notification != null)
{
_lastNotification = notification;
TaskbarIcon.ShowBalloonTip(notification.Title, notification.Message, BalloonIcon.Info);
}
}
}
}
The CheckNotifications method is called every 400 ms via a timer and checks for notifications from all enabled modules. When a notification is received, it is displayed as a popup window in the system tray.
Handling Notification Click
private void ClickNotification(object sender, EventArgs e)
{
if (_lastNotification != null)
{
Process.Start(new ProcessStartInfo(_lastNotification.Href) { UseShellExecute = true });
}
}
When clicking on a notification, the link specified in the Href property of the Notification object is opened.
Usage Recommendations
- Use notifications for important events requiring user attention (new messages, operation completion, errors, etc.)
- Store notifications in the module's internal queue and return them one at a time with each
PopNotificationcall - Use clear and informative titles and messages
- Ensure the link in
Hrefis correct and can be processed by the system - Do not send too many notifications in a row to avoid disturbing the user
- Consider grouping similar notifications