1

Compare commits

...

4 Commits

View File

@@ -1,5 +1,7 @@
#!/usr/bin/perl
# TODO: on i3wm reload (i3status restart), restore active windows status
# we need to disable hash shuffling in order to make as less prints to stdout as possible
BEGIN {
unless (defined $ENV{PERL_PERTURB_KEYS}) {
@@ -543,7 +545,30 @@ sub add_events () {
},
);
# Try to tcp connect to server
# check openvpn state-file mtime
if ($CONF->{vpn}->{enabled}) {
push @EP, AnyEvent->timer (
after => 0, # first invoke ASAP
interval => 3, # then invoke every 3 seconds
cb => sub { # the callback to invoke
my $mtime = (stat $CONF->{vpn}->{statusfile}) [8];
if (defined $mtime) {
if (($mtime - $file_check_mtime) < $CONF->{vpn}->{mtime_threshold}) {
$file_check = 1;
} else {
$file_check = 0;
}
$file_check_mtime = $mtime;
} else {
$mtime = 0;
$file_check = 0;
}
}
);
# Try to tcp connect to server in vpn network
if ($CONF->{vpn}->{tcp_check}->{enabled}) {
push @EP, AnyEvent->timer (
after => 0, # first invoke ASAP
@@ -568,33 +593,10 @@ sub add_events () {
}
);
}
# check file mtime
if ($CONF->{vpn}->{enabled}) {
push @EP, AnyEvent->timer (
after => 0, # first invoke ASAP
interval => 3, # then invoke every 3 seconds
cb => sub { # the callback to invoke
my $mtime = (stat $CONF->{vpn}->{statusfile}) [8];
if (defined $mtime) {
if (($mtime - $file_check_mtime) < $CONF->{vpn}->{mtime_threshold}) {
$file_check = 1;
} else {
$file_check = 0;
}
$file_check_mtime = $mtime;
} else {
$mtime = 0;
$file_check = 0;
}
}
);
}
# poll pulseaudio volume on first sink in list
if ($CONF->{clock}->{enabled}) {
if ($CONF->{'simple-volume-pa'}) {
push @EP, AnyEvent->timer (
after => 0, # first invoke ASAP
interval => 1, # then invoke every 1 second
@@ -648,9 +650,8 @@ sub spawn (@) {
} else {
exec $prg;
}
} else { # Unable to fork()
print STDERR "[{\"full_text\":\"ERROR: Could not fork new process: $!\",\"color\":\"#ff0000\"}],\n";
}
# else - we just unable to fork, so silently ignore event
}
return;
@@ -689,10 +690,16 @@ sub to_hours ($) {
}
sub readconf () {
my $file = "$ENV{HOME}/.i3/i3status-anyevent.json";
my $i3dir = "$ENV{HOME}/.config/i3";
unless (-d $i3dir) {
$i3dir = "$ENV{HOME}/.i3";
}
my $file = "$i3dir/i3status-anyevent.json";
unless (-f $file) {
$file = "$ENV{HOME}/.i3/config.json";
$file = "$i3dir/config.json";
}
my $FH;