fixed missing browser activation in linux

This commit is contained in:
Michael Peter Christen 2016-08-19 19:24:15 +02:00
parent d8504418b6
commit bf6709d196

View File

@ -29,6 +29,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Properties;
import net.yacy.cora.util.ConcurrentLog;
@ -88,38 +89,32 @@ public class Browser {
}
public static void openBrowser(final String url) {
boolean head = System.getProperty("java.awt.headless", "").equals("false");
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(new URI(url));
} catch (IOException | URISyntaxException e) {
openBrowserClassic(url);
}
} else {
openBrowserClassic(url);
}
}
public static void openBrowserClassic(final String url) {
try {
if (systemOS == systemMacOSX) {
openBrowserMac(url);
} else if (systemOS == systemUnix) {
//try {
// openBrowserUnixGeneric(url);
//} catch (final Exception e) {
openBrowserUnixFirefox(url);
//}
openBrowserUnixFirefox(url);
} else if (systemOS == systemWindows) {
openBrowserWin(url);
} else {
throw new RuntimeException("System unknown");
}
} catch (final Throwable e) {
if (head) {
try {
openBrowserJava(url);
} catch (final Exception ee) {
logBrowserFail(url);
}
} else {
logBrowserFail(url);
}
}
}
private static void openBrowserJava(final String url) throws Exception {
Desktop.getDesktop().browse(new URI(url));
}
private static void openBrowserMac(final String url) throws Exception {
Process p = Runtime.getRuntime().exec(new String[] {"/usr/bin/osascript", "-e", "open location \"" + url + "\""});
p.waitFor();
@ -129,21 +124,14 @@ public class Browser {
}
private static void openBrowserUnixFirefox(final String url) throws Exception {
String cmd = "firefox -remote openURL(" + url + ")";
String cmd = "firefox " + url;
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
if (p.exitValue() != 0) {
throw new RuntimeException("Unix Exec Error/Firefox: " + errorResponse(p));
}
}
/*
private static void openBrowserUnixGeneric(final String url) throws Exception {
String cmd = "/etc/alternatives/www-browser " + url;
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
if (p.exitValue() != 0) throw new RuntimeException("Unix Exec Error/generic: " + errorResponse(p));
}
*/
private static void openBrowserWin(final String url) throws Exception {
// see forum at http://forum.java.sun.com/thread.jsp?forum=57&thread=233364&message=838441
String cmd;
@ -160,11 +148,6 @@ public class Browser {
}
}
private static void logBrowserFail(final String url) {
//if (e != null) Log.logException(e);
ConcurrentLog.info("Browser", "please start your browser and open the following location: " + url);
}
private static String errorResponse(final Process p) {
final BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String line, error = "";