Skip to content

Commit

Permalink
CSS compiler improvements. WebView window is now disposed when it is …
Browse files Browse the repository at this point in the history
…done. No longer lingers. #2494
  • Loading branch information
shannah committed Aug 7, 2018
1 parent 24916e0 commit cc9fcda
Showing 1 changed file with 69 additions and 3 deletions.
72 changes: 69 additions & 3 deletions CodenameOneDesigner/src/com/codename1/designer/css/CN1CSSCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.logging.Logger;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
Expand All @@ -60,6 +61,13 @@ public class CN1CSSCLI extends Application {
static WebView web;
@Override
public void start(Stage stage) throws Exception {
Platform.setImplicitExit(false);
startImpl(stage);
//stage.hide();

}

private static void startImpl(Stage stage) throws Exception {
System.out.println("Opening JavaFX Webview to render some CSS styles");
web = new WebView();
web.getEngine().getLoadWorker().exceptionProperty().addListener(new ChangeListener<Throwable>() {
Expand All @@ -68,14 +76,18 @@ public void changed(ObservableValue<? extends Throwable> ov, Throwable t, Throwa
System.out.println("Received exception: "+t1.getMessage());
}
});

Scene scene = new Scene(web, 400, 800, Color.web("#666670"));
stage.setScene(scene);
stage.show();
synchronized(lock) {
lock.notify();
}
//stage.hide();

}

private static void relaunch() throws Exception {
Stage stage = new Stage();
startImpl(stage);
}

public static boolean watchmode;
Expand Down Expand Up @@ -280,7 +292,7 @@ public WebView getWebView() {
new Thread(()->{
launch(CN1CSSCLI.class, new String[0]);
}).start();
}
}
while (web == null) {
System.out.println("Waiting for web browser");
synchronized(lock) {
Expand All @@ -291,6 +303,49 @@ public WebView getWebView() {
}
}
}
final boolean[] showing = new boolean[1];
final boolean[] complete = new boolean[1];
Platform.runLater(new Runnable() {
public void run() {
if (!web.getScene().getWindow().isShowing()) {
try {
relaunch();
synchronized(complete) {
showing[0] = true;
complete[0] = true;
complete.notify();
}
} catch (Throwable t) {
t.printStackTrace();
} finally {
synchronized(complete) {
complete[0] = true;
complete.notify();
}
}

} else {
synchronized(complete) {
showing[0] = true;
complete[0] = true;
complete.notify();
}
}
}
});

while (!complete[0]) {
synchronized(complete) {
try {
complete.wait();
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
}
if (!showing[0]) {
throw new RuntimeException("Failed to open WebView for generating 9-piece images");
}
System.out.println("Web browser is available");
return web;
}
Expand Down Expand Up @@ -325,6 +380,17 @@ public WebView getWebView() {
if (channel != null) {
channel.close();
}
if (web != null) {
Platform.runLater(new Runnable() {
public void run() {
if (web != null) {
web.getScene().getWindow().hide();
}
}
});

}

}
}

Expand Down

0 comments on commit cc9fcda

Please sign in to comment.