Skip to content

Commit c18fcfe

Browse files
committed
FIX: gui.Tools.openUrlInWebBrowser(url) that works accross OSes,...
...and replaces the original (and unused) help() method.
1 parent e20986f commit c18fcfe

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/main/java/ai/nets/samj/gui/tools/Tools.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,37 @@
2020
package ai.nets.samj.gui.tools;
2121

2222
import java.awt.Desktop;
23-
import java.net.URL;
23+
import java.net.URI;
24+
import java.net.URISyntaxException;
25+
import java.io.IOException;
2426

2527
/**
2628
* Class that contains helper tools for SAMJ
2729
* @author Daniel Sage
2830
* @author Carlos Garcia
31+
* @author Vladimir Ulman
2932
*/
3033
public class Tools {
34+
public static final String URL_WITH_DEFAULT_IJ_HELP = "https://github.com/segment-anything-models-java/SAMJ-IJ";
3135

3236
/**
33-
* Method that opens a website where there is some documentation about SAMJ
34-
* @return true if the method was able to access the website or false otherwise
37+
* Opens user's default desktop web browser on the given 'url'.
3538
*/
36-
static public boolean help() {
37-
String url = "https://github.com/segment-anything-models-java/SAMJ-IJ";
38-
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
39-
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
40-
try {
41-
desktop.browse(new URL(url).toURI());
42-
return true;
39+
public static void openUrlInWebBrowser(final String url) {
40+
final String myOS = System.getProperty("os.name").toLowerCase();
41+
try {
42+
if (myOS.contains("mac")) {
43+
Runtime.getRuntime().exec("open "+url);
4344
}
44-
catch (Exception e) {
45-
e.printStackTrace();
45+
else if (myOS.contains("nux") || myOS.contains("nix")) {
46+
Runtime.getRuntime().exec("xdg-open "+url);
4647
}
47-
}
48-
return false;
48+
else if (Desktop.isDesktopSupported()) {
49+
Desktop.getDesktop().browse(new URI(url));
50+
}
51+
else {
52+
System.out.println("Please, open this URL yourself: "+url);
53+
}
54+
} catch (IOException | URISyntaxException ignored) {}
4955
}
5056
}

0 commit comments

Comments
 (0)