mirror of
https://github.com/i2p/i2p.i2p.git
synced 2026-10-22 21:53:43 +00:00
i2psnark standalone: Add DTG and notifications
This commit is contained in:
7 files changed
+99
-17
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user