#!/bin/sh
# configversion: 1

sxmo_hooks.sh statusbar all

while : ; do
	sleep 10 & wait
	sxmo_hooks.sh statusbar periodics
done &
STATUSTIMEPID=$!

udev_tmp="$(mktemp)"
udevadm monitor -u -s power_supply >> "$udev_tmp" &
UDEVPID=$!
tail -f "$udev_tmp" | while read -r; do
	sxmo_hooks.sh statusbar battery
done &
STATUSBATTERYPID=$!

while : ; do
        sleep 5
        sxmo_hooks.sh statusbar cputemp
done &
STATUSCPUTEMPPID=$!

while : ; do
        sleep 3
        sxmo_hooks.sh statusbar ram
done &
STATUSRAMPID=$!

while : ; do
        sleep 3
        sxmo_hooks.sh statusbar cpuusage
done &
STATUSCPUUSAGEPID=$!

finish() {
	kill "$STATUSTIMEPID"
	kill "$STATUSBATTERYPID"
	kill "$UDEVPID"
	rm "$udev_tmp"
        kill "$STATUSCPUTEMPPID"
        kill "$STATUSRAMPID"
        kill "$STATUSCPUUSAGEPID"
}
trap 'finish' TERM INT EXIT

wait "$STATUSTIMEPID"
wait "$STATUSBATTERYPID"
wait "$STATUSCPUTEMPPID"
wait "$STATUSRAMPID"
wait "$STATUSCPUUSAGEPID"
