atlas-engineer / cl-electron

Lisp Interface to Electron.
BSD 3-Clause "New" or "Revised" License
18 stars 2 forks source link

Synchronous javascript #29

Closed jmercouris closed 8 months ago

jmercouris commented 8 months ago

Rebased onto master.

jmercouris commented 8 months ago

I have changed my mind. I think this can belong in the core library. It is quite useful, doesn't need to be relegated just to the tests.

jmercouris commented 8 months ago

Should the user wish to implement their own way to create synchronous JavaScript, the callbacks are still available for them to use.

jmercouris commented 8 months ago

Synchronous JavaScript execution function will now signal an error whenever there is an error. Other JavaScript executions will function the same, and will simply return "ERROR" to the callback.

IF there was more intelligent handling of the error we could do, I would implement it. Unfortunately there is not due to limitations in Electron.

As I've detailed in my commit, the following two issues reference the problem:

https://github.com/electron/electron/pull/18635 https://github.com/electron/electron/issues/9102

Regardless, the latest set of changes means that execute-javascript-synchronous will not block on failure!

jmercouris commented 8 months ago

Overall, this addition is needed and it belongs to the library.

I have noticed an issue (see below) and I'm not sure how to fix.

> (electron::send-message-interface electron:*interface* "bogus")
"ReferenceError: bogus is not defined"
NIL
> (execute-javascript-synchronous (web-contents win) "bogus")
=> never returns

These are two very different things. One is running synchronous JavaScript within Electron (nodeJS) and one within the renderer.

aadcg commented 8 months ago

Regardless, the latest set of changes means that execute-javascript-synchronous will not block on failure!

This is not correct. I've made minor changes to your changes, namely replacing error by cerror. Nonetheless, when the error is raised and it is ignored in the debugger, it is still a blocking action. To reproduce it, replace ""1 + 1" with "bogus" at demo-views.lisp.

aadcg commented 8 months ago

I've merged the subset of this PR that doesn't deal with errors. 14c6d2a and bbfaacb.