diff --git a/src/java/net/i2p/i2pfirefox/I2PChromium.java b/src/java/net/i2p/i2pfirefox/I2PChromium.java index 9b04343..2375946 100644 --- a/src/java/net/i2p/i2pfirefox/I2PChromium.java +++ b/src/java/net/i2p/i2pfirefox/I2PChromium.java @@ -22,6 +22,7 @@ import java.util.ArrayList; public class I2PChromium { private final String[] CHROMIUM_SEARCH_PATHS = CHROMIUM_FINDER(); private final int DEFAULT_TIMEOUT = 200; + private Process p = null; /** * Construct an I2PChromium class which manages an instance of Chromium and @@ -467,6 +468,38 @@ public class I2PChromium { } + public Process launchAndDetatch(boolean privateWindow, String[] url){ + if (waitForProxy()) { + String profileDirectory = I2PChromiumProfileBuilder.profileDirectory(); + if (I2PChromiumProfileChecker.validateProfileDirectory(profileDirectory)) { + System.out.println("Valid profile directory: "+profileDirectory); + } else { + System.out.println("Invalid profile directory: "+profileDirectory+" rebuilding..."); + if (!I2PChromiumProfileBuilder.copyBaseProfiletoProfile()) { + System.out.println("Failed to rebuild profile directory: "+profileDirectory); + return null; + } else { + System.out.println("Rebuilt profile directory: "+profileDirectory); + } + } + ProcessBuilder pb = null; + if (privateWindow) { + pb = this.privateProcessBuilder(url); + } else { + pb = this.defaultProcessBuilder(url); + } + try{ + System.out.println(pb.command()); + p = pb.start(); + sleep(2000); + return p; + }catch(Throwable e){ + System.out.println(e); + } + } + return null; + } + /** * Populates a profile directory with a proxy configuration. * Waits for an HTTP proxy on the port 4444 to be ready. @@ -477,42 +510,19 @@ public class I2PChromium { * @since 0.0.17 */ public void launch(boolean privateWindow, String[] url){ - String profileDirectory = I2PChromiumProfileBuilder.profileDirectory(); - if (I2PChromiumProfileChecker.validateProfileDirectory(profileDirectory)) { - System.out.println("Valid profile directory: "+profileDirectory); - } else { - System.out.println("Invalid profile directory: "+profileDirectory+" rebuilding..."); - if (!I2PChromiumProfileBuilder.copyBaseProfiletoProfile()) { - System.out.println("Failed to rebuild profile directory: "+profileDirectory); - return; - } else { - System.out.println("Rebuilt profile directory: "+profileDirectory); - } - } - if (waitForProxy()){ - ProcessBuilder pb = null; - if (privateWindow) { - pb = this.privateProcessBuilder(url); - } else { - pb = this.defaultProcessBuilder(url); - } + if (waitForProxy()) { + p = launchAndDetatch(privateWindow, url); + System.out.println("I2PChromium"); try{ - System.out.println(pb.command()); - Process p = pb.start(); - sleep(2000); - System.out.println("I2PChromium"); - try{ - System.out.println("Waiting for I2PChromium to close..."); - int exit = p.waitFor(); - System.out.println("I2PChromium exited with value: "+exit); - }catch(Exception e){ - System.out.println("Error: "+e.getMessage()); - } + System.out.println("Waiting for I2PChromium to close..."); + int exit = p.waitFor(); + System.out.println("I2PChromium exited with value: "+exit); }catch(Exception e){ System.out.println("Error: "+e.getMessage()); } } } + /** * Populates a profile directory with a proxy configuration. * Waits for an HTTP proxy on the port 4444 to be ready. diff --git a/src/java/net/i2p/i2pfirefox/I2PFirefox.java b/src/java/net/i2p/i2pfirefox/I2PFirefox.java index e98df81..211db9c 100644 --- a/src/java/net/i2p/i2pfirefox/I2PFirefox.java +++ b/src/java/net/i2p/i2pfirefox/I2PFirefox.java @@ -22,6 +22,7 @@ import java.util.ArrayList; public class I2PFirefox { private final String[] FIREFOX_SEARCH_PATHS = FIREFOX_FINDER(); private final int DEFAULT_TIMEOUT = 200; + private Process p = null; /** * Construct an I2PFirefox class which manages an instance of Firefox and @@ -429,6 +430,40 @@ public class I2PFirefox { } } + + public Process launchAndDetatch(boolean privateWindow, String[] url){ + if (waitForProxy()){ + String profileDirectory = I2PFirefoxProfileBuilder.profileDirectory(); + if (I2PFirefoxProfileChecker.validateProfileDirectory(profileDirectory)) { + System.out.println("Valid profile directory: "+profileDirectory); + } else { + System.out.println("Invalid profile directory: "+profileDirectory+" rebuilding..."); + if (!I2PFirefoxProfileBuilder.copyBaseProfiletoProfile()) { + System.out.println("Failed to rebuild profile directory: "+profileDirectory); + return null; + } else { + System.out.println("Rebuilt profile directory: "+profileDirectory); + } + } + ProcessBuilder pb; + if (privateWindow) { + pb = privateProcessBuilder(url); + } else { + pb = defaultProcessBuilder(url); + } + try{ + System.out.println(pb.command()); + p = pb.start(); + System.out.println("I2PFirefox"); + sleep(2000); + return p; + }catch(Throwable e){ + System.out.println(e); + } + } + return null; + } + /** * Populates a profile directory with a proxy configuration. * Waits for an HTTP proxy on the port 4444 to be ready. @@ -439,37 +474,12 @@ public class I2PFirefox { * @since 0.0.17 */ public void launch(boolean privateWindow, String[] url){ - String profileDirectory = I2PFirefoxProfileBuilder.profileDirectory(); - if (I2PFirefoxProfileChecker.validateProfileDirectory(profileDirectory)) { - System.out.println("Valid profile directory: "+profileDirectory); - } else { - System.out.println("Invalid profile directory: "+profileDirectory+" rebuilding..."); - if (!I2PFirefoxProfileBuilder.copyBaseProfiletoProfile()) { - System.out.println("Failed to rebuild profile directory: "+profileDirectory); - return; - } else { - System.out.println("Rebuilt profile directory: "+profileDirectory); - } - } if (waitForProxy()){ - ProcessBuilder pb; - if (privateWindow) { - pb = privateProcessBuilder(url); - } else { - pb = defaultProcessBuilder(url); - } + p = launchAndDetatch(privateWindow, url); try{ - System.out.println(pb.command()); - Process p = pb.start(); - System.out.println("I2PFirefox"); - sleep(2000); - try{ - System.out.println("Waiting for I2PFirefox to close..."); - int exit = p.waitFor(); - System.out.println("I2PFirefox exited with value: "+exit); - }catch(Exception e){ - System.out.println("Error: "+e.getMessage()); - } + System.out.println("Waiting for I2PFirefox to close..."); + int exit = p.waitFor(); + System.out.println("I2PFirefox exited with value: "+exit); }catch(Exception e){ System.out.println("Error: "+e.getMessage()); } diff --git a/src/java/net/i2p/i2pfirefox/I2PGenericUnsafeBrowser.java b/src/java/net/i2p/i2pfirefox/I2PGenericUnsafeBrowser.java index 7cb6abf..a00517f 100644 --- a/src/java/net/i2p/i2pfirefox/I2PGenericUnsafeBrowser.java +++ b/src/java/net/i2p/i2pfirefox/I2PGenericUnsafeBrowser.java @@ -29,6 +29,7 @@ import java.util.Scanner; public class I2PGenericUnsafeBrowser { private final int DEFAULT_TIMEOUT = 200; public static String BROWSER = ""; + private Process p = null; // Ideally, EVERY browser in this list should honor http_proxy, https_proxy, ftp_proxy and no_proxy. // in practice, this is going to be hard to guarantee. For now, we're just assuming. So don't use this until // I understand the situation better, unless you think you know better. @@ -350,7 +351,7 @@ public class I2PGenericUnsafeBrowser { } - public void launch(boolean privateWindow, String[] url){ + public Process launchAndDetatch(boolean privateWindow, String[] url){ if (waitForProxy()){ ProcessBuilder pb; if (privateWindow) { @@ -360,25 +361,34 @@ public class I2PGenericUnsafeBrowser { } try{ System.out.println(pb.command()); - Process p = pb.start(); + p = pb.start(); System.out.println("I2PBrowser"); sleep(2000); - try{ - System.out.println("Waiting for I2PBrowser to close..."); - int exit = p.waitFor(); - if (privateWindow){ - if (deleteRuntimeDirectory()) - System.out.println("Private browsing enforced, deleting runtime directory"); - } - System.out.println("I2PBrowser exited with value: "+exit); - }catch(Exception e){ - System.out.println("Error: "+e.getMessage()); + return p; + }catch(Throwable e) { + System.out.println(e); + } + } + return null; + } + + public void launch(boolean privateWindow, String[] url){ + if (waitForProxy()){ + p = launchAndDetatch(privateWindow, url); + try{ + System.out.println("Waiting for I2PBrowser to close..."); + int exit = p.waitFor(); + if (privateWindow){ + if (deleteRuntimeDirectory()) + System.out.println("Private browsing enforced, deleting runtime directory"); } + System.out.println("I2PBrowser exited with value: "+exit); }catch(Exception e){ System.out.println("Error: "+e.getMessage()); } } } + private static void sleep(int millis) { try { Thread.sleep(millis);