Fixing badly sent parent pid.

This commit is contained in:
Sergiotarxz 2024-10-19 14:12:20 +02:00
parent cd46914add
commit 1dcfe0788e

View File

@ -97,12 +97,12 @@ has _last_script_run_device => ( is => 'rw', );
has _last_script_run_verbose => ( is => 'rw', );
has _safe_to_exit => ( is => 'rw', default => sub { 1 } );
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 _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' );
has parent_pid => ( is => 'rw' );
sub _tempdir_previews($self) {
if ( !defined $self->_tempdir_previews_guts ) {
@ -122,7 +122,8 @@ sub _tempdir_previews($self) {
}
}
sub start($self, $exd_file = undef) {
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(
@ -236,13 +237,12 @@ sub _open_action($self) {
);
}
sub _open_file($self, $file) {
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;
}
@ -333,9 +333,9 @@ sub _daemon_script_runner($self) {
close $read_from_script;
close $write_to_script;
while (1) {
my $fh = $self->_read_from_parent;
my $line = <$fh>;
if (!kill 0, $self->parent_pid) {
my $fh = $self->_read_from_parent;
my $line = <$fh>;
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;
}
@ -472,7 +477,7 @@ sub _monitor_run($self) {
my $data = $packet->{data};
$data =~ s/\s+$//;
$data =~ s/^\s+//;
if ($data =~ /^\s*$/) {
if ( $data =~ /^\s*$/ ) {
next;
}
$data .= "\n";
@ -635,7 +640,7 @@ sub _open_gallery($self) {
}
sub _log( $self, $message ) {
if ($message =~ /Fontconfig error: No writable cache directories/) {
if ( $message =~ /Fontconfig error: No writable cache directories/ ) {
return;
}
$self->_write_to_parent->say(
@ -750,14 +755,25 @@ sub _create_gallery_image( $self, $hash ) {
}
sub _open_fonts_gallery($self) {
my $font_gallery = Exd::Gui::FontGallery->new(app => $self);
my $font_gallery = Exd::Gui::FontGallery->new( app => $self );
$font_gallery->start;
}
sub _activate($self, $exd_file = undef) {
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 {
@ -785,7 +801,7 @@ sub _activate($self, $exd_file = undef) {
my $preview_button = Gtk4::Button->new_with_label('Preview');
my $select_printer = Gtk4::Button->new_with_label('Select Printer');
my $open_gallery = Gtk4::Button->new_with_label('Open image gallery');
my $edit_fonts = Gtk4::Button->new_with_label('Open font gallery');
my $edit_fonts = Gtk4::Button->new_with_label('Open font gallery');
$open_gallery->signal_connect(
'clicked',
sub {
@ -800,11 +816,14 @@ sub _activate($self, $exd_file = undef) {
$select_printer->signal_connect(
'clicked',
sub {
if ($self->_can_open_printer_configure) {
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;
Exd::Gui::PrinterConfigure->new(
app => $self,
on_close => sub {
$self->_can_open_printer_configure(1);
}
)->start;
}
}
);
@ -860,7 +879,7 @@ sub _activate($self, $exd_file = undef) {
$execute_log_window->set_child($execute_log);
$box_vertical->append($execute_log_window);
$win->set_child($box_vertical);
if (defined $exd_file) {
if ( defined $exd_file ) {
$self->_open_file($exd_file);
}
$win->present;