tazpkg rev 870

tazpkg-notify: also use notify-send for desktop notifications
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Nov 23 04:52:58 2015 +0200 (2015-11-23)
parents be92096053b2
children 8940809090af
files tazpkg-box tazpkg-notify
line diff
     1.1 --- a/tazpkg-box	Sun Nov 22 19:11:25 2015 +0100
     1.2 +++ b/tazpkg-box	Mon Nov 23 04:52:58 2015 +0200
     1.3 @@ -15,7 +15,7 @@
     1.4  text="<b>$(_ 'SliTaz Package Action')</b>"
     1.5  icon="system-software-install"
     1.6  opts="--window-icon=$icon --image=$icon --image-on-top --center --on-top \
     1.7 ---height=350 --width=520 --title=TazPkg"
     1.8 +--height=350 --width=570 --title=TazPkg"
     1.9  
    1.10  
    1.11  usage() {
    1.12 @@ -36,7 +36,7 @@
    1.13  # Nice GTK output for install and extract.
    1.14  
    1.15  output() {
    1.16 -	yad --text-info $opts --tail --margins='4' --text="$text" \
    1.17 +	yad --text-info $opts --tail --margins='4' --text="$text" --fontname='monospace,8' \
    1.18  		--button='gtk-close:0'
    1.19  }
    1.20  
     2.1 --- a/tazpkg-notify	Sun Nov 22 19:11:25 2015 +0100
     2.2 +++ b/tazpkg-notify	Mon Nov 23 04:52:58 2015 +0200
     2.3 @@ -21,6 +21,7 @@
     2.4  
     2.5  fifo=/tmp/$(basename $0).fifo
     2.6  doc="file:///usr/share/doc/tazpkg/tazpkg.html"
     2.7 +tp='http://127.0.0.1:82/user/pkgs.cgi'
     2.8  
     2.9  installed=$(wc -l < "$PKGS_DB/installed.info")
    2.10  text="$(_p \
    2.11 @@ -32,6 +33,19 @@
    2.12  up=0; [ -f "$PKGS_DB/packages.up" ] && up=$(wc -l < "$PKGS_DB/packages.up")
    2.13  
    2.14  
    2.15 +# Standard notification, if available
    2.16 +
    2.17 +notify() {
    2.18 +	if [ -n "$(which notify-send)" ]; then
    2.19 +		case $2 in
    2.20 +			info) icon='dialog-information'; urgency='normal';;
    2.21 +			*)    icon='dialog-warning';     urgency='critical';;
    2.22 +		esac
    2.23 +		notify-send -i $icon -u $urgency 'TazPkg' "$1" &
    2.24 +	fi
    2.25 +}
    2.26 +
    2.27 +
    2.28  # Notification icon
    2.29  
    2.30  listen() {
    2.31 @@ -42,8 +56,9 @@
    2.32  	exec 3<> $fifo
    2.33  
    2.34  	# Notification icon
    2.35 -	yad --notification --listen --image='software-update-available' \
    2.36 -		--text="$(_ 'Checking packages lists - %s' "$text")" <&3
    2.37 +	tooltip="$(_ 'Checking packages lists - %s' "$text")"
    2.38 +	notify "$tooltip" 'info' &
    2.39 +	yad --notification --listen --image='software-update-available' --text="$tooltip" <&3
    2.40  
    2.41  	# Clean-up
    2.42  	rm -f $fifo
    2.43 @@ -81,6 +96,7 @@
    2.44  		# Missing packages list
    2.45  		if [ ! -f "$PKGS_DB/packages.info" ]; then
    2.46  			tooltip="$(_ 'No packages list found - %s' "$text")"
    2.47 +			notify "$tooltip\n<a href=\"$tp?recharge\">$(_n 'Recharge lists')</a>" &
    2.48  			(echo "action:tazbox su tazpanel pkgs#recharge"
    2.49  			 echo "tooltip:$tooltip"
    2.50  			 echo "icon:software-update-urgent") > $fifo
    2.51 @@ -90,6 +106,7 @@
    2.52  		# Too old packages list
    2.53  		if [ -n "$mtime" ]; then
    2.54  			tooltip="$(_ 'Your packages list is older than 10 days')"
    2.55 +			notify "$tooltip\n<a href=\"$tp?recharge\">$(_n 'Recharge lists')</a>" &
    2.56  			(echo "action:tazbox su tazpanel pkgs#recharge"
    2.57  			 echo "action:quit"
    2.58  			 echo "tooltip:$tooltip"
    2.59 @@ -103,6 +120,7 @@
    2.60  				'There is %s upgradeable package' \
    2.61  				'There are %s upgradeable packages' "$up" \
    2.62  				"<b>$up</b>")"
    2.63 +			notify "$tooltip\n<a href=\"$tp?up\">$(_n 'Check upgrade')</a>" &
    2.64  			(echo "action:tazbox su tazpanel pkgs#up"
    2.65  			 echo "tooltip:$tooltip"
    2.66  			 echo "icon:software-update-urgent") > $fifo
    2.67 @@ -111,6 +129,7 @@
    2.68  
    2.69  		# Nothing to do, close notification
    2.70  		tooltip="$(_ 'System is up to date - %s' "$text")"
    2.71 +		notify "$tooltip" 'info' &
    2.72  		echo "tooltip:$tooltip" > $fifo
    2.73  		sleep 10
    2.74  		echo "quit" > $fifo