atlas-engineer / cl-electron

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

`setBrowserView` doesn't work as expected #12

Closed aadcg closed 1 year ago

aadcg commented 1 year ago

Following a simple example from the Electron docs:

CL-USER> (asdf:load-system :cl-electron)
T
CL-USER> (setf electron::*interface*
               (make-instance 'electron:interface
                              :electron-socket-path (uiop:xdg-runtime-dir "electron.socket")
                              :lisp-socket-path (uiop:xdg-runtime-dir "lisp.socket")))
CL-USER> (electron:launch)
CL-USER> (defvar view (make-instance 'electron:browser-view))
CL-USER> (defvar win (make-instance 'electron:browser-window))
CL-USER> (electron::add-browser-view win view)
"ReferenceError: ID663 is not defined"
NIL

Using either setBrowserView or addBrowserView results in the same error.

aadcg commented 1 year ago

I'm a bit confused about this. @jmercouris, any idea?

jmercouris commented 1 year ago

Let me take a look and see what is happening.

jmercouris commented 1 year ago

So what that error means is that somehow your object is not defined, perhaps it is getting garbage collected or something. The function produces logical code "ID344.addBrowserView(ID343)"

jmercouris commented 1 year ago

So if we look here, we shall see:

ELECTRON> (remote-symbol view)
"ID343"
ELECTRON> (remote-symbol win)
"ID344"
ELECTRON> (format nil "~a.addBrowserView(~a)"
           (remote-symbol win)
           (remote-symbol view))
"ID344.addBrowserView(ID343)"
ELECTRON> (add-browser-view win view)
"ReferenceError: ID343 is not defined"
NIL
ELECTRON> (get-bounds win)
"[object Object]"
NIL
ELECTRON> (focus win)
"undefined"
NIL

clearly our window is functional, but our view is not!

jmercouris commented 1 year ago

Will investigate view creation.

jmercouris commented 1 year ago

Aha!

(send-message win "new BrowserView()")
"ReferenceError: BrowserView is not defined"
NIL
jmercouris commented 1 year ago

Fixed with: e8ba297

please let me know if you have any more problems!

aadcg commented 1 year ago

Thanks!

aadcg commented 1 year ago

It's working well. On the left, a single Electron window with 2 views.

2023_07_21_10:52:57-nyxt

jmercouris commented 1 year ago

Nice!!!! Looks so cool!