juancarlospaco / webgui

Web Technologies based Crossplatform GUI Framework with Dark theme
https://juancarlospaco.github.io/webgui
MIT License
140 stars 8 forks source link

bindProcs issue: CONSOLE JS ERROR ReferenceError: Can't find variable: api #20

Open yaroslav-gwit opened 1 year ago

yaroslav-gwit commented 1 year ago

Hello again. Could you please help me out with this error message? It shows up in the Nim console:

index.html#loaded:53:4: CONSOLE JS ERROR ReferenceError: Can't find variable: api

Code snippets I used: app.nim

import webgui
import os
import strutils
import osproc

let app = newWebView(currentHtmlPath(), "Window Title", 650, 610)

app.bindProcs("api"):
  proc callback() = echo execCmd("echo 'Nim is awesome'")

app.run()
app.exit()

index.html button

<button onclick="api.callback()" type="button" class="btn btn-warning m-1" style="min-width: 170px;">Remind me later</button>
juancarlospaco commented 1 year ago

OS ?, Nim version ?

Please run the code, open the inspector, and in JavaScript run window.external and send screenshot, if possible showing the autocomplete, I need to know if you have window.external.* defined in JS in the window.

yaroslav-gwit commented 1 year ago

Version: Nim Compiler Version 1.6.8 [Linux: amd64] OS: PopOS 22.04

window.external is undefined:

> window.external
< undefined
juancarlospaco commented 1 year ago

So looks like it is in fact broken, but it is not my code, it seems something upstream has broken compatibilities, that sux.

danielRi commented 1 month ago

Hi @juancarlospaco , I have the same problem

webgui [(version: 0.9.0, checksum: d5f8f29259032cbebc5b1bf48548facf5b3534a7)] macOs 14.5 Nim Compiler Version 2.0.8 [MacOSX: amd64]

main.nim

import webgui
let app = newWebView "/path/to/index.html"

app.bindProcs("api"):
  proc callback() = echo "hello"

app.run()
app.exit()

index.html

<button onclick="api.callback()"> Run JavaScript </button>
Bildschirmfoto 2024-09-11 um 09 07 30

I would really love to use the package and build something. Is there anything I can do?