#!/bin/sh

## show a network manager applet in notification area

traywaiter () { until xwininfo -name "$1"; do sleep 1; done; } >/dev/null 2>&1
waitstopper () { sleep 8; kill "$1" 2>/dev/null; }
waitfor () { traywaiter "$1" & sleep 1; set -- "$!"; waitstopper $1 & wait $1; }
nmcheck () { type nm-applet && pidof NetworkManager; } >/dev/null 2>&1
nmstart () ( nmcheck && { nm-applet & waitfor 'NetworkManager Applet'; } )
wicdcheck () { type wicd-client && [ -f /var/run/wicd/wicd.pid ]; } >/dev/null 2>&1
wicdstart () ( wicdcheck $hush && { wicd-client -t & waitfor 'wicd-client.py'; } )

# start nm-applet
nmstart
set -- "$?"

# start wicd client
wicdstart

# If neither wicd nor nm applet stabilized, finish with error
[ "$?" -eq 0 ] || [ "$1" -eq 0 ]

