Fixup plugin start/stop

This commit is contained in:
zzz
2022-01-11 16:14:24 -05:00
parent eca5a15605
commit aa71e88958
2 changed files with 15 additions and 11 deletions

View File

@ -22,10 +22,9 @@ import net.i2p.app.*;
import static net.i2p.app.ClientAppState.*; import static net.i2p.app.ClientAppState.*;
import net.i2p.util.Log; import net.i2p.util.Log;
import net.i2p.itoopie.Main;
import net.i2p.itoopie.configuration.ConfigurationManager; import net.i2p.itoopie.configuration.ConfigurationManager;
import net.i2p.itoopie.gui.GUIHelper; import net.i2p.itoopie.gui.GUIHelper;
import net.i2p.itoopie.gui.TrayManager;
import net.i2p.itoopie.gui.WindowHandler;
/** /**
* *
@ -35,18 +34,19 @@ public class Itoopie implements ClientApp {
private final I2PAppContext _context; private final I2PAppContext _context;
private final Log _log; private final Log _log;
private final ClientAppManager _mgr; private final ClientAppManager _mgr;
private TrayManager trayManager; private final Main _main;
private ClientAppState _state = UNINITIALIZED; private ClientAppState _state = UNINITIALIZED;
public Itoopie(I2PAppContext ctx, ClientAppManager mgr, String args[]) { public Itoopie(I2PAppContext ctx, ClientAppManager mgr, String args[]) {
_context = ctx; _context = ctx;
_log = ctx.logManager().getLog(Itoopie.class); _log = ctx.logManager().getLog(Itoopie.class);
_mgr = mgr; _mgr = mgr;
_state = INITIALIZED;
// Set the conf dir so ConfigurationManager can find it // Set the conf dir so ConfigurationManager can find it
File d = new File(ctx.getConfigDir(), "plugins"); File d = new File(ctx.getConfigDir(), "plugins");
d = new File(d, "itoopie"); d = new File(d, "itoopie");
System.setProperty(ConfigurationManager.PROP_CONF_DIR, d.getAbsolutePath()); System.setProperty(ConfigurationManager.PROP_CONF_DIR, d.getAbsolutePath());
_main = new Main();
_state = INITIALIZED;
} }
/** /**
@ -63,14 +63,13 @@ public class Itoopie implements ClientApp {
_log.error("Start while state = " + _state); _log.error("Start while state = " + _state);
return; return;
} }
trayManager = TrayManager.getInstance(); System.setProperty("java.awt.headless", "false");
trayManager.startManager();
try { try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
GUIHelper.setDefaultStyle(); GUIHelper.setDefaultStyle();
} catch (Exception ex) {} } catch (Exception ex) {}
// Popup Main window. // Popup Main window.
WindowHandler.toggleFrames(); _main.startUp();
changeState(RUNNING); changeState(RUNNING);
} }
@ -78,9 +77,7 @@ public class Itoopie implements ClientApp {
if (_state == STOPPED) if (_state == STOPPED)
return; return;
changeState(STOPPING); changeState(STOPPING);
trayManager.stopManager(); _main.stop();
// TODO stop it
trayManager = null;
changeState(STOPPED); changeState(STOPPED);
} }

View File

@ -101,7 +101,14 @@ public class Main {
//testStuff(); // Delete Me //testStuff(); // Delete Me
} }
@SuppressWarnings("static-access") /**
* For plugin
*/
public void stop() {
if (trayManager != null)
trayManager.stopManager();
}
public void beginShutdown(){ public void beginShutdown(){
_conf.writeConfFile(); _conf.writeConfFile();
System.exit(0); System.exit(0);