diff --git a/apps/systray/java/build.xml b/apps/systray/java/build.xml
index 279b10d45..4b909d80d 100644
--- a/apps/systray/java/build.xml
+++ b/apps/systray/java/build.xml
@@ -22,13 +22,9 @@
-
-
-
-
diff --git a/apps/systray/java/src/net/i2p/apps/systray/BrowserChooser.java b/apps/systray/java/src/net/i2p/apps/systray/BrowserChooser.java
new file mode 100644
index 000000000..6c6cae9f0
--- /dev/null
+++ b/apps/systray/java/src/net/i2p/apps/systray/BrowserChooser.java
@@ -0,0 +1,31 @@
+/*
+ * I2P - An anonymous, secure, and fully-distributed communication network.
+ *
+ * BrowserChooser.java
+ * 2004 The I2P Project
+ * This code is public domain.
+ */
+
+package net.i2p.apps.systray;
+
+import java.awt.FileDialog;
+import java.awt.Frame;
+
+/**
+ * A rather nasty AWT file chooser dialog (thanks, Kaffe!) which allows the user
+ * to select their preferred browser with.
+ *
+ * @author hypercubus
+ */
+public class BrowserChooser extends FileDialog {
+
+ public BrowserChooser(Frame owner, String windowTitle) {
+ super(owner, windowTitle);
+ initialize();
+ }
+
+ public void initialize(){
+ this.setSize(300,400);
+ this.show();
+ }
+}
diff --git a/apps/systray/java/src/net/i2p/apps/systray/ShellCommand.java b/apps/systray/java/src/net/i2p/apps/systray/ShellCommand.java
index 18df8faba..b2f4f2015 100644
--- a/apps/systray/java/src/net/i2p/apps/systray/ShellCommand.java
+++ b/apps/systray/java/src/net/i2p/apps/systray/ShellCommand.java
@@ -184,7 +184,7 @@ public class ShellCommand {
* {@link #getErrorStream()}, respectively. Input can be passed to the
* STDIN
of the shell process via {@link #getInputStream()}.
*
- * @param shellCommand The command for the shell to execute.
+ * @param _shellCommand The command for the shell to execute.
*/
public void execute(String shellCommand) {
execute(shellCommand, NO_CONSUME_OUTPUT, NO_WAIT_FOR_EXIT_STATUS);
@@ -199,7 +199,7 @@ public class ShellCommand {
* Input can be passed to the STDIN
of the shell process via
* {@link #getInputStream()}.
*
- * @param shellCommand The command for the shell to execute.
+ * @param _shellCommand The command for the shell to execute.
* @return true
if the spawned shell process
* returns an exit status of 0 (indicating success),
* else false
.
@@ -221,7 +221,7 @@ public class ShellCommand {
* {@link #getErrorStream()}, respectively. Input can be passed to the
* STDIN
of the shell process via {@link #getInputStream()}.
*
- * @param shellCommand The command for the shell to execute.
+ * @param _shellCommand The command for the shell to execute.
* @param seconds The method will return true
if this
* number of seconds elapses without the process
* returning an exit status. A value of 0
@@ -256,7 +256,7 @@ public class ShellCommand {
* without waiting for an exit status. Any output produced by the executed
* command will not be displayed.
*
- * @param shellCommand The command for the shell to execute.
+ * @param _shellCommand The command for the shell to execute.
* @throws IOException
*/
public void executeSilent(String shellCommand) throws IOException {
@@ -268,7 +268,7 @@ public class ShellCommand {
* all of the command's resulting shell processes have completed. Any output
* produced by the executed command will not be displayed.
*
- * @param shellCommand The command for the shell to execute.
+ * @param _shellCommand The command for the shell to execute.
* @return true
if the spawned shell process
* returns an exit status of 0 (indicating success),
* else false
.
@@ -287,7 +287,7 @@ public class ShellCommand {
* specified number of seconds has elapsed first. Any output produced by the
* executed command will not be displayed.
*
- * @param shellCommand The command for the shell to execute.
+ * @param _shellCommand The command for the shell to execute.
* @param seconds The method will return true
if this
* number of seconds elapses without the process
* returning an exit status. A value of 0
diff --git a/apps/systray/java/src/net/i2p/apps/systray/SysTray.java b/apps/systray/java/src/net/i2p/apps/systray/SysTray.java
index 0db04e0c1..d284f0a4a 100644
--- a/apps/systray/java/src/net/i2p/apps/systray/SysTray.java
+++ b/apps/systray/java/src/net/i2p/apps/systray/SysTray.java
@@ -8,6 +8,8 @@
package net.i2p.apps.systray;
+import java.awt.Frame;
+
import snoozesoft.systray4j.SysTrayMenu;
import snoozesoft.systray4j.SysTrayMenuEvent;
import snoozesoft.systray4j.SysTrayMenuIcon;
@@ -23,18 +25,26 @@ import snoozesoft.systray4j.SysTrayMenuListener;
*/
public class SysTray implements SysTrayMenuListener {
- private SysTrayMenuItem itemExit = new SysTrayMenuItem("Exit systray", "exit");
- private SysTrayMenuItem itemSetBrowser = new SysTrayMenuItem("Set preferred browser...", "setbrowser");
- private SysTrayMenuIcon sysTrayMenuIcon = new SysTrayMenuIcon("../icons/iggy");
- private SysTrayMenu sysTrayMenu = new SysTrayMenu(sysTrayMenuIcon, "I2P Console");
+ private static String _browserString;
+
+ private BrowserChooser _browserChooser;
+ private Frame _frame;
+ private SysTrayMenuItem _itemExit = new SysTrayMenuItem("Exit systray", "exit");
+ private SysTrayMenuItem _itemSelectBrowser = new SysTrayMenuItem("Select preferred browser...", "selectbrowser");
+ private SysTrayMenuIcon _sysTrayMenuIcon = new SysTrayMenuIcon("../icons/iggy");
+ private SysTrayMenu _sysTrayMenu = new SysTrayMenu(_sysTrayMenuIcon, "I2P Console");
public SysTray() {
- sysTrayMenuIcon.addSysTrayMenuListener(this);
+ _sysTrayMenuIcon.addSysTrayMenuListener(this);
createSysTrayMenu();
}
public static void main(String[] args) {
new SysTray();
+
+ if (args.length == 1)
+ _browserString = args[0];
+
while(true)
try {
Thread.sleep(2 * 1000);
@@ -46,27 +56,52 @@ public class SysTray implements SysTrayMenuListener {
public void iconLeftClicked(SysTrayMenuEvent e) {}
public void iconLeftDoubleClicked(SysTrayMenuEvent e) {
- try {
- new UrlLauncher().openUrl("http://localhost:7657");
- } catch (Exception ex) {
- // Pop up a dialog or something.
+ if (_browserString == null || _browserString.equals("browser default")) {
+ try {
+ new UrlLauncher().openUrl("http://localhost:7657");
+ } catch (Exception ex) {
+ setBrowser(promptForBrowser("Please select another browser"));
+ }
+ } else {
+ try {
+ new UrlLauncher().openUrl("http://localhost:7657", _browserString);
+ } catch (Exception ex) {
+ setBrowser(promptForBrowser("Please select another browser"));
+ }
}
}
public void menuItemSelected(SysTrayMenuEvent e) {
if (e.getActionCommand().equals("exit")) {
- // exit systray
+ _browserChooser = null;
+ _frame = null;
+ _itemExit = null;
+ _itemSelectBrowser = null;
+ _sysTrayMenuIcon = null;
+ _sysTrayMenu = null;
System.exit(0);
- } else if (e.getActionCommand().equals("start")) {
- // Popup browser dialog
+ } else if (e.getActionCommand().equals("selectbrowser")) {
+ setBrowser(promptForBrowser("Select preferred browser"));
}
}
private void createSysTrayMenu() {
- itemSetBrowser.addSysTrayMenuListener(this);
- itemExit.addSysTrayMenuListener(this);
- sysTrayMenu.addItem(itemExit);
- sysTrayMenu.addSeparator();
- sysTrayMenu.addItem(itemSetBrowser);
+ _itemSelectBrowser.addSysTrayMenuListener(this);
+ _itemExit.addSysTrayMenuListener(this);
+ _sysTrayMenu.addItem(_itemExit);
+ _sysTrayMenu.addSeparator();
+ _sysTrayMenu.addItem(_itemSelectBrowser);
+ }
+
+ private String promptForBrowser(String windowTitle) {
+ _frame = new Frame();
+ _browserChooser = new BrowserChooser(_frame, windowTitle);
+ return _browserChooser.getDirectory() + _browserChooser.getFile();
+ }
+
+ private void setBrowser(String browser) {
+ _browserString = browser;
+ // change "clientApp.3.args=browser" property in clients.config here.
+ // System.out.println("User chose browser: " + browser);
}
}
\ No newline at end of file
diff --git a/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java b/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java
index ab85a3d30..d6c2cabf9 100644
--- a/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java
+++ b/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java
@@ -17,11 +17,11 @@ package net.i2p.apps.systray;
* Firefox, Netscape, Opera, and Safari.
*
* @author hypercubus
- *
- * TODO Add a method to allow opening a URL with a specific browser.
*/
public class UrlLauncher {
+ ShellCommand _shellCommand = new ShellCommand();
+
/**
* Discovers the operating system the installer is running under and tries
* to launch the given URL using the default browser for that platform; if
@@ -30,52 +30,59 @@ public class UrlLauncher {
*/
public boolean openUrl(String url) throws Exception {
- String osName = System.getProperty("os.name");
- ShellCommand shellCommand = new ShellCommand();
+ String osName = System.getProperty("os.name");
if (osName.toLowerCase().indexOf("mac") > -1) {
if (osName.toLowerCase().startsWith("mac os x")) {
- if (shellCommand.executeSilentAndWaitTimed("safari " + url, 5))
+ if (_shellCommand.executeSilentAndWaitTimed("safari " + url, 5))
return true;
} else {
return false;
}
- if (shellCommand.executeSilentAndWaitTimed("iexplore " + url, 5))
+ if (_shellCommand.executeSilentAndWaitTimed("iexplore " + url, 5))
return true;
} else if (osName.startsWith("Windows")) {
- if (shellCommand.executeSilentAndWaitTimed("\"C:\\Program Files\\Internet Explorer\\iexplore.exe\" " + url, 5))
+ if (_shellCommand.executeSilentAndWaitTimed("\"C:\\Program Files\\Internet Explorer\\iexplore.exe\" " + url, 5))
return true;
} else {
- if (shellCommand.executeSilentAndWaitTimed("konqueror " + url, 5))
+ if (_shellCommand.executeSilentAndWaitTimed("konqueror " + url, 5))
return true;
- if (shellCommand.executeSilentAndWaitTimed("galeon " + url, 5))
+ if (_shellCommand.executeSilentAndWaitTimed("galeon " + url, 5))
return true;
}
- if (shellCommand.executeSilentAndWaitTimed("firefox " + url, 5))
+ if (_shellCommand.executeSilentAndWaitTimed("firefox " + url, 5))
return true;
- if (shellCommand.executeSilentAndWaitTimed("opera -newpage " + url, 5))
+ if (_shellCommand.executeSilentAndWaitTimed("opera -newpage " + url, 5))
return true;
- if (shellCommand.executeSilentAndWaitTimed("mozilla " + url, 5))
+ if (_shellCommand.executeSilentAndWaitTimed("mozilla " + url, 5))
return true;
- if (shellCommand.executeSilentAndWaitTimed("netscape " + url, 5))
+ if (_shellCommand.executeSilentAndWaitTimed("netscape " + url, 5))
return true;
- if (shellCommand.executeSilentAndWaitTimed("links " + url, 5))
+ if (_shellCommand.executeSilentAndWaitTimed("links " + url, 5))
return true;
- if (shellCommand.executeSilentAndWaitTimed("lynx " + url, 5))
+ if (_shellCommand.executeSilentAndWaitTimed("lynx " + url, 5))
+ return true;
+
+ return false;
+ }
+
+ public boolean openUrl(String url, String browser) throws Exception {
+ // System.out.println("Launching: '" + browser + " " + url + "'");
+ if (_shellCommand.executeSilentAndWaitTimed(browser + " " + url, 5))
return true;
return false;