Minor refactor to trying to decrease blocking chances.
This commit is contained in:
parent
544d517ec9
commit
17746d9617
@ -100,6 +100,8 @@ has _save_path => ( is => 'rw' );
|
||||
has _want_to_close => ( is => 'rw' );
|
||||
has _last_save_pid => ( is => 'rw' );
|
||||
has _last_save_dest_file => ( is => 'rw' );
|
||||
has _can_open_printer_configure => ( is => 'rw', default => sub { 1 } );
|
||||
has parent_pid => ( is => 'rw' );
|
||||
|
||||
sub _tempdir_previews($self) {
|
||||
if ( !defined $self->_tempdir_previews_guts ) {
|
||||
@ -120,7 +122,6 @@ sub _tempdir_previews($self) {
|
||||
}
|
||||
|
||||
sub start($self, $exd_file = undef) {
|
||||
$self->_daemon_script_runner;
|
||||
my $app = Gtk4::Application->new( 'me.sergiotarxz.Exd', 'default-flags' );
|
||||
$self->_app($app);
|
||||
$app->signal_connect(
|
||||
@ -333,6 +334,10 @@ sub _daemon_script_runner($self) {
|
||||
while (1) {
|
||||
my $fh = $self->_read_from_parent;
|
||||
my $line = <$fh>;
|
||||
if (!kill 0, $self->parent_pid) {
|
||||
say 'Parent died at main fork loop, exiting...';
|
||||
exit 1;
|
||||
}
|
||||
my $packet = JSON::from_json($line);
|
||||
if ( $packet->{type} eq 'run_script' ) {
|
||||
$self->_on_run_script_packet( $packet->{data} );
|
||||
@ -744,6 +749,9 @@ sub _create_gallery_image( $self, $hash ) {
|
||||
}
|
||||
|
||||
sub _activate($self, $exd_file = undef) {
|
||||
say "My pid is $$.";
|
||||
$self->parent_pid($$);
|
||||
$self->_daemon_script_runner;
|
||||
Glib::Timeout->add(
|
||||
1000,
|
||||
sub {
|
||||
@ -780,7 +788,12 @@ sub _activate($self, $exd_file = undef) {
|
||||
$select_printer->signal_connect(
|
||||
'clicked',
|
||||
sub {
|
||||
Exd::Gui::PrinterConfigure->new( app => $self )->start;
|
||||
if ($self->_can_open_printer_configure) {
|
||||
$self->_can_open_printer_configure(0);
|
||||
Exd::Gui::PrinterConfigure->new( app => $self, on_close => sub {
|
||||
$self->_can_open_printer_configure(1);
|
||||
})->start;
|
||||
}
|
||||
}
|
||||
);
|
||||
$preview_button->signal_connect(
|
||||
|
@ -14,6 +14,7 @@ use JSON;
|
||||
use Net::Bluetooth qw//;
|
||||
|
||||
has app => (is => 'ro', required => 1);
|
||||
has on_close => ( is => 'ro', required => 1 );
|
||||
has _pid_daemon => (is => 'rw');
|
||||
has _read_from_daemon => (is => 'rw');
|
||||
has _write_to_app => (is => 'rw');
|
||||
@ -119,6 +120,10 @@ sub _start_daemon_bluetooth_search($self) {
|
||||
|
||||
sub _daemon_bluetooth_search_iteration($self) {
|
||||
say 'Listing bluetooth devices';
|
||||
if (!kill 0, $self->app->parent_pid) {
|
||||
say 'Parent died at bluetooth search iteration, exiting...';
|
||||
exit 1;
|
||||
}
|
||||
my $devices = Net::Bluetooth::get_remote_devices;
|
||||
my @return;
|
||||
for my $address (keys %$devices) {
|
||||
@ -136,8 +141,9 @@ sub _daemon_bluetooth_search_iteration($self) {
|
||||
}
|
||||
|
||||
sub _on_close($self) {
|
||||
kill 'TERM', $self->_pid_daemon;
|
||||
kill 'KILL', $self->_pid_daemon;
|
||||
waitpid $self->_pid_daemon, 0;
|
||||
$self->on_close->();
|
||||
say 'Finished printer select daemon';
|
||||
}
|
||||
1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user