|
8 | 8 | #
|
9 | 9 | #########################
|
10 | 10 | #
|
11 |
| -# Copyright (C) 2018 Vittorio Cagnetta |
| 11 | +# Copyright (C) 2019 Vittorio Cagnetta |
12 | 12 | #
|
13 | 13 | # Author: Vittorio Cagnetta <[email protected]>
|
14 | 14 | #
|
|
35 | 35 | #####################################
|
36 | 36 | #####################################
|
37 | 37 | #
|
38 |
| -LIB_VERSION="11.0.1" |
| 38 | +LIB_VERSION="12.0.0" |
39 | 39 | LIB_NAME="easybashgui.lib"
|
40 | 40 | LIB_URL="https://github.com/BashGui/easybashgui"
|
41 | 41 | LIB_AUTHOR="Vittorio Cagnetta"
|
|
494 | 494 | #
|
495 | 495 | ###############
|
496 | 496 | #
|
| 497 | +export notify_send_seconds=4 |
| 498 | +export notify_check_loop_seconds=5 |
| 499 | +# |
| 500 | +export notify_icon_default="gtk-stop" |
| 501 | +export notify_icon_good="gtk-home" |
| 502 | +export notify_icon_bad="gtk-help" |
| 503 | +# |
| 504 | +export notify_tooltip_default="${0##*/}-> starting..." |
| 505 | +export notify_tooltip_good="${0##*/}-> ok" |
| 506 | +export notify_tooltip_bad="${0##*/}-> bad!" |
| 507 | +# |
| 508 | +notify_send="NO" |
| 509 | +esistenza_notify_send="$(type 'notify-send' 2> /dev/null )" |
| 510 | +if [ ${#esistenza_notify_send} -gt 0 ] |
| 511 | + then |
| 512 | + notify_send="SI" |
| 513 | +fi |
| 514 | +# |
497 | 515 | #####################################
|
498 | 516 | #
|
499 | 517 | # This is only for test, it's preferable that mode is set automatically...
|
@@ -868,6 +886,180 @@ exit_if_user_closes_window()
|
868 | 886 | }
|
869 | 887 | #
|
870 | 888 | ##
|
| 889 | +# notify(), notify_change() |
| 890 | +if [ "${yad}" = "SI" ] |
| 891 | + then |
| 892 | + # notify <-c "[click command (for mouse left button)]"> <-i "[icon_good]#[icon_bad]"> <-t "[tooltip_good]#[tooltip_bad]"> "[menu item 1]" "[menu command 1]" ... "[menu item n]" "[menu command n]" |
| 893 | + # |
| 894 | + notify() |
| 895 | + { |
| 896 | + local FUNCT_NAME="notify" |
| 897 | + local IFS=$' \t\n' |
| 898 | + # |
| 899 | + unset click_command |
| 900 | + unset icons |
| 901 | + unset tooltips |
| 902 | + # |
| 903 | + while getopts ":c:i:t:" function_options |
| 904 | + do |
| 905 | + case ${function_options} in |
| 906 | + # |
| 907 | + c ) export click_command="${OPTARG}" ;; |
| 908 | + i ) export icons="${OPTARG}" ;; |
| 909 | + t ) export tooltips="${OPTARG}" ;; |
| 910 | + # |
| 911 | + esac |
| 912 | + done |
| 913 | + shift $((OPTIND-1)) |
| 914 | + # |
| 915 | + ############################## |
| 916 | + # |
| 917 | + local cut_char="#" |
| 918 | + # |
| 919 | + : notify_icon_good |
| 920 | + : notify_icon_bad |
| 921 | + if [ ${#icons} -gt 0 ] |
| 922 | + then |
| 923 | + notify_icon_good="$(echo "${icons}" | cut -d "${cut_char}" -f 1 )" |
| 924 | + notify_icon_bad="$(echo "${icons}" | cut -d "${cut_char}" -f 2 )" |
| 925 | + fi |
| 926 | + unset icons |
| 927 | + # |
| 928 | + : notify_tooltip_good |
| 929 | + : notify_tooltip_bad |
| 930 | + if [ ${#tooltips} -gt 0 ] |
| 931 | + then |
| 932 | + notify_tooltip_good="$(echo "${tooltips}" | cut -d "${cut_char}" -f 1 )" |
| 933 | + notify_tooltip_bad="$(echo "${tooltips}" | cut -d "${cut_char}" -f 2 )" |
| 934 | + fi |
| 935 | + unset tooltips |
| 936 | + # |
| 937 | + unset notify_args |
| 938 | + unset notify_commands |
| 939 | + local IFS=$'\n' |
| 940 | + threshold=${#} |
| 941 | + for (( num=1,array_index=0 ; num <= ${threshold} ; num++,num++,array_index++ )) |
| 942 | + do |
| 943 | + notify_args[${array_index}]="${1}" |
| 944 | + notify_commands[${array_index}]="${2}" |
| 945 | + # |
| 946 | + shift ; shift |
| 947 | + done |
| 948 | + local IFS=$' \t\n' |
| 949 | + : notify_args[@] |
| 950 | + : notify_commands[@] |
| 951 | + # |
| 952 | + local IFS=$'\n' |
| 953 | + notify_items="$(for (( index=0 ; index < ${#notify_args[@]} ; index++ )) |
| 954 | + do |
| 955 | + echo -ne "|-> " |
| 956 | + echo -ne "${notify_args[${index}]}" |
| 957 | + echo -ne "!" |
| 958 | + echo -ne "${notify_commands[${index}]}" |
| 959 | + done )" |
| 960 | + local IFS=$' \t\n' |
| 961 | + # |
| 962 | + notify_menu=" ${supertitle}${notify_items}|-> Quit!quit" |
| 963 | + # |
| 964 | + ## |
| 965 | + # |
| 966 | + # remove previously created FIFOs... |
| 967 | + for ebg_PIPE_file in $(ls "${dir_tmp}/${0##*/}".???????? 2>/dev/null ) |
| 968 | + do |
| 969 | + #echo "Removing \"${ebg_PIPE_file}\" ..." |
| 970 | + rm "${ebg_PIPE_file}" |
| 971 | + done |
| 972 | + # create a new FIFO file, used to manage the I/O redirection from shell... |
| 973 | + export ebg_PIPE="$(mktemp -u "${dir_tmp}/${0##*/}.XXXXXXXX" )" |
| 974 | + mkfifo "${ebg_PIPE}" |
| 975 | + # eventually attach a file descriptor to the FIFO... |
| 976 | + exec 3<> "${ebg_PIPE}" |
| 977 | + # |
| 978 | + ### |
| 979 | + # |
| 980 | + # add handler to manage process shutdown... |
| 981 | + notify_on_exit() |
| 982 | + { |
| 983 | + echo "quit" 1> "${ebg_PIPE}" |
| 984 | + rm -f "${ebg_PIPE}" |
| 985 | + clean_temp |
| 986 | + } |
| 987 | + trap notify_on_exit EXIT |
| 988 | + # |
| 989 | + # add handler for tray icon left click... |
| 990 | + notify_on_click() |
| 991 | + { |
| 992 | + echo "tooltip:${0##*/}-> wait..." 1> "${ebg_PIPE}" |
| 993 | + # |
| 994 | + if [ ${#click_command} -eq 0 ] |
| 995 | + then |
| 996 | + { |
| 997 | + export supericon="${notify_icon_good}" |
| 998 | + source easybashgui |
| 999 | + ok_message "\n ${supertitle}: powered by EasyBashGUI vers.${LIB_VERSION}" |
| 1000 | + clean_temp |
| 1001 | + } &>/dev/null |
| 1002 | + else |
| 1003 | + ${click_command} |
| 1004 | + fi |
| 1005 | + # |
| 1006 | + } |
| 1007 | + export -f notify_on_click |
| 1008 | + # |
| 1009 | + ##################################### |
| 1010 | + ##################################### |
| 1011 | + ##################################### |
| 1012 | + # |
| 1013 | + # |
| 1014 | + ######################### |
| 1015 | + # finally create the notification... |
| 1016 | + # |
| 1017 | + yad --notification \ |
| 1018 | + --no-middle \ |
| 1019 | + --listen \ |
| 1020 | + --kill-parent \ |
| 1021 | + --image="${notify_icon_default}" \ |
| 1022 | + --icon-size=48 \ |
| 1023 | + --text="${notify_tooltip_default}" \ |
| 1024 | + --menu="${notify_menu}" \ |
| 1025 | + --command="bash -c notify_on_click" 0<&3 & |
| 1026 | + # |
| 1027 | + } |
| 1028 | + # |
| 1029 | + ### |
| 1030 | + # |
| 1031 | + # notify_change "[good|bad]" |
| 1032 | + # |
| 1033 | + notify_change() |
| 1034 | + { |
| 1035 | + local FUNCT_NAME="notify_change" |
| 1036 | + local IFS=$' \t\n' |
| 1037 | + # |
| 1038 | + [ ${#ebg_PIPE} -eq 0 ] && break |
| 1039 | + [ ! -e "${ebg_PIPE}" ] && break |
| 1040 | + # |
| 1041 | + notify_change_how="${1}" |
| 1042 | + [ ${#notify_change_how} -eq 0 ] && notify_change_how="bad" |
| 1043 | + # |
| 1044 | + if [ "${notify_change_how}" = "good" -o "${notify_change_how}" = "GOOD" ] |
| 1045 | + then |
| 1046 | + # |
| 1047 | + echo "icon:${notify_icon_good}" |
| 1048 | + echo "tooltip:${notify_tooltip_good}" |
| 1049 | + # |
| 1050 | + elif [ "${notify_change_how}" = "bad" -o "${notify_change_how}" = "BAD" ] |
| 1051 | + then |
| 1052 | + # |
| 1053 | + echo "icon:${notify_icon_bad}" |
| 1054 | + echo "tooltip:${notify_tooltip_bad}" |
| 1055 | + # |
| 1056 | + fi 1> "${ebg_PIPE}" |
| 1057 | + # |
| 1058 | + } |
| 1059 | + # |
| 1060 | +fi #if [ "${yad}" = "SI" ] |
| 1061 | +# notify(), notify_change() |
| 1062 | +## |
871 | 1063 | #
|
872 | 1064 | # question()
|
873 | 1065 | errexit_option="NO"
|
@@ -1166,6 +1358,61 @@ fi
|
1166 | 1358 | #
|
1167 | 1359 | ##
|
1168 | 1360 | #
|
| 1361 | +# notify_message() |
| 1362 | +[ "${mode}" = "dialog" ] && notify_send="NO" |
| 1363 | +if [ "${notify_send}" = "SI" ] |
| 1364 | + then |
| 1365 | + notify_message() |
| 1366 | + { |
| 1367 | + local FUNCT_NAME="notify_message" |
| 1368 | + local IFS=$' \t\n' |
| 1369 | + # |
| 1370 | + notify_message_text="${@}" |
| 1371 | + # |
| 1372 | + notify_send_milliseconds=$(( ${notify_send_seconds} * 1000 )) |
| 1373 | + notify-send -t ${notify_send_milliseconds} -a "${0##*/}" -i "${notification_icon_default}" "${notify_message_text}" |
| 1374 | + # |
| 1375 | + } |
| 1376 | +elif [ "${notify_send}" = "NO" ] |
| 1377 | + then |
| 1378 | + notify_message() |
| 1379 | + { |
| 1380 | + local FUNCT_NAME="notify_message" |
| 1381 | + local IFS=$' \t\n' |
| 1382 | + # |
| 1383 | + export notify_message_text="${@}" |
| 1384 | + # |
| 1385 | + if [ "${mode}" = "dialog" ] |
| 1386 | + then |
| 1387 | + # |
| 1388 | + wait_for "${notify_message_text}" |
| 1389 | + sleep ${notify_send_seconds} |
| 1390 | + terminate_wait_for |
| 1391 | + # |
| 1392 | + elif [ "${mode}" != "dialog" ] |
| 1393 | + then |
| 1394 | + notify_dummy_var="$( |
| 1395 | + if [ "${kdialog}" = "SI" ] |
| 1396 | + then |
| 1397 | + export supermode=kdialog |
| 1398 | + fi |
| 1399 | + # |
| 1400 | + source easybashgui |
| 1401 | + # |
| 1402 | + wait_for "${notify_message_text}\n\n\n\n(Please install \"notify-send\" for a nicer notification)" |
| 1403 | + sleep ${notify_send_seconds} |
| 1404 | + terminate_wait_for |
| 1405 | + # |
| 1406 | + clean_temp |
| 1407 | + )" &>/dev/null & |
| 1408 | + fi |
| 1409 | + # |
| 1410 | + } |
| 1411 | + # |
| 1412 | +fi # if [ "${notify_send}" = "SI" ] |
| 1413 | +# notify_message() |
| 1414 | +## |
| 1415 | +# |
1169 | 1416 | # message()
|
1170 | 1417 | if [ "${mode}" = "yad" ]
|
1171 | 1418 | then
|
|
0 commit comments