70 lines
2.3 KiB
Perl
70 lines
2.3 KiB
Perl
# TTYverse Desktop Notifications Extension (libnotify-perl)
|
|
# Adapted from original TTYtter extension
|
|
# Provides desktop notifications using GTK Gtk2::Notify
|
|
# Published under the Floodgap Free Software License: http://www.floodgap.com/software/ffsl/
|
|
|
|
# What is it?
|
|
# This extension enables desktop notifications for TTYverse using the
|
|
# libnotify system on Linux/Unix with GUI environments.
|
|
|
|
# Requirements:
|
|
# - Gtk2::Notify Perl module
|
|
# - GUI environment with DISPLAY set
|
|
# - libnotify system installed
|
|
|
|
# Installation:
|
|
# Install dependency: cpan Gtk2::Notify
|
|
# Or on Debian/Ubuntu: sudo apt install libgtk2-notify-perl
|
|
# Or on Fedora/RHEL: sudo dnf install perl-Gtk2-Notify
|
|
# Or on Arch: sudo pacman -S perl-gtk2-notify
|
|
|
|
eval { require Gtk2::Notify };
|
|
if($@){
|
|
print "-- TTYverse notification extension requires Gtk2::Notify\n";
|
|
print "-- Install with: cpan Gtk2::Notify\n";
|
|
print "-- Or on Debian/Ubuntu: sudo apt install libgtk2-notify-perl\n";
|
|
print "-- Or on Fedora/RHEL: sudo dnf install perl-Gtk2-Notify\n";
|
|
print "-- Or on Arch: sudo pacman -S perl-gtk2-notify\n";
|
|
die();
|
|
}
|
|
|
|
sub notifier_libnotifyperl {
|
|
# Skip notifications if no GUI display available
|
|
return 1 if(!$ENV{'DISPLAY'});
|
|
|
|
my $class = shift;
|
|
my $text = shift;
|
|
my $ref = shift; # Post reference data (unused in this version)
|
|
|
|
# Handle initialization
|
|
if (!defined($class) || !defined($notify_send_path)) {
|
|
if (!defined($class)) {
|
|
return 1 if ($script); # Skip in script mode
|
|
$class = 'TTYverse Desktop Notifications';
|
|
$text = 'Desktop notifications are now active for TTYverse.';
|
|
Gtk2::Notify->init('ttyverse');
|
|
print $streamout "-- $text\n" if (!$silent);
|
|
}
|
|
}
|
|
|
|
# Show notification if system is properly initialized
|
|
if (Gtk2::Notify->is_initted()) {
|
|
my $notification = Gtk2::Notify->new(
|
|
"TTYverse: $class",
|
|
$text
|
|
);
|
|
|
|
# Set reasonable timeout (5 seconds)
|
|
$notification->set_timeout(5_000);
|
|
|
|
if($notification->show()) {
|
|
# Debug output (optional)
|
|
# print $streamout "-- Notification shown: $class\n" if ($debug);
|
|
}
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
# Make sure the module loads properly
|
|
1; |