-
Notifications
You must be signed in to change notification settings - Fork 42
Upgrade BareBonesBrowserLauncher; improve linux support #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
98 changes: 62 additions & 36 deletions
98
client/src/com/mirth/connect/client/ui/BareBonesBrowserLaunch.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1,73 @@ | ||
| // /////////////////////////////////////////////////////// | ||
| // Bare Bones Browser Launch // | ||
| // Version 1.5 // | ||
| // December 10, 2005 // | ||
| // Supports: Mac OS X, GNU/Linux, Unix, Windows XP // | ||
| // Example Usage: // | ||
| // String url = "http://www.centerkey.com/"; // | ||
| // BareBonesBrowserLaunch.openURL(url); // | ||
| // Public Domain Software -- Free to Use as You Like // | ||
| // /////////////////////////////////////////////////////// | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| // SPDX-FileCopyrightText: 2025 Tony Germano <tony@germano.name> | ||
| // SPDX-Contributor: Original Author Dem Pilafian (Original work licensed under WTFPL) | ||
|
|
||
| package com.mirth.connect.client.ui; | ||
|
|
||
| import java.lang.reflect.Method; | ||
| import java.util.Arrays; | ||
|
|
||
| /** | ||
| * Utility class to open a web page from a Swing application | ||
| * in the user's default browser. | ||
| * <p> | ||
| * Supports: Mac OS X, Linux, Unix, Windows | ||
| * <p> | ||
| * Example usage:<br> | ||
| * <code> | ||
| * String url = "https://dna-engine.org/";<br> | ||
| * BareBonesBrowserLaunch.openURL(url);</code> | ||
| * <p> | ||
| * Latest Version: <a href=https://centerkey.com/java/browser> | ||
| * https://centerkey.com/java/browser</a> | ||
| * <p> | ||
| * Published: October 24, 2010 | ||
| * Modified: 2025 | ||
| * <p> | ||
| * | ||
| * @author Dem Pilafian | ||
| * @version 3.2 | ||
| */ | ||
| public class BareBonesBrowserLaunch { | ||
|
|
||
| static final String[] browsers = { "xdg-open", "x-www-browser", "google-chrome", | ||
| "firefox", "opera", "epiphany", "konqueror", "conkeror", "midori", | ||
| "kazehakase", "mozilla" }; | ||
|
|
||
| /** | ||
| * Open the specified web page in the user's default browser | ||
| * | ||
| * @param url A web address (URL) of a web page (example: | ||
| * <code>"https://dna-engine.org/"</code>) | ||
| */ | ||
| public static void openURL(String url) { | ||
| String osName = System.getProperty("os.name"); | ||
| try { | ||
| if (osName.startsWith("Mac OS")) { | ||
| Class<?> fileMgr = Class.forName("com.apple.eio.FileManager"); | ||
| Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class }); | ||
| openURL.invoke(null, new Object[] { url }); | ||
| } else if (osName.startsWith("Windows")) { | ||
| Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); | ||
| } else { | ||
| // assume Unix or Linux | ||
| String[] browsers = { "firefox", "opera", "konqueror", "epiphany", "mozilla", | ||
| "netscape" }; | ||
| String browser = null; | ||
| for (int count = 0; count < browsers.length && browser == null; count++) { | ||
| if (Runtime.getRuntime().exec(new String[] { "which", | ||
| browsers[count] }).waitFor() == 0) { | ||
| browser = browsers[count]; | ||
| } | ||
| } | ||
| if (browser == null) { | ||
| throw new Exception("Could not find web browser"); | ||
| } else { | ||
| Runtime.getRuntime().exec(new String[] { browser, url }); | ||
| try { // attempt to use Desktop library from JDK 1.6+ | ||
jonbartels marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Class<?> d = Class.forName("java.awt.Desktop"); | ||
| d.getDeclaredMethod("browse", | ||
| new Class<?>[] { java.net.URI.class }).invoke( | ||
| d.getDeclaredMethod("getDesktop").invoke(null), | ||
| new Object[] { java.net.URI.create(url) }); | ||
| } catch (Exception ignore) { // library not available or failed | ||
jonbartels marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| String osName = System.getProperty("os.name"); | ||
| try { | ||
| if (osName.startsWith("Mac OS")) { | ||
| Class.forName("com.apple.eio.FileManager").getDeclaredMethod( | ||
| "openURL", new Class<?>[] { String.class }).invoke(null, | ||
| new Object[] { url }); | ||
| } else if (osName.startsWith("Windows")) | ||
| Runtime.getRuntime().exec(new String[] { | ||
| "rundll32", "url.dll,FileProtocolHandler", url }); | ||
| else { // assume Unix or Linux | ||
| String browser = null; | ||
| for (String b : browsers) | ||
| if (browser == null | ||
| && Runtime.getRuntime().exec(new String[] { "which", b }).getInputStream().read() != -1) | ||
| Runtime.getRuntime().exec(new String[] { browser = b, url }); | ||
| if (browser == null) | ||
| throw new Exception(Arrays.toString(browsers)); | ||
| } | ||
| } catch (Exception e) { | ||
jonbartels marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| PlatformUI.MIRTH_FRAME.alertThrowable(PlatformUI.MIRTH_FRAME, e); | ||
| } | ||
| } catch (Exception e) { | ||
| PlatformUI.MIRTH_FRAME.alertThrowable(PlatformUI.MIRTH_FRAME, e); | ||
| } | ||
| } | ||
| } | ||
97 changes: 61 additions & 36 deletions
97
manager/src/com/mirth/connect/manager/BareBonesBrowserLaunch.java
jonbartels marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,73 @@ | ||
| // Bare Bones Browser Launch // | ||
| // Version 1.5 // | ||
| // December 10, 2005 // | ||
| // Supports: Mac OS X, GNU/Linux, Unix, Windows XP // | ||
| // Example Usage: // | ||
| // String url = "http://www.centerkey.com/"; // | ||
| // BareBonesBrowserLaunch.openURL(url); // | ||
| // Public Domain Software -- Free to Use as You Like // | ||
| ///////////////////////////////////////////////////////// | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| // SPDX-FileCopyrightText: 2025 Tony Germano <tony@germano.name> | ||
| // SPDX-Contributor: Original Author Dem Pilafian (Original work licensed under WTFPL) | ||
|
|
||
| package com.mirth.connect.manager; | ||
|
|
||
| import java.lang.reflect.Method; | ||
| import java.util.Arrays; | ||
|
|
||
| /** | ||
| * Utility class to open a web page from a Swing application | ||
| * in the user's default browser. | ||
| * <p> | ||
| * Supports: Mac OS X, Linux, Unix, Windows | ||
| * <p> | ||
| * Example usage:<br> | ||
| * <code> | ||
| * String url = "https://dna-engine.org/";<br> | ||
| * BareBonesBrowserLaunch.openURL(url);</code> | ||
| * <p> | ||
| * Latest Version: <a href=https://centerkey.com/java/browser> | ||
| * https://centerkey.com/java/browser</a> | ||
| * <p> | ||
| * Published: October 24, 2010 | ||
| * Modified: 2025 | ||
| * <p> | ||
| * | ||
| * @author Dem Pilafian | ||
| * @version 3.2 | ||
| */ | ||
| public class BareBonesBrowserLaunch { | ||
|
|
||
| private static final String errMsg = "Error attempting to launch web browser"; | ||
| static final String[] browsers = { "xdg-open", "x-www-browser", "google-chrome", | ||
| "firefox", "opera", "epiphany", "konqueror", "conkeror", "midori", | ||
| "kazehakase", "mozilla" }; | ||
|
|
||
| /** | ||
| * Open the specified web page in the user's default browser | ||
| * | ||
| * @param url A web address (URL) of a web page (example: | ||
| * <code>"https://dna-engine.org/"</code>) | ||
| */ | ||
| public static void openURL(String url) { | ||
| String osName = System.getProperty("os.name"); | ||
| try { | ||
| if (osName.startsWith("Mac OS")) { | ||
| Class fileMgr = Class.forName("com.apple.eio.FileManager"); | ||
| Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class }); | ||
| openURL.invoke(null, new Object[] { url }); | ||
| } else if (osName.startsWith("Windows")) { | ||
| Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); | ||
| } else { | ||
| // assume Unix or Linux | ||
| String[] browsers = { "firefox", "opera", "konqueror", "epiphany", "mozilla", | ||
| "netscape" }; | ||
| String browser = null; | ||
| for (int count = 0; count < browsers.length && browser == null; count++) { | ||
| if (Runtime.getRuntime().exec(new String[] { "which", | ||
| browsers[count] }).waitFor() == 0) { | ||
| browser = browsers[count]; | ||
| } | ||
| } | ||
| if (browser == null) { | ||
| throw new Exception("Could not find web browser"); | ||
| } else { | ||
| Runtime.getRuntime().exec(new String[] { browser, url }); | ||
| try { // attempt to use Desktop library from JDK 1.6+ | ||
| Class<?> d = Class.forName("java.awt.Desktop"); | ||
| d.getDeclaredMethod("browse", | ||
| new Class<?>[] { java.net.URI.class }).invoke( | ||
| d.getDeclaredMethod("getDesktop").invoke(null), | ||
| new Object[] { java.net.URI.create(url) }); | ||
| } catch (Exception ignore) { // library not available or failed | ||
| String osName = System.getProperty("os.name"); | ||
| try { | ||
| if (osName.startsWith("Mac OS")) { | ||
| Class.forName("com.apple.eio.FileManager").getDeclaredMethod( | ||
| "openURL", new Class<?>[] { String.class }).invoke(null, | ||
| new Object[] { url }); | ||
| } else if (osName.startsWith("Windows")) | ||
| Runtime.getRuntime().exec(new String[] { | ||
| "rundll32", "url.dll,FileProtocolHandler", url }); | ||
| else { // assume Unix or Linux | ||
| String browser = null; | ||
| for (String b : browsers) | ||
| if (browser == null | ||
| && Runtime.getRuntime().exec(new String[] { "which", b }).getInputStream().read() != -1) | ||
| Runtime.getRuntime().exec(new String[] { browser = b, url }); | ||
| if (browser == null) | ||
| throw new Exception(Arrays.toString(browsers)); | ||
| } | ||
| } catch (Exception e) { | ||
| ManagerController.getInstance().alertErrorDialog("Could not open web browser."); | ||
| } | ||
| } catch (Exception e) { | ||
| ManagerController.getInstance().alertErrorDialog("Could not open web browser."); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.