webui-dev / nim-webui

Use any web browser as GUI, with Nim in the backend and HTML5 in the frontend.
https://webui.me
MIT License
130 stars 9 forks source link

WebUI v2.2.0 #10

Closed hassandraga closed 1 year ago

hassandraga commented 1 year ago

WebUI v2.2.0 is ready for release.

Big changes:

  1. Now, webui.h it's become more straightforward and smaller and optimized for wrapper creation
  2. webui_show() will replace webui_open() and webui_new_server()
  3. webui_window_t struct becomes a simple void*
  4. To solves the complexity of memory leaks when executing JS, now, the wrapper creates a local buffer and passes it to webui_script()
  5. All core internal functions are removed from webui.h

To create the new Nim wrapper, run c2nim webui.h. And remove all other functions from the old version v2.1.1. After that, we will start creating more big software in Nim as an example (Text editor, Media Player, Database viewer...), which will be very exciting to explore and learn new things!.

If you have any questions, please don't hesitate to ask me here. Thank you for maintaining the WebUI Nim wrapper. I appreciate it 👍

hassandraga commented 1 year ago

A quick clean c2nim webui.h

const
  WEBUI_VERSION* = "2.2.0"

##  -- Enums ---------------------------
type
  webui_browsers* = enum
    AnyBrowser = 0,           ##  0. Default recommended web browser
    Chrome,                   ##  1. Google Chrome
    Firefox,                  ##  2. Mozilla Firefox
    Edge,                     ##  3. Microsoft Edge
    Safari,                   ##  4. Apple Safari
    Chromium,                 ##  5. The Chromium Project
    Opera,                    ##  6. Opera Browser
    Brave,                    ##  7. The Brave Browser
    Vivaldi,                  ##  8. The Vivaldi Browser
    Epic,                     ##  9. The Epic Browser
    Yandex                    ##  10. The Yandex Browser

type
  webui_runtimes* = enum
    None = 0,                 ##  0. Prevent WebUI from using any runtime for .js and .ts files
    Deno,                     ##  1. Use Deno runtime for .js and .ts files
    NodeJS                    ##  2. Use Nodejs runtime for .js files

type
  webui_events* = enum
    WEBUI_EVENT_DISCONNECTED = 0, ##  0. Window disconnection event
    WEBUI_EVENT_CONNECTED,    ##  1. Window connection event
    WEBUI_EVENT_MULTI_CONNECTION, ##  2. New window connection event
    WEBUI_EVENT_UNWANTED_CONNECTION, ##  3. New unwanted window connection event
    WEBUI_EVENT_MOUSE_CLICK,  ##  4. Mouse click event
    WEBUI_EVENT_NAVIGATION,   ##  5. Window navigation event
    WEBUI_EVENT_CALLBACK      ##  6. Function call event

##  -- Structs -------------------------
type
  webui_event_t* {.bycopy.} = object
    window*: pointer
    ##  Pointer to the window object
    `type`*: cuint
    ##  Event type
    element*: cstring
    ##  HTML element ID
    data*: cstring
    ##  JavaScript data
    response*: cstring
    ##  Callback response

##  -- Definitions ---------------------
##  Create a new webui window object.
proc webui_new_window*(): pointer

##  Bind a specific html element click event with a function. Empty element means all events.
proc webui_bind*(window: pointer; element: cstring;
                `func`: proc (e: ptr webui_event_t)): cuint

##  Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
proc webui_show*(window: pointer; content: cstring): bool

##  Same as webui_show(). But with a specific web browser.
proc webui_show_browser*(window: pointer; content: cstring; browser: cuint): bool

##  Wait until all opened windows get closed.
proc webui_wait*()

##  Close a specific window.
proc webui_close*(window: pointer)

##  Close all opened windows. webui_wait() will break.
proc webui_exit*()

##  -- Other ---------------------------
proc webui_is_shown*(window: pointer): bool
proc webui_set_timeout*(second: cuint)
proc webui_set_icon*(window: pointer; icon: cstring; `type`: cstring)
proc webui_set_multi_access*(window: pointer; status: bool)

##  -- JavaScript ----------------------
##  Quickly run a JavaScript (no response waiting).
proc webui_run*(window: pointer; script: cstring): bool

##  Run a JavaScript, and get the response back (Make sure your local buffer can hold the response).
proc webui_script*(window: pointer; script: cstring; timeout: cuint; buffer: cstring;
                  buffer_length: csize_t): bool

##  Chose between Deno and Nodejs runtime for .js and .ts files.
proc webui_set_runtime*(window: pointer; runtime: cuint)

##  Parse argument as integer.
proc webui_get_int*(e: ptr webui_event_t): clonglong

##  Parse argument as string.
proc webui_get_string*(e: ptr webui_event_t): cstring

##  Parse argument as boolean.
proc webui_get_bool*(e: ptr webui_event_t): bool

##  Return the response to JavaScript as integer.
proc webui_return_int*(e: ptr webui_event_t; n: clonglong)

##  Return the response to JavaScript as string.
proc webui_return_string*(e: ptr webui_event_t; s: cstring)

##  Return the response to JavaScript as boolean.
proc webui_return_bool*(e: ptr webui_event_t; b: bool)

##  -- Interface -----------------------
##  Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, Response)
proc webui_interface_bind*(window: pointer; element: cstring; `func`: proc (
    a1: pointer; a2: cuint; a3: cstring; a4: cstring; a5: cstring)): cuint

##  When using `webui_interface_bind()` you need this function to easily set your callback response.
proc webui_interface_set_response*(`ptr`: cstring; response: cstring)

##  Check if the app still running or not. This replace webui_wait().
proc webui_interface_is_app_running*(): bool

##  Get window unique ID
proc webui_interface_get_window_id*(window: pointer): cuint
CardealRusso commented 1 year ago

@neroist please update

AlbertShown commented 1 year ago

Perhaps, you can please @neroist provide a deadline?

neroist commented 1 year ago

I have some free time, I should be able to get it done today.

hassandraga commented 1 year ago

WebUI v2.3.0 is pushed to the main branch. https://github.com/alifcommunity/webui/commit/ca7b4f50ed8eb52c2f92bbd2b066e5498e329337

The only difference from v2.2.0 on the side of the wrappers is:

neroist commented 1 year ago

Okay that was a really long day but its done 👍🏾 After making a new release I'll close this issue.

Also, thanks for the notice @hassandraga!