diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java index d1431361f..8bd19b1fe 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java @@ -5,6 +5,9 @@ import java.io.IOException; import java.util.List; import java.util.Properties; +import net.i2p.app.ClientApp; +import net.i2p.app.ClientAppManager; +import net.i2p.app.ClientAppState; import net.i2p.apps.systray.UrlLauncher; import net.i2p.router.Router; import net.i2p.router.RouterContext; @@ -191,6 +194,26 @@ public class ConfigServiceHandler extends FormHandler { return _context.router().gracefulShutdownInProgress(); } + /** + * Should we show the systray controls? + * + * @since 0.9.26 + */ + public boolean shouldShowSystray() { + return ! + (RouterConsoleRunner.DAEMON_USER.equals(System.getProperty("user.name")) || + (SystemVersion.isWindows() && _context.hasWrapper() && WrapperManager.isLaunchedAsService())); + } + + /** + * Is the systray enabled? + * + * @since 0.9.26 + */ + public boolean isSystrayEnabled() { + return _context.getBooleanProperty(RouterConsoleRunner.PROP_DTG_ENABLED); + } + @Override protected void processForm() { if (_action == null) return; @@ -249,6 +272,10 @@ public class ConfigServiceHandler extends FormHandler { } else if (_t("Force GC").equals(_action)) { Runtime.getRuntime().gc(); addFormNotice(_t("Full garbage collection requested")); + } else if (_t("Show systray icon").equals(_action)) { + changeSystray(true); + } else if (_t("Hide systray icon").equals(_action)) { + changeSystray(false); } else { //addFormNotice("Blah blah blah. whatever. I'm not going to " + _action); } @@ -292,4 +319,41 @@ public class ConfigServiceHandler extends FormHandler { } ClientAppConfig.writeClientAppConfig(_context, clients); } + + /** + * Enable/disable and start/stop systray + * + * @since 0.9.26 + */ + private void changeSystray(boolean enable) { + ClientAppManager mgr = _context.clientAppManager(); + if (mgr != null) { + try { + ClientApp dtg = mgr.getRegisteredApp("desktopgui"); + if (dtg != null) { + if (enable) { + if (dtg.getState() == ClientAppState.STOPPED) + dtg.startup(); + } else { + if (dtg.getState() == ClientAppState.RUNNING) + dtg.shutdown(null); + } + } else if (enable) { + dtg = new net.i2p.desktopgui.Main(_context, mgr, null); + dtg.startup(); + } + } catch (Throwable t) { + if (enable) + addFormError(_t("Failed to start systray") + ": " + t); + else + addFormError(_t("Failed to stop systray") + ": " + t); + } + } + + boolean saved = _context.router().saveConfig(RouterConsoleRunner.PROP_DTG_ENABLED, Boolean.toString(enable)); + if (saved) + addFormNotice(_t("Configuration saved successfully")); + else + addFormError(_t("Error saving the configuration (applied but not saved) - please see the error logs")); + } } diff --git a/apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java b/apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java index ac97a2652..a88bbb86a 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java @@ -131,7 +131,8 @@ public class RouterConsoleRunner implements RouterApp { private static final int MAX_THREADS = 24; private static final int MAX_IDLE_TIME = 90*1000; private static final String THREAD_NAME = "RouterConsole Jetty"; - private final static String DAEMON_USER = "i2psvc"; + public static final String DAEMON_USER = "i2psvc"; + public static final String PROP_DTG_ENABLED = "desktopgui.enabled"; /** *
@@ -280,7 +281,7 @@ public class RouterConsoleRunner implements RouterApp { } try { // default false for now - boolean desktopguiEnabled = _context.getBooleanProperty("desktopgui.enabled"); + boolean desktopguiEnabled = _context.getBooleanProperty(PROP_DTG_ENABLED); if (desktopguiEnabled) { //Check if we are in a headless environment, set properties accordingly System.setProperty("java.awt.headless", Boolean.toString(GraphicsEnvironment.isHeadless())); diff --git a/apps/routerconsole/jsp/configservice.jsp b/apps/routerconsole/jsp/configservice.jsp index 987aefdeb..b3a21a7d7 100644 --- a/apps/routerconsole/jsp/configservice.jsp +++ b/apps/routerconsole/jsp/configservice.jsp @@ -39,25 +39,30 @@ " > <% } %> - <% if ( (System.getProperty("os.name") != null) && (System.getProperty("os.name").startsWith("Win")) ) { %> +<% if (formhandler.shouldShowSystray()) { %><%=intl._t("Systray integration")%>
-<%=intl._t("On the windows platform, there is a small application to sit in the system tray, allowing you to view the router's status")%> - <%=intl._t("(later on, I2P client applications will be able to integrate their own functionality into the system tray as well).")%> - <%=intl._t("If you are on windows, you can either enable or disable that icon here.")%>
+<%=intl._t("Control the system tray icon")%>
- " > - " > +<% if (!formhandler.isSystrayEnabled()) { %> + " > +<% } else {%> + " > +<% } %>+<% + } + if ( (System.getProperty("os.name") != null) && (System.getProperty("os.name").startsWith("Win")) ) { %> +%><%=intl._t("Run on startup")%>
<%=intl._t("You can control whether I2P is run on startup or not by selecting one of the following options - I2P will install (or remove) a service accordingly.")%> <%=intl._t("If you prefer the command line, you can also run the ")%>
install_i2p_service_winnt.bat
(<%=intl._t("or")%>uninstall_i2p_service_winnt.bat
).- " > -" >+ " > +" ><%=intl._t("Note")%>: <%=intl._t("If you are running I2P as service right now, removing it will shut down your router immediately.")%> <%=intl._t("You may want to consider shutting down gracefully, as above, then running uninstall_i2p_service_winnt.bat.")%>
- <% } %> +<% } %><%=intl._t("Debugging")%>