Author: nextgens
Date: 2008-03-12 04:23:54 +0000 (Wed, 12 Mar 2008)
New Revision: 18480
Modified:
trunk/apps/thingamablog/src/freenet/utils/BrowserLaunch.java
Log:
Thingamablog: Improve the speed of the browser-detection code running it only
once on *nix
Modified: trunk/apps/thingamablog/src/freenet/utils/BrowserLaunch.java
===================================================================
--- trunk/apps/thingamablog/src/freenet/utils/BrowserLaunch.java
2008-03-12 03:59:50 UTC (rev 18479)
+++ trunk/apps/thingamablog/src/freenet/utils/BrowserLaunch.java
2008-03-12 04:23:54 UTC (rev 18480)
@@ -13,6 +13,26 @@
* @author Florent Daignière <nextgens at freenetproject.org>
*/
public class BrowserLaunch {
+ private final static boolean isMacos;
+ private final static boolean isWindows;
+ private static String BROWSER = null;
+
+ static {
+ String osName = System.getProperty("os.name");
+ isMacos = osName.startsWith("Mac OS");
+ isWindows = osName.startsWith("Windows");
+ if(!isMacos && !isWindows) {
+ //assume Unix or Linux
+ String[] browsers = {"firefox", "opera", "konqueror",
"epiphany", "mozilla", "netscape", "seamonkey"};
+
+ try {
+ for(int count = 0; count < browsers.length &&
BROWSER == null; count++)
+ if(Runtime.getRuntime().exec(new
String[]{"which", browsers[count]}).waitFor() == 0)
+ BROWSER = browsers[count];
+ } catch (Exception e) {}
+ }
+ }
+
public static void main(String arg[]) {
launch(arg[0]);
}
@@ -22,27 +42,20 @@
}
public static void launch(String url) {
- String osName = System.getProperty("os.name");
try {
- if (osName.startsWith("Mac OS")) {
+ if (isMacos) {
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 if (isWindows)
+ Runtime.getRuntime().exec("rundll32
url.dll,FileProtocolHandler " + url);
else {
- //assume Unix or Linux
- String[] browsers = {"firefox", "opera",
"konqueror", "epiphany", "mozilla", "netscape", "seamonkey" };
- 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)
+ if (BROWSER == null)
throw new Exception("Could not find
web browser");
else
- Runtime.getRuntime().exec(new String[]
{ browser, url});
+ Runtime.getRuntime().exec(new String[]
{ BROWSER, url });
}
}
catch (Exception e) {