Skip to content

Commit e7a9ff3

Browse files
committed
Fix WebTerminal to use a HttpServer rather than readng from jar.
DomTerm is now partual module-compatible, which doesn't seem to be comaptible with reading JavaScript from a jar:url scheme.
1 parent b61e9ef commit e7a9ff3

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

jfx-term.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717
<script type='text/javascript' src='hlib/wcwidth.js'> </script>
1818
<script type='text/javascript' src='hlib/browserkeymap.js'> </script>
1919
<script type='module' src='hlib/commands.js'> </script>
20-
<script type='text/javascript' src='hlib/domterm-client.js'> </script>
2120
<script type='text/javascript'>
2221
var termElement;
2322
var termInstance;
24-
function makeDomTerm() {
25-
termElement = document.getElementById("term1");
26-
var term = new DomTerm("term1");
23+
24+
function makeDomTerm() {
25+
let name = "kterm1";
26+
let term;
27+
termElement = DomTerm.makeElement(name, document.body);
28+
termInstance = new window.DTerminal(name);
29+
term = termInstance;
2730
term.processInputCharacters =
2831
function(str) { term.java.processInputCharacters(str); };
2932
term.reportEvent =
@@ -38,7 +41,6 @@
3841
term.log =
3942
function(str) {
4043
if (term && term.java) term.java.log(str); }
41-
termInstance = term;
4244
return term;
4345
}
4446
function initDomTerm() {
@@ -47,5 +49,5 @@
4749
}
4850
</script>
4951
</head>
50-
<body><div class="domterm" id="term1"></div></body>
52+
<body></body>
5153
</html>

org/domterm/javafx/WebTerminal.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import javafx.scene.layout.*;
4242
import org.w3c.dom.events.EventTarget;
4343
import netscape.javascript.JSObject;
44+
import java.io.IOException;
45+
import java.net.UnknownHostException;
4446
import javafx.application.Platform;
4547
import javafx.scene.control.Control;
4648
import javafx.scene.input.Clipboard;
@@ -64,6 +66,8 @@ public class WebTerminal extends VBox // FIXME should extend Control
6466
{
6567
public Backend backend;
6668
public void log(String str) { WTDebug.println(str); }
69+
70+
static DomHttpServer httpServer;
6771

6872
WebView webView;
6973
protected WebView getWebView() { return webView; }
@@ -172,6 +176,13 @@ public void setBackend(Backend backend) {
172176
}
173177

174178
public WebTerminal(final Backend backend) {
179+
if (httpServer == null) {
180+
try {
181+
startServer(0);
182+
} catch (Exception ex) {
183+
ex.printStackTrace();
184+
}
185+
}
175186
setBackend(backend);
176187
webView = new WebView();
177188
webEngine = webView.getEngine();
@@ -213,10 +224,7 @@ public void changed(ObservableValue<? extends State> ov, State t, State newValue
213224
*/
214225
protected String pageUrl() {
215226
String rname = "jfx-term.html";
216-
java.net.URL rurl = Backend.class.getClassLoader().getResource(rname);
217-
if (rurl == null)
218-
throw new RuntimeException("no initial web page "+rname);
219-
return rurl.toString();
227+
return "http://localhost:"+httpServer.getPort()+"/domterm/"+rname;
220228
}
221229

222230
/** Load the start page. Do not call directly.
@@ -266,4 +274,11 @@ public void run() {
266274

267275

268276
}
277+
278+
public static void startServer(int port)
279+
throws IOException, UnknownHostException {
280+
DomHttpServer s = new DomHttpServer(port, new String[0]);
281+
s.start();
282+
httpServer = s;
283+
}
269284
}

0 commit comments

Comments
 (0)