expand systray launcher to launch both variants

Former-commit-id: aa04b2ce21
Former-commit-id: 715de42407b76f5befd30dc14dfd37fd740ca21a
This commit is contained in:
idk
2022-10-23 01:20:46 -04:00
parent 6a8797536e
commit 204baca3d6
10 changed files with 125 additions and 62 deletions

View File

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

View File

@ -501,7 +501,8 @@ public class I2PChromium extends I2PCommonBrowser {
String[] newArgs = new String[arglength + 32];
newArgs[0] = chrome;
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[3] =
"--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[30] = "--disable-sharing-hub";
if (!I2PChromiumProfileBuilder.usability) {
newArgs[31] = "--load-extension=" +
new File(I2PChromiumProfileBuilder.profileDirectory(),
"extensions/i2pchrome.js")
.getAbsolutePath() +
"," +
new File(I2PChromiumProfileBuilder.profileDirectory(),
"extensions/https-everywhere.js")
.getAbsolutePath() +
"," +
new File(I2PChromiumProfileBuilder.profileDirectory(),
"extensions/noscript.js")
.getAbsolutePath();
newArgs[31] =
"--load-extension=" +
new File(I2PChromiumProfileBuilder.profileDirectory("base"),
"extensions/i2pchrome.js")
.getAbsolutePath() +
"," +
new File(I2PChromiumProfileBuilder.profileDirectory("base"),
"extensions/https-everywhere.js")
.getAbsolutePath() +
"," +
new File(I2PChromiumProfileBuilder.profileDirectory("base"),
"extensions/noscript.js")
.getAbsolutePath();
} else {
newArgs[31] = "--load-extension=" +
new File(I2PChromiumProfileBuilder.profileDirectory(),
"extensions/i2pchrome.js")
.getAbsolutePath() +
"," +
new File(I2PChromiumProfileBuilder.profileDirectory(),
"extensions/https-everywhere.js")
.getAbsolutePath() +
"," +
new File(I2PChromiumProfileBuilder.profileDirectory(),
"extensions/jshelter.js")
.getAbsolutePath() +
"," +
new File(I2PChromiumProfileBuilder.profileDirectory(),
"extensions/localcdn.js")
.getAbsolutePath() +
"," +
new File(I2PChromiumProfileBuilder.profileDirectory(),
"extensions/ublock.js")
.getAbsolutePath();
newArgs[31] =
"--load-extension=" +
new File(I2PChromiumProfileBuilder.profileDirectory("usability"),
"extensions/i2pchrome.js")
.getAbsolutePath() +
"," +
new File(I2PChromiumProfileBuilder.profileDirectory("usability"),
"extensions/https-everywhere.js")
.getAbsolutePath() +
"," +
new File(I2PChromiumProfileBuilder.profileDirectory("usability"),
"extensions/jshelter.js")
.getAbsolutePath() +
"," +
new File(I2PChromiumProfileBuilder.profileDirectory("usability"),
"extensions/localcdn.js")
.getAbsolutePath() +
"," +
new File(I2PChromiumProfileBuilder.profileDirectory("usability"),
"extensions/ublock.js")
.getAbsolutePath();
}
if (args != null) {
if (arglength > 0) {
@ -620,7 +623,8 @@ public class I2PChromium extends I2PCommonBrowser {
public Process launchAndDetatch(int privateWindow, String[] url) {
validateUserDir();
if (waitForProxy()) {
String profileDirectory = I2PChromiumProfileBuilder.profileDirectory();
String profileDirectory = I2PChromiumProfileBuilder.profileDirectory(
I2PChromiumProfileBuilder.usabilityMode());
if (I2PChromiumProfileChecker.validateProfileDirectory(
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
*/
public static String profileDirectory() {
return profileDirectory("I2P_CHROMIUM_PROFILE", "chromium", false);
public static String profileDirectory(String base) {
return profileDirectory("I2P_CHROMIUM_PROFILE", "chromium", base, false);
}
private static String baseProfileDir(String file, String mode) {
@ -106,7 +106,7 @@ public class I2PChromiumProfileBuilder extends I2PCommonBrowser {
return runtimeDirectory("");
}
private static String usabilityMode() {
public static String usabilityMode() {
if (usability)
return "usability";
return "base";
@ -119,7 +119,7 @@ public class I2PChromiumProfileBuilder extends I2PCommonBrowser {
*/
public static boolean copyBaseProfiletoProfile() {
String baseProfile = baseProfileDirectory(usabilityMode());
String profile = profileDirectory();
String profile = profileDirectory(usabilityMode());
logger.info("Copying base profile to profile directory: " + baseProfile +
" -> " + profile);
if (baseProfile.isEmpty() || profile.isEmpty()) {

View File

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

View File

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

View File

@ -242,7 +242,7 @@ public class I2PCommonBrowser {
* @since 0.0.19
*/
protected static String profileDirectory(String envVar, String browser,
boolean app) {
String base, boolean app) {
String pd = System.getenv(envVar);
if (pd != null && !pd.isEmpty()) {
File pdf = new File(pd);
@ -251,15 +251,17 @@ public class I2PCommonBrowser {
}
}
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 = "";
if (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();
}

View File

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

View File

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

View File

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

View File

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