Changeset 62296222


Ignore:
Timestamp:
May 6, 2016 5:54:27 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
7d11ec2f
Parents:
70f9cb1
Message:

Console:

  • Show systray controls for all OSes on /configservice
  • Implement backend for systray control
Location:
apps/routerconsole
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java

    r70f9cb1 r62296222  
    66import java.util.Properties;
    77
     8import net.i2p.app.ClientApp;
     9import net.i2p.app.ClientAppManager;
     10import net.i2p.app.ClientAppState;
    811import net.i2p.apps.systray.UrlLauncher;
    912import net.i2p.router.Router;
     
    190193    public boolean shouldShowCancelGraceful() {
    191194        return _context.router().gracefulShutdownInProgress();
     195    }
     196
     197    /**
     198     *  Should we show the systray controls?
     199     *
     200     *  @since 0.9.26
     201     */
     202    public boolean shouldShowSystray() {
     203        return !
     204            (RouterConsoleRunner.DAEMON_USER.equals(System.getProperty("user.name")) ||
     205             (SystemVersion.isWindows() && _context.hasWrapper() && WrapperManager.isLaunchedAsService()));
     206    }
     207
     208    /**
     209     *  Is the systray enabled?
     210     *
     211     *  @since 0.9.26
     212     */
     213    public boolean isSystrayEnabled() {
     214        return _context.getBooleanProperty(RouterConsoleRunner.PROP_DTG_ENABLED);
    192215    }
    193216
     
    250273            Runtime.getRuntime().gc();
    251274            addFormNotice(_t("Full garbage collection requested"));
     275        } else if (_t("Show systray icon").equals(_action)) {
     276            changeSystray(true);
     277        } else if (_t("Hide systray icon").equals(_action)) {
     278            changeSystray(false);
    252279        } else {
    253280            //addFormNotice("Blah blah blah.  whatever.  I'm not going to " + _action);
     
    293320        ClientAppConfig.writeClientAppConfig(_context, clients);
    294321    }
     322
     323    /**
     324     *  Enable/disable and start/stop systray
     325     *
     326     *  @since 0.9.26
     327     */
     328    private void changeSystray(boolean enable) {
     329        ClientAppManager mgr = _context.clientAppManager();
     330        if (mgr != null) {
     331            try {
     332                ClientApp dtg = mgr.getRegisteredApp("desktopgui");
     333                if (dtg != null) {
     334                    if (enable) {
     335                        if (dtg.getState() == ClientAppState.STOPPED)
     336                            dtg.startup();
     337                    } else {
     338                        if (dtg.getState() == ClientAppState.RUNNING)
     339                            dtg.shutdown(null);
     340                    }
     341                } else if (enable) {
     342                        dtg = new net.i2p.desktopgui.Main(_context, mgr, null);   
     343                        dtg.startup();
     344                }
     345            } catch (Throwable t) {
     346                if (enable)
     347                    addFormError(_t("Failed to start systray") + ": " + t);
     348                else
     349                    addFormError(_t("Failed to stop systray") + ": " + t);
     350            }
     351        }
     352
     353        boolean saved = _context.router().saveConfig(RouterConsoleRunner.PROP_DTG_ENABLED, Boolean.toString(enable));
     354        if (saved)
     355            addFormNotice(_t("Configuration saved successfully"));
     356        else
     357            addFormError(_t("Error saving the configuration (applied but not saved) - please see the error logs"));
     358    }
    295359}
  • apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java

    r70f9cb1 r62296222  
    132132    private static final int MAX_IDLE_TIME = 90*1000;
    133133    private static final String THREAD_NAME = "RouterConsole Jetty";
    134     private final static String DAEMON_USER = "i2psvc";
     134    public static final String DAEMON_USER = "i2psvc";
     135    public static final String PROP_DTG_ENABLED = "desktopgui.enabled";
    135136   
    136137    /**
     
    281282        try {
    282283            // default false for now
    283             boolean desktopguiEnabled = _context.getBooleanProperty("desktopgui.enabled");
     284            boolean desktopguiEnabled = _context.getBooleanProperty(PROP_DTG_ENABLED);
    284285            if (desktopguiEnabled) {
    285286                //Check if we are in a headless environment, set properties accordingly
  • apps/routerconsole/jsp/configservice.jsp

    r70f9cb1 r62296222  
    4040 <% } %></div>
    4141
    42  <% if ( (System.getProperty("os.name") != null) && (System.getProperty("os.name").startsWith("Win")) ) { %>
     42<% if (formhandler.shouldShowSystray()) { %>
    4343 <h3><%=intl._t("Systray integration")%></h3>
    44  <p><%=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")%>
    45     <%=intl._t("(later on, I2P client applications will be able to integrate their own functionality into the system tray as well).")%>
    46     <%=intl._t("If you are on windows, you can either enable or disable that icon here.")%></p>
     44 <p><%=intl._t("Control the system tray icon")%>
    4745 <hr><div class="formaction">
    48  <input type="submit" name="action" value="<%=intl._t("Show systray icon")%>" >
    49  <input type="submit" name="action" value="<%=intl._t("Hide systray icon")%>" >
     46<% if (!formhandler.isSystrayEnabled()) { %>
     47 <input type="submit" name="action" class="accept" value="<%=intl._t("Show systray icon")%>" >
     48<% } else {%>
     49 <input type="submit" name="action" class="cancel" value="<%=intl._t("Hide systray icon")%>" >
     50<% } %>
    5051 </div>
     52<%
     53   } 
     54   if ( (System.getProperty("os.name") != null) && (System.getProperty("os.name").startsWith("Win")) ) { %>
     55%>
    5156 <h3><%=intl._t("Run on startup")%></h3>
    5257 <p><%=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.")%>
     
    5459 <code>uninstall_i2p_service_winnt.bat</code>).</p>
    5560 <hr><div class="formaction">
    56  <input type="submit" name="action" value="<%=intl._t("Run I2P on startup")%>" >
    57 <input type="submit" name="action" value="<%=intl._t("Don't run I2P on startup")%>" ></div>
     61 <input type="submit" name="action" class="accept" value="<%=intl._t("Run I2P on startup")%>" >
     62<input type="submit" name="action" class="cancel" value="<%=intl._t("Don't run I2P on startup")%>" ></div>
    5863 <p><b><%=intl._t("Note")%>:</b> <%=intl._t("If you are running I2P as service right now, removing it will shut down your router immediately.")%>
    5964    <%=intl._t("You may want to consider shutting down gracefully, as above, then running uninstall_i2p_service_winnt.bat.")%></p>
    60  <% } %>
     65<% } %>
    6166
    6267 <h3><%=intl._t("Debugging")%></h3>
Note: See TracChangeset for help on using the changeset viewer.