forked from I2P_Developers/i2p.i2p
Console:
- Show systray controls for all OSes on /configservice - Implement backend for systray control
This commit is contained in:
@ -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"));
|
||||
}
|
||||
}
|
||||
|
@ -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";
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
@ -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()));
|
||||
|
@ -39,25 +39,30 @@
|
||||
<input type="submit" class="reload" name="action" value="<%=intl._t("Hard restart")%>" >
|
||||
<% } %></div>
|
||||
|
||||
<% if ( (System.getProperty("os.name") != null) && (System.getProperty("os.name").startsWith("Win")) ) { %>
|
||||
<% if (formhandler.shouldShowSystray()) { %>
|
||||
<h3><%=intl._t("Systray integration")%></h3>
|
||||
<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")%>
|
||||
<%=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.")%></p>
|
||||
<p><%=intl._t("Control the system tray icon")%>
|
||||
<hr><div class="formaction">
|
||||
<input type="submit" name="action" value="<%=intl._t("Show systray icon")%>" >
|
||||
<input type="submit" name="action" value="<%=intl._t("Hide systray icon")%>" >
|
||||
<% if (!formhandler.isSystrayEnabled()) { %>
|
||||
<input type="submit" name="action" class="accept" value="<%=intl._t("Show systray icon")%>" >
|
||||
<% } else {%>
|
||||
<input type="submit" name="action" class="cancel" value="<%=intl._t("Hide systray icon")%>" >
|
||||
<% } %>
|
||||
</div>
|
||||
<%
|
||||
}
|
||||
if ( (System.getProperty("os.name") != null) && (System.getProperty("os.name").startsWith("Win")) ) { %>
|
||||
%>
|
||||
<h3><%=intl._t("Run on startup")%></h3>
|
||||
<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.")%>
|
||||
<%=intl._t("If you prefer the command line, you can also run the ")%> <code>install_i2p_service_winnt.bat</code> (<%=intl._t("or")%>
|
||||
<code>uninstall_i2p_service_winnt.bat</code>).</p>
|
||||
<hr><div class="formaction">
|
||||
<input type="submit" name="action" value="<%=intl._t("Run I2P on startup")%>" >
|
||||
<input type="submit" name="action" value="<%=intl._t("Don't run I2P on startup")%>" ></div>
|
||||
<input type="submit" name="action" class="accept" value="<%=intl._t("Run I2P on startup")%>" >
|
||||
<input type="submit" name="action" class="cancel" value="<%=intl._t("Don't run I2P on startup")%>" ></div>
|
||||
<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.")%>
|
||||
<%=intl._t("You may want to consider shutting down gracefully, as above, then running uninstall_i2p_service_winnt.bat.")%></p>
|
||||
<% } %>
|
||||
<% } %>
|
||||
|
||||
<h3><%=intl._t("Debugging")%></h3>
|
||||
<p><a href="/jobs"><%=intl._t("View the job queue")%></a>
|
||||
|
Reference in New Issue
Block a user