Open sudomain opened 1 year ago
From my experience, termux-torch on
twice turns the light first on, then off. That bug works like the toggle behavior you just described, as long as it is used with the on
flag.
That unfortunately doesn't seem to be the case for my device (pixel 2, android 11)
For temporarily you Can use this
#!/bin/bash
# Set initial state
termux_torch_state="on"
termux-torch on
# Function to toggle the touch
toggle_switch() {
if [ "$termux_torch_state" == "on" ]; then
echo "Switching off"
termux-torch off
termux_torch_state="off"
else
echo "Switching ON"
termux-torch on
termux_torch_state="on"
fi
}
# Main script
echo "Toggle switch example"
while true; do
echo "Current state: $termux_torch_state"
echo "Press Enter to toggle the switch, or 'q' to quit"
read -rsn1 input
case $input in
q)
echo "Quitting script"
break
;;
*)
toggle_switch
;;
esac
done
You can save this script as torch.sh
in termux widgets folder or your desired folder
alternatively you can set torch state in a file
to remove the bash concepts like (bash functions,case, while loop) and without entering (temporarily struck in) into while loop,
using only if conditions
Simply saying about my idea above I mentioned
First time executing the script
Bash torch.sh
=> torch literal state on
Second time executing the file
Bash torch.sh
=> torch literal state off
In this way we can make toggle effect
(If I have free time, I would create script above I mentioned as a concept)
Btw, termux_torch_state
is not literal device's physical torch's state, I'm just simulating for in this case, it's just a variable
If you optimize this script more, please let Me know,
Feature description
termux-torch currently accepts on or off as arguments:
It would be nice if we could have a 3rd option to actually toggle the LED:
termux-torch toggle
which would check the current LED state and change it to to the opposite (off -> on, and on -> off)Reference implementation
Have you checked if the feature is accessible through the Android API? Yes Do you know of other open-source apps that has a similar feature as the one you want? (Provide links) N/A