You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix termux-notification and termux-toast from hanging when running from background
In termux-notification, if content is not passed as an argument and then using `[ -t 0 ]` to detect if stdin is also not available does not work for background commands since that is only meant to check if stdin is open and is associated with a terminal. When running in background, the check will fail, since stdin will not be attached to a terminal, but moreover, no data will be available on stdin either and termux-api will hang forever waiting for input.
In termux-toast, similar thing happens where if toast text argument is not passed, it is assumed that data will be available on stdin, which it may not be, making termux-api hang forever waiting for input.
Now for both, if arguments are not passed, then stdin is attempted to be read directly with a 3s timeout without relying on termux-api. If no data is available on stdin, then an empty string will be passed, after aborting after 3s.
Fixestermux/termux-app#1925
Thanks to @krystean for investigating the issue.
echo" -t/--title title notification title to show"
41
+
echo" --vibrate pattern vibrate pattern, comma separated as in 500,1000,200"
42
+
echo" --type type notification style to use (default/media)"
43
+
echo"Media actions (available with --type \"media\"):"
44
+
echo" --media-next action to execute on the media-next button"
45
+
echo" --media-pause action to execute on the media-pause button"
46
+
echo" --media-play action to execute on the media-play button"
47
+
echo" --media-previous action to execute on the media-previous button"
48
+
exit 0
41
49
}
42
50
43
51
show_help_actions () {
44
-
echo"This help refers to the arguments to options like --action, --on-delete, --button-1-action and --media-next."
45
-
echo
46
-
echo"All these commands take an action string as their argument, which is fed to \`dash -c\`."
47
-
echo"A few important things must be kept in mind when using actions:"
48
-
echo
49
-
echo"You should use actions that do things outside of the terminal, like --action \"termux-toast hello\"."
50
-
echo"Anything that outputs to the terminal is useless, so the output should either be redirected (--action \"ls > ~/ls.txt\") or shown to the user in a different way (--action \"ls|termux-toast\")."
51
-
echo
52
-
echo"Running more than one command in a single action is as easy as"
echo"For anything more complex, you should put your script in a file, make it executable, and use that as the action:"
58
-
echo"--action ~/bin/script"
59
-
echo
60
-
echo"The action is run in a different environment (not a subshell). Thus your environment is lost (most notably \$PATH), and ~/.profile is not sourced either. So if you need your \$PATH you should either:"
61
-
echo" - if the action is a script, set it explicitly in the script (e.g. export PATH=\"\$HOME/bin:\$PATH\")"
62
-
echo" - or use something like --action \"bash -l -c 'command1; command2'\")."
63
-
echo
64
-
echo"On Android N or above, you can use the special variable \$REPLY in your actions to use Android's Direct Reply feature."
65
-
echo"This prompts the user to enter some text directly in the notification, which is then substituted into your action."
echo" - termux-toast \"Some text entered by the user\""
69
-
echo"Be careful to escape shell commands correctly for single or double quotes, e.g."
70
-
echo" --button1-action 'something \$REPLY' or --button1-action \"something \\\$REPLY\""
52
+
echo"This help refers to the arguments to options like --action, --on-delete, --button-1-action and --media-next."
53
+
echo
54
+
echo"All these commands take an action string as their argument, which is fed to \`dash -c\`."
55
+
echo"A few important things must be kept in mind when using actions:"
56
+
echo
57
+
echo"You should use actions that do things outside of the terminal, like --action \"termux-toast hello\"."
58
+
echo"Anything that outputs to the terminal is useless, so the output should either be redirected (--action \"ls > ~/ls.txt\") or shown to the user in a different way (--action \"ls|termux-toast\")."
59
+
echo
60
+
echo"Running more than one command in a single action is as easy as"
echo"For anything more complex, you should put your script in a file, make it executable, and use that as the action:"
66
+
echo"--action ~/bin/script"
67
+
echo
68
+
echo"The action is run in a different environment (not a subshell). Thus your environment is lost (most notably \$PATH), and ~/.profile is not sourced either. So if you need your \$PATH you should either:"
69
+
echo" - if the action is a script, set it explicitly in the script (e.g. export PATH=\"\$HOME/bin:\$PATH\")"
70
+
echo" - or use something like --action \"bash -l -c 'command1; command2'\")."
71
+
echo
72
+
echo"On Android N or above, you can use the special variable \$REPLY in your actions to use Android's Direct Reply feature."
73
+
echo"This prompts the user to enter some text directly in the notification, which is then substituted into your action."
echo"Show text in a Toast (a transient popup). The text to show is either supplied as arguments or read from stdin if no arguments are given."
8
-
echo" -h show this help"
9
-
echo" -b set background color (default: gray)"
10
-
echo" -c set text color (default: white)"
11
-
echo" -g set position of toast: [top, middle, or bottom] (default: middle)"
12
-
echo" -s only show the toast for a short while"
13
-
echo"NOTE: color can be a standard name (i.e. red) or 6 / 8 digit hex value (i.e. \"#FF0000\" or \"#FFFF0000\") where order is (AA)RRGGBB. Invalid color will revert to default value"
echo"The toast text is either supplied as arguments or read from stdin"
9
+
echo"if no arguments are given. Arguments will take precedence over stdin."
10
+
echo"If toast text is not passed as arguments or with stdin, then there will"
11
+
echo"be a 3s delay."
12
+
echo" -h show this help"
13
+
echo" -b set background color (default: gray)"
14
+
echo" -c set text color (default: white)"
15
+
echo" -g set position of toast: [top, middle, or bottom] (default: middle)"
16
+
echo" -s only show the toast for a short while"
17
+
echo"NOTE: color can be a standard name (i.e. red) or 6 / 8 digit hex value (i.e. \"#FF0000\" or \"#FFFF0000\") where order is (AA)RRGGBB. Invalid color will revert to default value"
0 commit comments