From ac3d5a34fbafbc91d0391f7d68a0e2653bd05be7 Mon Sep 17 00:00:00 2001 From: idk Date: Sun, 21 Aug 2022 21:17:28 -0400 Subject: [PATCH] Universal launcher class, launches first available Firefox->Chrome --- i2pbrowser-private.cmd | 3 + i2pbrowser.cmd | 3 + release.sh | 4 +- src/java/net/i2p/i2pfirefox/I2PBrowser.java | 120 ++++++++++++++++++++ 4 files changed, 128 insertions(+), 2 deletions(-) create mode 100755 i2pbrowser-private.cmd create mode 100755 i2pbrowser.cmd create mode 100644 src/java/net/i2p/i2pfirefox/I2PBrowser.java diff --git a/i2pbrowser-private.cmd b/i2pbrowser-private.cmd new file mode 100755 index 0000000..ef9f21b --- /dev/null +++ b/i2pbrowser-private.cmd @@ -0,0 +1,3 @@ +:; dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd); java -cp "$dir"/src/build/i2pfirefox.jar net.i2p.i2pfirefox.I2PBrowser -private; exit $? +@ECHO OFF +java -cp %cd%/src/build/i2pfirefox.jar net.i2p.i2pfirefox.I2PBrowser -private \ No newline at end of file diff --git a/i2pbrowser.cmd b/i2pbrowser.cmd new file mode 100755 index 0000000..d9ebf3a --- /dev/null +++ b/i2pbrowser.cmd @@ -0,0 +1,3 @@ +:; dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd); java -cp "$dir"/src/build/i2pfirefox.jar net.i2p.i2pfirefox.I2PBrowser; exit $? +@ECHO OFF +java -cp %cd%/src/build/i2pfirefox.jar net.i2p.i2pfirefox.I2PBrowser \ No newline at end of file diff --git a/release.sh b/release.sh index b2e5693..3d2d1bc 100755 --- a/release.sh +++ b/release.sh @@ -2,9 +2,9 @@ GITHUB_USER=eyedeekay GITHUB_REPO=i2p.plugins.firefox -GITHUB_NAME="Which adds the ability to pass the -private flag to the command line to launch a private browser instance." +GITHUB_NAME="Which adds a launcher that automatically chooses the first available browser starting from Firefox" GITHUB_DESCRIPTION=$(cat CHANGES.md) -GITHUB_TAG=0.0.15 +GITHUB_TAG=0.0.16 ant distclean ant jar freeZip github-release release --user "${GITHUB_USER}" \ diff --git a/src/java/net/i2p/i2pfirefox/I2PBrowser.java b/src/java/net/i2p/i2pfirefox/I2PBrowser.java new file mode 100644 index 0000000..7ef9c92 --- /dev/null +++ b/src/java/net/i2p/i2pfirefox/I2PBrowser.java @@ -0,0 +1,120 @@ +package net.i2p.i2pfirefox; + + +public class I2PBrowser { + private final I2PFirefox i2pFirefox = new I2PFirefox(); + private final I2PChromium i2pChromium = new I2PChromium(); + public static boolean firefox = false; + public static boolean chromium = false; + + private void launchFirefox(boolean privateWindow) { + System.out.println("I2PFirefox"); + i2pFirefox.launch(privateWindow); + } + private void launchChromium(boolean privateWindow) { + System.out.println("I2PChromium"); + i2pChromium.launch(privateWindow); + } + + /* + * Construct an I2PBrowser class which manages an instance of Chromium and + * an accompanying Chromium profile. This version includes Chromium variants + * and forks. + * + * @since 0.0.16 + */ + public I2PBrowser() { + } + + /* + * Return true if there is a Chromium available + * + * @return true if Chromium is available, false otherwise + * @since 0.0.16 + */ + public boolean hasChromium() { + String chrome = i2pChromium.topChromium(); + if (chrome == null) { + return false; + } + if (chrome.isEmpty()) { + return false; + } + return true; + } + + /* + * Return true if there is a Firefox variant available + * + * @return true if Firefox variant is available, false otherwise + * @since 0.0.16 + */ + public boolean hasFirefox() { + String fox = i2pFirefox.topFirefox(); + if (fox == null) { + return false; + } + if (fox.isEmpty()) { + return false; + } + return true; + } + + /* + * Populates a profile directory with a proxy configuration. + * Waits for an HTTP proxy on the port 4444 to be ready. + * Launches Chromium with the profile directory. + * + * @param bool if true, the profile will be ephemeral(i.e. a --private-window profile). + * @since 0.0.16 + */ + public void launch(boolean privateWindow){ + if ((chromium && firefox) || (!chromium && !firefox)) { + if (this.hasFirefox()) { + this.launchFirefox(privateWindow); + } else if (this.hasChromium()) { + this.launchChromium(privateWindow); + } + } + if (firefox) { + this.launchFirefox(privateWindow); + return; + } + if (chromium) { + this.launchChromium(privateWindow); + return; + } + } + + /* + * Populates a profile directory with a proxy configuration. + * Waits for an HTTP proxy on the port 4444 to be ready. + * Launches Chromium with the profile directory. + * + * @since 0.0.16 + */ + public void launch(){ + launch(false); + } + + public static void main(String[] args) { + boolean privateBrowsing = false; + if (args != null && args.length > 0) { + for (String arg : args) { + if (arg.equals("-private")) { + privateBrowsing = true; + } + if (arg.equals("-chromium")) { + chromium = true; + } + if (arg.equals("-firefox")) { + firefox = true; + } + } + } + System.out.println("I2PBrowser"); + I2PBrowser I2PBrowser = new I2PBrowser(); + I2PBrowser.launch(privateBrowsing); + } + +} \ No newline at end of file