Open achieved!!

This commit is contained in:
Sergiotarxz 2024-10-30 02:09:35 +01:00
parent 2f5c5d08a0
commit b817a9bb25
4 changed files with 69 additions and 32 deletions

View File

@ -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);
}
);
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;

View File

@ -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 );

View File

@ -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'

1
run.pl
View File

@ -3,6 +3,7 @@
use v5.40.0;
use strict;
use warnings;
use Carp::Always;
use File::Basename qw/dirname/;