expand systray launcher to launch both variants

This commit is contained in:
idk
2022-10-23 01:20:46 -04:00
parent b96d79261a
commit aa04b2ce21
10 changed files with 125 additions and 62 deletions

View File

@ -1,6 +1,7 @@
package net.i2p.i2pfirefox; package net.i2p.i2pfirefox;
import java.awt.Image; import java.awt.Image;
import java.awt.Menu;
import java.awt.MenuItem; import java.awt.MenuItem;
import java.awt.PopupMenu; import java.awt.PopupMenu;
import java.awt.SystemTray; import java.awt.SystemTray;
@ -229,6 +230,9 @@ public class I2PBrowser extends I2PCommonBrowser {
if (arg.equals("-usability")) { if (arg.equals("-usability")) {
i2pBrowser.usability = true; i2pBrowser.usability = true;
} }
if (arg.equals("-strict")) {
i2pBrowser.usability = false;
}
if (arg.equals("-generic")) { if (arg.equals("-generic")) {
i2pBrowser.generic = true; i2pBrowser.generic = true;
} }
@ -307,39 +311,81 @@ public class I2PBrowser extends I2PCommonBrowser {
Image image = toolkit.getImage("icon.png"); Image image = toolkit.getImage("icon.png");
PopupMenu menu = new PopupMenu(); PopupMenu menu = new PopupMenu();
Menu submenuStrict = new Menu("Strict Mode");
MenuItem launchRegularBrowser = new MenuItem("Launch I2P Browser"); MenuItem launchRegularBrowserStrict = new MenuItem("Launch I2P Browser");
launchRegularBrowser.addActionListener(new ActionListener() { launchRegularBrowserStrict.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ArrayList<String> argsList = new ArrayList<String>(); ArrayList<String> argsList = new ArrayList<String>();
argsList.addAll(Arrays.asList(args)); argsList.addAll(Arrays.asList(args));
argsList.add("-strict");
main(argsList.toArray(args)); main(argsList.toArray(args));
} }
}); });
menu.add(launchRegularBrowser); submenuStrict.add(launchRegularBrowserStrict);
MenuItem launchPrivateBrowser = MenuItem launchPrivateBrowserStrict =
new MenuItem("Launch I2P Browser - Throwaway Session"); new MenuItem("Launch I2P Browser - Throwaway Session");
launchPrivateBrowser.addActionListener(new ActionListener() { launchPrivateBrowserStrict.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ArrayList<String> argsList = ArrayList<String> argsList =
new ArrayList<String>(Arrays.asList(new String[] {"-private"})); new ArrayList<String>(Arrays.asList(new String[] {"-private"}));
argsList.addAll(Arrays.asList(args)); argsList.addAll(Arrays.asList(args));
argsList.add("-strict");
main(argsList.toArray(args)); main(argsList.toArray(args));
} }
}); });
menu.add(launchPrivateBrowser); submenuStrict.add(launchPrivateBrowserStrict);
MenuItem launchConfigBrowser = new MenuItem("Launch I2P Console"); MenuItem launchConfigBrowserStrict = new MenuItem("Launch I2P Console");
launchConfigBrowser.addActionListener(new ActionListener() { launchConfigBrowserStrict.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ArrayList<String> argsList = new ArrayList<String>( ArrayList<String> argsList = new ArrayList<String>(
Arrays.asList(new String[] {"-app", "http://127.0.0.1:7657"})); Arrays.asList(new String[] {"-app", "http://127.0.0.1:7657"}));
argsList.addAll(Arrays.asList(args)); argsList.addAll(Arrays.asList(args));
argsList.add("-strict");
main(argsList.toArray(args)); main(argsList.toArray(args));
} }
}); });
menu.add(launchConfigBrowser); submenuStrict.add(launchConfigBrowserStrict);
menu.add(submenuStrict);
Menu submenuUsability = new Menu("Usability Mode");
MenuItem launchRegularBrowserUsability = new MenuItem("Launch I2P Browser");
launchRegularBrowserUsability.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ArrayList<String> argsList = new ArrayList<String>();
argsList.addAll(Arrays.asList(args));
argsList.add("-usability");
main(argsList.toArray(args));
}
});
submenuUsability.add(launchRegularBrowserUsability);
MenuItem launchPrivateBrowserUsability =
new MenuItem("Launch I2P Browser - Throwaway Session");
launchPrivateBrowserUsability.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ArrayList<String> argsList =
new ArrayList<String>(Arrays.asList(new String[] {"-private"}));
argsList.addAll(Arrays.asList(args));
argsList.add("-usability");
main(argsList.toArray(args));
}
});
submenuUsability.add(launchPrivateBrowserUsability);
MenuItem launchConfigBrowserUsability = new MenuItem("Launch I2P Console");
launchConfigBrowserUsability.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ArrayList<String> argsList = new ArrayList<String>(
Arrays.asList(new String[] {"-app", "http://127.0.0.1:7657"}));
argsList.addAll(Arrays.asList(args));
argsList.add("-usability");
main(argsList.toArray(args));
}
});
submenuUsability.add(launchConfigBrowserUsability);
menu.add(submenuUsability);
MenuItem closeItem = new MenuItem("Close"); MenuItem closeItem = new MenuItem("Close");
closeItem.addActionListener(new ActionListener() { closeItem.addActionListener(new ActionListener() {

View File

@ -501,7 +501,8 @@ public class I2PChromium extends I2PCommonBrowser {
String[] newArgs = new String[arglength + 32]; String[] newArgs = new String[arglength + 32];
newArgs[0] = chrome; newArgs[0] = chrome;
newArgs[1] = newArgs[1] =
"--user-data-dir=" + I2PChromiumProfileBuilder.profileDirectory(); "--user-data-dir=" + I2PChromiumProfileBuilder.profileDirectory(
I2PChromiumProfileBuilder.usabilityMode());
newArgs[2] = "--proxy-server=http://127.0.0.1:4444"; newArgs[2] = "--proxy-server=http://127.0.0.1:4444";
newArgs[3] = newArgs[3] =
"--proxy-bypass-list=http://localhost:7657,http://127.0.0.1:7657"; "--proxy-bypass-list=http://localhost:7657,http://127.0.0.1:7657";
@ -533,40 +534,42 @@ public class I2PChromium extends I2PCommonBrowser {
newArgs[29] = "--force-punycode-hostnames"; newArgs[29] = "--force-punycode-hostnames";
newArgs[30] = "--disable-sharing-hub"; newArgs[30] = "--disable-sharing-hub";
if (!I2PChromiumProfileBuilder.usability) { if (!I2PChromiumProfileBuilder.usability) {
newArgs[31] = "--load-extension=" + newArgs[31] =
new File(I2PChromiumProfileBuilder.profileDirectory(), "--load-extension=" +
"extensions/i2pchrome.js") new File(I2PChromiumProfileBuilder.profileDirectory("base"),
.getAbsolutePath() + "extensions/i2pchrome.js")
"," + .getAbsolutePath() +
new File(I2PChromiumProfileBuilder.profileDirectory(), "," +
"extensions/https-everywhere.js") new File(I2PChromiumProfileBuilder.profileDirectory("base"),
.getAbsolutePath() + "extensions/https-everywhere.js")
"," + .getAbsolutePath() +
new File(I2PChromiumProfileBuilder.profileDirectory(), "," +
"extensions/noscript.js") new File(I2PChromiumProfileBuilder.profileDirectory("base"),
.getAbsolutePath(); "extensions/noscript.js")
.getAbsolutePath();
} else { } else {
newArgs[31] = "--load-extension=" + newArgs[31] =
new File(I2PChromiumProfileBuilder.profileDirectory(), "--load-extension=" +
"extensions/i2pchrome.js") new File(I2PChromiumProfileBuilder.profileDirectory("usability"),
.getAbsolutePath() + "extensions/i2pchrome.js")
"," + .getAbsolutePath() +
new File(I2PChromiumProfileBuilder.profileDirectory(), "," +
"extensions/https-everywhere.js") new File(I2PChromiumProfileBuilder.profileDirectory("usability"),
.getAbsolutePath() + "extensions/https-everywhere.js")
"," + .getAbsolutePath() +
new File(I2PChromiumProfileBuilder.profileDirectory(), "," +
"extensions/jshelter.js") new File(I2PChromiumProfileBuilder.profileDirectory("usability"),
.getAbsolutePath() + "extensions/jshelter.js")
"," + .getAbsolutePath() +
new File(I2PChromiumProfileBuilder.profileDirectory(), "," +
"extensions/localcdn.js") new File(I2PChromiumProfileBuilder.profileDirectory("usability"),
.getAbsolutePath() + "extensions/localcdn.js")
"," + .getAbsolutePath() +
new File(I2PChromiumProfileBuilder.profileDirectory(), "," +
"extensions/ublock.js") new File(I2PChromiumProfileBuilder.profileDirectory("usability"),
.getAbsolutePath(); "extensions/ublock.js")
.getAbsolutePath();
} }
if (args != null) { if (args != null) {
if (arglength > 0) { if (arglength > 0) {
@ -620,7 +623,8 @@ public class I2PChromium extends I2PCommonBrowser {
public Process launchAndDetatch(int privateWindow, String[] url) { public Process launchAndDetatch(int privateWindow, String[] url) {
validateUserDir(); validateUserDir();
if (waitForProxy()) { if (waitForProxy()) {
String profileDirectory = I2PChromiumProfileBuilder.profileDirectory(); String profileDirectory = I2PChromiumProfileBuilder.profileDirectory(
I2PChromiumProfileBuilder.usabilityMode());
if (I2PChromiumProfileChecker.validateProfileDirectory( if (I2PChromiumProfileChecker.validateProfileDirectory(
profileDirectory)) { profileDirectory)) {
logger.info("Valid profile directory: " + profileDirectory); logger.info("Valid profile directory: " + profileDirectory);

View File

@ -28,8 +28,8 @@ public class I2PChromiumProfileBuilder extends I2PCommonBrowser {
* *
* @return the profile directory, or null if it could not be created * @return the profile directory, or null if it could not be created
*/ */
public static String profileDirectory() { public static String profileDirectory(String base) {
return profileDirectory("I2P_CHROMIUM_PROFILE", "chromium", false); return profileDirectory("I2P_CHROMIUM_PROFILE", "chromium", base, false);
} }
private static String baseProfileDir(String file, String mode) { private static String baseProfileDir(String file, String mode) {
@ -106,7 +106,7 @@ public class I2PChromiumProfileBuilder extends I2PCommonBrowser {
return runtimeDirectory(""); return runtimeDirectory("");
} }
private static String usabilityMode() { public static String usabilityMode() {
if (usability) if (usability)
return "usability"; return "usability";
return "base"; return "base";
@ -119,7 +119,7 @@ public class I2PChromiumProfileBuilder extends I2PCommonBrowser {
*/ */
public static boolean copyBaseProfiletoProfile() { public static boolean copyBaseProfiletoProfile() {
String baseProfile = baseProfileDirectory(usabilityMode()); String baseProfile = baseProfileDirectory(usabilityMode());
String profile = profileDirectory(); String profile = profileDirectory(usabilityMode());
logger.info("Copying base profile to profile directory: " + baseProfile + logger.info("Copying base profile to profile directory: " + baseProfile +
" -> " + profile); " -> " + profile);
if (baseProfile.isEmpty() || profile.isEmpty()) { if (baseProfile.isEmpty() || profile.isEmpty()) {

View File

@ -27,7 +27,8 @@ public class I2PChromiumProfileChecker extends I2PCommonBrowser {
* @since 0.0.1 * @since 0.0.1
*/ */
public static void main(String[] args) { public static void main(String[] args) {
String profileDirectory = I2PChromiumProfileBuilder.profileDirectory(); String profileDirectory =
I2PChromiumProfileBuilder.profileDirectory("base");
if (profileDirectory == null) { if (profileDirectory == null) {
logger.info("No profile directory found"); logger.info("No profile directory found");
return; return;

View File

@ -21,7 +21,8 @@ package net.i2p.i2pfirefox;
public class I2PChromiumProfileUnpacker extends I2PCommonBrowser { public class I2PChromiumProfileUnpacker extends I2PCommonBrowser {
public static void main(String[] args) { public static void main(String[] args) {
String profileDirectory = I2PChromiumProfileBuilder.profileDirectory(); String profileDirectory =
I2PChromiumProfileBuilder.profileDirectory("base");
if (profileDirectory == null) { if (profileDirectory == null) {
logger.info("No profile directory found"); logger.info("No profile directory found");
return; return;

View File

@ -242,7 +242,7 @@ public class I2PCommonBrowser {
* @since 0.0.19 * @since 0.0.19
*/ */
protected static String profileDirectory(String envVar, String browser, protected static String profileDirectory(String envVar, String browser,
boolean app) { String base, boolean app) {
String pd = System.getenv(envVar); String pd = System.getenv(envVar);
if (pd != null && !pd.isEmpty()) { if (pd != null && !pd.isEmpty()) {
File pdf = new File(pd); File pdf = new File(pd);
@ -251,15 +251,17 @@ public class I2PCommonBrowser {
} }
} }
String rtd = runtimeDirectory(""); String rtd = runtimeDirectory("");
return profileDir(rtd, browser, app); return profileDir(rtd, browser, base, app);
} }
protected static String profileDir(String file, String browser, boolean app) { protected static String profileDir(String file, String browser, String base,
boolean app) {
String appString = ""; String appString = "";
if (app) { if (app) {
appString = ".app"; appString = ".app";
} }
File profileDir = new File(file, "i2p." + browser + ".profile" + appString); File profileDir =
new File(file, "i2p." + browser + ".profile." + base + appString);
return profileDir.getAbsolutePath(); return profileDir.getAbsolutePath();
} }

View File

@ -32,6 +32,12 @@ public class I2PFirefox extends I2PCommonBrowser {
private Process p = null; private Process p = null;
public static boolean usability = false; public static boolean usability = false;
private static String baseMode() {
if (usability)
return "usability";
return "base";
}
/** /**
* Construct an I2PFirefox class which manages an instance of Firefox and * Construct an I2PFirefox class which manages an instance of Firefox and
* an accompanying Firefox profile. This version includes Firefox variants * an accompanying Firefox profile. This version includes Firefox variants
@ -574,7 +580,7 @@ public class I2PFirefox extends I2PCommonBrowser {
newArgs[0] = firefox; newArgs[0] = firefox;
newArgs[1] = "--new-instance"; newArgs[1] = "--new-instance";
newArgs[2] = "--profile"; newArgs[2] = "--profile";
newArgs[3] = I2PFirefoxProfileBuilder.profileDirectory(app); newArgs[3] = I2PFirefoxProfileBuilder.profileDirectory(app, baseMode());
if (args != null) { if (args != null) {
if (arglength > 0) { if (arglength > 0) {
for (int i = 0; i < arglength; i++) { for (int i = 0; i < arglength; i++) {
@ -639,7 +645,8 @@ public class I2PFirefox extends I2PCommonBrowser {
if (privateWindow == 2) if (privateWindow == 2)
app = true; app = true;
if (waitForProxy()) { if (waitForProxy()) {
String profileDirectory = I2PFirefoxProfileBuilder.profileDirectory(app); String profileDirectory =
I2PFirefoxProfileBuilder.profileDirectory(app, baseMode());
if (I2PFirefoxProfileChecker.validateProfileDirectory(profileDirectory)) { if (I2PFirefoxProfileChecker.validateProfileDirectory(profileDirectory)) {
logger.info("Valid profile directory: " + profileDirectory); logger.info("Valid profile directory: " + profileDirectory);
} else { } else {

View File

@ -107,8 +107,8 @@ public class I2PFirefoxProfileBuilder extends I2PCommonBrowser {
* *
* @return the profile directory, or null if it could not be created * @return the profile directory, or null if it could not be created
*/ */
public static String profileDirectory(boolean app) { public static String profileDirectory(boolean app, String base) {
return profileDirectory("I2P_FIREFOX_PROFILE", "firefox", app); return profileDirectory("I2P_FIREFOX_PROFILE", "firefox", base, app);
} }
private static String baseProfileDir(String file, String base) { private static String baseProfileDir(String file, String base) {
@ -188,7 +188,7 @@ public class I2PFirefoxProfileBuilder extends I2PCommonBrowser {
*/ */
public static boolean copyBaseProfiletoProfile(String base, boolean app) { public static boolean copyBaseProfiletoProfile(String base, boolean app) {
String baseProfile = baseProfileDirectory(base); String baseProfile = baseProfileDirectory(base);
String profile = profileDirectory(app); String profile = profileDirectory(app, base);
logger.info("Copying base profile to profile directory: " + baseProfile + logger.info("Copying base profile to profile directory: " + baseProfile +
" -> " + profile); " -> " + profile);
if (baseProfile.isEmpty() || profile.isEmpty()) { if (baseProfile.isEmpty() || profile.isEmpty()) {
@ -250,7 +250,7 @@ public class I2PFirefoxProfileBuilder extends I2PCommonBrowser {
public static boolean copyStrictOptions(String base, boolean app) { public static boolean copyStrictOptions(String base, boolean app) {
logger.info("Checking strict options"); logger.info("Checking strict options");
String baseProfile = baseProfileDirectory(base); String baseProfile = baseProfileDirectory(base);
String profile = profileDirectory(app); String profile = profileDirectory(app, base);
if (baseProfile.isEmpty() || profile.isEmpty()) { if (baseProfile.isEmpty() || profile.isEmpty()) {
logger.info("Empty paths"); logger.info("Empty paths");
return false; return false;

View File

@ -30,7 +30,8 @@ public class I2PFirefoxProfileChecker extends I2PCommonBrowser {
* @param args unused * @param args unused
*/ */
public static void main(String[] args) { public static void main(String[] args) {
String profileDirectory = I2PFirefoxProfileBuilder.profileDirectory(false); String profileDirectory =
I2PFirefoxProfileBuilder.profileDirectory(false, "base");
if (profileDirectory == null) { if (profileDirectory == null) {
logger.info("No profile directory found"); logger.info("No profile directory found");
return; return;

View File

@ -21,7 +21,8 @@ package net.i2p.i2pfirefox;
public class I2PFirefoxProfileUnpacker extends I2PCommonBrowser { public class I2PFirefoxProfileUnpacker extends I2PCommonBrowser {
public static void main(String[] args) { public static void main(String[] args) {
String profileDirectory = I2PFirefoxProfileBuilder.profileDirectory(false); String profileDirectory =
I2PFirefoxProfileBuilder.profileDirectory(false, "base");
if (profileDirectory == null) { if (profileDirectory == null) {
logger.info("No profile directory found"); logger.info("No profile directory found");
return; return;