#!/usr/bin/perl

=head1 NAME

parcimonie-applet - (deprecated) system tray applet for parcimonie

=head1 DESCRIPTION

parcimonie-applet displays an icon in the "system tray" or
"notification area", following the FreeDesktop System Tray
Specification on X11. It may or may not work for you, depending on
your desktop environment.

=head1 DEPRECATION WARNING

The underlying technologies have been deprecated in GNOME 3 and
GTK+ 3.14. The author of this applet does not use it anymore.
Therefore, the author cannot support it and this applet will be
removed from the parcimonie package at some point, unless someone
takes over its maintenance.

=head2 Future plans

=head3 GNOME

Modern GNOME technologies will be supported at some point, most likely
in the form of a GNOME Shell extension; the exact user interactions
have not been designed yet. For more details, see:

=over

=item https://bugs.debian.org/799942

=item https://bugs.debian.org/850217

=back

=head3 Other desktop environments

Ideally, someone should create an applet that works for non-GNOME
users, possibly using the FreeDesktop Status Notifier Item
specification. It would have to talk to the parcimonie daemon over
D-Bus.

=cut

use strict;
use warnings;
use 5.10.0;

use FindBin;
use lib "$FindBin::Bin/../lib";

use Carp;
use Try::Tiny;

my $mu;
sub record_memory_usage { 1 }
sub report_memory_usage { 1 }

BEGIN {
    if (exists $ENV{REPORT_MEMORY_USAGE}
            && defined $ENV{REPORT_MEMORY_USAGE}
            && $ENV{REPORT_MEMORY_USAGE}) {
        try {
            require Memory::Usage;
        } catch {
            croak "Memory::Usage is needed when REPORT_MEMORY_USAGE is set."
        };
        $mu = Memory::Usage->new();
        no warnings 'redefine';
        *record_memory_usage = sub { $mu->record(shift) };
        *report_memory_usage = sub { $mu->dump() };
    }
}

BEGIN {
    record_memory_usage('before loading App::Parcimonie::Applet');
    require App::Parcimonie::Applet;
    App::Parcimonie::Applet->import();
    record_memory_usage('after loading App::Parcimonie::Applet');
}

$SIG{'INT'}  = $SIG{'TERM'} = sub { report_memory_usage(); exit(0); };
$SIG{'USR1'} = sub { report_memory_usage(); };

App::Parcimonie::Applet->new->run;
report_memory_usage();
