mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-24 12:46:45 +00:00
better handling of server connection editing
This commit is contained in:
parent
d49f85fe5b
commit
2b48b4cd6e
6 changed files with 87 additions and 23 deletions
|
@ -532,6 +532,14 @@ public class AppController implements Initializable {
|
|||
return onlineProperty.get();
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
serverToggle.selectedProperty().set(true);
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
serverToggle.selectedProperty().set(false);
|
||||
}
|
||||
|
||||
public static BooleanProperty onlineProperty() { return onlineProperty; }
|
||||
|
||||
public static Integer getCurrentBlockHeight() {
|
||||
|
@ -1214,4 +1222,14 @@ public class AppController implements Initializable {
|
|||
public void requestQRScan(RequestQRScanEvent event) {
|
||||
openTransactionFromQR(null);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void requestConnect(RequestConnectEvent event) {
|
||||
connect();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void requestDisconnect(RequestDisconnectEvent event) {
|
||||
disconnect();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.sparrowwallet.sparrow.event;
|
||||
|
||||
public class RequestConnectEvent {
|
||||
//Empty event class used to request programmatic connection to the server
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.sparrowwallet.sparrow.event;
|
||||
|
||||
public class RequestDisconnectEvent {
|
||||
//Empty event class used to request programmatic disconnection from the server
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
package com.sparrowwallet.sparrow.preferences;
|
||||
|
||||
import com.sparrowwallet.sparrow.AppController;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.event.RequestConnectEvent;
|
||||
import com.sparrowwallet.sparrow.io.Config;
|
||||
import com.sparrowwallet.sparrow.net.ElectrumServer;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.control.ButtonBar;
|
||||
import javafx.scene.control.ButtonType;
|
||||
|
@ -12,6 +15,8 @@ import org.controlsfx.tools.Borders;
|
|||
import java.io.IOException;
|
||||
|
||||
public class PreferencesDialog extends Dialog<Boolean> {
|
||||
private final boolean existingConnection;
|
||||
|
||||
public PreferencesDialog() {
|
||||
this(null);
|
||||
}
|
||||
|
@ -45,6 +50,13 @@ public class PreferencesDialog extends Dialog<Boolean> {
|
|||
dialogPane.setPrefWidth(650);
|
||||
dialogPane.setPrefHeight(500);
|
||||
|
||||
existingConnection = ElectrumServer.isConnected();
|
||||
setOnCloseRequest(event -> {
|
||||
if(existingConnection && !ElectrumServer.isConnected()) {
|
||||
EventManager.get().post(new RequestConnectEvent());
|
||||
}
|
||||
});
|
||||
|
||||
setResultConverter(dialogButton -> dialogButton == newWalletButtonType ? Boolean.TRUE : null);
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.sparrowwallet.sparrow.preferences;
|
||||
|
||||
import com.google.common.net.HostAndPort;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.control.TextFieldValidator;
|
||||
import com.sparrowwallet.sparrow.control.UnlabeledToggleSwitch;
|
||||
import com.sparrowwallet.sparrow.event.ConnectionEvent;
|
||||
import com.sparrowwallet.sparrow.event.RequestDisconnectEvent;
|
||||
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
|
||||
import com.sparrowwallet.sparrow.io.Config;
|
||||
import com.sparrowwallet.sparrow.net.ElectrumServer;
|
||||
|
@ -61,6 +63,9 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
|||
@FXML
|
||||
private Button testConnection;
|
||||
|
||||
@FXML
|
||||
private Button editConnection;
|
||||
|
||||
@FXML
|
||||
private TextArea testResults;
|
||||
|
||||
|
@ -125,20 +130,15 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
|||
}
|
||||
});
|
||||
|
||||
testConnection.setDisable(ElectrumServer.isConnected());
|
||||
boolean isConnected = ElectrumServer.isConnected();
|
||||
setFieldsEditable(!isConnected);
|
||||
|
||||
testConnection.managedProperty().bind(testConnection.visibleProperty());
|
||||
testConnection.setVisible(!isConnected);
|
||||
testConnection.setOnAction(event -> {
|
||||
testResults.setText("Connecting to " + config.getElectrumServer() + "...");
|
||||
testConnection.setGraphic(getGlyph(FontAwesome5.Glyph.ELLIPSIS_H, null));
|
||||
|
||||
boolean existingConnection = ElectrumServer.isConnected();
|
||||
if(existingConnection) {
|
||||
ElectrumServer.ServerBannerService serverBannerService = new ElectrumServer.ServerBannerService();
|
||||
serverBannerService.setOnSucceeded(successEvent -> {
|
||||
showConnectionSuccess(null, serverBannerService.getValue());
|
||||
});
|
||||
serverBannerService.setOnFailed(this::showConnectionFailure);
|
||||
serverBannerService.start();
|
||||
} else {
|
||||
ElectrumServer.ConnectionService connectionService = new ElectrumServer.ConnectionService(false);
|
||||
connectionService.setPeriod(Duration.minutes(1));
|
||||
connectionService.setOnSucceeded(successEvent -> {
|
||||
|
@ -151,7 +151,15 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
|||
connectionService.cancel();
|
||||
});
|
||||
connectionService.start();
|
||||
}
|
||||
});
|
||||
|
||||
editConnection.managedProperty().bind(editConnection.visibleProperty());
|
||||
editConnection.setVisible(isConnected);
|
||||
editConnection.setOnAction(event -> {
|
||||
EventManager.get().post(new RequestDisconnectEvent());
|
||||
setFieldsEditable(true);
|
||||
editConnection.setVisible(false);
|
||||
testConnection.setVisible(true);
|
||||
});
|
||||
|
||||
String electrumServer = config.getElectrumServer();
|
||||
|
@ -196,6 +204,17 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
|||
}
|
||||
}
|
||||
|
||||
private void setFieldsEditable(boolean editable) {
|
||||
host.setEditable(editable);
|
||||
port.setEditable(editable);
|
||||
useSsl.setDisable(!editable);
|
||||
certificate.setEditable(editable);
|
||||
certificateSelect.setDisable(!editable);
|
||||
useProxy.setDisable(!editable);
|
||||
proxyHost.setEditable(editable);
|
||||
proxyPort.setEditable(editable);
|
||||
}
|
||||
|
||||
private void showConnectionSuccess(List<String> serverVersion, String serverBanner) {
|
||||
testConnection.setGraphic(getGlyph(FontAwesome5.Glyph.CHECK_CIRCLE, Color.rgb(80, 161, 79)));
|
||||
if(serverVersion != null) {
|
||||
|
|
|
@ -59,6 +59,11 @@
|
|||
<Glyph fontFamily="FontAwesome" icon="QUESTION_CIRCLE" prefWidth="13" />
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button fx:id="editConnection" graphicTextGap="5" text="Edit Existing Connection">
|
||||
<graphic>
|
||||
<Glyph fontFamily="FontAwesome" icon="EDIT" prefWidth="15" />
|
||||
</graphic>
|
||||
</Button>
|
||||
</StackPane>
|
||||
|
||||
<StackPane GridPane.columnIndex="0" GridPane.rowIndex="2">
|
||||
|
|
Loading…
Reference in a new issue