1

i3status-anyevent: Add cron plugin

This commit is contained in:
Sergei Fedosov
2021-02-25 18:50:25 +03:00
parent 58d896c597
commit 035afae865
2 changed files with 46 additions and 2 deletions

View File

@@ -1,6 +1,8 @@
#!/usr/bin/perl
# TODO: on i3wm reload (i3status restart), restore active windows status
# TODO: on i3wm reload (i3status restart), restore active windows status
# TODO: make battery plugin take into account charge level, add ability to call suspend2disk on critical charge level
# TODO: More complex PA-plugin with volume adjustment of default sink
# we need to disable hash shuffling in order to make as less prints to stdout as possible
BEGIN {
@@ -18,6 +20,7 @@ use utf8;
use open qw (:std :utf8);
use Fcntl qw (:seek);
use AnyEvent;
use AnyEvent::Timer::Cron;
use AnyEvent::I3;
use JSON::XS;
use Encode;
@@ -150,7 +153,7 @@ sub add_events () {
# Actually print messages there
push @EP, AnyEvent->timer (
after => 1, # sleep 1 second
interval => 0.3, # then invoke every 1 second
interval => 0.3, # then invoke every ~1/3 second
cb => sub { # the callback to invoke
my $OUTPUT;
@@ -664,6 +667,21 @@ sub add_events () {
);
}
# run all cron jobs from config
if ($CONF->{'cron'}->{enabled}) {
foreach my $task (@{$CONF->{'cron'}->{tasks}}) {
push @EP, AnyEvent::Timer::Cron->new (
time_zone => 'local',
cron => $task->{time},
cb => sub {
foreach my $cmd (@{$task->{cmd}}) {
`$cmd`;
}
}
)
}
}
return;
}