From ee93d2aac17ddb996ba42e1f898e34a970ade88a Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 17 Nov 2021 10:29:41 +0100 Subject: [PATCH] Configure init and cleanup asynchronously Accessing the settings (like --show-touches) on start should not delay screen mirroring. PR #2802 --- .../main/java/com/genymobile/scrcpy/Server.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index db5bc7ec..5a1f4619 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -63,7 +63,7 @@ public final class Server { final Device device = new Device(options); List codecOptions = CodecOption.parse(options.getCodecOptions()); - initAndCleanUp(options); + Thread initThread = startInitThread(options); boolean tunnelForward = options.isTunnelForward(); @@ -95,6 +95,7 @@ public final class Server { // this is expected on close Ln.d("Screen streaming stopped"); } finally { + initThread.interrupt(); if (controllerThread != null) { controllerThread.interrupt(); } @@ -105,6 +106,17 @@ public final class Server { } } + private static Thread startInitThread(final Options options) { + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + initAndCleanUp(options); + } + }); + thread.start(); + return thread; + } + private static Thread startController(final Controller controller) { Thread thread = new Thread(new Runnable() { @Override