forked from I2P_Developers/i2p.i2p
DTG: Use actual console URL
Hide browse menu item if not supported
This commit is contained in:
@ -1,5 +1,7 @@
|
|||||||
package net.i2p.desktopgui;
|
package net.i2p.desktopgui;
|
||||||
|
|
||||||
|
import java.awt.Desktop;
|
||||||
|
import java.awt.Desktop.Action;
|
||||||
import java.awt.MenuItem;
|
import java.awt.MenuItem;
|
||||||
import java.awt.PopupMenu;
|
import java.awt.PopupMenu;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@ -15,6 +17,7 @@ import net.i2p.desktopgui.util.BrowseException;
|
|||||||
import net.i2p.desktopgui.util.I2PDesktop;
|
import net.i2p.desktopgui.util.I2PDesktop;
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
import net.i2p.util.PortMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* java -cp i2p.jar:router.jar:desktopgui.jar net.i2p.desktopgui.Main
|
* java -cp i2p.jar:router.jar:desktopgui.jar net.i2p.desktopgui.Main
|
||||||
@ -28,6 +31,9 @@ class InternalTrayManager extends TrayManager {
|
|||||||
private MenuItem _restartItem, _stopItem, _cancelItem;
|
private MenuItem _restartItem, _stopItem, _cancelItem;
|
||||||
private JMenuItem _jrestartItem, _jstopItem, _jcancelItem;
|
private JMenuItem _jrestartItem, _jstopItem, _jcancelItem;
|
||||||
|
|
||||||
|
private static final boolean CONSOLE_ENABLED = Desktop.isDesktopSupported() &&
|
||||||
|
Desktop.getDesktop().isSupported(Action.BROWSE);
|
||||||
|
|
||||||
public InternalTrayManager(RouterContext ctx, Main main, boolean useSwing) {
|
public InternalTrayManager(RouterContext ctx, Main main, boolean useSwing) {
|
||||||
super(ctx, main, useSwing);
|
super(ctx, main, useSwing);
|
||||||
_context = ctx;
|
_context = ctx;
|
||||||
@ -37,7 +43,9 @@ class InternalTrayManager extends TrayManager {
|
|||||||
public PopupMenu getMainMenu() {
|
public PopupMenu getMainMenu() {
|
||||||
PopupMenu popup = new PopupMenu();
|
PopupMenu popup = new PopupMenu();
|
||||||
|
|
||||||
MenuItem browserLauncher = new MenuItem(_t("Launch I2P Browser"));
|
MenuItem browserLauncher;
|
||||||
|
if (CONSOLE_ENABLED) {
|
||||||
|
browserLauncher = new MenuItem(_t("Launch I2P Browser"));
|
||||||
browserLauncher.addActionListener(new ActionListener() {
|
browserLauncher.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
@ -49,15 +57,14 @@ class InternalTrayManager extends TrayManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void done() {
|
protected void done() {
|
||||||
try {
|
launchBrowser();
|
||||||
I2PDesktop.browse("http://localhost:7657");
|
|
||||||
} catch (BrowseException e1) {
|
|
||||||
log.log(Log.WARN, "Failed to open browser!", e1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
browserLauncher = null;
|
||||||
|
}
|
||||||
|
|
||||||
PopupMenu desktopguiConfigurationLauncher = new PopupMenu(_t("Configure I2P System Tray"));
|
PopupMenu desktopguiConfigurationLauncher = new PopupMenu(_t("Configure I2P System Tray"));
|
||||||
MenuItem configSubmenu = new MenuItem(_t("Disable"));
|
MenuItem configSubmenu = new MenuItem(_t("Disable"));
|
||||||
@ -154,8 +161,10 @@ class InternalTrayManager extends TrayManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (CONSOLE_ENABLED) {
|
||||||
popup.add(browserLauncher);
|
popup.add(browserLauncher);
|
||||||
popup.addSeparator();
|
popup.addSeparator();
|
||||||
|
}
|
||||||
desktopguiConfigurationLauncher.add(configSubmenu);
|
desktopguiConfigurationLauncher.add(configSubmenu);
|
||||||
popup.add(desktopguiConfigurationLauncher);
|
popup.add(desktopguiConfigurationLauncher);
|
||||||
popup.addSeparator();
|
popup.addSeparator();
|
||||||
@ -177,7 +186,9 @@ class InternalTrayManager extends TrayManager {
|
|||||||
public JPopupMenu getSwingMainMenu() {
|
public JPopupMenu getSwingMainMenu() {
|
||||||
JPopupMenu popup = new JPopupMenu();
|
JPopupMenu popup = new JPopupMenu();
|
||||||
|
|
||||||
JMenuItem browserLauncher = new JMenuItem(_t("Launch I2P Browser"));
|
JMenuItem browserLauncher;
|
||||||
|
if (CONSOLE_ENABLED) {
|
||||||
|
browserLauncher = new JMenuItem(_t("Launch I2P Browser"));
|
||||||
browserLauncher.addActionListener(new ActionListener() {
|
browserLauncher.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
@ -189,15 +200,14 @@ class InternalTrayManager extends TrayManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void done() {
|
protected void done() {
|
||||||
try {
|
launchBrowser();
|
||||||
I2PDesktop.browse("http://localhost:7657");
|
|
||||||
} catch (BrowseException e1) {
|
|
||||||
log.log(Log.WARN, "Failed to open browser!", e1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
browserLauncher = null;
|
||||||
|
}
|
||||||
|
|
||||||
JMenu desktopguiConfigurationLauncher = new JMenu(_t("Configure I2P System Tray"));
|
JMenu desktopguiConfigurationLauncher = new JMenu(_t("Configure I2P System Tray"));
|
||||||
JMenuItem configSubmenu = new JMenuItem(_t("Disable"));
|
JMenuItem configSubmenu = new JMenuItem(_t("Disable"));
|
||||||
@ -294,8 +304,10 @@ class InternalTrayManager extends TrayManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (CONSOLE_ENABLED) {
|
||||||
popup.add(browserLauncher);
|
popup.add(browserLauncher);
|
||||||
popup.addSeparator();
|
popup.addSeparator();
|
||||||
|
}
|
||||||
desktopguiConfigurationLauncher.add(configSubmenu);
|
desktopguiConfigurationLauncher.add(configSubmenu);
|
||||||
popup.add(desktopguiConfigurationLauncher);
|
popup.add(desktopguiConfigurationLauncher);
|
||||||
popup.addSeparator();
|
popup.addSeparator();
|
||||||
@ -351,4 +363,36 @@ class InternalTrayManager extends TrayManager {
|
|||||||
log.error("Error saving config", ex);
|
log.error("Error saving config", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the console URL with info from the port mapper,
|
||||||
|
* and launch the browser at it.
|
||||||
|
*
|
||||||
|
* Modified from I2PTunnelHTTPClientBase.
|
||||||
|
* TODO perhaps move this to a new PortMapper method.
|
||||||
|
*
|
||||||
|
* @since 0.9.26
|
||||||
|
*/
|
||||||
|
private void launchBrowser() {
|
||||||
|
String unset = "*unset*";
|
||||||
|
PortMapper pm = _context.portMapper();
|
||||||
|
String httpHost = pm.getActualHost(PortMapper.SVC_CONSOLE, unset);
|
||||||
|
String httpsHost = pm.getActualHost(PortMapper.SVC_HTTPS_CONSOLE, unset);
|
||||||
|
int httpPort = pm.getPort(PortMapper.SVC_CONSOLE, 7657);
|
||||||
|
int httpsPort = pm.getPort(PortMapper.SVC_HTTPS_CONSOLE, -1);
|
||||||
|
boolean httpsOnly = httpsPort > 0 && httpHost.equals(unset) && !httpsHost.equals(unset);
|
||||||
|
String url;
|
||||||
|
if (httpsOnly) {
|
||||||
|
url = "https://" + httpsHost + ':' + httpsPort + '/';
|
||||||
|
} else {
|
||||||
|
if (httpHost.equals(unset))
|
||||||
|
httpHost = "127.0.0.1";
|
||||||
|
url = "http://" + httpHost + ':' + httpPort + '/';
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
I2PDesktop.browse(url);
|
||||||
|
} catch (BrowseException e1) {
|
||||||
|
log.log(Log.WARN, "Failed to open browser!", e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user