JuliaGizmos / Blink.jl

Web-based GUIs for Julia
Other
360 stars 75 forks source link

Loading blink.js on loadURL #320

Open bypie5 opened 8 months ago

bypie5 commented 8 months ago

Addresses an issue brought up here https://github.com/JuliaGizmos/Blink.jl/issues/150 and here https://github.com/JuliaGizmos/Blink.jl/issues/303. To summarize, those issues both mention that Blink was not defined when using loadurl.

This PR addresses the issue by loading blink.js and webio.bundle.js whenever content is loaded using a custom URL. This was achieved by passing the URL of the websocket server to createWindow in main.js. This allowed the required JS files to be loaded whenever the Electron BrowserWindow does a navigation (i.e. when Julia calls loadurl or creates a window with :url defined).

Also, this PR fixes a warning that would fire every time the WebSocket would reconnect or whenever blink.js was reloaded. The warning was being fired from here:

// server.jl
function ws_handler(ws)
  id = try parse(Int, split(ws.request.target, "/", keepempty=false)[end]) catch e @goto fail end
  haskey(pool, id) || @goto fail
  p = pool[id].value
  active(p) && @goto fail

  p.sock = ws
  @async @errs get(handlers(p), "init", identity)(p)
  try
    put!(p.cb, true) # HERE (Warning: ErrorException("internal consistency error detected for Future"))
  catch e
    @warn e
  end

Finally, I saw this #TODO in src/AtomShell/window.jl that might be relevant to these changes:

Screenshot 2024-01-28 at 11 42 21 PM

Is there any way I can address that #TODO in this PR?