i2psnark standalone: Add DTG and notifications

This commit is contained in:
zzz
2022-03-11 07:23:46 -05:00
parent 981c5e3878
commit 7e3e42ce42
7 changed files with 99 additions and 17 deletions

View File

@@ -6,3 +6,5 @@
#routerconsole.browser=/bin/false
# change browser
#routerconsole.browser=firefox
# disable system tray
#desktopgui.enabled=false

View File

@@ -21,6 +21,8 @@
<pathelement location="../../jetty/jettylib/javax.servlet.jar" />
<!-- jsp-api.jar only present for debian builds -->
<pathelement location="../../jetty/jettylib/jsp-api.jar" />
<!-- following jars only for standalone builds -->
<pathelement location="../../desktopgui/dist/desktopgui.jar" />
</classpath>
</depend>
</target>
@@ -60,6 +62,7 @@
<pathelement location="../../systray/java/build/systray.jar" />
<pathelement location="../../jetty/jettylib/org.mortbay.jetty.jar" />
<pathelement location="../../jetty/jettylib/jetty-util.jar" />
<pathelement location="../../desktopgui/dist/desktopgui.jar" />
</classpath>
</javac>
</target>
@@ -236,6 +239,7 @@
<zipfileset src="../../streaming/java/build/streaming.jar" />
<zipfileset src="../../systray/java/build/systray.jar" />
<zipfileset src="../../../build/jbigi.jar" />
<zipfileset src="../../desktopgui/dist/desktopgui.jar" />
<!-- Countries translations. The i2psnark translations are in the war but it's easier to put these here -->
<!-- 300KB just to translate "Brazil", but why not... -->
<!--

View File

@@ -2566,7 +2566,7 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
boolean oldOK = routerOK;
// standalone, first time only
if (doMagnets && !_context.isRouterContext())
System.out.println(_t("Connecting to I2P") + ' ' + _util.getI2CPHost() + ':' + _util.getI2CPPort());
dtgNotify(Log.INFO, _t("Connecting to I2P") + ' ' + _util.getI2CPHost() + ':' + _util.getI2CPPort());
routerOK = getBWLimit();
if (routerOK) {
autostart = shouldAutoStart();
@@ -2580,7 +2580,7 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
String msg = _t("Connecting to I2P");
addMessage(msg);
if (!_context.isRouterContext())
System.out.println(msg + ' ' + _util.getI2CPHost() + ':' + _util.getI2CPPort());
dtgNotify(Log.INFO, msg + ' ' + _util.getI2CPHost() + ':' + _util.getI2CPPort());
// getBWLimit() was successful so this should work
boolean ok = _util.connect();
if (!ok) {
@@ -2589,7 +2589,7 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
} else {
msg = _t("Error connecting to I2P - check your I2CP settings!") + ' ' + _util.getI2CPHost() + ':' + _util.getI2CPPort();
addMessage(msg);
System.out.println(msg);
dtgNotify(Log.ERROR, msg);
}
routerOK = false;
autostart = false;
@@ -2598,7 +2598,7 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
if (!_context.isRouterContext()) {
msg = "Connected to I2P at " + ' ' + _util.getI2CPHost() + ':' + _util.getI2CPPort();
addMessage(msg);
System.out.println(msg);
dtgNotify(Log.INFO, msg);
}
}
}
@@ -2653,7 +2653,7 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
} else {
String msg = _t("Error connecting to I2P - check your I2CP settings!") + ' ' + _util.getI2CPHost() + ':' + _util.getI2CPPort();
addMessage(msg);
System.out.println(msg);
dtgNotify(Log.ERROR, msg);
}
}
}
@@ -2674,15 +2674,9 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
return;
if (snark.getDownloaded() > 0) {
addMessageNoEscape(_t("Download finished: {0}", linkify(snark)));
ClientAppManager cmgr = _context.clientAppManager();
if (cmgr != null) {
NotificationService ns = (NotificationService) cmgr.getRegisteredApp("desktopgui");
if (ns != null) {
ns.notify("I2PSnark", null, Log.INFO, _t("I2PSnark"),
_t("Download finished: {0}", snark.getName()),
"/i2psnark/" + linkify(snark));
}
}
dtgNotify(Log.INFO,
_t("Download finished: {0}", snark.getName()),
"/i2psnark/" + linkify(snark));
}
updateStatus(snark);
}
@@ -2773,6 +2767,38 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
// End Snark.CompleteListeners
/**
* Send a notification to the user via desktopgui and,
* if standalone, on the console.
*
* @param priority log level
* @param message translated
* @since 0.9.54
*/
private void dtgNotify(int priority, String message) {
dtgNotify(priority, message, null);
}
/**
* Send a notification to the user via desktopgui and,
* if standalone, on the console.
*
* @param priority log level
* @param message translated
* @param path in console for more information, starting with /, must be URL-escaped, or null
* @since 0.9.54
*/
private void dtgNotify(int priority, String message, String path) {
ClientAppManager cmgr = _context.clientAppManager();
if (cmgr != null) {
NotificationService ns = (NotificationService) cmgr.getRegisteredApp("desktopgui");
if (ns != null)
ns.notify("I2PSnark", null, priority, _t("I2PSnark"), message, path);
}
if (!_context.isRouterContext())
System.out.println(message);
}
/**
* An HTML link to the file if complete and a single file,
* to the directory if not complete or not a single file,

View File

@@ -1,5 +1,6 @@
package org.klomp.snark.standalone;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
@@ -9,8 +10,10 @@ import org.eclipse.jetty.util.log.Log;
import net.i2p.I2PAppContext;
import net.i2p.apps.systray.UrlLauncher;
import net.i2p.data.DataHelper;
import net.i2p.desktopgui.ExternalMain;
import net.i2p.jetty.I2PLogger;
import net.i2p.jetty.JettyStart;
import net.i2p.util.SystemVersion;
/**
* @since moved from ../web and fixed in 0.9.27
@@ -23,6 +26,7 @@ public class RunStandalone {
private String _host = "127.0.0.1";
private static RunStandalone _instance;
static final File APP_CONFIG_FILE = new File("i2psnark-appctx.config");
private static final String PROP_DTG_ENABLED = "desktopgui.enabled";
private RunStandalone(String args[]) throws Exception {
Properties p = new Properties();
@@ -68,6 +72,7 @@ public class RunStandalone {
try {
String url = "http://" + _host + ':' + _port + "/i2psnark/";
System.out.println("Starting i2psnark at " + url);
startTrayApp();
_jettyStart.startup();
try {
Thread.sleep(1000);
@@ -93,4 +98,39 @@ public class RunStandalone {
} catch (InterruptedException ie) {}
System.exit(1);
}
/**
* @since 0.9.54 adapted from RouterConsoleRunner
*/
private static boolean isSystrayEnabled(I2PAppContext context) {
if (GraphicsEnvironment.isHeadless())
return false;
// default false except on OSX and Windows,
// and on Linux KDE and LXDE.
// Xubuntu XFCE works but doesn't look very good
// Ubuntu Unity was far too buggy to enable
// Ubuntu GNOME does not work, SystemTray.isSupported() returns false
String xdg = System.getenv("XDG_CURRENT_DESKTOP");
boolean dflt = SystemVersion.isWindows() ||
SystemVersion.isMac() ||
//"XFCE".equals(xdg) ||
"KDE".equals(xdg) ||
"LXDE".equals(xdg);
return context.getProperty(PROP_DTG_ENABLED, dflt);
}
/**
* @since 0.9.54 adapted from RouterConsoleRunner
*/
private void startTrayApp() {
try {
if (isSystrayEnabled(_context)) {
System.setProperty("java.awt.headless", "false");
ExternalMain dtg = new ExternalMain(_context, _context.clientAppManager(), null);
dtg.startup();
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}

View File

@@ -342,7 +342,8 @@
<copy file="apps/i2pcontrol/build/jsonrpc.war" todir="build/" />
</target>
<target name="buildI2PSnark" depends="buildMinistreaming, buildJetty, buildSystray" >
<!-- DTG only for standalone, but snark compiles standalone classes for non-standalone, to be fixed -->
<target name="buildI2PSnark" depends="buildMinistreaming, buildJetty, buildSystray, buildDesktopGui" >
<ant dir="apps/i2psnark/java/" target="war" />
<copy file="apps/i2psnark/i2psnark.war" todir="build/" />
<copy file="apps/i2psnark/java/build/i2psnark.jar" todir="build/" />
@@ -2132,7 +2133,7 @@
</target> -->
<!-- standalone i2psnark zip -->
<target name="i2psnark" depends="buildStreaming, buildJetty, buildSystray, jbigi" >
<target name="i2psnark" depends="buildStreaming, buildJetty, buildSystray, jbigi, buildDesktopGui" >
<ant dir="apps/i2psnark/java" target="standalone" />
<copy file="apps/i2psnark/java/i2psnark-standalone.zip" todir="." />
</target>

View File

@@ -1,3 +1,12 @@
2022-03-11 zzz
* i2psnark standalone: Add DTG
2022-03-10 zzz
* SSU2: Fixes
2022-03-09 zzz
* DTG: Add new ExternalMain class for app context use
2022-03-08 zzz
* I2NP: Fix TunnelGatewayMessage.calculateWrittenLength()
* SSU2: Fixes

View File

@@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Git";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 5;
public final static long BUILD = 6;
/** for example "-test" */
public final static String EXTRA = "";