diff --git a/G-Earth/src/main/java/gearth/protocol/HConnection.java b/G-Earth/src/main/java/gearth/protocol/HConnection.java index 417e79f..495481f 100644 --- a/G-Earth/src/main/java/gearth/protocol/HConnection.java +++ b/G-Earth/src/main/java/gearth/protocol/HConnection.java @@ -15,6 +15,7 @@ import gearth.protocol.connection.proxy.unity.UnityProxyProvider; import gearth.services.extension_handler.ExtensionHandler; import java.io.IOException; +import java.util.function.Consumer; public class HConnection { @@ -25,6 +26,7 @@ public class HConnection { private volatile Object[] trafficObservables = {new Observable(), new Observable(), new Observable()}; private volatile Observable stateObservable = new Observable<>(); + private volatile Observable> developerModeChangeObservable = new Observable<>(); private volatile HState state = HState.NOT_CONNECTED; private volatile HProxy proxy = null; @@ -196,6 +198,11 @@ public class HConnection { public void setDeveloperMode(boolean developerMode) { this.developerMode = developerMode; + developerModeChangeObservable.fireEvent(listener -> listener.accept(developerMode)); + } + + public void onDeveloperModeChange(Consumer onChange) { + developerModeChangeObservable.addListener(onChange); } public String getClientHost() { diff --git a/G-Earth/src/main/java/gearth/ui/SubForm.java b/G-Earth/src/main/java/gearth/ui/SubForm.java index 9b0ba73..0423a31 100644 --- a/G-Earth/src/main/java/gearth/ui/SubForm.java +++ b/G-Earth/src/main/java/gearth/ui/SubForm.java @@ -33,6 +33,9 @@ public class SubForm { } protected HConnection getHConnection() { + if (parentController == null) { + return null; + } return parentController.getHConnection(); } protected void writeToLog(javafx.scene.paint.Color color, String text) { diff --git a/G-Earth/src/main/java/gearth/ui/subforms/extensions/ExtensionsController.java b/G-Earth/src/main/java/gearth/ui/subforms/extensions/ExtensionsController.java index 83da26a..d5c01c5 100644 --- a/G-Earth/src/main/java/gearth/ui/subforms/extensions/ExtensionsController.java +++ b/G-Earth/src/main/java/gearth/ui/subforms/extensions/ExtensionsController.java @@ -79,6 +79,8 @@ public class ExtensionsController extends SubForm { extensionLogger.log(text); } })); + + getHConnection().onDeveloperModeChange(this::setLocalInstallingEnabled); } @@ -117,7 +119,6 @@ public class ExtensionsController extends SubForm { btn_install.setDisable(!enabled); } - private volatile int gpytonShellCounter = 1; private volatile boolean pythonShellLaunching = false; public void gpythonBtnClicked(ActionEvent actionEvent) { diff --git a/G-Earth/src/main/java/gearth/ui/subforms/extra/ExtraController.java b/G-Earth/src/main/java/gearth/ui/subforms/extra/ExtraController.java index 7b5a2f6..409a36a 100644 --- a/G-Earth/src/main/java/gearth/ui/subforms/extra/ExtraController.java +++ b/G-Earth/src/main/java/gearth/ui/subforms/extra/ExtraController.java @@ -266,7 +266,6 @@ public class ExtraController extends SubForm implements SocksConfiguration { private void setDevelopMode(boolean enabled) { cbx_develop.setSelected(enabled); getHConnection().setDeveloperMode(enabled); - parentController.extensionsController.setLocalInstallingEnabled(enabled); } public void adminCbxClick(ActionEvent actionEvent) { diff --git a/G-Earth/src/main/java/gearth/ui/subforms/injection/InjectionController.java b/G-Earth/src/main/java/gearth/ui/subforms/injection/InjectionController.java index bb40ca6..aca0358 100644 --- a/G-Earth/src/main/java/gearth/ui/subforms/injection/InjectionController.java +++ b/G-Earth/src/main/java/gearth/ui/subforms/injection/InjectionController.java @@ -38,6 +38,7 @@ public class InjectionController extends SubForm { private TranslatableString corruption, pcktInfo; protected void onParentSet() { + getHConnection().onDeveloperModeChange(developMode -> updateUI()); getHConnection().getStateObservable().addListener((oldState, newState) -> Platform.runLater(this::updateUI)); inputPacket.textProperty().addListener(event -> Platform.runLater(this::updateUI)); diff --git a/G-Earth/src/main/java/gearth/ui/subforms/scheduler/SchedulerController.java b/G-Earth/src/main/java/gearth/ui/subforms/scheduler/SchedulerController.java index 307b21c..b2a95c5 100644 --- a/G-Earth/src/main/java/gearth/ui/subforms/scheduler/SchedulerController.java +++ b/G-Earth/src/main/java/gearth/ui/subforms/scheduler/SchedulerController.java @@ -1,6 +1,10 @@ package gearth.ui.subforms.scheduler; import com.tulskiy.keymaster.common.Provider; +import gearth.extensions.parsers.HDirection; +import gearth.protocol.HConnection; +import gearth.protocol.StateChangeListener; +import gearth.protocol.connection.HState; import gearth.services.scheduler.Interval; import gearth.services.scheduler.Scheduler; import gearth.ui.translations.LanguageBundle; @@ -19,6 +23,7 @@ import javax.swing.*; import java.io.*; import java.util.ArrayList; import java.util.List; +import java.util.function.Consumer; /** * Created by Jonas on 06/04/18. @@ -61,8 +66,6 @@ public class SchedulerController extends SubForm { txt_packet.textProperty().addListener(event -> Platform.runLater(this::updateUI)); txt_delay.textProperty().addListener(event -> Platform.runLater(this::updateUI)); - updateUI(); - //register hotkeys //disable some output things PrintStream err = System.err; @@ -85,6 +88,9 @@ public class SchedulerController extends SubForm { @Override protected void onParentSet() { scheduler = new Scheduler<>(getHConnection()); + getHConnection().onDeveloperModeChange(developMode -> updateUI()); + getHConnection().getStateObservable().addListener((oldState, newState) -> updateUI()); + updateUI(); } private void switchPauseHotkey(int index) { @@ -104,7 +110,14 @@ public class SchedulerController extends SubForm { } private void updateUI() { - btn_addoredit.setDisable(!Interval.isValid(txt_delay.getText()) || new HPacket(txt_packet.getText()).isCorrupted()); + HConnection connection = getHConnection(); + if (connection == null) return; + + HMessage.Direction direction = rb_incoming.isSelected() ? HMessage.Direction.TOCLIENT : HMessage.Direction.TOSERVER; + HPacket packet = new HPacket(txt_packet.getText()); + boolean isPacketOk = connection.canSendPacket(direction, packet); + + btn_addoredit.setDisable(!Interval.isValid(txt_delay.getText()) || !isPacketOk); } public void scheduleBtnClicked(ActionEvent actionEvent) { diff --git a/G-Earth/src/main/resources/gearth/ui/subforms/extensions/Extensions.fxml b/G-Earth/src/main/resources/gearth/ui/subforms/extensions/Extensions.fxml index 5dd0051..61f211c 100644 --- a/G-Earth/src/main/resources/gearth/ui/subforms/extensions/Extensions.fxml +++ b/G-Earth/src/main/resources/gearth/ui/subforms/extensions/Extensions.fxml @@ -4,7 +4,7 @@ - + diff --git a/G-Earth/src/main/resources/gearth/ui/subforms/extra/Extra.fxml b/G-Earth/src/main/resources/gearth/ui/subforms/extra/Extra.fxml index 5e35d4b..cbe84a7 100644 --- a/G-Earth/src/main/resources/gearth/ui/subforms/extra/Extra.fxml +++ b/G-Earth/src/main/resources/gearth/ui/subforms/extra/Extra.fxml @@ -5,7 +5,7 @@ - + diff --git a/G-Earth/src/main/resources/gearth/ui/subforms/info/Info.fxml b/G-Earth/src/main/resources/gearth/ui/subforms/info/Info.fxml index 31ccf85..33b8e24 100644 --- a/G-Earth/src/main/resources/gearth/ui/subforms/info/Info.fxml +++ b/G-Earth/src/main/resources/gearth/ui/subforms/info/Info.fxml @@ -5,7 +5,7 @@ - +