From 5ee6826241a550e8d8763564657f8a853c9f4115 Mon Sep 17 00:00:00 2001 From: zzz Date: Sat, 9 May 2015 15:28:43 +0000 Subject: [PATCH] Plugins: Add support for custom icons (ticket #1550) --- .../src/net/i2p/router/web/NavHelper.java | 27 ++++++++++++------- .../src/net/i2p/router/web/PluginStarter.java | 20 ++++++++++---- history.txt | 6 +++++ .../src/net/i2p/router/RouterVersion.java | 4 +-- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/web/NavHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/NavHelper.java index 6055c83bc..713520c94 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/NavHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/NavHelper.java @@ -10,8 +10,9 @@ import net.i2p.I2PAppContext; import net.i2p.router.web.HomeHelper.App; public class NavHelper { - private static Map _apps = new ConcurrentHashMap(4); - private static Map _tooltips = new ConcurrentHashMap(4); + private static final Map _apps = new ConcurrentHashMap(4); + private static final Map _tooltips = new ConcurrentHashMap(4); + private static final Map _icons = new ConcurrentHashMap(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"; diff --git a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java index ec10c0fce..e6bb87b70 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/PluginStarter.java @@ -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; diff --git a/history.txt b/history.txt index 539011085..14c134dbe 100644 --- a/history.txt +++ b/history.txt @@ -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 * SAM: Close datagram or raw session when underlying I2P session closes (ticket #1563) diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 80cfb9c84..987fc2f75 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,10 +18,10 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 18; + public final static long BUILD = 19; /** for example "-test" */ - public final static String EXTRA = ""; + public final static String EXTRA = "-rc"; public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA; public static void main(String args[]) { System.out.println("I2P Router version: " + FULL_VERSION);