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
@@ -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,