added browser selection dialog
This commit is contained in:
@ -22,13 +22,9 @@
|
|||||||
<copy todir="./build/icons">
|
<copy todir="./build/icons">
|
||||||
<fileset dir="./src/net/i2p/apps/systray/icons" />
|
<fileset dir="./src/net/i2p/apps/systray/icons" />
|
||||||
</copy>
|
</copy>
|
||||||
<copy todir="./build/jar_temp/doc">
|
|
||||||
<fileset dir="../doc" />
|
|
||||||
</copy>
|
|
||||||
<mkdir dir="./build/jar_temp" />
|
<mkdir dir="./build/jar_temp" />
|
||||||
<copy todir="./build/jar_temp">
|
<copy todir="./build/jar_temp">
|
||||||
<fileset dir="./build/obj" includes="**/*.class" />
|
<fileset dir="./build/obj" includes="**/*.class" />
|
||||||
<fileset dir="./src/net/i2p/apps/systray" includes="doc/*" />
|
|
||||||
</copy>
|
</copy>
|
||||||
<jar destfile="./build/lib/systray.jar" basedir="./build/jar_temp" includes="**/*">
|
<jar destfile="./build/lib/systray.jar" basedir="./build/jar_temp" includes="**/*">
|
||||||
<manifest>
|
<manifest>
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -184,7 +184,7 @@ public class ShellCommand {
|
|||||||
* {@link #getErrorStream()}, respectively. Input can be passed to the
|
* {@link #getErrorStream()}, respectively. Input can be passed to the
|
||||||
* <code>STDIN</code> of the shell process via {@link #getInputStream()}.
|
* <code>STDIN</code> 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) {
|
public void execute(String shellCommand) {
|
||||||
execute(shellCommand, NO_CONSUME_OUTPUT, NO_WAIT_FOR_EXIT_STATUS);
|
execute(shellCommand, NO_CONSUME_OUTPUT, NO_WAIT_FOR_EXIT_STATUS);
|
||||||
@ -199,7 +199,7 @@ public class ShellCommand {
|
|||||||
* Input can be passed to the <code>STDIN</code> of the shell process via
|
* Input can be passed to the <code>STDIN</code> of the shell process via
|
||||||
* {@link #getInputStream()}.
|
* {@link #getInputStream()}.
|
||||||
*
|
*
|
||||||
* @param shellCommand The command for the shell to execute.
|
* @param _shellCommand The command for the shell to execute.
|
||||||
* @return <code>true</code> if the spawned shell process
|
* @return <code>true</code> if the spawned shell process
|
||||||
* returns an exit status of 0 (indicating success),
|
* returns an exit status of 0 (indicating success),
|
||||||
* else <code>false</code>.
|
* else <code>false</code>.
|
||||||
@ -221,7 +221,7 @@ public class ShellCommand {
|
|||||||
* {@link #getErrorStream()}, respectively. Input can be passed to the
|
* {@link #getErrorStream()}, respectively. Input can be passed to the
|
||||||
* <code>STDIN</code> of the shell process via {@link #getInputStream()}.
|
* <code>STDIN</code> 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 <code>true</code> if this
|
* @param seconds The method will return <code>true</code> if this
|
||||||
* number of seconds elapses without the process
|
* number of seconds elapses without the process
|
||||||
* returning an exit status. A value of <code>0</code>
|
* returning an exit status. A value of <code>0</code>
|
||||||
@ -256,7 +256,7 @@ public class ShellCommand {
|
|||||||
* without waiting for an exit status. Any output produced by the executed
|
* without waiting for an exit status. Any output produced by the executed
|
||||||
* command will not be displayed.
|
* 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
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void executeSilent(String shellCommand) 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
|
* all of the command's resulting shell processes have completed. Any output
|
||||||
* produced by the executed command will not be displayed.
|
* 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 <code>true</code> if the spawned shell process
|
* @return <code>true</code> if the spawned shell process
|
||||||
* returns an exit status of 0 (indicating success),
|
* returns an exit status of 0 (indicating success),
|
||||||
* else <code>false</code>.
|
* else <code>false</code>.
|
||||||
@ -287,7 +287,7 @@ public class ShellCommand {
|
|||||||
* specified number of seconds has elapsed first. Any output produced by the
|
* specified number of seconds has elapsed first. Any output produced by the
|
||||||
* executed command will not be displayed.
|
* 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 <code>true</code> if this
|
* @param seconds The method will return <code>true</code> if this
|
||||||
* number of seconds elapses without the process
|
* number of seconds elapses without the process
|
||||||
* returning an exit status. A value of <code>0</code>
|
* returning an exit status. A value of <code>0</code>
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
package net.i2p.apps.systray;
|
package net.i2p.apps.systray;
|
||||||
|
|
||||||
|
import java.awt.Frame;
|
||||||
|
|
||||||
import snoozesoft.systray4j.SysTrayMenu;
|
import snoozesoft.systray4j.SysTrayMenu;
|
||||||
import snoozesoft.systray4j.SysTrayMenuEvent;
|
import snoozesoft.systray4j.SysTrayMenuEvent;
|
||||||
import snoozesoft.systray4j.SysTrayMenuIcon;
|
import snoozesoft.systray4j.SysTrayMenuIcon;
|
||||||
@ -23,18 +25,26 @@ import snoozesoft.systray4j.SysTrayMenuListener;
|
|||||||
*/
|
*/
|
||||||
public class SysTray implements SysTrayMenuListener {
|
public class SysTray implements SysTrayMenuListener {
|
||||||
|
|
||||||
private SysTrayMenuItem itemExit = new SysTrayMenuItem("Exit systray", "exit");
|
private static String _browserString;
|
||||||
private SysTrayMenuItem itemSetBrowser = new SysTrayMenuItem("Set preferred browser...", "setbrowser");
|
|
||||||
private SysTrayMenuIcon sysTrayMenuIcon = new SysTrayMenuIcon("../icons/iggy");
|
private BrowserChooser _browserChooser;
|
||||||
private SysTrayMenu sysTrayMenu = new SysTrayMenu(sysTrayMenuIcon, "I2P Console");
|
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() {
|
public SysTray() {
|
||||||
sysTrayMenuIcon.addSysTrayMenuListener(this);
|
_sysTrayMenuIcon.addSysTrayMenuListener(this);
|
||||||
createSysTrayMenu();
|
createSysTrayMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new SysTray();
|
new SysTray();
|
||||||
|
|
||||||
|
if (args.length == 1)
|
||||||
|
_browserString = args[0];
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2 * 1000);
|
Thread.sleep(2 * 1000);
|
||||||
@ -46,27 +56,52 @@ public class SysTray implements SysTrayMenuListener {
|
|||||||
public void iconLeftClicked(SysTrayMenuEvent e) {}
|
public void iconLeftClicked(SysTrayMenuEvent e) {}
|
||||||
|
|
||||||
public void iconLeftDoubleClicked(SysTrayMenuEvent e) {
|
public void iconLeftDoubleClicked(SysTrayMenuEvent e) {
|
||||||
try {
|
if (_browserString == null || _browserString.equals("browser default")) {
|
||||||
new UrlLauncher().openUrl("http://localhost:7657");
|
try {
|
||||||
} catch (Exception ex) {
|
new UrlLauncher().openUrl("http://localhost:7657");
|
||||||
// Pop up a dialog or something.
|
} 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) {
|
public void menuItemSelected(SysTrayMenuEvent e) {
|
||||||
if (e.getActionCommand().equals("exit")) {
|
if (e.getActionCommand().equals("exit")) {
|
||||||
// exit systray
|
_browserChooser = null;
|
||||||
|
_frame = null;
|
||||||
|
_itemExit = null;
|
||||||
|
_itemSelectBrowser = null;
|
||||||
|
_sysTrayMenuIcon = null;
|
||||||
|
_sysTrayMenu = null;
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
} else if (e.getActionCommand().equals("start")) {
|
} else if (e.getActionCommand().equals("selectbrowser")) {
|
||||||
// Popup browser dialog
|
setBrowser(promptForBrowser("Select preferred browser"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createSysTrayMenu() {
|
private void createSysTrayMenu() {
|
||||||
itemSetBrowser.addSysTrayMenuListener(this);
|
_itemSelectBrowser.addSysTrayMenuListener(this);
|
||||||
itemExit.addSysTrayMenuListener(this);
|
_itemExit.addSysTrayMenuListener(this);
|
||||||
sysTrayMenu.addItem(itemExit);
|
_sysTrayMenu.addItem(_itemExit);
|
||||||
sysTrayMenu.addSeparator();
|
_sysTrayMenu.addSeparator();
|
||||||
sysTrayMenu.addItem(itemSetBrowser);
|
_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);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,11 +17,11 @@ package net.i2p.apps.systray;
|
|||||||
* Firefox, Netscape, Opera, and Safari.
|
* Firefox, Netscape, Opera, and Safari.
|
||||||
*
|
*
|
||||||
* @author hypercubus
|
* @author hypercubus
|
||||||
*
|
|
||||||
* TODO Add a method to allow opening a URL with a specific browser.
|
|
||||||
*/
|
*/
|
||||||
public class UrlLauncher {
|
public class UrlLauncher {
|
||||||
|
|
||||||
|
ShellCommand _shellCommand = new ShellCommand();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Discovers the operating system the installer is running under and tries
|
* Discovers the operating system the installer is running under and tries
|
||||||
* to launch the given URL using the default browser for that platform; if
|
* 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 {
|
public boolean openUrl(String url) throws Exception {
|
||||||
|
|
||||||
String osName = System.getProperty("os.name");
|
String osName = System.getProperty("os.name");
|
||||||
ShellCommand shellCommand = new ShellCommand();
|
|
||||||
|
|
||||||
if (osName.toLowerCase().indexOf("mac") > -1) {
|
if (osName.toLowerCase().indexOf("mac") > -1) {
|
||||||
if (osName.toLowerCase().startsWith("mac os x")) {
|
if (osName.toLowerCase().startsWith("mac os x")) {
|
||||||
|
|
||||||
if (shellCommand.executeSilentAndWaitTimed("safari " + url, 5))
|
if (_shellCommand.executeSilentAndWaitTimed("safari " + url, 5))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shellCommand.executeSilentAndWaitTimed("iexplore " + url, 5))
|
if (_shellCommand.executeSilentAndWaitTimed("iexplore " + url, 5))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (osName.startsWith("Windows")) {
|
} 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;
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (shellCommand.executeSilentAndWaitTimed("konqueror " + url, 5))
|
if (_shellCommand.executeSilentAndWaitTimed("konqueror " + url, 5))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (shellCommand.executeSilentAndWaitTimed("galeon " + url, 5))
|
if (_shellCommand.executeSilentAndWaitTimed("galeon " + url, 5))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shellCommand.executeSilentAndWaitTimed("firefox " + url, 5))
|
if (_shellCommand.executeSilentAndWaitTimed("firefox " + url, 5))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (shellCommand.executeSilentAndWaitTimed("opera -newpage " + url, 5))
|
if (_shellCommand.executeSilentAndWaitTimed("opera -newpage " + url, 5))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (shellCommand.executeSilentAndWaitTimed("mozilla " + url, 5))
|
if (_shellCommand.executeSilentAndWaitTimed("mozilla " + url, 5))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (shellCommand.executeSilentAndWaitTimed("netscape " + url, 5))
|
if (_shellCommand.executeSilentAndWaitTimed("netscape " + url, 5))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (shellCommand.executeSilentAndWaitTimed("links " + url, 5))
|
if (_shellCommand.executeSilentAndWaitTimed("links " + url, 5))
|
||||||
return true;
|
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 true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user