forked from I2P_Developers/i2p.i2p
Moved I2PProperties callback to the RouterContext.
This commit is contained in:
@@ -9,6 +9,7 @@ import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.desktopgui.router.RouterManager;
|
||||
import net.i2p.desktopgui.util.*;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.Translate;
|
||||
@@ -25,23 +26,24 @@ public class Main {
|
||||
|
||||
/**
|
||||
* Start the tray icon code (loads tray icon in the tray area).
|
||||
* @throws Exception
|
||||
*/
|
||||
private void startUp() {
|
||||
private void startUp() throws Exception {
|
||||
trayManager = TrayManager.getInstance();
|
||||
trayManager.startManager();
|
||||
I2PAppContext.getCurrentContext().addPropertyCallback(new I2PPropertyCallback() {
|
||||
|
||||
if(RouterManager.inI2P()) {
|
||||
RouterManager.getRouterContext().addPropertyCallback(new I2PPropertyCallback() {
|
||||
|
||||
@Override
|
||||
public String getPropertyKey() {
|
||||
return Translate.PROP_LANG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void propertyChanged(String arg0, String arg1) {
|
||||
trayManager.languageChanged();
|
||||
}
|
||||
|
||||
});
|
||||
@Override
|
||||
public void propertyChanged(String arg0, String arg1) {
|
||||
if(arg0.equals(Translate.PROP_LANG)) {
|
||||
trayManager.languageChanged();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +73,12 @@ public class Main {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
main.startUp();
|
||||
try {
|
||||
main.startUp();
|
||||
}
|
||||
catch(Exception e) {
|
||||
log.error("Failed while running desktopgui!", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -17,9 +17,28 @@ import net.i2p.util.Log;
|
||||
public class RouterManager {
|
||||
|
||||
private final static Log log = new Log(RouterManager.class);
|
||||
private static I2PAppContext context = I2PAppContext.getCurrentContext();
|
||||
|
||||
public static I2PAppContext getAppContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public static RouterContext getRouterContext() throws Exception {
|
||||
if(context.isRouterContext()) {
|
||||
return (RouterContext) context;
|
||||
}
|
||||
else {
|
||||
throw new Exception("No RouterContext available!");
|
||||
}
|
||||
}
|
||||
|
||||
private static Router getRouter() {
|
||||
return RouterContext.listContexts().get(0).router();
|
||||
try {
|
||||
return getRouterContext().router();
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to get router. Why did we request it if no RouterContext is available?", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,14 +46,13 @@ public class RouterManager {
|
||||
* This method has limited knowledge
|
||||
* (there is no I2P instance running to collect information from).
|
||||
*
|
||||
* It needs to determine itself where the I2P instance is located,
|
||||
* except if the location has been given through command-line arguments.
|
||||
* It determines the I2P location using the I2PAppContext.
|
||||
*/
|
||||
public static void start() {
|
||||
try {
|
||||
//TODO: set/get PID
|
||||
String separator = System.getProperty("file.separator");
|
||||
String location = I2PAppContext.getCurrentContext().getBaseDir().getAbsolutePath();
|
||||
String location = getAppContext().getBaseDir().getAbsolutePath();
|
||||
|
||||
Runtime.getRuntime().exec(location + separator + "i2psvc " + location + separator + "wrapper.config");
|
||||
} catch (IOException e) {
|
||||
@@ -46,24 +64,24 @@ public class RouterManager {
|
||||
* Restart the running I2P instance.
|
||||
*/
|
||||
public static void restart() {
|
||||
getRouter().restart();
|
||||
if(inI2P()) {
|
||||
getRouter().restart();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the running I2P instance.
|
||||
*/
|
||||
public static void shutDown() {
|
||||
getRouter().shutdownGracefully();
|
||||
if(inI2P()) {
|
||||
getRouter().shutdownGracefully();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we are running inside I2P.
|
||||
*/
|
||||
public static boolean inI2P() {
|
||||
return (RouterContext.listContexts().size() > 0);
|
||||
return context.isRouterContext();
|
||||
}
|
||||
|
||||
private static String _(String s) {
|
||||
return DesktopguiTranslator._(s);
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ public class ContentHelper extends HelperBase {
|
||||
_startAtBeginning = Boolean.valueOf(""+moo).booleanValue();
|
||||
}
|
||||
public void setLang(String l) {
|
||||
if(_lang == null || !_lang.equals(l)) {
|
||||
if((_lang == null || !_lang.equals(l)) && (l != null)) {
|
||||
//Set language for router console
|
||||
_lang = l;
|
||||
|
||||
|
Reference in New Issue
Block a user