scrcpy icon indicating copy to clipboard operation
scrcpy copied to clipboard

[Feature Request] Run commands/script on disconnect

Open digg33 opened this issue 1 year ago • 1 comments

  • [X] I have checked that a similar feature request does not already exist.

Is your feature request related to a problem? Please describe. A momentary network disruption would break the running scrcpy connection, as expected. However, this leaves the phone in the unlocked state it was in when scrcpy was being used, posing a potential security and/or privacy risk. Also since the introduction of the new audio forwarding feature, if loud media was being played on the phone but listened through headphones on PC, the media continues to play on the phone loudspeaker in these situations, which may be undesirable. Finally, I run adb shell wm size to make the screen size more comfortable for desktop use before starting the mirroring session, which is reverted when scrcpy window is closed via my launcher script. A network problem could prevent the final adb shell wm resize revert action from being run on the device which leaves it with a display setting unsuitable for phone use.

Describe the solution you'd like Option to specify a shell script placed locally on the device to be run by scrcpy-server on exit (whether normal or abnormal). Alternatively, in a similar fashion to how the scrcpy-server binary is uploaded, the script could be kept on the PC and uploaded on each connect. In this script, the user would be able to run any cleanup tasks specific to their setup. This would certainly at least solve the problems I stated above, by allowing me to run input keyevent 26 (lock screen), input keyevent VOLUME_MUTE, and wm resize locally in the phone on disconnect.

Describe alternatives you've considered I wonder if as a workaround, it might be possible to somehow detect the scrcpy disconnect on the phone, but that seems like a more fragile solution than the one proposed. Not much else, but any input on alternatives/workarounds would be highly appreciated.

Additional context N/A.

digg33 avatar Apr 09 '23 22:04 digg33

#3191

yume-chan avatar Apr 10 '23 06:04 yume-chan