Fixing badly sent parent pid.

This commit is contained in:
Sergiotarxz 2024-10-19 14:12:20 +02:00
parent cd46914add
commit 1dcfe0788e
1 changed files with 44 additions and 25 deletions

View File

@ -123,6 +123,7 @@ 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(
@ -239,10 +240,9 @@ sub _open_action($self) {
sub _open_file( $self, $file ) {
$self->_save_path($file);
my $window = $self->window;
$window->set_title( "Exd (Thermal Printer) "
. path( $self->_save_path )->basename );
$self->_file_format(
Exd::FileFormat->from_zip_file($file) );
$window->set_title(
"Exd (Thermal Printer) " . path( $self->_save_path )->basename );
$self->_file_format( Exd::FileFormat->from_zip_file($file) );
$self->_update_editor_buffer;
}
@ -335,7 +335,7 @@ sub _daemon_script_runner($self) {
while (1) {
my $fh = $self->_read_from_parent;
my $line = <$fh>;
if (!kill 0, $self->parent_pid) {
if ( defined $self->parent_pid && !kill 0, $self->parent_pid ) {
say 'Parent died at main fork loop, exiting...';
exit 1;
}
@ -348,6 +348,11 @@ sub _daemon_script_runner($self) {
$self->_on_save_packet( $packet->{data} );
next;
}
if ( $packet->{type} eq 'parent-pid' ) {
$self->parent_pid($packet->{data});
say 'Got parent pid ' . $self->parent_pid;
next;
}
}
exit;
}
@ -754,10 +759,21 @@ sub _open_fonts_gallery($self) {
$font_gallery->start;
}
sub _send_parent_pid($self) {
$self->_write_to_script->say(
JSON::to_json(
{
type => 'parent-pid',
data => $self->parent_pid,
}
)
);
}
sub _activate( $self, $exd_file = undef ) {
say "My pid is $$.";
$self->parent_pid($$);
$self->_daemon_script_runner;
$self->_send_parent_pid;
Glib::Timeout->add(
1000,
sub {
@ -802,9 +818,12 @@ sub _activate($self, $exd_file = undef) {
sub {
if ( $self->_can_open_printer_configure ) {
$self->_can_open_printer_configure(0);
Exd::Gui::PrinterConfigure->new( app => $self, on_close => sub {
Exd::Gui::PrinterConfigure->new(
app => $self,
on_close => sub {
$self->_can_open_printer_configure(1);
})->start;
}
)->start;
}
}
);