From b817a9bb255f05092ea14107a5a9c2d2202f1ebd Mon Sep 17 00:00:00 2001 From: Sergiotarxz Date: Wed, 30 Oct 2024 02:09:35 +0100 Subject: [PATCH] Open achieved!! --- lib/Exd/Gui.pm | 98 ++++++++++++++++++++++++++++------------- lib/Exd/Gui/Instance.pm | 1 - me.sergiotarxz.Exd.yml | 1 + run.pl | 1 + 4 files changed, 69 insertions(+), 32 deletions(-) diff --git a/lib/Exd/Gui.pm b/lib/Exd/Gui.pm index 732d40c..e99722e 100644 --- a/lib/Exd/Gui.pm +++ b/lib/Exd/Gui.pm @@ -31,6 +31,32 @@ use Exd; use JSON; use Net::DBus; +use Inline C => + <<'EOF' => LIBS => '', ccflags => '-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/sysprof-6 -pthread'; +#include "glib-2.0/gio/gio.h" + +void +__get_first_file(SV *class, size_t int_files) { + dSP; + ENTER; + SAVETMPS; + + GFile *file = (((GFile **)int_files)[0]); + char *path = g_file_get_path(file); + + PUSHMARK(SP); + EXTEND(SP, 2); + PUSHs(class); + PUSHs(sv_2mortal(newSVpv(path, 0))); + PUTBACK; + + call_pv("_activate", G_DISCARD); + + FREETMPS; + LEAVE; +} +EOF + Glib::Object::Introspection->setup( basename => 'Gtk', version => '4.0', @@ -83,7 +109,7 @@ has _last_instance_id => ( is => 'rw', default => sub { 0 } ); has parent_pid => ( is => 'rw' ); has instances => ( is => 'rw', default => sub { return {} } ); has _gresources_path => ( is => 'lazy', ); -has _exd => ( is => 'lazy' ); +has _exd => ( is => 'lazy' ); sub _build__gresources_path($self) { my $root = path(__FILE__)->parent->parent->parent; @@ -101,9 +127,8 @@ sub _build__gresources_path($self) { sub start($self) { Glib::IO::resources_register( Glib::IO::Resource::load( $self->_gresources_path ) ); - my $app = Adw::Application->new( 'me.sergiotarxz.Exd', - [qw/handles-open/] ); - my $bus = Net::DBus->session; + my $app = Adw::Application->new( 'me.sergiotarxz.Exd', [qw/handles-open/] ); + my $bus = Net::DBus->session; my $started = 0; eval { $bus->get_service('me.sergiotarxz.Exd'); @@ -117,19 +142,21 @@ sub start($self) { $self->_startup; } ); + my $file = Glib::IO::File::new_for_path('hola'); + print Data::Dumper::Dumper $file; + $app->signal_connect( + open => sub( $app, $files, $n_files, $hint ) { + if ( $n_files > 0 ) { + $self->__get_first_file($files); + } + } + ); $app->signal_connect( activate => sub { - $self->_activate(undef); + $self->_activate(undef); } ); - my $file = shift @ARGV; - $app->signal_connect( - open => sub($files, $hint) { - warn $file; - $self->_activate($file); - } - ); - $app->run(); + $app->run( [ $0, @ARGV ] ); } sub _startup($self) { @@ -142,13 +169,16 @@ sub send_packet_to_daemon( $self, $instance, $packet ) { $self->_write_to_script->flush; } -sub send_packet_check_if_activated( $self, $instance, $uuid) { - $self->send_packet_to_daemon($instance, { - type => 'check-activated', - data => { - uuid => $uuid, +sub send_packet_check_if_activated( $self, $instance, $uuid ) { + $self->send_packet_to_daemon( + $instance, + { + type => 'check-activated', + data => { + uuid => $uuid, + } } - }); + ); } sub _daemon_runner($self) { @@ -196,11 +226,11 @@ sub _daemon_runner($self) { if ( $packet->{type} eq 'font-scan' ) { next; } - if ( $packet->{type} eq 'check-activated') { - $self->_on_check_activated($instance_id, $packet->{data}); + if ( $packet->{type} eq 'check-activated' ) { + $self->_on_check_activated( $instance_id, $packet->{data} ); next; } - warn 'Packet not recognized: '. Data::Dumper::Dumper $packet; + warn 'Packet not recognized: ' . Data::Dumper::Dumper $packet; } exit; } @@ -212,20 +242,26 @@ sub _build__exd($self) { return Exd->new; } -sub _on_check_activated($self, $instance_id, $data) { +sub _on_check_activated( $self, $instance_id, $data ) { my $pid = fork; - if (!$pid) { + if ( !$pid ) { while (1) { eval { - my $url = $self->_exd->licenser_server.'/get_paid/'.$self->_exd->uuid; - my $ua = Mojo::UserAgent->new; + my $url = + $self->_exd->licenser_server + . '/get_paid/' + . $self->_exd->uuid; + my $ua = Mojo::UserAgent->new; my $activated = $ua->get($url)->result->json; if ($activated) { say 'Program sucessfully activated, thank you!'; $self->_exd->activate_license; - $self->send_packet_to_window($instance_id, { - type => 'activated!', - }); + $self->send_packet_to_window( + $instance_id, + { + type => 'activated!', + } + ); exit; } }; @@ -233,7 +269,7 @@ sub _on_check_activated($self, $instance_id, $data) { warn $@; } sleep 5; - if (!kill 0, $self->parent_pid) { + if ( !kill 0, $self->parent_pid ) { exit; } } @@ -408,7 +444,6 @@ sub _activate( $self, $exd_file = undef ) { $self->_run_on_first_time_activation if $self->_first_time; $self->instances->{$instance_id} = Exd::Gui::Instance->new( instance_id => $instance_id, app => $self ); - warn $exd_file; $self->instances->{$instance_id}->start($exd_file); } @@ -435,3 +470,4 @@ sub _save( $self, $instance_id, $exd, $dest_file ) { } 1; + diff --git a/lib/Exd/Gui/Instance.pm b/lib/Exd/Gui/Instance.pm index f3e2d05..0b1af95 100644 --- a/lib/Exd/Gui/Instance.pm +++ b/lib/Exd/Gui/Instance.pm @@ -74,7 +74,6 @@ sub start( $self, $exd_file ) { $win->set_show_menubar(1); $self->window($win); if ( defined $exd_file ) { - say $exd_file; $self->_open_file($exd_file); } my $box_vertical = Gtk4::Box->new( 'vertical', 10 ); diff --git a/me.sergiotarxz.Exd.yml b/me.sergiotarxz.Exd.yml index 89f8782..8dff316 100644 --- a/me.sergiotarxz.Exd.yml +++ b/me.sergiotarxz.Exd.yml @@ -87,6 +87,7 @@ modules: build-commands: - 'cd HiperthermiaSource; perl lib/Exd/Fontconfig.pm' - 'cd HiperthermiaSource; perl lib/Exd/FileFormat/Fontconfig.pm' + - 'cd HiperthermiaSource; perl -Ilib lib/Exd/Gui.pm' - 'cd HiperthermiaSource; chmod 755 -R _Inline/' - 'cp -vr HiperthermiaSource ${FLATPAK_DEST}/Hiperthermia' - 'glib-compile-resources --sourcedir=${FLATPAK_DEST}/Hiperthermia ${FLATPAK_DEST}/Hiperthermia/resources.xml' diff --git a/run.pl b/run.pl index b94eb9f..346e6de 100755 --- a/run.pl +++ b/run.pl @@ -3,6 +3,7 @@ use v5.40.0; use strict; use warnings; +use Carp::Always; use File::Basename qw/dirname/;