Notifier.pm 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Notify about the end of slicing.
  2. # The notifications are sent out using the Growl protocol if installed, and using DBus XWindow protocol.
  3. package Slic3r::GUI::Notifier;
  4. use Moo;
  5. has 'growler' => (is => 'rw');
  6. my $icon = Slic3r::var("Slic3r.png");
  7. sub BUILD {
  8. my ($self) = @_;
  9. if (eval 'use Growl::GNTP; 1') {
  10. # register with growl
  11. eval {
  12. $self->growler(Growl::GNTP->new(AppName => 'Slic3r', AppIcon => $icon));
  13. $self->growler->register([{Name => 'SKEIN_DONE', DisplayName => 'Slicing Done'}]);
  14. };
  15. # if register() fails (for example because of a timeout), disable growler at all
  16. $self->growler(undef) if $@;
  17. }
  18. }
  19. sub notify {
  20. my ($self, $message) = @_;
  21. my $title = 'Slicing Done!';
  22. eval {
  23. $self->growler->notify(Event => 'SKEIN_DONE', Title => $title, Message => $message)
  24. if $self->growler;
  25. };
  26. # Net::DBus is broken in multithreaded environment
  27. if (0 && eval 'use Net::DBus; 1') {
  28. eval {
  29. my $session = Net::DBus->session;
  30. my $serv = $session->get_service('org.freedesktop.Notifications');
  31. my $notifier = $serv->get_object('/org/freedesktop/Notifications',
  32. 'org.freedesktop.Notifications');
  33. $notifier->Notify('Slic3r', 0, $icon, $title, $message, [], {}, -1);
  34. undef $Net::DBus::bus_session;
  35. };
  36. }
  37. }
  38. 1;