remove redundant menu item, don't worry about a thread for the Firefox, it doesn't even need to know if it's started, don't force logs into a file where logs don't belong

This commit is contained in:
eyedeekay
2024-03-07 11:00:13 -05:00
parent 515e52eeb2
commit b25cb2c9b3
7 changed files with 74 additions and 123 deletions

View File

@ -12,8 +12,8 @@ noscript
11.4.29 11.4.29
https://addons.mozilla.org/firefox/downloads/file/4206186/noscript-11.4.29.xpi https://addons.mozilla.org/firefox/downloads/file/4206186/noscript-11.4.29.xpi
localcdn-fork-of-decentraleyes localcdn-fork-of-decentraleyes
2.6.63 2.6.64
https://addons.mozilla.org/firefox/downloads/file/4231487/localcdn_fork_of_decentraleyes-2.6.63.xpi https://addons.mozilla.org/firefox/downloads/file/4243456/localcdn_fork_of_decentraleyes-2.6.64.xpi
onion-in-container-browsing onion-in-container-browsing
0.82 0.82
https://addons.mozilla.org/firefox/downloads/file/3904685/onion_in_container_browsing-0.82.xpi https://addons.mozilla.org/firefox/downloads/file/3904685/onion_in_container_browsing-0.82.xpi

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Tue Mar 05 18:07:41 EST 2024 #Thu Mar 07 10:50:24 EST 2024
build.number=650 build.number=698

View File

@ -53,12 +53,13 @@ public class I2PBrowser extends I2PGenericUnsafeBrowser {
public boolean usability = false; public boolean usability = false;
public int privateBrowsing = 0; public int privateBrowsing = 0;
private boolean outputConfig = false; private boolean outputConfig = false;
private boolean useSystray = true;
public void launchFirefox(int privateWindow, String[] url) { public void launchFirefox(int privateWindow, String[] url) {
String priv = privateWindow == 1 ? "private-window" : "long-profile"; String priv = privateWindow == 1 ? "private-window" : "long-profile";
logger.info("I2PFirefox" + priv); logger.info("I2PFirefox" + priv);
i2pFirefox.usability = usability; i2pFirefox.usability = usability;
if (url == null)
url = new String[] { "about:blank" };
if (outputConfig) if (outputConfig)
i2pFirefox.storeFirefoxDefaults(); i2pFirefox.storeFirefoxDefaults();
i2pFirefox.launch(privateWindow, url); i2pFirefox.launch(privateWindow, url);
@ -67,6 +68,8 @@ public class I2PBrowser extends I2PGenericUnsafeBrowser {
String priv = privateWindow == 1 ? "private-window" : "long-profile"; String priv = privateWindow == 1 ? "private-window" : "long-profile";
logger.info("I2PChromium" + priv); logger.info("I2PChromium" + priv);
i2pChromium.usability = usability; i2pChromium.usability = usability;
if (url == null)
url = new String[] { "about:blank" };
if (outputConfig) if (outputConfig)
i2pChromium.storeChromiumDefaults(); i2pChromium.storeChromiumDefaults();
i2pChromium.launch(privateWindow, url); i2pChromium.launch(privateWindow, url);
@ -74,6 +77,8 @@ public class I2PBrowser extends I2PGenericUnsafeBrowser {
private void launchGeneric(int privateWindowInt, String[] url) { private void launchGeneric(int privateWindowInt, String[] url) {
String priv = privateWindowInt == 1 ? "private-window" : "long-profile"; String priv = privateWindowInt == 1 ? "private-window" : "long-profile";
boolean privateWindow = false; boolean privateWindow = false;
if (url == null)
url = new String[] { "about:blank" };
if (privateWindowInt == 1) if (privateWindowInt == 1)
privateWindow = true; privateWindow = true;
if (outputConfig) if (outputConfig)
@ -144,7 +149,6 @@ public class I2PBrowser extends I2PGenericUnsafeBrowser {
* @since 0.0.17 * @since 0.0.17
*/ */
public void launch(int privateWindow, String[] url) { public void launch(int privateWindow, String[] url) {
validateUserDirectory();
if (chromiumFirst) { if (chromiumFirst) {
if (chromium) { if (chromium) {
this.launchChromium(privateWindow, url); this.launchChromium(privateWindow, url);
@ -231,7 +235,6 @@ public class I2PBrowser extends I2PGenericUnsafeBrowser {
i2pBrowser.startup(args); i2pBrowser.startup(args);
} }
public ArrayList<String> parseArgs(String[] args) { public ArrayList<String> parseArgs(String[] args) {
validateUserDirectory();
logger.info("I2PBrowser"); logger.info("I2PBrowser");
ArrayList<String> visitURL = new ArrayList<String>(); ArrayList<String> visitURL = new ArrayList<String>();
if (args != null) { if (args != null) {
@ -262,9 +265,6 @@ public class I2PBrowser extends I2PGenericUnsafeBrowser {
if (arg.equals("-outputconfig")) { if (arg.equals("-outputconfig")) {
outputConfig = true; outputConfig = true;
} }
if (arg.equals("-nosystray")) {
useSystray = false;
}
if (arg.equals("-noproxycheck")) { if (arg.equals("-noproxycheck")) {
logger.info("zeroing out proxy check"); logger.info("zeroing out proxy check");
this.setProxyTimeoutTime(0); this.setProxyTimeoutTime(0);
@ -280,43 +280,14 @@ public class I2PBrowser extends I2PGenericUnsafeBrowser {
public void startup(String[] args) { public void startup(String[] args) {
ArrayList<String> visitURL = parseArgs(args); ArrayList<String> visitURL = parseArgs(args);
try { try {
if (useSystray) { Runtime.getRuntime().addShutdownHook(new Thread() {
Runtime.getRuntime().addShutdownHook(new Thread() { @Override
@Override public void run() {}
public void run() {} });
});
}
} catch (Exception e) { } catch (Exception e) {
logger.warning(e.toString()); logger.warning(e.toString());
} }
this.launch(this.privateBrowsing, this.launch(this.privateBrowsing,
visitURL.toArray(new String[visitURL.size()])); visitURL.toArray(new String[visitURL.size()]));
} }
protected boolean createSystrayRunningFile() {
if (!systrayRunningExternally()) {
try {
File systrayIsRunningFile =
new File(runtimeDirectory(""), "systray.running");
FileWriter myWriter = new FileWriter(systrayIsRunningFile);
myWriter.write("systray.running file created");
myWriter.close();
return true;
} catch (IOException ioe) {
logger.warning(ioe.toString());
}
return false;
}
return false;
}
protected boolean systrayRunningExternally() {
File systrayIsRunningFile =
new File(runtimeDirectory(""), "systray.running");
if (systrayIsRunningFile.exists()) {
logger.info("Systray is already running in another process: " +
systrayIsRunningFile.toString());
return true;
}
logger.info("Systray does not appear to be running");
return false;
}
} }

View File

@ -29,6 +29,7 @@ import java.util.stream.Stream;
public class I2PChromium extends I2PChromiumProfileUnpacker { public class I2PChromium extends I2PChromiumProfileUnpacker {
private final String[] CHROMIUM_SEARCH_PATHS = CHROMIUM_FINDER(); private final String[] CHROMIUM_SEARCH_PATHS = CHROMIUM_FINDER();
private Process p = null; private Process p = null;
private String chromePath;
/** /**
* Construct an I2PChromium class which manages an instance of Chromium and * Construct an I2PChromium class which manages an instance of Chromium and
@ -388,11 +389,13 @@ public class I2PChromium extends I2PChromiumProfileUnpacker {
File chromeFile = new File(chrome); File chromeFile = new File(chrome);
if (chromeFile.exists()) { if (chromeFile.exists()) {
// if it does, return it // if it does, return it
chromePath = chrome;
return chrome; return chrome;
} }
} }
String[] chromees = onlyValidChromiums(); String[] chromees = onlyValidChromiums();
if (chromees.length > 0) { if (chromees.length > 0) {
chromePath = chromees[0];
return chromees[0]; return chromees[0];
} else { } else {
return ""; return "";

View File

@ -40,17 +40,9 @@ public class I2PCommonBrowser {
public I2PCommonBrowser() { public I2PCommonBrowser() {
try { try {
// This block configure the logger with handler and formatter
fh = new FileHandler(logFile().toString());
logger.addHandler(fh);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
// the following statement is used to log any messages
logger.info("Browser log"); logger.info("Browser log");
} catch (SecurityException e) { } catch (SecurityException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} }
loadPropertiesFile(new File(runtimeDirectory(""), "browser.config")); loadPropertiesFile(new File(runtimeDirectory(""), "browser.config"));
} }
@ -200,15 +192,15 @@ public class I2PCommonBrowser {
* *
* @return the log file for the browser launcher * @return the log file for the browser launcher
*/ */
private File logFile() { /*private File logFile() {
validateUserDirectory(); // validateUserDirectory();
String userDirectory = System.getProperty("user.dir"); String userDirectory = System.getProperty("user.dir");
File logDirectory = new File(userDirectory, "logs"); File logDirectory = new File(userDirectory, "logs");
if (!logDirectory.exists()) { if (!logDirectory.exists()) {
logDirectory.mkdirs(); logDirectory.mkdirs();
} }
return new File(logDirectory, "browserlauncher.log"); return new File(logDirectory, "browserlauncher.log");
} }*/
/** /**
* Get the runtime directory, creating it if create=true. * Get the runtime directory, creating it if create=true.

View File

@ -30,6 +30,7 @@ import java.util.stream.Stream;
public class I2PFirefox extends I2PFirefoxProfileUnpacker { public class I2PFirefox extends I2PFirefoxProfileUnpacker {
private final String[] FIREFOX_SEARCH_PATHS = FIREFOX_FINDER(); private final String[] FIREFOX_SEARCH_PATHS = FIREFOX_FINDER();
private Process process = null; private Process process = null;
private String firefoxPath;
public boolean usability = false; public boolean usability = false;
private String baseMode() { private String baseMode() {
@ -379,6 +380,9 @@ public class I2PFirefox extends I2PFirefoxProfileUnpacker {
* @since 0.0.1 * @since 0.0.1
*/ */
public String topFirefox() { public String topFirefox() {
if (firefoxPath != null) {
return firefoxPath;
}
// get the FIREFOX environment variable // get the FIREFOX environment variable
String firefox = System.getenv("FIREFOX"); String firefox = System.getenv("FIREFOX");
// if it is not null and not empty // if it is not null and not empty
@ -387,11 +391,13 @@ public class I2PFirefox extends I2PFirefoxProfileUnpacker {
File firefoxFile = new File(firefox); File firefoxFile = new File(firefox);
if (firefoxFile.exists()) { if (firefoxFile.exists()) {
// if it does, return it // if it does, return it
firefoxPath = firefox;
return firefox; return firefox;
} }
} }
String[] firefoxes = onlyValidFirefoxes(); String[] firefoxes = onlyValidFirefoxes();
if (firefoxes.length > 0) { if (firefoxes.length > 0) {
firefoxPath = firefoxes[0];
return firefoxes[0]; return firefoxes[0];
} else { } else {
return ""; return "";

View File

@ -40,9 +40,9 @@ public class I2PBrowserPlugin extends I2PBrowser implements ClientApp {
private final ClientAppManager _mgr; private final ClientAppManager _mgr;
private final String _args[]; private final String _args[];
private static final String PROP_DTG_ENABLED = "desktopgui.enabled"; private static final String PROP_DTG_ENABLED = "desktopgui.enabled";
private final I2PBrowser i2pBrowser;
private final File pluginDir; private final File pluginDir;
private final File profileDir; private final File profileDir;
private MenuHandle lmh;
public I2PBrowserPlugin() { public I2PBrowserPlugin() {
_context = new I2PAppContext(); _context = new I2PAppContext();
_mgr = null; _mgr = null;
@ -50,10 +50,6 @@ public class I2PBrowserPlugin extends I2PBrowser implements ClientApp {
_log = _context.logManager().getLog(I2PBrowserPlugin.class); _log = _context.logManager().getLog(I2PBrowserPlugin.class);
pluginDir = new File(_context.getAppDir(), "plugins/i2pfirefox/"); pluginDir = new File(_context.getAppDir(), "plugins/i2pfirefox/");
profileDir = new File(pluginDir, "profile/"); profileDir = new File(pluginDir, "profile/");
i2pBrowser = new I2PBrowser(profileDir.getAbsolutePath());
i2pBrowser.firefox = true;
i2pBrowser.chromiumFirst = false;
i2pBrowser.generic = false;
} }
public I2PBrowserPlugin(I2PAppContext ctx, ClientAppManager mgr, public I2PBrowserPlugin(I2PAppContext ctx, ClientAppManager mgr,
String args[]) { String args[]) {
@ -63,45 +59,39 @@ public class I2PBrowserPlugin extends I2PBrowser implements ClientApp {
_log = ctx.logManager().getLog(I2PBrowserPlugin.class); _log = ctx.logManager().getLog(I2PBrowserPlugin.class);
pluginDir = new File(_context.getAppDir(), "plugins/i2pfirefox/"); pluginDir = new File(_context.getAppDir(), "plugins/i2pfirefox/");
profileDir = new File(pluginDir, "profile/"); profileDir = new File(pluginDir, "profile/");
i2pBrowser = new I2PBrowser(profileDir.getAbsolutePath());
i2pBrowser.firefox = true;
i2pBrowser.chromiumFirst = false;
i2pBrowser.generic = false;
} }
public String getDisplayName() { return "I2P Browser"; } public String getDisplayName() { return "I2P Browser"; }
public String getName() { return "I2P Browser"; } public String getName() { return "I2P Browser"; }
public ClientAppState getState() { public ClientAppState getState() { return ClientAppState.STOPPED; }
if (i2pBrowser == null)
return ClientAppState.STOPPED;
if (!isSystrayEnabled())
if (!i2pBrowser.running())
return ClientAppState.STOPPED;
if (i2pBrowser.running())
return ClientAppState.RUNNING;
return ClientAppState.STOPPED;
}
public void shutdown(String[] args) { public void shutdown(String[] args) {
if (!isSystrayEnabled()) { if (!isSystrayEnabled()) {
_log.info("I2P Browser tray manager not supported"); _log.info("I2P Browser tray manager not supported");
i2pBrowser.stop();
changeState(ClientAppState.STOPPED);
return;
} else { } else {
_log.info("I2P Browser tray manager shutting down");
MenuService dtg = startTrayApp();
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
}
if (dtg != null) {
dtg.removeMenu(lmh);
}
} }
changeState(ClientAppState.STOPPED);
} }
public void startup() { public void startup() {
changeState(ClientAppState.STOPPED);
if (!isSystrayEnabled()) { if (!isSystrayEnabled()) {
_log.info("I2P Browser tray manager not supported"); _log.info("I2P Browser tray manager not supported");
try { try {
String url = "http://proxy.i2p"; I2PBrowser i2pBrowser = new I2PBrowser(profileDir.getAbsolutePath());
i2pBrowser.launchFirefox(0, new String[] {url}); String[] args = {"http://proxy.i2p"};
i2pBrowser.launchFirefox(0, args);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); _log.error("Error starting I2P Browser", e);
} }
return;
} else { } else {
try { try {
String url = "http://proxy.i2p";
_log.info( _log.info(
"Starting I2P Browser tray manager by testing http://proxy.i2p"); "Starting I2P Browser tray manager by testing http://proxy.i2p");
MenuService dtg = startTrayApp(); MenuService dtg = startTrayApp();
@ -109,13 +99,19 @@ public class I2PBrowserPlugin extends I2PBrowser implements ClientApp {
Thread.sleep(1000); Thread.sleep(1000);
} catch (InterruptedException ie) { } catch (InterruptedException ie) {
} }
i2pBrowser.launchFirefox(0, new String[] {url});
if (dtg != null) { if (dtg != null) {
dtg.addMenu("Launch I2P Browser", new Starter(dtg)); _log.info("I2P Browser integrating with I2P tray manager");
dtg.addMenu("Quit I2P Browser", new Stopper(dtg)); lmh = dtg.addMenu("Launch I2P Browser", new Starter(dtg));
dtg.showMenu(lmh);
dtg.enableMenu(lmh);
} else {
_log.info("I2P Browser tray manager not found");
} }
I2PBrowser i2pBrowser = new I2PBrowser(profileDir.getAbsolutePath());
String[] args = {"http://proxy.i2p"};
i2pBrowser.launchFirefox(0, args);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); _log.error("Error starting I2P Browser tray manager", e);
} }
} }
} }
@ -163,49 +159,32 @@ public class I2PBrowserPlugin extends I2PBrowser implements ClientApp {
private final MenuService _ms; private final MenuService _ms;
public Starter(MenuService ms) { _ms = ms; } public Starter(MenuService ms) { _ms = ms; }
public void clicked(MenuHandle menu) { public void clicked(MenuHandle menu) {
_ms.disableMenu(menu); // Thread t = new I2PAppThread(new StarterThread(),
_ms.updateMenu("I2PBrowser-Launcher starting", menu); //"I2PBrowser-Launcher start", true);
Thread t = new I2PAppThread(new StarterThread(), // t.start();
"I2PBrowser-Launcher start", true); _log.info("I2P Browser starting up");
t.start(); try {
I2PBrowser i2pBrowser = new I2PBrowser(profileDir.getAbsolutePath());
String[] args = {"http://proxy.i2p"};
i2pBrowser.launchFirefox(0, args);
} catch (Exception e) {
_log.error("Error starting I2P Browser", e);
}
_log.info("I2P Browser ran");
} }
} }
/**
* Threaded startup
* @since 0.9.61
*/
public class StarterThread implements Runnable { public class StarterThread implements Runnable {
public void run() { public void run() {
i2pBrowser.launchFirefox(0, null); _log.info("I2P Browser starting up");
changeState(ClientAppState.RUNNING); try {
} I2PBrowser i2pBrowser = new I2PBrowser(profileDir.getAbsolutePath());
} String[] args = {"http://proxy.i2p"};
i2pBrowser.launchFirefox(0, args);
/** } catch (Exception e) {
* Callback when Stop I2PBrowser is clicked in systray _log.error("Error starting I2P Browser", e);
* @since 0.9.61 }
*/ _log.info("I2P Browser ran");
public class Stopper implements MenuCallback {
private final MenuService _ms;
public Stopper(MenuService ms) { _ms = ms; }
public void clicked(MenuHandle menu) {
_ms.disableMenu(menu);
_ms.updateMenu("I2PBrowser-Launcher stopping", menu);
Thread t = new I2PAppThread(new StopperThread(),
"I2PBrowser-Launcher stop", true);
t.start();
}
}
/**
* Threaded startup
* @since 0.9.61
*/
public class StopperThread implements Runnable {
public void run() {
i2pBrowser.stop();
changeState(ClientAppState.STOPPED);
} }
} }