Unfortunately, my Zaurus likes to go to sleep rather quickly. So when trying to copy over a new file that I just downloaded, more often than not the network connection is already gone. That's why I decided to have a little utility to monitor the status by pinging the Zaurus every second. Of course, it can be used to monitor any host (if it's not in your local network, you should set the timeout higher).
This is a bit of a hack, and only works because Win32::GUI has a "feature" that allows you to delete notifyicons by adding another icon with the same data. If anyone knows a more elegant solution, please do tell me about it. I'd also like to be able to embed the icons as data, rather reading them from external files. (You can download my somewhat boring icons if you like.)
#!/usr/bin/perl
# 2003/03/15, 2003/04/02 crenz@web42.com
# display icon indicating whether zaurus is alive
# only works due to weird Win32::GUI behaviour -- a notifyicon
# will be deleted if another one with the same text and id is
# created
use strict;
use warnings;
use vars qw(*Timer_Timer *DeadIcon_Click *DeadIcon_RightClick
*AliveIcon_Click *AliveIcon_RightClick);
use Win32::GUI;
use Net::Ping; # or use Win32::PingICMP
my $hostname = $ARGV[0] || 'zaurus'; # or use '192.168.3.2'
my $timer_itvl = 1000;
my $off = Win32::GUI::Icon->new("zaurus_off.ico");
my $on = Win32::GUI::Icon->new("zaurus_on.ico");
my $frame;
my $isAlive = 0;
my $iconID = 0;
# low timeout, since we're in "local network" (USB connection)
my $p = Net::Ping->new("icmp", .2);
sub isAliveOrDead {
$p->ping($hostname); # for testing: -r 'c:\projects\z.txt';
}
sub sayDead {
$frame->AddNotifyIcon(
-icon => $off,
-id => $iconID,
-name => 'DeadIcon',
-tip => "$hostname Is Dead");
$isAlive = 0;
}
sub sayAlive {
$frame->AddNotifyIcon(
-icon => $on,
-id => $iconID,
-name => 'AliveIcon',
-tip => "$hostname Is Alive");
$isAlive = 1;
}
sub toggle {
if ($isAlive) {
sayAlive; $iconID++; sayDead;
} else {
sayDead; $iconID++; sayAlive;
}
}
sub check {
toggle if $isAlive != isAliveOrDead;
}
sub quit {
-1;
}
$frame = Win32::GUI::Window->new(
-name => 'Main',
-title => 'ZaurusAlive',
-width => 100,
-height => 100);
sayDead;
check;
$frame->AddTimer("Timer", $timer_itvl);
*Timer_Timer = \✓
# force check on click; alternatively set to \&toggle for debugging
*DeadIcon_Click = \✓
*AliveIcon_Click = \✓
*DeadIcon_RightClick = \&quit;
*AliveIcon_RightClick = \&quit;
# note that the frame is never shown -- we only want the icon
Win32::GUI::Dialog;