gnirehtet icon indicating copy to clipboard operation
gnirehtet copied to clipboard

Can I make Gnirehtet close automatically when phone is disconnected?

Open simonferndriger opened this issue 3 years ago • 2 comments

The reason for why I'm asking is, when I connect the phone, disconnect it from the PC and connect the cable again, most of the time Gnirehtet is not working properly anymore with popular apps. So when I close Gnirehtet on the phone, and plug the cable out and in again, it usually works just fine.

Also, mobile data won't work when Gnirehtet is running, so automatically closing Gnirehtet when disconnecting the phone with the PC seems to be like the obvious choice. How can it be done?

simonferndriger avatar Aug 22 '22 13:08 simonferndriger

You can use a simple bash script to monitor the device connection and automatically stop gnirehtet when the phone disconnects:

#!/bin/bash

while true; do adb get-state 2>&1 | grep -q "device" if [ $? -eq 0 ]; then echo "Device connected" if ! pgrep -f "gnirehtet run" > /dev/null; then echo "Starting gnirehtet..." ./gnirehtet run > /dev/null 2>&1 & fi else echo "Device disconnected" pkill -f "gnirehtet run" fi sleep 2 done What This Does: Checks every 2 seconds if the phone is connected via adb.

Starts gnirehtet if it's not already running.

Kills it automatically when the device disconnects.

This way, Gnirehtet stops gracefully when you unplug your phone, avoiding mobile data block or stuck VPN tunnel issues.

VaradGupta23 avatar Jul 11 '25 11:07 VaradGupta23

This may help, maybe:

Pulled the stop-on-disconnect feature and uploaded the binaries here: (stop-on-disconnect is enabled hardcoded in java)

https://github.com/salihmarangoz/gnirehtet/tree/master/COMPILED_BY_ME

salihmarangoz avatar Aug 04 '25 05:08 salihmarangoz