restructure
Some checks failed
CI - Multi-Platform Native / Build iOS (RSSuper) (push) Has been cancelled
CI - Multi-Platform Native / Build macOS (push) Has been cancelled
CI - Multi-Platform Native / Build Android (push) Has been cancelled
CI - Multi-Platform Native / Build Linux (push) Has been cancelled
CI - Multi-Platform Native / Build Summary (push) Has been cancelled
Some checks failed
CI - Multi-Platform Native / Build iOS (RSSuper) (push) Has been cancelled
CI - Multi-Platform Native / Build macOS (push) Has been cancelled
CI - Multi-Platform Native / Build Android (push) Has been cancelled
CI - Multi-Platform Native / Build Linux (push) Has been cancelled
CI - Multi-Platform Native / Build Summary (push) Has been cancelled
This commit is contained in:
232
linux/src/notification-service.vala
Normal file
232
linux/src/notification-service.vala
Normal file
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* notification-service.vala
|
||||
*
|
||||
* Main notification service for RSSuper on Linux.
|
||||
* Implements Gio.Notification API following freedesktop.org spec.
|
||||
*/
|
||||
|
||||
using Gio;
|
||||
using GLib;
|
||||
|
||||
namespace RSSuper {
|
||||
|
||||
/**
|
||||
* NotificationService - Main notification service for Linux
|
||||
*
|
||||
* Handles desktop notifications using Gio.Notification.
|
||||
* Follows freedesktop.org notify-send specification.
|
||||
*/
|
||||
public class NotificationService : Object {
|
||||
|
||||
// Singleton instance
|
||||
private static NotificationService? _instance;
|
||||
|
||||
// Gio.Notification instance
|
||||
private Gio.Notification? _notification;
|
||||
|
||||
// Tray icon reference
|
||||
private Gtk.App? _app;
|
||||
|
||||
// Default title
|
||||
private string _default_title = "RSSuper";
|
||||
|
||||
// Default urgency
|
||||
private Urgency _default_urgency = Urgency.NORMAL;
|
||||
|
||||
/**
|
||||
* Get singleton instance
|
||||
*/
|
||||
public static NotificationService? get_instance() {
|
||||
if (_instance == null) {
|
||||
_instance = new NotificationService();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance (for singleton pattern)
|
||||
*/
|
||||
private NotificationService() {
|
||||
_app = Gtk.App.get_active();
|
||||
_default_title = _app != null ? _app.get_name() : "RSSuper";
|
||||
_default_urgency = Urgency.NORMAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if notification service is available
|
||||
*/
|
||||
public bool is_available() {
|
||||
return Gio.Notification.is_available();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new notification
|
||||
*
|
||||
* @param title The notification title
|
||||
* @param body The notification body
|
||||
* @param urgency Urgency level (NORMAL, CRITICAL, LOW)
|
||||
* @param timestamp Optional timestamp (defaults to now)
|
||||
*/
|
||||
public Notification create(string title, string body,
|
||||
Urgency urgency = Urgency.NORMAL,
|
||||
DateTime timestamp = null) {
|
||||
|
||||
_notification = Gio.Notification.new(_default_title);
|
||||
_notification.set_body(body);
|
||||
_notification.set_urgency(urgency);
|
||||
|
||||
if (timestamp == null) {
|
||||
_notification.set_time_now();
|
||||
} else {
|
||||
_notification.set_time(timestamp);
|
||||
}
|
||||
|
||||
return _notification;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a notification with summary and icon
|
||||
*/
|
||||
public Notification create(string title, string body, string icon,
|
||||
Urgency urgency = Urgency.NORMAL,
|
||||
DateTime timestamp = null) {
|
||||
|
||||
_notification = Gio.Notification.new(title);
|
||||
_notification.set_body(body);
|
||||
_notification.set_urgency(urgency);
|
||||
|
||||
if (timestamp == null) {
|
||||
_notification.set_time_now();
|
||||
} else {
|
||||
_notification.set_time(timestamp);
|
||||
}
|
||||
|
||||
// Set icon
|
||||
try {
|
||||
_notification.set_icon(icon);
|
||||
} catch (Error e) {
|
||||
warning("Failed to set icon: %s", e.message);
|
||||
}
|
||||
|
||||
return _notification;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a notification with summary, body, and icon
|
||||
*/
|
||||
public Notification create(string summary, string body, string icon,
|
||||
Urgency urgency = Urgency.NORMAL,
|
||||
DateTime timestamp = null) {
|
||||
|
||||
_notification = Gio.Notification.new(summary);
|
||||
_notification.set_body(body);
|
||||
_notification.set_urgency(urgency);
|
||||
|
||||
if (timestamp == null) {
|
||||
_notification.set_time_now();
|
||||
} else {
|
||||
_notification.set_time(timestamp);
|
||||
}
|
||||
|
||||
// Set icon
|
||||
try {
|
||||
_notification.set_icon(icon);
|
||||
} catch (Error e) {
|
||||
warning("Failed to set icon: %s", e.message);
|
||||
}
|
||||
|
||||
return _notification;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the notification
|
||||
*/
|
||||
public void show() {
|
||||
if (_notification == null) {
|
||||
warning("Cannot show null notification");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
_notification.show();
|
||||
} catch (Error e) {
|
||||
warning("Failed to show notification: %s", e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the notification with timeout
|
||||
*
|
||||
* @param timeout_seconds Timeout in seconds (default: 5)
|
||||
*/
|
||||
public void show_with_timeout(int timeout_seconds = 5) {
|
||||
if (_notification == null) {
|
||||
warning("Cannot show null notification");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
_notification.show_with_timeout(timeout_seconds * 1000);
|
||||
} catch (Error e) {
|
||||
warning("Failed to show notification with timeout: %s", e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification instance
|
||||
*/
|
||||
public Gio.Notification? get_notification() {
|
||||
return _notification;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default title
|
||||
*/
|
||||
public void set_default_title(string title) {
|
||||
_default_title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default urgency
|
||||
*/
|
||||
public void set_default_urgency(Urgency urgency) {
|
||||
_default_urgency = urgency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default title
|
||||
*/
|
||||
public string get_default_title() {
|
||||
return _default_title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default urgency
|
||||
*/
|
||||
public Urgency get_default_urgency() {
|
||||
return _default_urgency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the app reference
|
||||
*/
|
||||
public Gtk.App? get_app() {
|
||||
return _app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the notification can be shown
|
||||
*/
|
||||
public bool can_show() {
|
||||
return _notification != null && _notification.can_show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available urgency levels
|
||||
*/
|
||||
public static List<Urgency> get_available_urgencies() {
|
||||
return Urgency.get_available();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user