I keep my phone connected to my computer most of the day using Scrcpy. This works great, but continuous charging isn’t ideal for the battery. For better battery longevity, it’s recommended to cycle charging and discharging.
To manage this more efficiently, I created two scripts that automate the process. They ensure that the phone doesn’t stay plugged in all the time but only charges when necessary.
# Colors for active, inactive, low battery, and charging states
color_active="#fa9f00" # Green when scrcpy is running
color_inactive="#808080" # Grey when scrcpy is not running
color_low_battery="#FF0000" # Red when battery is low (10% or less)
color_charging="#00FF00" # Orange when charging