2004-08-23 07:33:14 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
2012-05-20 18:12:41 +00:00
|
|
|
import java.io.File;
|
2004-08-31 21:25:23 +00:00
|
|
|
import java.io.IOException;
|
2009-01-02 20:09:20 +00:00
|
|
|
import java.util.List;
|
2014-03-12 12:33:36 +00:00
|
|
|
import java.util.Properties;
|
2004-08-31 21:25:23 +00:00
|
|
|
|
2017-12-01 14:07:29 +00:00
|
|
|
import net.i2p.I2PAppContext;
|
2016-05-06 17:54:27 +00:00
|
|
|
import net.i2p.app.ClientApp;
|
|
|
|
import net.i2p.app.ClientAppManager;
|
|
|
|
import net.i2p.app.ClientAppState;
|
2004-11-25 21:57:19 +00:00
|
|
|
import net.i2p.apps.systray.UrlLauncher;
|
2008-07-16 13:42:54 +00:00
|
|
|
import net.i2p.router.Router;
|
2011-07-15 01:13:35 +00:00
|
|
|
import net.i2p.router.RouterContext;
|
2009-01-02 20:09:20 +00:00
|
|
|
import net.i2p.router.startup.ClientAppConfig;
|
2012-10-13 13:06:22 +00:00
|
|
|
import net.i2p.util.PortMapper;
|
2012-09-09 15:40:14 +00:00
|
|
|
import net.i2p.util.SystemVersion;
|
2012-01-09 23:59:58 +00:00
|
|
|
import net.i2p.util.VersionComparator;
|
2008-07-16 13:42:54 +00:00
|
|
|
|
2004-08-23 21:32:24 +00:00
|
|
|
import org.tanukisoftware.wrapper.WrapperManager;
|
2004-08-23 07:33:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler to deal with form submissions from the service config form and act
|
|
|
|
* upon the values.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class ConfigServiceHandler extends FormHandler {
|
|
|
|
|
2012-01-09 23:59:58 +00:00
|
|
|
private static WrapperListener _wrapperListener;
|
2012-01-08 13:15:47 +00:00
|
|
|
|
2012-01-09 23:59:58 +00:00
|
|
|
private static final String LISTENER_AVAILABLE = "3.2.0";
|
2014-07-03 13:07:41 +00:00
|
|
|
private static final String PROPERTIES_AVAILABLE = "3.2.0";
|
2017-12-01 14:07:29 +00:00
|
|
|
private static final String LOCATION_AVAILABLE = "3.3.7";
|
2012-01-08 13:15:47 +00:00
|
|
|
|
2011-07-15 01:13:35 +00:00
|
|
|
/**
|
|
|
|
* Register two shutdown hooks, one to rekey and/or tell the wrapper we are stopping,
|
|
|
|
* and a final one to tell the wrapper we are stopped.
|
|
|
|
*
|
|
|
|
* @since 0.8.8
|
|
|
|
*/
|
|
|
|
private void registerWrapperNotifier(int code, boolean rekey) {
|
|
|
|
registerWrapperNotifier(_context, code, rekey);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register two shutdown hooks, one to rekey and/or tell the wrapper we are stopping,
|
|
|
|
* and a final one to tell the wrapper we are stopped.
|
|
|
|
*
|
|
|
|
* @since 0.8.8
|
|
|
|
*/
|
|
|
|
public static void registerWrapperNotifier(RouterContext ctx, int code, boolean rekey) {
|
|
|
|
Runnable task = new UpdateWrapperOrRekeyTask(rekey, ctx.hasWrapper());
|
|
|
|
ctx.addShutdownTask(task);
|
|
|
|
if (ctx.hasWrapper()) {
|
|
|
|
task = new FinalWrapperTask(code);
|
|
|
|
ctx.addFinalShutdownTask(task);
|
2004-09-07 07:17:02 +00:00
|
|
|
}
|
2011-07-15 01:13:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rekey and/or tell the wrapper we are stopping,
|
|
|
|
*/
|
|
|
|
private static class UpdateWrapperOrRekeyTask implements Runnable {
|
|
|
|
private final boolean _rekey;
|
|
|
|
private final boolean _tellWrapper;
|
|
|
|
private static final int HASHCODE = -123999871;
|
2014-03-12 12:33:36 +00:00
|
|
|
// RPi takes a long time to write out the peer profiles
|
|
|
|
private static final int WAIT = SystemVersion.isARM() ? 4*60*1000 : 2*60*1000;
|
2011-07-15 01:13:35 +00:00
|
|
|
|
|
|
|
public UpdateWrapperOrRekeyTask(boolean rekey, boolean tellWrapper) {
|
|
|
|
_rekey = rekey;
|
|
|
|
_tellWrapper = tellWrapper;
|
|
|
|
}
|
|
|
|
|
2004-09-07 07:17:02 +00:00
|
|
|
public void run() {
|
|
|
|
try {
|
2011-07-15 01:13:35 +00:00
|
|
|
if (_rekey)
|
|
|
|
ContextHelper.getContext(null).router().killKeys();
|
2014-03-12 12:33:36 +00:00
|
|
|
if (_tellWrapper) {
|
|
|
|
int wait = WAIT;
|
2014-07-03 13:07:41 +00:00
|
|
|
String wv = System.getProperty("wrapper.version");
|
|
|
|
if (wv != null && VersionComparator.comp(wv, PROPERTIES_AVAILABLE) >= 0) {
|
|
|
|
try {
|
|
|
|
Properties props = WrapperManager.getProperties();
|
|
|
|
String tmout = props.getProperty("wrapper.jvm_exit.timeout");
|
|
|
|
if (tmout != null) {
|
|
|
|
try {
|
|
|
|
int cwait = Integer.parseInt(tmout) * 1000;
|
|
|
|
if (cwait > wait)
|
|
|
|
wait = cwait;
|
|
|
|
} catch (NumberFormatException nfe) {}
|
|
|
|
}
|
|
|
|
} catch (Throwable t) {}
|
|
|
|
}
|
2014-03-12 12:33:36 +00:00
|
|
|
WrapperManager.signalStopping(wait);
|
|
|
|
}
|
2004-09-07 07:17:02 +00:00
|
|
|
} catch (Throwable t) {
|
|
|
|
t.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2011-07-15 01:13:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make them all look the same since the hooks are stored in a set
|
|
|
|
* and we don't want dups
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return HASHCODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make them all look the same since the hooks are stored in a set
|
|
|
|
* and we don't want dups
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
return (o != null) && (o instanceof UpdateWrapperOrRekeyTask);
|
|
|
|
}
|
2004-09-07 07:17:02 +00:00
|
|
|
}
|
2005-11-26 09:16:11 +00:00
|
|
|
|
2011-07-15 01:13:35 +00:00
|
|
|
/**
|
|
|
|
* Tell the wrapper we are stopped.
|
|
|
|
*
|
|
|
|
* @since 0.8.8
|
|
|
|
*/
|
|
|
|
private static class FinalWrapperTask implements Runnable {
|
|
|
|
private final int _exitCode;
|
|
|
|
private static final int HASHCODE = 123999871;
|
|
|
|
|
|
|
|
public FinalWrapperTask(int exitCode) {
|
2005-11-26 09:16:11 +00:00
|
|
|
_exitCode = exitCode;
|
|
|
|
}
|
2011-07-15 01:13:35 +00:00
|
|
|
|
2005-11-26 09:16:11 +00:00
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
WrapperManager.signalStopped(_exitCode);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
t.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2011-07-15 01:13:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make them all look the same since the hooks are stored in a set
|
|
|
|
* and we don't want dups
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return HASHCODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make them all look the same since the hooks are stored in a set
|
|
|
|
* and we don't want dups
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
return (o != null) && (o instanceof FinalWrapperTask);
|
|
|
|
}
|
2005-11-26 09:16:11 +00:00
|
|
|
}
|
2011-07-15 01:13:35 +00:00
|
|
|
|
2012-01-08 13:15:47 +00:00
|
|
|
/**
|
|
|
|
* Register a handler for signals,
|
2015-12-20 14:33:24 +00:00
|
|
|
* so we can handle HUP from the wrapper (wrapper 3.2.0 or higher)
|
2012-01-08 13:15:47 +00:00
|
|
|
*
|
|
|
|
* @since 0.8.13
|
|
|
|
*/
|
|
|
|
synchronized static void registerSignalHandler(RouterContext ctx) {
|
2015-12-11 15:13:40 +00:00
|
|
|
if (ctx.hasWrapper() && _wrapperListener == null) {
|
2012-01-09 23:59:58 +00:00
|
|
|
String wv = System.getProperty("wrapper.version");
|
2013-05-26 17:25:02 +00:00
|
|
|
if (wv != null && VersionComparator.comp(wv, LISTENER_AVAILABLE) >= 0) {
|
2012-01-09 23:59:58 +00:00
|
|
|
try {
|
|
|
|
_wrapperListener = new WrapperListener(ctx);
|
|
|
|
} catch (Throwable t) {}
|
|
|
|
}
|
2012-01-08 13:15:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister the handler for signals
|
|
|
|
*
|
|
|
|
* @since 0.8.13
|
|
|
|
*/
|
|
|
|
public synchronized static void unregisterSignalHandler() {
|
2012-01-09 23:59:58 +00:00
|
|
|
if (_wrapperListener != null) {
|
|
|
|
_wrapperListener.unregister();
|
|
|
|
_wrapperListener = null;
|
2012-01-08 13:15:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-08 20:23:00 +00:00
|
|
|
/**
|
|
|
|
* Should we show the cancel button?
|
|
|
|
*
|
|
|
|
* @since 0.9.19
|
|
|
|
*/
|
|
|
|
public boolean shouldShowCancelGraceful() {
|
|
|
|
return _context.router().gracefulShutdownInProgress();
|
|
|
|
}
|
|
|
|
|
2016-05-06 17:54:27 +00:00
|
|
|
/**
|
|
|
|
* Should we show the systray controls?
|
|
|
|
*
|
|
|
|
* @since 0.9.26
|
|
|
|
*/
|
|
|
|
public boolean shouldShowSystray() {
|
|
|
|
return !
|
2016-11-06 00:49:34 +00:00
|
|
|
(SystemVersion.isLinuxService() ||
|
2017-11-19 00:40:50 +00:00
|
|
|
(SystemVersion.isWindows() && _context.hasWrapper() && WrapperManager.isLaunchedAsService()));
|
2016-05-06 17:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is the systray enabled?
|
|
|
|
*
|
|
|
|
* @since 0.9.26
|
|
|
|
*/
|
|
|
|
public boolean isSystrayEnabled() {
|
2017-11-19 00:40:50 +00:00
|
|
|
// default false for now, except on OSX and non-service windows
|
2016-09-24 14:54:30 +00:00
|
|
|
String sdtg = _context.getProperty(RouterConsoleRunner.PROP_DTG_ENABLED);
|
|
|
|
return Boolean.parseBoolean(sdtg) ||
|
2017-11-19 00:40:50 +00:00
|
|
|
(sdtg == null && (SystemVersion.isWindows() || SystemVersion.isMac()));
|
2016-05-06 17:54:27 +00:00
|
|
|
}
|
|
|
|
|
2018-01-18 13:25:21 +00:00
|
|
|
/**
|
|
|
|
* @since 0.9.33
|
|
|
|
*/
|
|
|
|
public String getConsoleURL() {
|
|
|
|
return _context.portMapper().getConsoleURL();
|
|
|
|
}
|
|
|
|
|
2009-08-15 16:08:33 +00:00
|
|
|
@Override
|
2004-08-23 07:33:14 +00:00
|
|
|
protected void processForm() {
|
2015-09-25 19:55:36 +00:00
|
|
|
if (_t("Shutdown gracefully").equals(_action)) {
|
2011-07-03 13:46:29 +00:00
|
|
|
if (_context.hasWrapper())
|
2011-07-15 01:13:35 +00:00
|
|
|
registerWrapperNotifier(Router.EXIT_GRACEFUL, false);
|
2004-08-23 07:33:14 +00:00
|
|
|
_context.router().shutdownGracefully();
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormNotice(_t("Graceful shutdown initiated"));
|
|
|
|
} else if (_t("Shutdown immediately").equals(_action)) {
|
2011-07-03 13:46:29 +00:00
|
|
|
if (_context.hasWrapper())
|
2011-07-15 01:13:35 +00:00
|
|
|
registerWrapperNotifier(Router.EXIT_HARD, false);
|
2004-08-23 21:32:24 +00:00
|
|
|
_context.router().shutdown(Router.EXIT_HARD);
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormNotice(_t("Shutdown immediately"));
|
|
|
|
} else if (_t("Cancel graceful shutdown").equals(_action)) {
|
2004-08-23 07:33:14 +00:00
|
|
|
_context.router().cancelGracefulShutdown();
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormNotice(_t("Graceful shutdown cancelled"));
|
|
|
|
} else if (_t("Graceful restart").equals(_action)) {
|
2011-07-03 13:46:29 +00:00
|
|
|
// should have wrapper if restart button is visible
|
|
|
|
if (_context.hasWrapper())
|
2011-07-15 01:13:35 +00:00
|
|
|
registerWrapperNotifier(Router.EXIT_GRACEFUL_RESTART, false);
|
2004-09-06 05:20:40 +00:00
|
|
|
_context.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART);
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormNotice(_t("Graceful restart requested"));
|
|
|
|
} else if (_t("Hard restart").equals(_action)) {
|
2011-07-03 13:46:29 +00:00
|
|
|
// should have wrapper if restart button is visible
|
|
|
|
if (_context.hasWrapper())
|
2011-07-15 01:13:35 +00:00
|
|
|
registerWrapperNotifier(Router.EXIT_HARD_RESTART, false);
|
2004-08-24 18:02:48 +00:00
|
|
|
_context.router().shutdown(Router.EXIT_HARD_RESTART);
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormNotice(_t("Hard restart requested"));
|
|
|
|
} else if (_t("Rekey and Restart").equals(_action)) {
|
|
|
|
addFormNotice(_t("Rekeying after graceful restart"));
|
2011-07-15 01:13:35 +00:00
|
|
|
registerWrapperNotifier(Router.EXIT_GRACEFUL_RESTART, true);
|
2005-11-26 09:16:11 +00:00
|
|
|
_context.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART);
|
2015-09-25 19:55:36 +00:00
|
|
|
} else if (_t("Rekey and Shutdown").equals(_action)) {
|
|
|
|
addFormNotice(_t("Rekeying after graceful shutdown"));
|
2011-07-15 01:13:35 +00:00
|
|
|
registerWrapperNotifier(Router.EXIT_GRACEFUL, true);
|
2005-11-26 09:16:11 +00:00
|
|
|
_context.router().shutdownGracefully(Router.EXIT_GRACEFUL);
|
2015-09-25 19:55:36 +00:00
|
|
|
} else if (_t("Run I2P on startup").equals(_action)) {
|
2004-08-31 21:25:23 +00:00
|
|
|
installService();
|
2015-09-25 19:55:36 +00:00
|
|
|
} else if (_t("Don't run I2P on startup").equals(_action)) {
|
2004-08-31 21:25:23 +00:00
|
|
|
uninstallService();
|
2015-09-25 19:55:36 +00:00
|
|
|
} else if (_t("Dump threads").equals(_action)) {
|
2004-08-26 03:12:52 +00:00
|
|
|
try {
|
|
|
|
WrapperManager.requestThreadDump();
|
|
|
|
} catch (Throwable t) {
|
2019-12-15 15:48:19 +00:00
|
|
|
addFormError("Warning: unable to contact the service manager - " + t.getLocalizedMessage());
|
2004-08-26 03:12:52 +00:00
|
|
|
}
|
2017-12-01 14:07:29 +00:00
|
|
|
File wlog = wrapperLogFile(_context);
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormNotice(_t("Threads dumped to {0}", wlog.getAbsolutePath()));
|
|
|
|
} else if (_t("View console on startup").equals(_action)) {
|
2004-11-25 21:57:19 +00:00
|
|
|
browseOnStartup(true);
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormNotice(_t("Console is to be shown on startup"));
|
|
|
|
} else if (_t("Do not view console on startup").equals(_action)) {
|
2004-11-25 21:57:19 +00:00
|
|
|
browseOnStartup(false);
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormNotice(_t("Console is not to be shown on startup"));
|
|
|
|
} else if (_t("Force GC").equals(_action)) {
|
2012-10-05 13:09:34 +00:00
|
|
|
Runtime.getRuntime().gc();
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormNotice(_t("Full garbage collection requested"));
|
2016-05-06 17:54:27 +00:00
|
|
|
} else if (_t("Show systray icon").equals(_action)) {
|
|
|
|
changeSystray(true);
|
|
|
|
} else if (_t("Hide systray icon").equals(_action)) {
|
|
|
|
changeSystray(false);
|
2004-08-23 07:33:14 +00:00
|
|
|
} else {
|
2006-02-15 05:33:17 +00:00
|
|
|
//addFormNotice("Blah blah blah. whatever. I'm not going to " + _action);
|
2004-08-23 07:33:14 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-31 21:25:23 +00:00
|
|
|
|
2017-12-01 14:07:29 +00:00
|
|
|
/**
|
|
|
|
* Does not necessarily exist.
|
|
|
|
*
|
|
|
|
* @return non-null, doesn't necessarily exist
|
|
|
|
* @since 0.9.1, public since 0.9.27, moved from LogsHelper in 0.9.33
|
|
|
|
*/
|
|
|
|
public static File wrapperLogFile(I2PAppContext ctx) {
|
|
|
|
File f = null;
|
|
|
|
if (ctx.hasWrapper()) {
|
|
|
|
String wv = System.getProperty("wrapper.version");
|
|
|
|
if (wv != null && VersionComparator.comp(wv, LOCATION_AVAILABLE) >= 0) {
|
|
|
|
try {
|
|
|
|
f = WrapperManager.getWrapperLogFile();
|
|
|
|
} catch (Throwable t) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (f == null || !f.exists()) {
|
|
|
|
// RouterLaunch puts the location here if no wrapper
|
|
|
|
String path = System.getProperty("wrapper.logfile");
|
|
|
|
if (path != null) {
|
|
|
|
f = new File(path);
|
|
|
|
} else {
|
|
|
|
// look in new and old places
|
|
|
|
f = new File(System.getProperty("java.io.tmpdir"), "wrapper.log");
|
|
|
|
if (!f.exists())
|
|
|
|
f = new File(ctx.getBaseDir(), "wrapper.log");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2004-08-31 21:25:23 +00:00
|
|
|
private void installService() {
|
|
|
|
try {
|
|
|
|
Runtime.getRuntime().exec("install_i2p_service_winnt.bat");
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormNotice(_t("Service installed"));
|
2004-08-31 21:25:23 +00:00
|
|
|
} catch (IOException ioe) {
|
2019-12-15 15:48:19 +00:00
|
|
|
addFormError(_t("Warning: unable to install the service") + " - " + ioe.getLocalizedMessage());
|
2004-08-31 21:25:23 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-08 13:15:47 +00:00
|
|
|
|
2004-08-31 21:25:23 +00:00
|
|
|
private void uninstallService() {
|
|
|
|
try {
|
|
|
|
Runtime.getRuntime().exec("uninstall_i2p_service_winnt.bat");
|
2015-09-25 19:55:36 +00:00
|
|
|
addFormNotice(_t("Service removed"));
|
2004-08-31 21:25:23 +00:00
|
|
|
} catch (IOException ioe) {
|
2019-12-15 15:48:19 +00:00
|
|
|
addFormError(_t("Warning: unable to remove the service") + " - " + ioe.getLocalizedMessage());
|
2004-08-31 21:25:23 +00:00
|
|
|
}
|
|
|
|
}
|
2004-11-25 21:57:19 +00:00
|
|
|
|
|
|
|
private void browseOnStartup(boolean shouldLaunchBrowser) {
|
2013-11-21 11:31:50 +00:00
|
|
|
List<ClientAppConfig> clients = ClientAppConfig.getClientApps(_context);
|
2019-05-10 14:58:41 +00:00
|
|
|
ClientAppConfig ca = null;
|
2009-01-02 20:09:20 +00:00
|
|
|
for (int cur = 0; cur < clients.size(); cur++) {
|
2019-05-10 14:58:41 +00:00
|
|
|
ClientAppConfig cac = clients.get(cur);
|
|
|
|
if (UrlLauncher.class.getName().equals(cac.className)) {
|
|
|
|
ca = cac;
|
2009-01-02 20:09:20 +00:00
|
|
|
ca.disabled = !shouldLaunchBrowser;
|
|
|
|
break;
|
2004-11-25 21:57:19 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-02 20:09:20 +00:00
|
|
|
// releases <= 0.6.5 deleted the entry completely
|
2019-05-10 14:58:41 +00:00
|
|
|
if (shouldLaunchBrowser && ca == null) {
|
2018-01-18 13:25:21 +00:00
|
|
|
String url = _context.portMapper().getConsoleURL();
|
2019-05-10 14:58:41 +00:00
|
|
|
ca = new ClientAppConfig(UrlLauncher.class.getName(), "consoleBrowser",
|
|
|
|
url, 5, false);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (ca != null)
|
|
|
|
ClientAppConfig.writeClientAppConfig(_context, ca);
|
|
|
|
addFormNotice(_t("Configuration saved successfully"));
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
addFormError(_t("Error saving the configuration (applied but not saved) - please see the error logs"));
|
|
|
|
addFormError(ioe.getLocalizedMessage());
|
2009-01-02 20:09:20 +00:00
|
|
|
}
|
2004-11-25 21:57:19 +00:00
|
|
|
}
|
2016-05-06 17:54:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2016-05-09 14:26:07 +00:00
|
|
|
if (dtg.getState() == ClientAppState.STOPPED) {
|
2016-05-06 17:54:27 +00:00
|
|
|
dtg.startup();
|
2016-05-09 14:26:07 +00:00
|
|
|
addFormNotice(_t("Enabled system tray"));
|
|
|
|
}
|
2016-05-06 17:54:27 +00:00
|
|
|
} else {
|
2016-05-09 14:26:07 +00:00
|
|
|
if (dtg.getState() == ClientAppState.RUNNING) {
|
2016-05-06 17:54:27 +00:00
|
|
|
dtg.shutdown(null);
|
2016-05-09 14:26:07 +00:00
|
|
|
addFormNotice(_t("Disabled system tray"));
|
|
|
|
}
|
2016-05-06 17:54:27 +00:00
|
|
|
}
|
|
|
|
} else if (enable) {
|
2016-05-09 14:26:07 +00:00
|
|
|
// already set to true, GraphicsEnvironment initialized, can't change it now
|
|
|
|
if (Boolean.valueOf(System.getProperty("java.awt.headless"))) {
|
|
|
|
addFormError(_t("Restart required to take effect"));
|
|
|
|
} else {
|
2016-05-06 17:54:27 +00:00
|
|
|
dtg = new net.i2p.desktopgui.Main(_context, mgr, null);
|
|
|
|
dtg.startup();
|
2016-05-09 14:26:07 +00:00
|
|
|
addFormNotice(_t("Enabled system tray"));
|
|
|
|
}
|
2016-05-06 17:54:27 +00:00
|
|
|
}
|
|
|
|
} 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"));
|
|
|
|
}
|
2005-11-26 09:16:11 +00:00
|
|
|
}
|