2016-09-14 09:22:41 +00:00
|
|
|
# Notify about the end of slicing.
|
|
|
|
# The notifications are sent out using the Growl protocol if installed, and using DBus XWindow protocol.
|
|
|
|
|
2014-06-14 17:54:18 +00:00
|
|
|
package Slic3r::GUI::Notifier;
|
|
|
|
use Moo;
|
|
|
|
|
|
|
|
has 'growler' => (is => 'rw');
|
|
|
|
|
2016-04-09 17:10:57 +00:00
|
|
|
my $icon = $Slic3r::var->("Slic3r.png");
|
2014-06-14 17:54:18 +00:00
|
|
|
|
|
|
|
sub BUILD {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
if (eval 'use Growl::GNTP; 1') {
|
|
|
|
# register with growl
|
|
|
|
eval {
|
|
|
|
$self->growler(Growl::GNTP->new(AppName => 'Slic3r', AppIcon => $icon));
|
|
|
|
$self->growler->register([{Name => 'SKEIN_DONE', DisplayName => 'Slicing Done'}]);
|
|
|
|
};
|
2015-01-01 11:37:38 +00:00
|
|
|
# if register() fails (for example because of a timeout), disable growler at all
|
|
|
|
$self->growler(undef) if $@;
|
2014-06-14 17:54:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub notify {
|
|
|
|
my ($self, $message) = @_;
|
|
|
|
my $title = 'Slicing Done!';
|
|
|
|
|
|
|
|
eval {
|
|
|
|
$self->growler->notify(Event => 'SKEIN_DONE', Title => $title, Message => $message)
|
|
|
|
if $self->growler;
|
|
|
|
};
|
|
|
|
# Net::DBus is broken in multithreaded environment
|
|
|
|
if (0 && eval 'use Net::DBus; 1') {
|
|
|
|
eval {
|
|
|
|
my $session = Net::DBus->session;
|
|
|
|
my $serv = $session->get_service('org.freedesktop.Notifications');
|
|
|
|
my $notifier = $serv->get_object('/org/freedesktop/Notifications',
|
|
|
|
'org.freedesktop.Notifications');
|
|
|
|
$notifier->Notify('Slic3r', 0, $icon, $title, $message, [], {}, -1);
|
|
|
|
undef $Net::DBus::bus_session;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|