Search in sources :

Example 6 with ClientApp

use of net.i2p.app.ClientApp in project i2p.i2p by i2p.

the class ConfigServiceHandler method changeSystray.

/**
 *  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();
                        addFormNotice(_t("Enabled system tray"));
                    }
                } else {
                    if (dtg.getState() == ClientAppState.RUNNING) {
                        dtg.shutdown(null);
                        addFormNotice(_t("Disabled system tray"));
                    }
                }
            } else if (enable) {
                // 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 {
                    dtg = new net.i2p.desktopgui.Main(_context, mgr, null);
                    dtg.startup();
                    addFormNotice(_t("Enabled system tray"));
                }
            }
        } 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"));
}
Also used : ClientApp(net.i2p.app.ClientApp) ClientAppManager(net.i2p.app.ClientAppManager)

Aggregations

ClientApp (net.i2p.app.ClientApp)6 IOException (java.io.IOException)3 ClientAppManager (net.i2p.app.ClientAppManager)3 ClientAppConfig (net.i2p.router.startup.ClientAppConfig)3 OutputStream (java.io.OutputStream)2 Socket (java.net.Socket)2 I2PException (net.i2p.I2PException)2 Outproxy (net.i2p.app.Outproxy)2 I2PSocket (net.i2p.client.streaming.I2PSocket)2 I2PSocketOptions (net.i2p.client.streaming.I2PSocketOptions)2 Destination (net.i2p.data.Destination)2 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 I2PSession (net.i2p.client.I2PSession)1 Hash (net.i2p.data.Hash)1