- Added README

- Added configuration
- Added option to start I2P from desktopgui
- Cleanup
This commit is contained in:
mathiasdm
2010-11-25 18:12:32 +00:00
parent b434a475a3
commit b885046c64
8 changed files with 179 additions and 25 deletions

13
apps/desktopgui/README Normal file
View File

@@ -0,0 +1,13 @@
Current setup:
* Build desktopgui:
* 'ant jar' in the desktopgui directory
OR
* 'ant desktopgui' in the i2p.i2p directory
* Place desktopgui.jar in the $I2P/lib/ directory.
* Add to .i2p/clients.config:
#Desktopgui
clientApp.6.args=--startWithI2P --I2PLocation=/SOME_LOCATION
clientApp.6.delay=5
clientApp.6.main=net.i2p.desktopgui.Main
clientApp.6.name=desktopgui
clientApp.6.startOnLoad=true

View File

@@ -1,8 +1,17 @@
HIGH PRIORITY:
- Allow desktopgui to start, stop and restart I2P. - DONE
- Internationalisation
- Correct logging system
UNKNOWN:
- API to allow applications to add themselves to the menu?
* registerApplication(); -- should return a positive number on success, -1 on failure
* unregisterApplication(int); -- should return nothing (or bool for success?), and the parameter should be the number given when registering the application
- Internationalisation
- Fetch I2P localhost from the core I2P application?
- Correct logging system
- Use I2PAppContext::appDir (something like that) for desktopgui data.
- Check core/java/src/net/i2p/util/FileUtil.java for dynamic jar loading
- Consider SWT as option
* Check core/java/src/net/i2p/util/FileUtil.java for dynamic jar loading
* Possible logic:
- First try to load SWT (has the most options and is not ugly)
- Then load AWT
- Access router.jar from other JVM? Is this possible? -- no: use I2CP with auth (not ready yet)
- Start desktopgui with another user than the user starting I2P (required for daemon usage).

View File

@@ -43,7 +43,8 @@
</manifest>
</jar>
</target>
<target name="dist" depends="jar" />
<target name="all" depends="jar" />
</project>

View File

@@ -9,6 +9,7 @@ import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.i2p.desktopgui.util.*;
/**
* The main class of the application.
@@ -39,7 +40,10 @@ public class Main {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
ConfigurationManager.getInstance().loadArguments(args);
final Main main = new Main();
main.launchForeverLoop();
//We'll be doing GUI work, so let's stay in the event dispatcher thread.
SwingUtilities.invokeLater(new Runnable() {

View File

@@ -9,6 +9,7 @@ import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.Desktop.Action;
import java.awt.TrayIcon.MessageType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
@@ -20,6 +21,7 @@ import java.util.Properties;
import javax.swing.SwingWorker;
import net.i2p.desktopgui.router.RouterManager;
import net.i2p.desktopgui.util.*;
import net.i2p.router.Router;
/**
@@ -54,6 +56,8 @@ public class TrayManager {
* @return popup menu
*/
public PopupMenu getMainMenu() {
boolean inI2P = ConfigurationManager.getInstance().getBooleanConfiguration("startWithI2P", false);
PopupMenu popup = new PopupMenu();
MenuItem browserLauncher = new MenuItem("Launch I2P Browser");
browserLauncher.addActionListener(new ActionListener() {
@@ -95,6 +99,32 @@ public class TrayManager {
});
popup.add(browserLauncher);
popup.addSeparator();
MenuItem startItem = new MenuItem("Start I2P");
startItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new SwingWorker<Object, Object>() {
@Override
protected Object doInBackground() throws Exception {
RouterManager.start();
return null;
}
@Override
protected void done() {
trayIcon.displayMessage("Starting", "I2P is starting!", TrayIcon.MessageType.INFO);
tray.remove(trayIcon);
}
}.execute();
}
});
if(!inI2P) {
popup.add(startItem);
}
MenuItem restartItem = new MenuItem("Restart I2P");
restartItem.addActionListener(new ActionListener() {
@@ -104,7 +134,7 @@ public class TrayManager {
@Override
protected Object doInBackground() throws Exception {
RouterManager.shutDown(Router.EXIT_GRACEFUL_RESTART);
RouterManager.restart();
return null;
}
@@ -113,7 +143,9 @@ public class TrayManager {
}
});
popup.add(restartItem);
if(inI2P) {
popup.add(restartItem);
}
MenuItem stopItem = new MenuItem("Stop I2P");
stopItem.addActionListener(new ActionListener() {
@@ -123,7 +155,7 @@ public class TrayManager {
@Override
protected Object doInBackground() throws Exception {
RouterManager.shutDown(Router.EXIT_GRACEFUL);
RouterManager.shutDown();
return null;
}
@@ -132,7 +164,9 @@ public class TrayManager {
}
});
popup.add(stopItem);
if(inI2P) {
popup.add(stopItem);
}
return popup;
}

View File

@@ -1,23 +1,34 @@
package net.i2p.desktopgui.router;
import net.i2p.I2PAppContext;
import org.tanukisoftware.wrapper.WrapperManager;
import java.io.IOException;
import net.i2p.desktopgui.util.ConfigurationManager;
import net.i2p.router.Router;
import net.i2p.router.RouterContext;
public class RouterManager {
private static Router getRouter() {
return RouterContext.listContexts().get(0).router();
}
public static void start() {
try {
String location = ConfigurationManager.getInstance().getStringConfiguration("I2PLocation", "/home/i2p");
//TODO: detect I2P directory
//TODO: crossplatform
Runtime.getRuntime().exec(location + "/i2psvc " + location + "/wrapper.config");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void restart() {
getRouter().restart();
}
public static void shutDown(final int exitCode) {
I2PAppContext.getGlobalContext().addShutdownTask(new Runnable() {
@Override
public void run() {
try {
WrapperManager.signalStopped(exitCode);
}
catch(Throwable t) {
//TODO: log
}
}
});
public static void shutDown() {
getRouter().shutdownGracefully();
}
}

View File

@@ -0,0 +1,82 @@
package net.i2p.desktopgui.util;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
/**
* Manage the configuration of desktopgui.
* @author mathias
*
*/
public class ConfigurationManager {
private static ConfigurationManager instance;
private Map<String, String> stringConfigurations = new HashMap<String, String>();
private Map<String, Boolean> booleanConfigurations = new HashMap<String, Boolean>();
private ConfigurationManager() {}
public static ConfigurationManager getInstance() {
if(instance == null) {
instance = new ConfigurationManager();
}
return instance;
}
public void loadArguments(String[] args) {
//Match pattern of the form --word=true or --word=false
Pattern booleanConfiguration = Pattern.compile("--(\\w)");
//Match pattern of the form --word=word
Pattern stringConfiguration = Pattern.compile("--(\\w)=(\\w)");
//Match pattern of the form --word
Pattern existsConfiguration = Pattern.compile("--(\\w)");
for(int i=0; i<args.length; i++) {
String arg = args[i];
if(arg.startsWith("--")) {
arg = arg.substring(2);
if(arg.length() < 1) {
continue;
}
int equals = arg.indexOf('=');
if(equals != -1 && equals < arg.length() - 1) { //String configuration
loadStringConfiguration(arg, equals);
}
else { //Boolean configuration
loadBooleanConfiguration(arg);
}
}
else if(arg.startsWith("-")) { //Boolean configuration
loadBooleanConfiguration(arg);
}
}
}
public void loadBooleanConfiguration(String arg) {
booleanConfigurations.put(arg, Boolean.TRUE);
}
public void loadStringConfiguration(String arg, int equalsPosition) {
String key = arg.substring(0, equalsPosition);
String value = arg.substring(equalsPosition+1);
stringConfigurations.put(key, value);
}
public boolean getBooleanConfiguration(String arg, boolean defaultValue) {
Boolean value = ((Boolean) booleanConfigurations.get("startWithI2P"));
System.out.println(value);
if(value != null) {
return value;
}
return defaultValue;
}
public String getStringConfiguration(String arg, String defaultValue) {
String value = stringConfigurations.get(arg);
System.out.println(value);
if(value != null) {
return value;
}
return defaultValue;
}
}

View File

@@ -687,7 +687,7 @@
<ant dir="core/java/" target="fullclovertest" />
<ant dir="router/java/" target="fullclovertest" />
</target>
<target name="desktopgui">
<target name="desktopgui" depends="builddepSmall">
<ant dir="apps/desktopgui" target="jar" />
<copy file="apps/desktopgui/dist/desktopgui.jar" todir="." />
</target>