diff --git a/client/src/main/java/ctbrec/ui/ExternalBrowser.java b/client/src/main/java/ctbrec/ui/ExternalBrowser.java index 648014d7..b31fc313 100644 --- a/client/src/main/java/ctbrec/ui/ExternalBrowser.java +++ b/client/src/main/java/ctbrec/ui/ExternalBrowser.java @@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory; import ctbrec.OS; import ctbrec.io.StreamRedirectThread; +// TODO implement proxy support public class ExternalBrowser implements AutoCloseable { private static final transient Logger LOG = LoggerFactory.getLogger(ExternalBrowser.class); private static final ExternalBrowser INSTANCE = new ExternalBrowser(); @@ -35,30 +36,35 @@ public class ExternalBrowser implements AutoCloseable { } public void run(String jsonConfig, Consumer messageListener) throws InterruptedException, IOException { + LOG.debug("Running browser with config {}", jsonConfig); lock.lock(); - stopped = false; - this.messageListener = messageListener; + try { + stopped = false; + this.messageListener = messageListener; - p = new ProcessBuilder(OS.getBrowserCommand()).start(); - new StreamRedirectThread(p.getInputStream(), System.err); - new StreamRedirectThread(p.getErrorStream(), System.err); - LOG.debug("Browser started"); + p = new ProcessBuilder(OS.getBrowserCommand()).start(); + new StreamRedirectThread(p.getInputStream(), System.err); + new StreamRedirectThread(p.getErrorStream(), System.err); + LOG.debug("Browser started"); - connectToRemoteControlSocket(); - LOG.debug("Connected to remote control server. Sending config {}", jsonConfig); + connectToRemoteControlSocket(); + LOG.debug("Connected to remote control server. Sending config {}", jsonConfig); - out.write(jsonConfig.getBytes("utf-8")); - out.write('\n'); - out.flush(); + out.write(jsonConfig.getBytes("utf-8")); + out.write('\n'); + out.flush(); - LOG.debug("Waiting for browser to terminate"); - p.waitFor(); - int exitValue = p.exitValue(); - p = null; - LOG.debug("Browser Process terminated with {}", exitValue); + LOG.debug("Waiting for browser to terminate"); + p.waitFor(); + int exitValue = p.exitValue(); + p = null; + LOG.debug("Browser Process terminated with {}", exitValue); + } finally { + lock.unlock(); + } } - private void connectToRemoteControlSocket() { + private void connectToRemoteControlSocket() throws IOException { for (int i = 0; i < 20; i++) { try { socket = new Socket("localhost", 3202); @@ -70,7 +76,7 @@ public class ExternalBrowser implements AutoCloseable { } catch (IOException e) { if(i == 19) { LOG.error("Connection to remote control socket failed", e); - return; + throw e; } } @@ -134,8 +140,4 @@ public class ExternalBrowser implements AutoCloseable { } } } - - public void release() { - lock.unlock(); - } } diff --git a/client/src/main/java/ctbrec/ui/sites/bonga/BongaCamsElectronLoginDialog.java b/client/src/main/java/ctbrec/ui/sites/bonga/BongaCamsElectronLoginDialog.java index 82df391b..73146f5f 100644 --- a/client/src/main/java/ctbrec/ui/sites/bonga/BongaCamsElectronLoginDialog.java +++ b/client/src/main/java/ctbrec/ui/sites/bonga/BongaCamsElectronLoginDialog.java @@ -43,7 +43,6 @@ public class BongaCamsElectronLoginDialog { throw new IOException("Couldn't wait for login dialog", e); } finally { browser.close(); - browser.release(); } } diff --git a/client/src/main/java/ctbrec/ui/sites/cam4/Cam4ElectronLoginDialog.java b/client/src/main/java/ctbrec/ui/sites/cam4/Cam4ElectronLoginDialog.java index 117849d0..5424e2ff 100644 --- a/client/src/main/java/ctbrec/ui/sites/cam4/Cam4ElectronLoginDialog.java +++ b/client/src/main/java/ctbrec/ui/sites/cam4/Cam4ElectronLoginDialog.java @@ -43,7 +43,6 @@ public class Cam4ElectronLoginDialog { throw new IOException("Couldn't wait for login dialog", e); } finally { browser.close(); - browser.release(); } } diff --git a/client/src/main/java/ctbrec/ui/sites/jasmin/LiveJasminElectronLoginDialog.java b/client/src/main/java/ctbrec/ui/sites/jasmin/LiveJasminElectronLoginDialog.java index 4efd2d23..b5191dd8 100644 --- a/client/src/main/java/ctbrec/ui/sites/jasmin/LiveJasminElectronLoginDialog.java +++ b/client/src/main/java/ctbrec/ui/sites/jasmin/LiveJasminElectronLoginDialog.java @@ -41,7 +41,6 @@ public class LiveJasminElectronLoginDialog { LOG.debug("Error while starting the browser or communication to it", e); } finally { browser.close(); - browser.release(); } }