disable server toggle when no server is configured (url host is empty)

This commit is contained in:
Craig Raw 2023-02-09 10:29:19 +02:00
parent b15d6308bd
commit 545342dfb4
3 changed files with 12 additions and 7 deletions

View file

@ -386,7 +386,7 @@ public class AppController implements Initializable {
configureSwitchServer(); configureSwitchServer();
setServerType(Config.get().getServerType()); setServerType(Config.get().getServerType());
serverToggle.setSelected(isConnected()); serverToggle.setSelected(isConnected());
serverToggle.setDisable(Config.get().getServerType() == null); serverToggle.setDisable(!Config.get().hasServer());
onlineProperty().bindBidirectional(serverToggle.selectedProperty()); onlineProperty().bindBidirectional(serverToggle.selectedProperty());
onlineProperty().addListener(new WeakChangeListener<>(serverToggleOnlineListener)); onlineProperty().addListener(new WeakChangeListener<>(serverToggleOnlineListener));
serverToggle.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> { serverToggle.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
@ -1248,6 +1248,7 @@ public class AppController implements Initializable {
PreferencesDialog preferencesDialog = new PreferencesDialog(preferenceGroup); PreferencesDialog preferencesDialog = new PreferencesDialog(preferenceGroup);
preferencesDialog.showAndWait(); preferencesDialog.showAndWait();
configureSwitchServer(); configureSwitchServer();
serverToggle.setDisable(!Config.get().hasServer());
} }
public void signVerifyMessage(ActionEvent event) { public void signVerifyMessage(ActionEvent event) {
@ -2091,7 +2092,7 @@ public class AppController implements Initializable {
serverToggle.getStyleClass().remove("core-server"); serverToggle.getStyleClass().remove("core-server");
} }
serverToggle.setDisable(false); serverToggle.setDisable(!Config.get().hasServer());
} }
public void setTheme(ActionEvent event) { public void setTheme(ActionEvent event) {

View file

@ -748,11 +748,13 @@ public class ServerPreferencesController extends PreferencesDetailController {
String hostAsString = getHost(coreHost.getText()); String hostAsString = getHost(coreHost.getText());
Integer portAsInteger = getPort(corePort.getText()); Integer portAsInteger = getPort(corePort.getText());
if(hostAsString != null && portAsInteger != null && isValidPort(portAsInteger)) { if(hostAsString != null && !hostAsString.isEmpty() && portAsInteger != null && isValidPort(portAsInteger)) {
Protocol protocol = portAsInteger == Protocol.HTTPS.getDefaultPort() ? Protocol.HTTPS : Protocol.HTTP; Protocol protocol = portAsInteger == Protocol.HTTPS.getDefaultPort() ? Protocol.HTTPS : Protocol.HTTP;
config.setCoreServer(new Server(protocol.toUrlString(hostAsString, portAsInteger))); config.setCoreServer(new Server(protocol.toUrlString(hostAsString, portAsInteger)));
} else if(hostAsString != null) { } else if(hostAsString != null && !hostAsString.isEmpty()) {
config.setCoreServer(new Server(Protocol.HTTP.toUrlString(hostAsString))); config.setCoreServer(new Server(Protocol.HTTP.toUrlString(hostAsString)));
} else {
config.setCoreServer(null);
} }
} }
@ -781,10 +783,12 @@ public class ServerPreferencesController extends PreferencesDetailController {
String hostAsString = getHost(electrumHost.getText()); String hostAsString = getHost(electrumHost.getText());
Integer portAsInteger = getPort(electrumPort.getText()); Integer portAsInteger = getPort(electrumPort.getText());
if(hostAsString != null && portAsInteger != null && isValidPort(portAsInteger)) { if(hostAsString != null && !hostAsString.isEmpty() && portAsInteger != null && isValidPort(portAsInteger)) {
config.setElectrumServer(new Server(getProtocol().toUrlString(hostAsString, portAsInteger))); config.setElectrumServer(new Server(getProtocol().toUrlString(hostAsString, portAsInteger)));
} else if(hostAsString != null) { } else if(hostAsString != null && !hostAsString.isEmpty()) {
config.setElectrumServer(new Server(getProtocol().toUrlString(hostAsString))); config.setElectrumServer(new Server(getProtocol().toUrlString(hostAsString)));
} else {
config.setElectrumServer(null);
} }
} }

View file

@ -154,7 +154,7 @@
<ComboBox fx:id="recentElectrumServers" /> <ComboBox fx:id="recentElectrumServers" />
<ComboBoxTextField fx:id="electrumHost" promptText="e.g. 127.0.0.1 or Tor hostname (.onion)" comboProperty="$recentElectrumServers" /> <ComboBoxTextField fx:id="electrumHost" promptText="e.g. 127.0.0.1 or Tor hostname (.onion)" comboProperty="$recentElectrumServers" />
</StackPane> </StackPane>
<TextField fx:id="electrumPort" promptText="e.g. 50002" maxWidth="120" /> <TextField fx:id="electrumPort" promptText="e.g. 50001" maxWidth="120" />
</Field> </Field>
<Field text="Use SSL:"> <Field text="Use SSL:">
<UnlabeledToggleSwitch fx:id="electrumUseSsl"/> <UnlabeledToggleSwitch fx:id="electrumUseSsl"/>