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,33 +545,7 @@ sub add_events () {
},
);
# Try to tcp connect to server
if ($CONF->{vpn}->{tcp_check}->{enabled}) {
push @EP, AnyEvent->timer (
after => 0, # first invoke ASAP
interval => 5, # then invoke every 5 seconds
cb => sub { # the callback to invoke
if (
my $sock = IO::Socket->new (
Domain => AF_INET,
proto => 'tcp',
PeerHost => $CONF->{vpn}->{tcp_check}->{host},
PeerPort => $CONF->{vpn}->{tcp_check}->{port},
Type => SOCK_STREAM,
Timeout => $CONF->{vpn}->{tcp_check}->{timeout}
)
) {
$sock->shutdown (SHUT_WR);
$sock->close ();
$tcp_check = 1;
} else {
$tcp_check = 0;
}
}
);
}
# check file mtime
# check openvpn state-file mtime
if ($CONF->{vpn}->{enabled}) {
push @EP, AnyEvent->timer (
after => 0, # first invoke ASAP
@@ -591,10 +567,36 @@ sub add_events () {
}
}
);
# Try to tcp connect to server in vpn network
if ($CONF->{vpn}->{tcp_check}->{enabled}) {
push @EP, AnyEvent->timer (
after => 0, # first invoke ASAP
interval => 5, # then invoke every 5 seconds
cb => sub { # the callback to invoke
if (
my $sock = IO::Socket->new (
Domain => AF_INET,
proto => 'tcp',
PeerHost => $CONF->{vpn}->{tcp_check}->{host},
PeerPort => $CONF->{vpn}->{tcp_check}->{port},
Type => SOCK_STREAM,
Timeout => $CONF->{vpn}->{tcp_check}->{timeout}
)
) {
$sock->shutdown (SHUT_WR);
$sock->close ();
$tcp_check = 1;
} else {
$tcp_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;