From 51bf23a34c63a57eafaae24bcd6d9e339a17c7f8 Mon Sep 17 00:00:00 2001 From: zzz Date: Wed, 12 Dec 2018 15:17:51 +0000 Subject: [PATCH] DTG: Use UrlLauncher to launch browser --- apps/desktopgui/build.xml | 1 + .../i2p/desktopgui/InternalTrayManager.java | 12 ++++----- .../src/net/i2p/desktopgui/Main.java | 1 - .../i2p/desktopgui/util/BrowseException.java | 23 ---------------- .../net/i2p/desktopgui/util/I2PDesktop.java | 27 ------------------- build.xml | 5 +--- 6 files changed, 8 insertions(+), 61 deletions(-) delete mode 100644 apps/desktopgui/src/net/i2p/desktopgui/util/BrowseException.java delete mode 100644 apps/desktopgui/src/net/i2p/desktopgui/util/I2PDesktop.java diff --git a/apps/desktopgui/build.xml b/apps/desktopgui/build.xml index 5a18942ac5..02196c4162 100644 --- a/apps/desktopgui/build.xml +++ b/apps/desktopgui/build.xml @@ -34,6 +34,7 @@ + diff --git a/apps/desktopgui/src/net/i2p/desktopgui/InternalTrayManager.java b/apps/desktopgui/src/net/i2p/desktopgui/InternalTrayManager.java index 3b7984abeb..eeb9c958d3 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/InternalTrayManager.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/InternalTrayManager.java @@ -6,16 +6,15 @@ import java.awt.MenuItem; import java.awt.PopupMenu; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; - +import java.io.IOException; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.SwingWorker; +import net.i2p.apps.systray.UrlLauncher; import net.i2p.data.DataHelper; 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.util.Log; import net.i2p.util.PortMapper; @@ -433,15 +432,16 @@ class InternalTrayManager extends TrayManager { * 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() { + // null args ok + UrlLauncher launcher = new UrlLauncher(_context, null, null); String url = _context.portMapper().getConsoleURL(); try { - I2PDesktop.browse(url); - } catch (BrowseException e1) { + launcher.openUrl(url); + } catch (IOException e1) { log.log(Log.WARN, "Failed to open browser!", e1); } } diff --git a/apps/desktopgui/src/net/i2p/desktopgui/Main.java b/apps/desktopgui/src/net/i2p/desktopgui/Main.java index 754723b2b3..70b96d7a43 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/Main.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/Main.java @@ -17,7 +17,6 @@ import net.i2p.app.ClientAppManager; import net.i2p.app.ClientAppState; import static net.i2p.app.ClientAppState.*; import net.i2p.desktopgui.router.RouterManager; -import net.i2p.desktopgui.util.*; import net.i2p.router.RouterContext; import net.i2p.router.app.RouterApp; import net.i2p.util.Log; diff --git a/apps/desktopgui/src/net/i2p/desktopgui/util/BrowseException.java b/apps/desktopgui/src/net/i2p/desktopgui/util/BrowseException.java deleted file mode 100644 index a5e4f4350c..0000000000 --- a/apps/desktopgui/src/net/i2p/desktopgui/util/BrowseException.java +++ /dev/null @@ -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); - } - -} \ No newline at end of file diff --git a/apps/desktopgui/src/net/i2p/desktopgui/util/I2PDesktop.java b/apps/desktopgui/src/net/i2p/desktopgui/util/I2PDesktop.java deleted file mode 100644 index 696088cfb6..0000000000 --- a/apps/desktopgui/src/net/i2p/desktopgui/util/I2PDesktop.java +++ /dev/null @@ -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(); - } - } -} diff --git a/build.xml b/build.xml index cfa7ea22f4..e836af31ca 100644 --- a/build.xml +++ b/build.xml @@ -388,10 +388,7 @@ - - +