Rather than piggybacking on first alert call, use the fact that the server and FX Web View are in the same VM and notify the view that bck2brwsr.js is about to be served from the server.
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.launcher;
20 import org.apidesign.bck2brwsr.launcher.impl.FXBrwsr;
21 import java.io.IOException;
22 import java.lang.reflect.Method;
25 import java.net.URLClassLoader;
27 import java.util.concurrent.Executors;
28 import java.util.logging.Level;
29 import java.util.logging.Logger;
30 import javafx.application.Platform;
31 import org.apidesign.bck2brwsr.launcher.impl.JVMBridge;
32 import org.apidesign.vm4brwsr.Bck2Brwsr;
36 * @author Jaroslav Tulach <jtulach@netbeans.org>
38 final class WebViewLauncher extends Bck2BrwsrLauncher {
39 private static final Logger LOG = Logger.getLogger(WebViewLauncher.class.getName());
42 Method m = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
43 m.setAccessible(true);
44 URL l = new URL("file://" + System.getProperty("java.home") + "/lib/jfxrt.jar");
45 LOG.log(Level.INFO, "url : {0}", l);
46 m.invoke(ClassLoader.getSystemClassLoader(), l);
47 } catch (Exception ex) {
48 throw new LinkageError("Can't add jfxrt.jar on the classpath", ex);
52 public WebViewLauncher() {
57 protected Object[] showBrwsr(final URI url) throws IOException {
59 JVMBridge.registerClassLoaders(loaders());
60 Executors.newSingleThreadExecutor().submit(new Runnable() {
63 FXBrwsr.launch(FXBrwsr.class, url.toString());
64 LOG.log(Level.FINE, "Launcher is back!");
67 } catch (IOException ex) {
68 LOG.log(Level.WARNING, null, ex);
73 } catch (Throwable ex) {
74 LOG.log(Level.WARNING, "Can't open WebView", ex);
80 void generateBck2BrwsrJS(StringBuilder sb, Bck2Brwsr.Resources loader) throws IOException {
81 sb.append("(function() {\n"
82 + " var impl = this.bck2brwsr;\n"
83 + " this.bck2brwsr = function() { return impl; };\n"
86 JVMBridge.onBck2BrwsrLoad();
92 public void close() throws IOException {