Skip to content

Commit bc6d423

Browse files
committed
update to WebUI 2.1.1
1 parent 61f72b5 commit bc6d423

File tree

3 files changed

+49
-72
lines changed

3 files changed

+49
-72
lines changed

webui.nim

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Nim wrapper for [WebUI](https://github.com/alifcommunity/webui)
33
44
:Author: Jasmine
5-
:WebUI Version: 2.1.0
5+
:WebUI Version: 2.1.1
66
77
See: https://neroist.github.io/webui-docs/
88
]###
@@ -59,13 +59,22 @@ type
5959
RuntimeDeno
6060
RuntimeNodeJs
6161

62-
# forward declarations, needed for `bind` and `bindAll`
62+
WebUIEvent* = enum
63+
EventConnected = 1
64+
EventMultiConnection
65+
EventUnwantedConnection
66+
EventDisconnected
67+
EventMouseClick
68+
EventNavigation
69+
EventCallback
70+
71+
# forward declarations, needed for `bind`
6372
proc getNumber*(win: Window): int
6473

6574
# vars
6675
var cbs: array[bindings.WEBUI_MAX_ARRAY, array[bindings.WEBUI_MAX_ARRAY, proc (e: Event)]] ## \
6776
## array of binded callbacks.
68-
## Needed for `bind` and `bindAll`
77+
## Needed for `bind`
6978

7079
proc wait*() =
7180
## Run application run until the user closes all
@@ -309,9 +318,6 @@ proc serverRoot*(winCore: WindowCore): bool =
309318
proc serverPort*(winCore: WindowCore): int =
310319
int winCore.impl.serverPort
311320

312-
proc bindAll*(winCore: WindowCore): bool =
313-
bool winCore.impl.isBindAll
314-
315321
proc url*(winCore: WindowCore): string =
316322
$ winCore.impl.url
317323

@@ -352,6 +358,9 @@ proc runtime*(winCore: WindowCore): Runtime =
352358
proc detectProcessClose*(winCore: WindowCore): bool =
353359
winCore.impl.detectProcessClose
354360

361+
proc hasEvents*(winCore: WindowCore): bool =
362+
bool winCore.impl.hasEvents
363+
355364
# -------- Window --------
356365

357366
proc newWindow*(): Window =
@@ -483,48 +492,6 @@ proc `bind`*(win: Window; element: string; `func`: proc (e: Event): bool) =
483492
e.returnBool(res)
484493
)
485494

486-
proc bindAll*(win: Window; `func`: proc (e: Event)) =
487-
## Bind all elements
488-
489-
bindings.bindAll(win.impl, bindHandler)
490-
let wid = win.getNumber()
491-
492-
# bindInterface was going to return zero anyway
493-
#
494-
# C source of `webui_bind_interface`:
495-
# ...
496-
# if(_webui_is_empty(element)) {
497-
# webui_bind_all(win, webui_bind_interface_all_handler);
498-
# webui.cb_interface_all[0] = func;
499-
# return 0;
500-
# }
501-
# ...
502-
503-
cbs[wid][0] = `func`
504-
505-
proc bindAll*(win: Window; `func`: proc (e: Event): string) =
506-
win.bindAll(
507-
proc (e: Event) =
508-
let res = `func`(e)
509-
e.returnString(res)
510-
)
511-
512-
proc bindAll*(win: Window; `func`: proc (e: Event): int) =
513-
win.bindAll(
514-
proc (e: Event) =
515-
let res = `func`(e)
516-
e.returnInt(res)
517-
)
518-
519-
proc bindAll*(win: Window; `func`: proc (e: Event): bool) =
520-
## Bind all elements to `func` automatically pass return value of `func` to Javascript
521-
522-
win.bindAll(
523-
proc (e: Event) =
524-
let res = `func`(e)
525-
e.returnBool(res)
526-
)
527-
528495
proc open*(win: Window; url: string | Uri; browser: Browser = BrowserAny): bool {.discardable.} =
529496
bindings.open(win.impl, cstring $url, cuint ord(browser))
530497

@@ -544,8 +511,8 @@ proc receive*(win: Window; packet: string; len: int) =
544511
proc send*(win: Window; packet: string; packetsSize: int) =
545512
bindings.windowSend(win.impl, cstring packet, csize_t packetsSize)
546513

547-
proc event*(win: Window; elementId, element: string; data: pointer; dataLen: int) =
548-
bindings.windowEvent(win.impl, cstring elementId, cstring element, data, cuint dataLen)
514+
proc event*(win: Window; elementId, element: string; data: pointer; dataLen: int, eventType: int | WebUIEvent) =
515+
bindings.windowEvent(win.impl, cstring elementId, cstring element, data, cuint dataLen, cint ord eventType)
549516

550517
proc getNumber*(win: Window): int =
551518
int bindings.windowGetNumber(win.impl)
@@ -612,6 +579,9 @@ proc waitProcess*(win: Window; status: bool) =
612579
proc generateJsBridge*(win: Window): string =
613580
$ bindings.generateJsBridge(win.impl)
614581

582+
proc generateInternalId*(win: Window, element: string) =
583+
bindings.generateInternalId(win.impl, cstring element)
584+
615585
export
616586
bindings.webui,
617587
bindings.WEBUI_VERSION

webui/bindings.nim

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,26 @@ else:
8484
{.deadCodeElim: on.}
8585

8686
const
87-
WEBUI_VERSION* = "2.1.0" ## Version
88-
WEBUI_HEADER_SIGNATURE* = 0xFF ## All packets should start with this 8bit
89-
WEBUI_HEADER_JS* = 0xFE ## Javascript result in frontend
90-
WEBUI_HEADER_CLICK* = 0xFD ## Click event
91-
WEBUI_HEADER_SWITCH* = 0xFC ## Frontend refresh
92-
WEBUI_HEADER_CLOSE* = 0xFB ## Close window
93-
WEBUI_HEADER_CALL_FUNC* = 0xFA ## Call a backend function
94-
WEBUI_MAX_ARRAY* = (1024) ## Max num of threads, servers, windows, pointers...
95-
WEBUI_MIN_PORT* = (10000) ## Minimum socket port
96-
WEBUI_MAX_PORT* = (65500) ## Should be less than 65535
97-
WEBUI_MAX_BUF* = (1024000) ## 1024 Kb max dynamic memory allocation
98-
WEBUI_DEFAULT_PATH* = "." ## Default root path
99-
WEBUI_DEF_TIMEOUT* = (8) ## Default startup timeout in seconds
87+
WEBUI_VERSION* = "2.1.1" ## Version
88+
WEBUI_HEADER_SIGNATURE* = 0xFF ## All packets should start with this 8bit
89+
WEBUI_HEADER_JS* = 0xFE ## Javascript result in frontend
90+
WEBUI_HEADER_CLICK* = 0xFD ## Click event
91+
WEBUI_HEADER_SWITCH* = 0xFC ## Frontend refresh
92+
WEBUI_HEADER_CLOSE* = 0xFB ## Close window
93+
WEBUI_HEADER_CALL_FUNC* = 0xFA ## Call a backend function
94+
WEBUI_MAX_ARRAY* = (1024) ## Max num of threads, servers, windows, pointers...
95+
WEBUI_MIN_PORT* = (10000) ## Minimum socket port
96+
WEBUI_MAX_PORT* = (65500) ## Should be less than 65535
97+
WEBUI_MAX_BUF* = (1024000) ## 1024 Kb max dynamic memory allocation
98+
WEBUI_DEFAULT_PATH* = "." ## Default root path
99+
WEBUI_DEF_TIMEOUT* = (8) ## Default startup timeout in seconds
100+
WEBUI_EVENT_CONNECTED* = (1) ## Window connected
101+
WEBUI_EVENT_MULTI_CONNECTION* = (2) ## Multi clients connected
102+
WEBUI_EVENT_UNWANTED_CONNECTION* = (3) ## Unwanted client connected
103+
WEBUI_EVENT_DISCONNECTED* = (4) ## Window disconnected
104+
WEBUI_EVENT_MOUSE_CLICK* = (5) ## Mouse Click
105+
WEBUI_EVENT_NAVIGATION* = (6) ## The window URL changed
106+
WEBUI_EVENT_CALLBACK* = (7) ## Function call
100107

101108
# -- Types -------------------------
102109

@@ -113,9 +120,7 @@ type
113120
multiAccess*: bool
114121
serverRoot*: bool
115122
serverPort*: cuint
116-
isBindAll*: bool
117123
url*: cstring
118-
cbAll*: array[1, proc (e: Event)]
119124
html*: cstring
120125
htmlCpy*: cstring
121126
icon*: cstring
@@ -126,6 +131,7 @@ type
126131
connections*: cuint
127132
runtime*: cuint
128133
detectProcessClose*: bool
134+
hasEvents*: bool
129135
#when defined(windows):
130136
# serverThread: Handle
131137
#else:
@@ -142,6 +148,7 @@ type
142148
window*: ptr Window
143149
data*: pointer
144150
response*: pointer
151+
`type`*: cint
145152

146153
JavascriptResult* {.bycopy.} = object
147154
error*: bool
@@ -158,6 +165,8 @@ type
158165
internalId*: cstring
159166
elementName*: cstring
160167
data*: pointer
168+
dataLen*: cuint
169+
eventType*: cint
161170

162171
CmdAsync* {.bycopy.} = object
163172
win*: ptr Window
@@ -214,9 +223,6 @@ type
214223
cb_interface*: array[WEBUI_MAX_ARRAY, proc (elementId: cuint;
215224
windowId: cuint; elementName: cstring; window: ptr Window;
216225
data: cstring; response: cstringArray) {.cdecl.}]
217-
cb_interface_all*: array[1, proc(elementId: cuint; windowId: cuint;
218-
elementName: cstring; window: ptr Window; data: cstring;
219-
response: cstringArray) {.cdecl.}]
220226
executablePath*: cstring
221227
ptrList*: array[WEBUI_MAX_ARRAY, pointer]
222228
ptrPosition*: cuint
@@ -248,8 +254,6 @@ proc script*(win: ptr Window; script: ptr Script) {.cdecl,
248254
proc `bind`*(win: ptr Window; element: cstring; `func`: proc (
249255
e: ptr Event) {.cdecl.}): cuint {.
250256
cdecl, importc: "webui_bind", webui.}
251-
proc bindAll*(win: ptr Window; `func`: proc (e: ptr Event) {.cdecl.}) {.cdecl,
252-
importc: "webui_bind_all", webui.}
253257
proc open*(win: ptr Window; url: cstring; browser: cuint): bool {.cdecl,
254258
importc: "webui_open", webui.}
255259
proc scriptCleanup*(script: ptr Script) {.cdecl,
@@ -309,7 +313,7 @@ proc windowReceive*(win: ptr Window; packet: cstring; len: csize_t) {.cdecl,
309313
proc windowSend*(win: ptr Window; packet: cstring;
310314
packetsSize: csize_t) {.cdecl, importc: "_webui_window_send", webui.}
311315
proc windowEvent*(win: ptr Window; elementId: cstring; element: cstring;
312-
data: pointer; dataLen: cuint) {.cdecl,
316+
data: pointer; dataLen: cuint, eventType: cint) {.cdecl,
313317
importc: "_webui_window_event", webui.}
314318
proc windowGetNumber*(win: ptr Window): cuint {.cdecl,
315319
importc: "_webui_window_get_number", webui.}
@@ -388,3 +392,6 @@ proc freeAllMem*() {.cdecl, importc: "_webui_free_all_mem", webui.}
388392

389393
proc showWindow*(win: ptr Window; html: cstring; browser: cuint): bool {.cdecl,
390394
importc: "_webui_show_window", webui.}
395+
proc generateInternalId*(win: ptr Window; element: cstring): cstring {.cdecl,
396+
importc: "_webui_generate_internal_id", webui.}
397+

webui/webui

Submodule webui updated from cf7b7fb to 9a38611

0 commit comments

Comments
 (0)