forked from I2P_Developers/i2p.i2p
Plugins: Add support for custom icons (ticket #1550)
This commit is contained in:
@@ -10,8 +10,9 @@ import net.i2p.I2PAppContext;
|
|||||||
import net.i2p.router.web.HomeHelper.App;
|
import net.i2p.router.web.HomeHelper.App;
|
||||||
|
|
||||||
public class NavHelper {
|
public class NavHelper {
|
||||||
private static Map<String, String> _apps = new ConcurrentHashMap<String, String>(4);
|
private static final Map<String, String> _apps = new ConcurrentHashMap<String, String>(4);
|
||||||
private static Map<String, String> _tooltips = new ConcurrentHashMap<String, String>(4);
|
private static final Map<String, String> _tooltips = new ConcurrentHashMap<String, String>(4);
|
||||||
|
private static final Map<String, String> _icons = new ConcurrentHashMap<String, String>(4);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To register a new client application so that it shows up on the router
|
* To register a new client application so that it shows up on the router
|
||||||
@@ -19,20 +20,24 @@ public class NavHelper {
|
|||||||
*
|
*
|
||||||
* @param name pretty name the app will be called in the link
|
* @param name pretty name the app will be called in the link
|
||||||
* @param path full path pointing to the application's root
|
* @param path full path pointing to the application's root
|
||||||
* (e.g. /i2ptunnel/index.jsp)
|
* (e.g. /i2ptunnel/index.jsp), non-null
|
||||||
|
* @param tooltip HTML escaped text or null
|
||||||
|
* @param iconpath path-only URL starting with /, HTML escaped, or null
|
||||||
|
* @since 0.9.20 added iconpath parameter
|
||||||
*/
|
*/
|
||||||
public static void registerApp(String name, String path) {
|
public static void registerApp(String name, String path, String tooltip, String iconpath) {
|
||||||
_apps.put(name, path);
|
_apps.put(name, path);
|
||||||
}
|
if (tooltip != null)
|
||||||
|
_tooltips.put(name, tooltip);
|
||||||
|
if (iconpath != null && iconpath.startsWith("/"))
|
||||||
|
_icons.put(name, iconpath);
|
||||||
|
|
||||||
public static void registerApp(String name, String path, String tooltip) {
|
|
||||||
_apps.put(name, path);
|
|
||||||
_tooltips.put(name, tooltip);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unregisterApp(String name) {
|
public static void unregisterApp(String name) {
|
||||||
_apps.remove(name);
|
_apps.remove(name);
|
||||||
_tooltips.remove(name);
|
_tooltips.remove(name);
|
||||||
|
_icons.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,9 +81,11 @@ public class NavHelper {
|
|||||||
String tip = _tooltips.get(name);
|
String tip = _tooltips.get(name);
|
||||||
if (tip == null)
|
if (tip == null)
|
||||||
tip = "";
|
tip = "";
|
||||||
// hardcoded hack
|
|
||||||
String icon;
|
String icon;
|
||||||
if (path.equals("/i2pbote/index.jsp"))
|
if (_icons.containsKey(name))
|
||||||
|
icon = _icons.get(name);
|
||||||
|
// hardcoded hack
|
||||||
|
else if (path.equals("/i2pbote/index.jsp"))
|
||||||
icon = "/themes/console/images/email.png";
|
icon = "/themes/console/images/email.png";
|
||||||
else
|
else
|
||||||
icon = "/themes/console/images/plugin.png";
|
icon = "/themes/console/images/plugin.png";
|
||||||
|
@@ -261,6 +261,7 @@ public class PluginStarter implements Runnable {
|
|||||||
public static boolean startPlugin(RouterContext ctx, String appName) throws Exception {
|
public static boolean startPlugin(RouterContext ctx, String appName) throws Exception {
|
||||||
Log log = ctx.logManager().getLog(PluginStarter.class);
|
Log log = ctx.logManager().getLog(PluginStarter.class);
|
||||||
File pluginDir = new File(ctx.getConfigDir(), PLUGIN_DIR + '/' + appName);
|
File pluginDir = new File(ctx.getConfigDir(), PLUGIN_DIR + '/' + appName);
|
||||||
|
String iconfile = null;
|
||||||
if ((!pluginDir.exists()) || (!pluginDir.isDirectory())) {
|
if ((!pluginDir.exists()) || (!pluginDir.isDirectory())) {
|
||||||
log.error("Cannot start nonexistent plugin: " + appName);
|
log.error("Cannot start nonexistent plugin: " + appName);
|
||||||
disablePlugin(appName);
|
disablePlugin(appName);
|
||||||
@@ -288,6 +289,9 @@ public class PluginStarter implements Runnable {
|
|||||||
|
|
||||||
Properties props = pluginProperties(ctx, appName);
|
Properties props = pluginProperties(ctx, appName);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String minVersion = ConfigClientsHelper.stripHTML(props, "min-i2p-version");
|
String minVersion = ConfigClientsHelper.stripHTML(props, "min-i2p-version");
|
||||||
if (minVersion != null &&
|
if (minVersion != null &&
|
||||||
VersionComparator.comp(CoreVersion.VERSION, minVersion) < 0) {
|
VersionComparator.comp(CoreVersion.VERSION, minVersion) < 0) {
|
||||||
@@ -380,6 +384,16 @@ public class PluginStarter implements Runnable {
|
|||||||
log.error("Error resolving '" + fileNames[i] + "' in '" + webappDir, ioe);
|
log.error("Error resolving '" + fileNames[i] + "' in '" + webappDir, ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check for iconfile in plugin.properties
|
||||||
|
String icfile = ConfigClientsHelper.stripHTML(props, "console-icon");
|
||||||
|
if (icfile != null && !icfile.contains("..")) {
|
||||||
|
StringBuilder buf = new StringBuilder(32);
|
||||||
|
buf.append('/').append(appName);
|
||||||
|
if (!icfile.startsWith("/"))
|
||||||
|
buf.append('/');
|
||||||
|
buf.append(icfile);
|
||||||
|
iconfile = buf.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.error("No console web server to start plugins?");
|
log.error("No console web server to start plugins?");
|
||||||
@@ -409,7 +423,6 @@ public class PluginStarter implements Runnable {
|
|||||||
Translate.clearCache();
|
Translate.clearCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add summary bar link
|
// add summary bar link
|
||||||
String name = ConfigClientsHelper.stripHTML(props, "consoleLinkName_" + Messages.getLanguage(ctx));
|
String name = ConfigClientsHelper.stripHTML(props, "consoleLinkName_" + Messages.getLanguage(ctx));
|
||||||
if (name == null)
|
if (name == null)
|
||||||
@@ -419,10 +432,7 @@ public class PluginStarter implements Runnable {
|
|||||||
String tip = ConfigClientsHelper.stripHTML(props, "consoleLinkTooltip_" + Messages.getLanguage(ctx));
|
String tip = ConfigClientsHelper.stripHTML(props, "consoleLinkTooltip_" + Messages.getLanguage(ctx));
|
||||||
if (tip == null)
|
if (tip == null)
|
||||||
tip = ConfigClientsHelper.stripHTML(props, "consoleLinkTooltip");
|
tip = ConfigClientsHelper.stripHTML(props, "consoleLinkTooltip");
|
||||||
if (tip != null)
|
NavHelper.registerApp(name, url, tip, iconfile);
|
||||||
NavHelper.registerApp(name, url, tip);
|
|
||||||
else
|
|
||||||
NavHelper.registerApp(name, url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -1,3 +1,9 @@
|
|||||||
|
2015-05-09 zzz
|
||||||
|
* Plugins: Add support for custom icons (ticket #1550)
|
||||||
|
|
||||||
|
2015-05-08 zzz
|
||||||
|
* Reseed: Don't reseed while shutting down (ticket #1565)
|
||||||
|
|
||||||
2015-05-07 zzz
|
2015-05-07 zzz
|
||||||
* SAM: Close datagram or raw session when underlying
|
* SAM: Close datagram or raw session when underlying
|
||||||
I2P session closes (ticket #1563)
|
I2P session closes (ticket #1563)
|
||||||
|
@@ -18,10 +18,10 @@ public class RouterVersion {
|
|||||||
/** deprecated */
|
/** deprecated */
|
||||||
public final static String ID = "Monotone";
|
public final static String ID = "Monotone";
|
||||||
public final static String VERSION = CoreVersion.VERSION;
|
public final static String VERSION = CoreVersion.VERSION;
|
||||||
public final static long BUILD = 18;
|
public final static long BUILD = 19;
|
||||||
|
|
||||||
/** for example "-test" */
|
/** for example "-test" */
|
||||||
public final static String EXTRA = "";
|
public final static String EXTRA = "-rc";
|
||||||
public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;
|
public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
System.out.println("I2P Router version: " + FULL_VERSION);
|
System.out.println("I2P Router version: " + FULL_VERSION);
|
||||||
|
Reference in New Issue
Block a user