From 22973d1c95a66012ee955e20d83a567fc52be30d Mon Sep 17 00:00:00 2001 From: Rohit Awate Date: Tue, 31 Jul 2018 20:06:42 +0530 Subject: [PATCH] Fix issues where LoadingLayer's progressBar was frozen and while sending new request while one is already being sent --- .../controllers/DashboardController.java | 17 +++++++++++++---- .../controllers/HomeWindowController.java | 3 ++- .../resources/fxml/homewindow/Dashboard.fxml | 2 +- .../resources/fxml/homewindow/HomeWindow.fxml | 4 ++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java index aeaf040..7e83be0 100644 --- a/src/main/java/com/rohitawate/everest/controllers/DashboardController.java +++ b/src/main/java/com/rohitawate/everest/controllers/DashboardController.java @@ -78,7 +78,7 @@ public class DashboardController implements Initializable { private Label statusCode, statusCodeDescription, responseTime, responseSize, errorTitle, errorDetails; @FXML - private JFXButton cancelButton, copyBodyButton; + private JFXButton sendButton, cancelButton, copyBodyButton; @FXML TabPane requestOptionsTab, responseTabPane; @FXML @@ -204,6 +204,12 @@ public class DashboardController implements Initializable { @FXML void sendRequest() { + if (requestManager != null) { + while (requestManager.isRunning()) + requestManager.cancel(); + requestManager.reset(); + } + if (responseBox.getChildren().size() == 2) { responseBox.getChildren().remove(0); responseArea.clear(); @@ -349,18 +355,19 @@ public class DashboardController implements Initializable { private void onCancelled(Event event) { showLayer(ResponseLayer.PROMPT); - snackbar.show("Request canceled.", 2000); requestManager.reset(); addressField.requestFocus(); } private void onSucceeded(Event event) { - showResponse(requestManager.getValue()); showLayer(ResponseLayer.RESPONSE); + showResponse(requestManager.getValue()); requestManager.reset(); } private void whileRunning(Event event) { + progressBar.requestLayout(); + progressBar.progressProperty().bind(requestManager.progressProperty()); responseArea.clear(); showLayer(ResponseLayer.LOADING); } @@ -398,6 +405,9 @@ public class DashboardController implements Initializable { } private void showResponse(EverestResponse response) { + if (response == null) + return; + prettifyResponseBody(response); statusCode.setText(Integer.toString(response.getStatusCode())); statusCodeDescription.setText(Response.Status.fromStatusCode(response.getStatusCode()).getReasonPhrase()); @@ -491,7 +501,6 @@ public class DashboardController implements Initializable { private void prettifyResponseBody(EverestResponse response) { String type; - if (response.getMediaType() != null) type = response.getMediaType().toString(); else diff --git a/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java b/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java index 135c7b1..df29977 100644 --- a/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java +++ b/src/main/java/com/rohitawate/everest/controllers/HomeWindowController.java @@ -251,7 +251,8 @@ public class HomeWindowController implements Initializable { addTab(); } } catch (IOException e) { - Services.loggingService.logWarning("Application state file is possibly corrupted. State recovery failed. Loading default state.", e, LocalDateTime.now()); + Services.loggingService.logWarning("Application state file is either corrupted or outdated. State recovery failed. Loading default state.", e, LocalDateTime.now()); + addTab(); } finally { Services.loggingService.logInfo("Application loaded.", LocalDateTime.now()); } diff --git a/src/main/resources/fxml/homewindow/Dashboard.fxml b/src/main/resources/fxml/homewindow/Dashboard.fxml index 59b8341..d8caa35 100644 --- a/src/main/resources/fxml/homewindow/Dashboard.fxml +++ b/src/main/resources/fxml/homewindow/Dashboard.fxml @@ -22,7 +22,7 @@ - diff --git a/src/main/resources/fxml/homewindow/HomeWindow.fxml b/src/main/resources/fxml/homewindow/HomeWindow.fxml index 82953b8..79796e7 100644 --- a/src/main/resources/fxml/homewindow/HomeWindow.fxml +++ b/src/main/resources/fxml/homewindow/HomeWindow.fxml @@ -22,7 +22,7 @@ - @@ -32,7 +32,7 @@ + onAction="#addTab" ripplerFill="WHITE" HBox.hgrow="ALWAYS">