Skip to content

Commit

Permalink
Check to see if browse action is supported else use xdg-open
Browse files Browse the repository at this point in the history
  • Loading branch information
pawandubey committed May 2, 2018
1 parent 3202839 commit f2f3811
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/main/java/com/pawandubey/griffin/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,29 @@ protected void openBrowser() {

if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(new URI(url));

if (desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(new URI(url));
}
catch (IOException | URISyntaxException e) {
}
}
catch (IOException | URISyntaxException e) {
else {
openBrowserUsingXdg(url);
}
}
else {
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("xdg-open " + url);
}
catch (IOException e) {
}
openBrowserUsingXdg(url);
}
}

private void openBrowserUsingXdg(String url) {
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec("xdg-open " + url);
}
catch (IOException e) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void execute() {
}
else {
griffin.printAsciiGriffin();
System.out.println("Starting preview on port " + port);
griffin.preview(port);
}
}
Expand Down

0 comments on commit f2f3811

Please sign in to comment.