DTG: Use UrlLauncher to launch browser

This commit is contained in:
zzz
2018-12-12 15:17:51 +00:00
parent 5eda30644f
commit 51bf23a34c
6 changed files with 8 additions and 61 deletions

View File

@ -34,6 +34,7 @@
<pathelement location="../../core/java/build/i2p.jar" /> <pathelement location="../../core/java/build/i2p.jar" />
<pathelement location="../../installer/lib/wrapper/all/wrapper.jar" /> <pathelement location="../../installer/lib/wrapper/all/wrapper.jar" />
<pathelement location="../../router/java/build/router.jar" /> <pathelement location="../../router/java/build/router.jar" />
<pathelement location="../systray/java/build/systray.jar" />
</classpath> </classpath>
</javac> </javac>
</target> </target>

View File

@ -6,16 +6,15 @@ import java.awt.MenuItem;
import java.awt.PopupMenu; import java.awt.PopupMenu;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JMenu; import javax.swing.JMenu;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.JPopupMenu; import javax.swing.JPopupMenu;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
import net.i2p.apps.systray.UrlLauncher;
import net.i2p.data.DataHelper; import net.i2p.data.DataHelper;
import net.i2p.desktopgui.router.RouterManager; import net.i2p.desktopgui.router.RouterManager;
import net.i2p.desktopgui.util.BrowseException;
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; import net.i2p.util.PortMapper;
@ -433,15 +432,16 @@ class InternalTrayManager extends TrayManager {
* and launch the browser at it. * and launch the browser at it.
* *
* Modified from I2PTunnelHTTPClientBase. * Modified from I2PTunnelHTTPClientBase.
* TODO perhaps move this to a new PortMapper method.
* *
* @since 0.9.26 * @since 0.9.26
*/ */
private void launchBrowser() { private void launchBrowser() {
// null args ok
UrlLauncher launcher = new UrlLauncher(_context, null, null);
String url = _context.portMapper().getConsoleURL(); String url = _context.portMapper().getConsoleURL();
try { try {
I2PDesktop.browse(url); launcher.openUrl(url);
} catch (BrowseException e1) { } catch (IOException e1) {
log.log(Log.WARN, "Failed to open browser!", e1); log.log(Log.WARN, "Failed to open browser!", e1);
} }
} }

View File

@ -17,7 +17,6 @@ import net.i2p.app.ClientAppManager;
import net.i2p.app.ClientAppState; import net.i2p.app.ClientAppState;
import static net.i2p.app.ClientAppState.*; import static net.i2p.app.ClientAppState.*;
import net.i2p.desktopgui.router.RouterManager; import net.i2p.desktopgui.router.RouterManager;
import net.i2p.desktopgui.util.*;
import net.i2p.router.RouterContext; import net.i2p.router.RouterContext;
import net.i2p.router.app.RouterApp; import net.i2p.router.app.RouterApp;
import net.i2p.util.Log; import net.i2p.util.Log;

View File

@ -1,23 +0,0 @@
package net.i2p.desktopgui.util;
public class BrowseException extends Exception {
private static final long serialVersionUID = 1L;
public BrowseException() {
super();
}
public BrowseException(String s) {
super(s);
}
public BrowseException(String s, Throwable t) {
super(s, t);
}
public BrowseException(Throwable t) {
super(t);
}
}

View File

@ -1,27 +0,0 @@
package net.i2p.desktopgui.util;
import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.net.URI;
public class I2PDesktop {
public static void browse(String url) throws BrowseException {
if(Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
if(desktop.isSupported(Action.BROWSE)) {
try {
desktop.browse(new URI(url));
} catch (Exception e) {
throw new BrowseException();
}
}
else {
throw new BrowseException();
}
}
else {
throw new BrowseException();
}
}
}

View File

@ -388,10 +388,7 @@
<copy file="apps/i2ptunnel/java/build/i2ptunnel.war" todir="build/" /> <copy file="apps/i2ptunnel/java/build/i2ptunnel.war" todir="build/" />
</target> </target>
<target name="buildDesktopGui" depends="buildCore, buildrouter" > <target name="buildDesktopGui" depends="buildCore, buildrouter, buildSystray" >
<!--
<ant dir="apps/desktopgui" target="clean" />
-->
<ant dir="apps/desktopgui" target="jar" /> <ant dir="apps/desktopgui" target="jar" />
<copy file="apps/desktopgui/dist/desktopgui.jar" todir="build/" /> <copy file="apps/desktopgui/dist/desktopgui.jar" todir="build/" />
</target> </target>