mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-07-31 05:08:59 +00:00
Add option to not power on on start
By default, on start, the device is powered on. To prevent this behavior, add a new option --no-power-on. Fixes #3148 <https://github.com/Genymobile/scrcpy/issues/3148> PR #3210 <https://github.com/Genymobile/scrcpy/pull/3210>
This commit is contained in:
parent
326897a0d4
commit
0fca2ad830
13 changed files with 51 additions and 3 deletions
|
@ -22,6 +22,7 @@ public class Controller {
|
|||
private final DesktopConnection connection;
|
||||
private final DeviceMessageSender sender;
|
||||
private final boolean clipboardAutosync;
|
||||
private final boolean powerOn;
|
||||
|
||||
private final KeyCharacterMap charMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
|
||||
|
||||
|
@ -32,10 +33,11 @@ public class Controller {
|
|||
|
||||
private boolean keepPowerModeOff;
|
||||
|
||||
public Controller(Device device, DesktopConnection connection, boolean clipboardAutosync) {
|
||||
public Controller(Device device, DesktopConnection connection, boolean clipboardAutosync, boolean powerOn) {
|
||||
this.device = device;
|
||||
this.connection = connection;
|
||||
this.clipboardAutosync = clipboardAutosync;
|
||||
this.powerOn = powerOn;
|
||||
initPointers();
|
||||
sender = new DeviceMessageSender(connection);
|
||||
}
|
||||
|
@ -56,7 +58,7 @@ public class Controller {
|
|||
|
||||
public void control() throws IOException {
|
||||
// on start, power on the device
|
||||
if (!Device.isScreenOn()) {
|
||||
if (powerOn && !Device.isScreenOn()) {
|
||||
device.pressReleaseKeycode(KeyEvent.KEYCODE_POWER, Device.INJECT_MODE_ASYNC);
|
||||
|
||||
// dirty hack
|
||||
|
|
|
@ -22,6 +22,7 @@ public class Options {
|
|||
private boolean clipboardAutosync = true;
|
||||
private boolean downsizeOnError = true;
|
||||
private boolean cleanup = true;
|
||||
private boolean powerOn = true;
|
||||
|
||||
// Options not used by the scrcpy client, but useful to use scrcpy-server directly
|
||||
private boolean sendDeviceMeta = true; // send device name and size
|
||||
|
@ -164,6 +165,14 @@ public class Options {
|
|||
this.cleanup = cleanup;
|
||||
}
|
||||
|
||||
public boolean getPowerOn() {
|
||||
return powerOn;
|
||||
}
|
||||
|
||||
public void setPowerOn(boolean powerOn) {
|
||||
this.powerOn = powerOn;
|
||||
}
|
||||
|
||||
public boolean getSendDeviceMeta() {
|
||||
return sendDeviceMeta;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ public final class Server {
|
|||
Thread controllerThread = null;
|
||||
Thread deviceMessageSenderThread = null;
|
||||
if (control) {
|
||||
final Controller controller = new Controller(device, connection, options.getClipboardAutosync());
|
||||
final Controller controller = new Controller(device, connection, options.getClipboardAutosync(), options.getPowerOn());
|
||||
|
||||
// asynchronous
|
||||
controllerThread = startController(controller);
|
||||
|
@ -248,6 +248,10 @@ public final class Server {
|
|||
boolean cleanup = Boolean.parseBoolean(value);
|
||||
options.setCleanup(cleanup);
|
||||
break;
|
||||
case "power_on":
|
||||
boolean powerOn = Boolean.parseBoolean(value);
|
||||
options.setPowerOn(powerOn);
|
||||
break;
|
||||
case "send_device_meta":
|
||||
boolean sendDeviceMeta = Boolean.parseBoolean(value);
|
||||
options.setSendDeviceMeta(sendDeviceMeta);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue