mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06: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();
|
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 BooleanProperty onlineProperty() { return onlineProperty; }
|
||||||
|
|
||||||
public static Integer getCurrentBlockHeight() {
|
public static Integer getCurrentBlockHeight() {
|
||||||
|
@ -1214,4 +1222,14 @@ public class AppController implements Initializable {
|
||||||
public void requestQRScan(RequestQRScanEvent event) {
|
public void requestQRScan(RequestQRScanEvent event) {
|
||||||
openTransactionFromQR(null);
|
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;
|
package com.sparrowwallet.sparrow.preferences;
|
||||||
|
|
||||||
import com.sparrowwallet.sparrow.AppController;
|
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.io.Config;
|
||||||
|
import com.sparrowwallet.sparrow.net.ElectrumServer;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.control.ButtonBar;
|
import javafx.scene.control.ButtonBar;
|
||||||
import javafx.scene.control.ButtonType;
|
import javafx.scene.control.ButtonType;
|
||||||
|
@ -12,6 +15,8 @@ import org.controlsfx.tools.Borders;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class PreferencesDialog extends Dialog<Boolean> {
|
public class PreferencesDialog extends Dialog<Boolean> {
|
||||||
|
private final boolean existingConnection;
|
||||||
|
|
||||||
public PreferencesDialog() {
|
public PreferencesDialog() {
|
||||||
this(null);
|
this(null);
|
||||||
}
|
}
|
||||||
|
@ -45,6 +50,13 @@ public class PreferencesDialog extends Dialog<Boolean> {
|
||||||
dialogPane.setPrefWidth(650);
|
dialogPane.setPrefWidth(650);
|
||||||
dialogPane.setPrefHeight(500);
|
dialogPane.setPrefHeight(500);
|
||||||
|
|
||||||
|
existingConnection = ElectrumServer.isConnected();
|
||||||
|
setOnCloseRequest(event -> {
|
||||||
|
if(existingConnection && !ElectrumServer.isConnected()) {
|
||||||
|
EventManager.get().post(new RequestConnectEvent());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
setResultConverter(dialogButton -> dialogButton == newWalletButtonType ? Boolean.TRUE : null);
|
setResultConverter(dialogButton -> dialogButton == newWalletButtonType ? Boolean.TRUE : null);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package com.sparrowwallet.sparrow.preferences;
|
package com.sparrowwallet.sparrow.preferences;
|
||||||
|
|
||||||
import com.google.common.net.HostAndPort;
|
import com.google.common.net.HostAndPort;
|
||||||
|
import com.sparrowwallet.sparrow.EventManager;
|
||||||
import com.sparrowwallet.sparrow.control.TextFieldValidator;
|
import com.sparrowwallet.sparrow.control.TextFieldValidator;
|
||||||
import com.sparrowwallet.sparrow.control.UnlabeledToggleSwitch;
|
import com.sparrowwallet.sparrow.control.UnlabeledToggleSwitch;
|
||||||
import com.sparrowwallet.sparrow.event.ConnectionEvent;
|
import com.sparrowwallet.sparrow.event.ConnectionEvent;
|
||||||
|
import com.sparrowwallet.sparrow.event.RequestDisconnectEvent;
|
||||||
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
|
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
|
||||||
import com.sparrowwallet.sparrow.io.Config;
|
import com.sparrowwallet.sparrow.io.Config;
|
||||||
import com.sparrowwallet.sparrow.net.ElectrumServer;
|
import com.sparrowwallet.sparrow.net.ElectrumServer;
|
||||||
|
@ -61,6 +63,9 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||||
@FXML
|
@FXML
|
||||||
private Button testConnection;
|
private Button testConnection;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button editConnection;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextArea testResults;
|
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 -> {
|
testConnection.setOnAction(event -> {
|
||||||
testResults.setText("Connecting to " + config.getElectrumServer() + "...");
|
testResults.setText("Connecting to " + config.getElectrumServer() + "...");
|
||||||
testConnection.setGraphic(getGlyph(FontAwesome5.Glyph.ELLIPSIS_H, null));
|
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);
|
ElectrumServer.ConnectionService connectionService = new ElectrumServer.ConnectionService(false);
|
||||||
connectionService.setPeriod(Duration.minutes(1));
|
connectionService.setPeriod(Duration.minutes(1));
|
||||||
connectionService.setOnSucceeded(successEvent -> {
|
connectionService.setOnSucceeded(successEvent -> {
|
||||||
|
@ -151,7 +151,15 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||||
connectionService.cancel();
|
connectionService.cancel();
|
||||||
});
|
});
|
||||||
connectionService.start();
|
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();
|
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) {
|
private void showConnectionSuccess(List<String> serverVersion, String serverBanner) {
|
||||||
testConnection.setGraphic(getGlyph(FontAwesome5.Glyph.CHECK_CIRCLE, Color.rgb(80, 161, 79)));
|
testConnection.setGraphic(getGlyph(FontAwesome5.Glyph.CHECK_CIRCLE, Color.rgb(80, 161, 79)));
|
||||||
if(serverVersion != null) {
|
if(serverVersion != null) {
|
||||||
|
|
|
@ -59,6 +59,11 @@
|
||||||
<Glyph fontFamily="FontAwesome" icon="QUESTION_CIRCLE" prefWidth="13" />
|
<Glyph fontFamily="FontAwesome" icon="QUESTION_CIRCLE" prefWidth="13" />
|
||||||
</graphic>
|
</graphic>
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button fx:id="editConnection" graphicTextGap="5" text="Edit Existing Connection">
|
||||||
|
<graphic>
|
||||||
|
<Glyph fontFamily="FontAwesome" icon="EDIT" prefWidth="15" />
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
</StackPane>
|
</StackPane>
|
||||||
|
|
||||||
<StackPane GridPane.columnIndex="0" GridPane.rowIndex="2">
|
<StackPane GridPane.columnIndex="0" GridPane.rowIndex="2">
|
||||||
|
|
Loading…
Reference in a new issue