Plugins: Add support for custom icons (ticket #1550)

This commit is contained in:
zzz
2015-05-09 15:28:43 +00:00
parent 68951c4c6b
commit 5ee6826241
4 changed files with 40 additions and 17 deletions

View File

@ -10,8 +10,9 @@ import net.i2p.I2PAppContext;
import net.i2p.router.web.HomeHelper.App;
public class NavHelper {
private static 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> _apps = 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
@ -19,20 +20,24 @@ public class NavHelper {
*
* @param name pretty name the app will be called in the link
* @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);
}
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) {
_apps.remove(name);
_tooltips.remove(name);
_icons.remove(name);
}
/**
@ -76,9 +81,11 @@ public class NavHelper {
String tip = _tooltips.get(name);
if (tip == null)
tip = "";
// hardcoded hack
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";
else
icon = "/themes/console/images/plugin.png";

View File

@ -261,6 +261,7 @@ public class PluginStarter implements Runnable {
public static boolean startPlugin(RouterContext ctx, String appName) throws Exception {
Log log = ctx.logManager().getLog(PluginStarter.class);
File pluginDir = new File(ctx.getConfigDir(), PLUGIN_DIR + '/' + appName);
String iconfile = null;
if ((!pluginDir.exists()) || (!pluginDir.isDirectory())) {
log.error("Cannot start nonexistent plugin: " + appName);
disablePlugin(appName);
@ -288,6 +289,9 @@ public class PluginStarter implements Runnable {
Properties props = pluginProperties(ctx, appName);
String minVersion = ConfigClientsHelper.stripHTML(props, "min-i2p-version");
if (minVersion != null &&
VersionComparator.comp(CoreVersion.VERSION, minVersion) < 0) {
@ -380,6 +384,16 @@ public class PluginStarter implements Runnable {
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 {
log.error("No console web server to start plugins?");
@ -409,7 +423,6 @@ public class PluginStarter implements Runnable {
Translate.clearCache();
}
}
// add summary bar link
String name = ConfigClientsHelper.stripHTML(props, "consoleLinkName_" + Messages.getLanguage(ctx));
if (name == null)
@ -419,10 +432,7 @@ public class PluginStarter implements Runnable {
String tip = ConfigClientsHelper.stripHTML(props, "consoleLinkTooltip_" + Messages.getLanguage(ctx));
if (tip == null)
tip = ConfigClientsHelper.stripHTML(props, "consoleLinkTooltip");
if (tip != null)
NavHelper.registerApp(name, url, tip);
else
NavHelper.registerApp(name, url);
NavHelper.registerApp(name, url, tip, iconfile);
}
return true;