Don't use as many static variables in I2pBrowser.Java, fully enable usage as a console plugin

This commit is contained in:
idk
2022-12-19 00:28:44 +00:00
parent 25e565d2fb
commit 420d034fa2
5 changed files with 65 additions and 33 deletions

Binary file not shown.

View File

@ -1,6 +1,6 @@
clientApp.0.main=net.i2p.i2pfirefox.I2PBrowser clientApp.0.main=net.i2p.i2pfirefox.I2PBrowser
clientApp.0.name=I2PBrowser clientApp.0.name=I2PBrowser
clientApp.0.delay=15 clientApp.0.delay=0
clientApp.0.startOnLoad=true clientApp.0.startOnLoad=true
# we also use i2p.jar and i2ptunnel.jar, they are in the standard router classpath # we also use i2p.jar and i2ptunnel.jar, they are in the standard router classpath
clientApp.0.classpath=$PLUGIN/lib/i2pfirefox.jar,$I2P/lib/i2psnark.jar clientApp.0.classpath=$PLUGIN/lib/i2pfirefox.jar,$I2P/lib/i2psnark.jar

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Sun Dec 18 23:17:23 UTC 2022 #Mon Dec 19 00:25:16 UTC 2022
build.number=213 build.number=234

View File

@ -6,8 +6,8 @@ consoleLinkTooltip=Firefox process manager for I2P
icon-code=iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABm1BMVEUAAAAZGRkZGRkaGhoZGRkZGRkZGRkZGRkYGBgZGRkYGBgZGRkYGBgZGRkZGRkXFxcYGBgZGRkZGRkZGRkZGRkAAAAZGRnziRYTExPzfhbzbhbzdxbzgxbzlRYLCwvzjhbzcxbMzMzzkBb~~~~~~Pl0dHRdXV3GxsYnJyfe3t7OycbBwcGcnJyHh4cjEgP39~f96dSurq5~f397e3tra2tlZWU7OzseHh7haRSGSAsOBwGpqKeWlpbgpnRUVFRNTU00NDTxmynPbRJwNgpXLwdEJQY4IAUVCwLy8vL83sK7u7uysrL7yqf6v5Tdr4H4t3H4rGz2pEvnjUnqnkQvLy~zii30gyjxdCLqdhXLexK9bhGQTQ1-QAtlLgn-9u~Pxr7Uvqr71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95VOcKGOb2I5NqklaBOZkN589ritlJmYDMvII4iSBW2f9iErxt63GlgkURZDAzigkmtXOHeQNaNXjLAYGhy1sASJjCZ7iiqwbnRhcgoup1pHiyCgiVktMMsI-N428G0C0UVogl1E5kWOdQQmV8xrIkhwsXgFqZu8DnG-oop8CBVzTLolOJI1gjxEVq5yxlFFjBdtgIRlocYBSciTVf0cVOTs7qOAjqLCTnCwLLZzepENbn79-JYP39IEwttBThrZ5IwNx2FNIM7z8gvZ5jMMX8NDIEAXcRgHGbYi0O~LFfwGFpGmcRnznTyGbMJv7Ft4mabRAxsJL7VSxpFtrsPwIww3QhM9zSjxir1AyD70sRpMwFZuYYdpYI~vY~uIwE5SpoepAQS64iLw-98E7rMsQvnXKEgFvAQubSLb9MHwI1yQhKrzKy37EhblJrJNLwzfmz6~0upYDJDIPmSTsQ-0aGIRsOKzkVYGg8H3yB7jX4KUOSzzCPjD0rm99hnZ4sbDNspaPAcO-PSnLTLYa-ckbmjP7FxEpk-bXt7k8c-~GffeCV1wC-fBAX~x8z7dX3HmJ-uGl3Eny5734gIjilXruAMlzOEoLzA0vDSVeBhZ8DRk5DtLYXNpkZWKdFsJiAZu4RQrssrKvGTCQsH4si7FB1iZZ1JoDuBhq9OvcxRPskLTtNRN4Zz5~aMzx~wXPBbFdhj3Ryt58GMHd-nFtpkP0SzOSWX3TxtnbRBPR1m5X6nhyEciaonEO17UDG5H8rzhqNjyyHIO44FhuViAbt6X8Uhn5ZYHqG8WmER4GuN-dWhEYq4Ull7txXG2izdd3nobbZ8sF8LJBGZE4JcY6CrYavsAt98lcA0kLb8ZCofDw8sSor4DLqfbVutbZd76Nvrc~6P51tt~v97-t1i3~38A57d5M52iLPcAAAAASUVORK5CYII=
description=Firefox process manager for I2P description=Firefox process manager for I2P
author=idk author=idk
updateURL=/i2psnark/i2p.plugins.firefox/plugins/i2pfirefox-update.xpi2p updateURL=/i2psnark/i2p.plugins.firefox/i2pfirefox-update.xpi2p
updateURL.su3=/i2psnark/i2p.plugins.firefox/plugins/i2pfirefox-update.su3 updateURL.su3=/i2psnark/i2p.plugins.firefox/i2pfirefox-update.su3
websiteURL=http://idk.i2p/i2p.plugins.firefox/ websiteURL=http://idk.i2p/i2p.plugins.firefox/
license=Apache 2.0 license=Apache 2.0
min-jetty-version=9 min-jetty-version=9

View File

@ -17,7 +17,9 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import net.i2p.I2PAppContext;
import net.i2p.app.ClientApp; import net.i2p.app.ClientApp;
import net.i2p.app.ClientAppManager;
import net.i2p.app.ClientAppState; import net.i2p.app.ClientAppState;
/** /**
@ -43,11 +45,15 @@ public class I2PBrowser extends I2PCommonBrowser implements ClientApp {
private final I2PChromium i2pChromium = new I2PChromium(); private final I2PChromium i2pChromium = new I2PChromium();
private final I2PGenericUnsafeBrowser i2pGeneral = private final I2PGenericUnsafeBrowser i2pGeneral =
new I2PGenericUnsafeBrowser(); new I2PGenericUnsafeBrowser();
private final SystemTray tray = initTray();
private final TrayIcon icon = initIcon();
private final PopupMenu menu = initMenu();
public boolean firefox = false; public boolean firefox = false;
public boolean chromium = false; public boolean chromium = false;
public boolean generic = false; public boolean generic = false;
public boolean chromiumFirst = false; public boolean chromiumFirst = false;
public boolean usability = false; public boolean usability = false;
public int privateBrowsing = 0;
static private boolean outputConfig = false; static private boolean outputConfig = false;
static private boolean useSystray = true; static private boolean useSystray = true;
@ -92,6 +98,8 @@ public class I2PBrowser extends I2PCommonBrowser implements ClientApp {
public I2PBrowser(String browserPath) { public I2PBrowser(String browserPath) {
I2PGenericUnsafeBrowser.BROWSER = browserPath; I2PGenericUnsafeBrowser.BROWSER = browserPath;
} }
public I2PBrowser(I2PAppContext context, ClientAppManager listener,
String[] args) {}
public void setBrowser(String browserPath) { public void setBrowser(String browserPath) {
I2PGenericUnsafeBrowser.BROWSER = browserPath; I2PGenericUnsafeBrowser.BROWSER = browserPath;
@ -212,34 +220,37 @@ public class I2PBrowser extends I2PCommonBrowser implements ClientApp {
} }
public static void main(String[] args) { public static void main(String[] args) {
I2PBrowser i2pBrowser = new I2PBrowser();
i2pBrowser.startup(args);
}
public ArrayList<String> parseArgs(String[] args) {
validateUserDir(); validateUserDir();
int privateBrowsing = 0; int privateBrowsing = 0;
logger.info("I2PBrowser"); logger.info("I2PBrowser");
I2PBrowser i2pBrowser = new I2PBrowser();
ArrayList<String> visitURL = new ArrayList<String>(); ArrayList<String> visitURL = new ArrayList<String>();
if (args != null) { if (args != null) {
if (args.length > 0) { if (args.length > 0) {
for (String arg : args) { for (String arg : args) {
if (arg.equals("-private")) { if (arg.equals("-private")) {
privateBrowsing = 1; this.privateBrowsing = 1;
} }
if (arg.equals("-chromium")) { if (arg.equals("-chromium")) {
i2pBrowser.chromium = true; this.chromium = true;
} }
if (arg.equals("-firefox")) { if (arg.equals("-firefox")) {
i2pBrowser.firefox = true; this.firefox = true;
} }
if (arg.equals("-usability")) { if (arg.equals("-usability")) {
i2pBrowser.usability = true; this.usability = true;
} }
if (arg.equals("-strict")) { if (arg.equals("-strict")) {
i2pBrowser.usability = false; this.usability = false;
} }
if (arg.equals("-generic")) { if (arg.equals("-generic")) {
i2pBrowser.generic = true; this.generic = true;
} }
if (arg.equals("-app")) { if (arg.equals("-app")) {
i2pBrowser.usability = true; this.usability = true;
privateBrowsing = 2; privateBrowsing = 2;
} }
if (arg.equals("-outputconfig")) { if (arg.equals("-outputconfig")) {
@ -250,7 +261,7 @@ public class I2PBrowser extends I2PCommonBrowser implements ClientApp {
} }
if (arg.equals("-noproxycheck")) { if (arg.equals("-noproxycheck")) {
logger.info("zeroing out proxy check"); logger.info("zeroing out proxy check");
i2pBrowser.setProxyTimeoutTime(0); this.setProxyTimeoutTime(0);
} }
if (!arg.startsWith("-")) { if (!arg.startsWith("-")) {
visitURL.add(ValidURL(arg)); visitURL.add(ValidURL(arg));
@ -258,6 +269,10 @@ public class I2PBrowser extends I2PCommonBrowser implements ClientApp {
} }
} }
} }
return visitURL;
}
public void startup(String[] args) {
ArrayList<String> visitURL = parseArgs(args);
try { try {
if (useSystray) { if (useSystray) {
logger.info("Starting systray"); logger.info("Starting systray");
@ -272,8 +287,8 @@ public class I2PBrowser extends I2PCommonBrowser implements ClientApp {
} catch (Exception e) { } catch (Exception e) {
logger.warning(e.toString()); logger.warning(e.toString());
} }
i2pBrowser.launch(privateBrowsing, this.launch(this.privateBrowsing,
visitURL.toArray(new String[visitURL.size()])); visitURL.toArray(new String[visitURL.size()]));
} }
private static boolean systrayIsRunningExternally() { private static boolean systrayIsRunningExternally() {
File systrayIsRunningFile = File systrayIsRunningFile =
@ -292,35 +307,51 @@ public class I2PBrowser extends I2PCommonBrowser implements ClientApp {
} }
return false; return false;
} }
private static void shutdownSystray() { private void shutdownSystray() {
File systrayIsRunningFile = File systrayIsRunningFile =
new File(runtimeDirectory(""), "systray.running"); new File(runtimeDirectory(""), "systray.running");
if (systrayIsRunningFile.exists()) if (systrayIsRunningFile.exists())
systrayIsRunningFile.delete(); systrayIsRunningFile.delete();
tray.remove(icon);
} }
public static boolean systray(String[] args) throws Exception { private SystemTray initTray() {
if (systrayIsRunningExternally()) { if (systrayIsRunningExternally()) {
return false; return null;
} }
if (!SystemTray.isSupported()) { if (!SystemTray.isSupported()) {
logger.warning("SystemTray is not supported"); logger.warning("SystemTray is not supported");
return false; return null;
} }
return SystemTray.getSystemTray();
}
SystemTray tray = SystemTray.getSystemTray(); private PopupMenu initMenu() {
Toolkit toolkit = Toolkit.getDefaultToolkit(); PopupMenu menu = new PopupMenu();
return menu;
}
private TrayIcon initIcon() {
File iconFile = new File(runtimeDirectory(""), "icon.png"); File iconFile = new File(runtimeDirectory(""), "icon.png");
if (!iconFile.exists()) { if (!iconFile.exists()) {
InputStream resources = InputStream resources =
I2PBrowser.class.getClassLoader().getResourceAsStream("icon.png"); I2PBrowser.class.getClassLoader().getResourceAsStream("icon.png");
OutputStream fos = new FileOutputStream(iconFile); try {
copy(resources, fos); OutputStream fos = new FileOutputStream(iconFile);
copy(resources, fos);
} catch (IOException e) {
logger.warning(e.toString());
}
} }
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image image = toolkit.getImage("icon.png"); Image image = toolkit.getImage("icon.png");
PopupMenu menu = new PopupMenu();
TrayIcon icon = new TrayIcon(image, "I2P Browser Profile Controller", menu); TrayIcon icon = new TrayIcon(image, "I2P Browser Profile Controller", menu);
icon.setImageAutoSize(true); icon.setImageAutoSize(true);
return icon;
}
public boolean systray(String[] args) throws Exception {
if (tray == null)
throw new Exception("System Tray is Null Exception");
tray.add(icon); tray.add(icon);
Menu submenuStrict = new Menu("Strict Mode"); Menu submenuStrict = new Menu("Strict Mode");
@ -403,8 +434,8 @@ public class I2PBrowser extends I2PCommonBrowser implements ClientApp {
closeItem.addActionListener(new ActionListener() { closeItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
shutdownSystray(); shutdownSystray();
tray.remove(icon);
System.exit(0); // System.exit(0);
} }
}); });
menu.add(closeItem); menu.add(closeItem);
@ -412,13 +443,14 @@ public class I2PBrowser extends I2PCommonBrowser implements ClientApp {
} }
public String getDisplayName() { return "Browser Profile Manager"; } public String getDisplayName() { return "Browser Profile Manager"; }
public String getName() { return "browserProfileManager"; } public String getName() { return "browserProfileManager"; }
public void shutdown(String[] args) { public void shutdown(String[] args) { shutdownSystray(); }
shutdownSystray();
System.exit(0);
}
public void startup() { public void startup() {
String[] args = {""}; String[] args = {};
systray(args); try {
this.startup(args);
} catch (Exception e) {
logger.info(e.toString());
}
} }
public ClientAppState getState() { public ClientAppState getState() {
if (systrayIsRunningExternally()) { if (systrayIsRunningExternally()) {