This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-05
Channels
- # announcements (12)
- # babashka (29)
- # bangalore-clj (3)
- # beginners (153)
- # calva (2)
- # chlorine-clover (46)
- # cider (11)
- # clj-kondo (21)
- # cljfx (20)
- # cljs-dev (3)
- # clojure (393)
- # clojure-australia (2)
- # clojure-europe (15)
- # clojure-spec (40)
- # clojure-uk (1)
- # clojurescript (3)
- # community-development (1)
- # conjure (2)
- # cursive (1)
- # data-oriented-programming (1)
- # datomic (7)
- # defnpodcast (2)
- # docs (2)
- # figwheel-main (5)
- # fulcro (52)
- # graalvm (2)
- # inf-clojure (21)
- # malli (10)
- # meander (6)
- # mid-cities-meetup (13)
- # nrepl (1)
- # off-topic (24)
- # other-languages (1)
- # pathom (3)
- # polylith (18)
- # re-frame (6)
- # reitit (11)
- # ring-swagger (2)
- # shadow-cljs (56)
- # specter (1)
- # xtdb (7)
Hi, I'm trying to use web-views and wondering how can I send an event from javascript to cljfx. any idea ?
what I ended up doing was using WebSockets via Sente (https://github.com/ptaoussanis/sente) to create an event bus, this is a little bit involved but ultimately has a nice property: you can transparently dispatch events between the webview and javafx bi-directionally using the same re-frame esque conventions (if you also plan on using ClojureScript in the Webview)
I would suggest having a look at this: https://openjfx.io/javadoc/14/javafx.web/javafx/scene/web/WebEngine.html
here are some examples of built-in custom props that access WebEngine: https://github.com/cljfx/cljfx/blob/master/src/cljfx/ext/web_view.clj
thank you a lot, I was hoping for something builtin to cljfx, but it seems doable. So if I understand well, I will have to create my own lifecycle, which will setup the communication in its create method (by using WebEngine)?
you will create extension lifecycle that wraps web-view lifecycle:
(def ext-with-my-stuff
(fx/make-ext-with-props
{:my-custom-prop-that-establishes-communication ...}))
{:fx/type ext-with-my-stuff
:props {:my-custom-prop-that-establishes-communication ...}
:desc {:fx/type :web-view
...}}
I've got a java question (I'm not so much familiar with clj/java interop). I'm trying to make this snippet work in the context of my cljfx app: (its from the https://openjfx.io/javadoc/14/javafx.web/javafx/scene/web/WebEngine.html you've linked)
EventListener listener = new EventListener() {
public void handleEvent(Event ev) {
Platform.exit();
}
};
Document doc = webEngine.getDocument();
Element el = doc.getElementById("exit-app");
((EventTarget) el).addEventListener("click", listener, false);
To be honest I don't even understand the first statement... And I don't know how can I translate it to clojure... sorry for the noobyness :)first statement — you mean this?
EventListener listener = new EventListener() {
public void handleEvent(Event ev) {
Platform.exit();
}
}
it’s like that in clojure:
(reify EventListener
(handleEvent [this ev]
(Platform/exit)))
@U0508P8EK seems appealing to be able to use clojurescript in a webview, i've tryed without success. do you have some code to show ?
@U47G49KHQ, ho! I'm surprised that it is so simple! thank you (looking at the javadoc I taught that I would need a proxy)
@U47G49KHQ, when I try to evaluate your expression I get this error
Syntax error (IllegalArgumentException) compiling reify* at (codemirror.clj:75:1).
Can't define method not in interfaces: handleEvent
Maybe EventListener is not what I taught it was. I'm using java.util.EventListener
Am I missing something ?I found it like that: WebEngine’s document property is defined here: https://openjfx.io/javadoc/14/javafx.web/javafx/scene/web/WebEngine.html#documentProperty()
it returns a value of type “Document”, and it’s has a link leading here: https://docs.oracle.com/en/java/javase/12/docs/api/java.xml/org/w3c/dom/Document.html?is-external=true
So this is something from the JDK, and at that site I searched for addEventListener
and found this: https://docs.oracle.com/en/java/javase/12/docs/api/java.xml/org/w3c/dom/events/EventTarget.html#addEventListener(java.lang.String,org.w3c.dom.events.EventListener,boolean)