fix bug in extensionForm 2

This commit is contained in:
sirjonasxx 2018-11-06 15:37:58 +01:00
parent 4d29895f5f
commit 3636c42245
3 changed files with 34 additions and 41 deletions

View File

@ -157,12 +157,7 @@ public class BlockAndReplacePackets extends ExtensionForm {
@Override @Override
protected void initExtension() { protected void initExtension() {
intercept(HMessage.Side.TOSERVER, new Extension.MessageListener() { intercept(HMessage.Side.TOSERVER, message -> System.out.println("just testing"));
@Override
public void act(HMessage message) {
System.out.println("just testing");
}
});
} }
@Override @Override

View File

@ -13,19 +13,17 @@ import java.util.concurrent.Semaphore;
*/ */
public abstract class ExtensionForm extends Application { public abstract class ExtensionForm extends Application {
private Extension extension = null; private volatile Extension extension;
protected static String[] args; protected static String[] args;
protected volatile Stage primaryStage; protected volatile Stage primaryStage;
private ExtensionForm realForm = null; private volatile ExtensionForm realForm = null;
@Override @Override
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {
ExtensionInfo extInfo = getClass().getAnnotation(ExtensionInfo.class); ExtensionInfo extInfo = getClass().getAnnotation(ExtensionInfo.class);
Semaphore semaphore = new Semaphore(1);
semaphore.acquire();
realForm = launchForm(primaryStage); realForm = launchForm(primaryStage);
Thread t = new Thread(() -> {
realForm.extension = new Extension(args) { realForm.extension = new Extension(args) {
@Override @Override
protected void init() { protected void init() {
@ -52,7 +50,8 @@ public abstract class ExtensionForm extends Application {
return extInfo; return extInfo;
} }
}; };
semaphore.release(); realForm.primaryStage = primaryStage;
Thread t = new Thread(() -> {
realForm.extension.run(); realForm.extension.run();
// Platform.runLater(primaryStage::close); // Platform.runLater(primaryStage::close);
//when the extension has ended, close this process //when the extension has ended, close this process
@ -60,10 +59,7 @@ public abstract class ExtensionForm extends Application {
}); });
t.start(); t.start();
semaphore.acquire();
Platform.setImplicitExit(false); Platform.setImplicitExit(false);
realForm = launchForm(primaryStage);
realForm.primaryStage = primaryStage;
primaryStage.setOnCloseRequest(event -> { primaryStage.setOnCloseRequest(event -> {
event.consume(); event.consume();

View File

@ -291,7 +291,9 @@ public class Extensions extends SubForm {
e.printStackTrace(); e.printStackTrace();
} }
}); });
extension.onClick(observable -> extension.sendMessage(new HPacket(OUTGOING_MESSAGES_IDS.ONDOUBLECLICK))); extension.onClick(observable -> {
extension.sendMessage(new HPacket(OUTGOING_MESSAGES_IDS.ONDOUBLECLICK));
});
Platform.runLater(() -> producer.extensionConnected(extension)); Platform.runLater(() -> producer.extensionConnected(extension));
} }