Notifier.pm 1.3 KB

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