Skip to content

Commit

Permalink
Capture CANCELLED WebView state (qzind#1184)
Browse files Browse the repository at this point in the history
* Capture CANCELLED WebView state
* Add new listener to log webapp status messages
* Closes qzind#1183

---------

Co-authored-by: Berenz <5912715+akberenz@users.noreply.github.com>
  • Loading branch information
tresf and akberenz authored Oct 4, 2023
1 parent 119de93 commit cc4454e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/qz/printer/action/html/WebApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public class WebApp extends Application {
private static ChangeListener<Worker.State> stateListener = (ov, oldState, newState) -> {
log.trace("New state: {} > {}", oldState, newState);

// Cancelled should probably throw exception listener, but does not
if (newState == Worker.State.CANCELLED) {
// This can happen for file downloads, e.g. "response-content-disposition=attachment"
// See https://github.com/qzind/tray/issues/1183
unlatch(new IOException("Page load was cancelled for an unknown reason"));
}
if (newState == Worker.State.SUCCEEDED) {
boolean hasBody = (boolean)webView.getEngine().executeScript("document.body != null");
if (!hasBody) {
Expand Down Expand Up @@ -142,6 +148,8 @@ public void handle(long l) {
//listens for load progress
private static ChangeListener<Number> workDoneListener = (ov, oldWork, newWork) -> log.trace("Done: {} > {}", oldWork, newWork);

private static ChangeListener<String> msgListener = (ov, oldMsg, newMsg) -> log.trace("New status: {}", newMsg);

//listens for failures
private static ChangeListener<Throwable> exceptListener = (obs, oldExc, newExc) -> {
if (newExc != null) { unlatch(newExc); }
Expand Down Expand Up @@ -242,6 +250,7 @@ public void start(Stage st) throws Exception {
worker.stateProperty().addListener(stateListener);
worker.workDoneProperty().addListener(workDoneListener);
worker.exceptionProperty().addListener(exceptListener);
worker.messageProperty().addListener(msgListener);

//prevents JavaFX from shutting down when hiding window
Platform.setImplicitExit(false);
Expand Down

0 comments on commit cc4454e

Please sign in to comment.