Compare commits

...

2 Commits

5 changed files with 119 additions and 13 deletions

View File

@ -128,6 +128,7 @@ sub start($self) {
$self->_activate(undef);
}
);
print Data::Dumper::Dumper $app;
$app->run( [ $0, @ARGV ] );
}
@ -202,6 +203,10 @@ sub _daemon_runner($self) {
$self->_on_check_activated( $instance_id, $packet->{data} );
next;
}
if ( $packet->{type} eq 'get-price' ) {
$self->_on_get_price($instance_id);
next;
}
warn 'Packet not recognized: ' . Data::Dumper::Dumper $packet;
}
exit;
@ -214,6 +219,38 @@ sub _build__exd($self) {
return Exd->new;
}
sub _on_get_price( $self, $instance_id ) {
my $pid = fork;
if ( !$pid ) {
eval {
my $ua = Mojo::UserAgent->new;
my $url =
$self->_exd->licenser_server . '/price/' . $self->_exd->uuid;
my $price_json = $ua->get($url)->result->json;
if ( !defined $price_json ) {
warn 'Server error retrieving price';
exit;
}
my ( $price, $discount ) = $price_json->@{ 'price', 'discount' };
$self->send_packet_to_window(
$instance_id,
{
type => 'price',
data => {
price => $price,
discount => $discount,
}
}
);
exit;
};
if ($@) {
warn $@;
exit;
}
}
}
sub _on_check_activated( $self, $instance_id, $data ) {
my $pid = fork;
if ( !$pid ) {

View File

@ -20,6 +20,7 @@ has app => ( is => 'rw', required => 1, weak_ref => 1 );
has instance_id => ( is => 'rw', required => 1 );
has window => ( is => 'rw' );
has _editor => ( is => 'rw', );
has _window_price_discount => ( is => 'rw', );
has _safe_to_exit => ( is => 'rw', default => sub { 1 } );
has _transparent_avoid_input => ( is => 'rw' );
has _paywall => ( is => 'rw' );
@ -28,6 +29,8 @@ has _pay_url => ( is => 'lazy' );
has _activated => ( is => 'rw' );
has _last_valid_preview_file => ( is => 'rw' );
has _is_showing_paywall => ( is => 'rw' );
has _price => ( is => 'rw' );
has _discount => ( is => 'rw' );
has file_format => (
is => 'rw',
default => sub {
@ -129,6 +132,13 @@ sub start( $self, $exd_file ) {
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 $printers_and_supplies =
Gtk4::Button->new_with_label('Buy printers and supplies');
$printers_and_supplies->signal_connect(
clicked => sub {
$self->_show_recommended_printers;
}
);
$open_gallery->signal_connect(
'clicked',
sub {
@ -187,6 +197,7 @@ sub start( $self, $exd_file ) {
$box_buttons->append($select_printer);
$box_buttons->append($open_gallery);
$box_buttons->append($edit_fonts);
$box_buttons->append($printers_and_supplies);
$self->_populate_editor_and_preview($box_vertical);
$box_vertical->append($box_buttons);
my $execute_log_window = Gtk4::ScrolledWindow->new;
@ -214,7 +225,7 @@ sub start( $self, $exd_file ) {
if ( !$self->_activated ) {
my $uuid = $self->_exd->uuid;
my $instance_id = $self->instance_id;
$self->_show_paywall($overlay);
$self->_add_timeout_paywall($overlay);
$self->app->send_packet_check_if_activated( $self, $uuid );
}
$win->set_child($overlay);
@ -229,9 +240,7 @@ sub _show_about_dialog($self) {
my $picture = Gtk4::Picture->new;
$picture->set_property( 'width-request', 256 );
$picture->set_property( 'height-request', 256 );
$picture->set_filename(
Exd->root->child('exd-logo.png')
. '' );
$picture->set_filename( Exd->root->child('exd-logo.png') . '' );
my $label = Gtk4::Label->new(undef);
$label->set_markup(<<"EOF");
Welcome to Hiperthermia.
@ -288,7 +297,8 @@ sub _show_paywall( $self, $overlay ) {
$paywall->set_property( 'height-request', 800 );
$paywall->add_css_class('paywall');
my $inner_paywall_box = Gtk4::Box->new( 'vertical', 10 );
my $title = Gtk4::Label->new('This program is not activated');
my $title = Gtk4::Label->new;
$title->set_markup('<big>This program is not activated</big>');
my $activate = Gtk4::Button->new_with_label('Pay and activate');
my $about = Gtk4::Button->new_with_label('More about the program');
my $remind_me_later = Gtk4::Button->new_with_label('Remind me later');
@ -313,9 +323,8 @@ sub _show_paywall( $self, $overlay ) {
$self->_add_timeout_paywall($overlay);
}
);
my $picture = Gtk4::Image->new_from_file(
Exd->root->child('exd-logo.png')
. '' );
my $picture =
Gtk4::Image->new_from_file( Exd->root->child('exd-logo.png') . '' );
$picture->set_pixel_size(256);
$inner_paywall_box->append($picture);
$inner_paywall_box->append($title);
@ -325,6 +334,14 @@ sub _show_paywall( $self, $overlay ) {
);
$inner_paywall_box->append($debug_message);
}
my $window_price_discount = Gtk4::ScrolledWindow->new;
$self->_window_price_discount($window_price_discount);
if ( defined $self->_price ) {
$self->_on_receive_price;
} else {
$self->_send_get_price;
}
$inner_paywall_box->append($window_price_discount);
$inner_paywall_box->append($activate);
$inner_paywall_box->append($remind_me_later);
$inner_paywall_box->append($about);
@ -438,10 +455,8 @@ sub _create_popover_menu( $self, $box ) {
$file_menu->append( 'Open', 'app.open.' . $self->instance_id );
$file_menu->append( 'Save', 'app.save.' . $self->instance_id );
$file_menu->append( 'Save as', 'app.save-as.' . $self->instance_id );
$help_menu->append(
'Recommended printers and supplies',
'app.good-printers.' . $self->instance_id
);
$help_menu->append( 'Buy printers and supplies',
'app.good-printers.' . $self->instance_id );
$help_menu->append( 'About and contact',
'app.about.' . $self->instance_id );
$menu_model->append_submenu( 'File', $file_menu );
@ -519,7 +534,7 @@ sub _show_recommended_printers($self) {
for my $product (@products) {
my $product_box = Gtk4::Box->new( 'horizontal', 10 );
my $image_file = Exd->root->child( $product->{image} );
my $image = Gtk4::Image->new_from_file($image_file);
my $image = Gtk4::Image->new_from_file($image_file);
$image->set_pixel_size(256);
$product_box->append($image);
my $right_side_product_box = Gtk4::Box->new( 'vertical', 10 );
@ -676,7 +691,43 @@ sub _run_script( $self, $device = undef, $verbose = 1 ) {
);
}
sub _on_receive_price($self) {
my $price = $self->_price;
my $discount = $self->_discount;
if ( !$self->_is_showing_paywall ) {
return;
}
my $window_price_discount = $self->_window_price_discount;
if ( !defined $window_price_discount ) {
return;
}
my $box = Gtk4::Box->new( 'horizontal', 10 );
$box->set_halign('center');
my $discount_label = Gtk4::Label->new(undef);
$discount_label->set_markup("<big>-$discount% Cheaper than usual</big>");
$discount_label->add_css_class('discount');
if ( !defined $price ) {
return;
}
$price =~ s/(..)$/.$1/;
my $price_label = Gtk4::Label->new(undef);
$price_label->set_markup("<big>Activate now for: $price€</big>");
$box->append($price_label);
if ( $discount > 2 ) {
$box->append($discount_label);
}
$window_price_discount->set_child($box);
}
sub receive_packet( $self, $packet ) {
if ( $packet->{type} eq 'price' ) {
my $data = $packet->{data};
my ( $price, $discount ) = $data->@{ 'price', 'discount' };
$self->_price($price);
$self->_discount($discount);
$self->_on_receive_price;
return;
}
if ( $packet->{type} eq 'log' ) {
my $data = $packet->{data};
$data =~ s/\s+$//;
@ -980,6 +1031,15 @@ sub _save_action($self) {
);
}
sub _send_get_price( $self ) {
$self->app->send_packet_to_daemon(
$self,
{
type => 'get-price',
}
);
}
sub _send_save_request( $self, $exd_dir, $dest_file ) {
$self->app->send_packet_to_daemon(
$self,

View File

@ -30,6 +30,11 @@
<releases>
<release version="v1.0.12" date="2024-11-11">
<description>
<p>Make more prominent affiliated printers and supplies and implementing discounts</p>
</description>
</release>
<release version="v1.0.11" date="2024-11-11">
<description>
<p>Better startup script to run Glib::Object::Introspection INIT code</p>

Binary file not shown.

View File

@ -6,6 +6,10 @@ button {
min-width: 0;
}
label.discount {
color: red;
}
box.paywall {
background: white;
}