-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebui.odin
1362 lines (1231 loc) · 39.6 KB
/
webui.odin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package webui
import "base:intrinsics"
import "base:runtime"
import "core:c"
import "core:encoding/json"
import "core:fmt"
import "core:strings"
import "core:time"
when ODIN_OS == .Windows {
when ODIN_DEBUG {
foreign import webui {"webui/debug/webui-2-static.lib", "system:Ws2_32.lib", "system:Ole32.lib", "system:Advapi32.lib", "system:User32.lib", "system:Shell32.lib"}} else {
foreign import webui {"webui/webui-2-static.lib", "system:Ws2_32.lib", "system:Ole32.lib", "system:Advapi32.lib", "system:User32.lib", "system:Shell32.lib"}
}
} else when ODIN_OS == .Darwin {
when ODIN_DEBUG {
@(extra_linker_flags = "-framework Cocoa -framework WebKit")
foreign import webui "webui/debug/libwebui-2-static.a"} else {
@(extra_linker_flags = "-framework Cocoa -framework WebKit")
foreign import webui "webui/libwebui-2-static.a"}
} else {
when ODIN_DEBUG {
foreign import webui "webui/debug/libwebui-2-static.a"} else {
foreign import webui "webui/libwebui-2-static.a"}
}
// == WebUI C Enums ===========================================================
// C-version: webui_browser
Browser :: enum {
NoBrowser, // 0. No web browser
AnyBrowser, // 1. Default recommended web browser
Chrome, // 2. Google Chrome
Firefox, // 3. Mozilla Firefox
Edge, // 4. Microsoft Edge
Safari, // 5. Apple Safari
Chromium, // 6. The Chromium Project
Opera, // 7. Opera Browser
Brave, // 8. The Brave Browser
Vivaldi, // 9. The Vivaldi Browser
Epic, // 10. The Epic Browser
Yandex, // 11. The Yandex Browser
ChromiumBased, // 12. Any Chromium based browser
Webview, // 13. WebView (Non-web-browser)
}
// C-version: webui_runtime
WebuiJSRuntime :: enum {
None, // 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
Bun, // 3. Use Bun runtime for .js and .ts files
}
// C-version: webui_event
EventType :: enum {
Disconnected, // 0. Window disconnection event
Connected, // 1. Window connection event
MouseClick, // 2. Mouse click event
Navigation, // 3. Window navigation event
Callback, // 4. Function call event
}
// C-version: webui_config
Config :: enum {
// Control if `webui_show()`, `webui_show_browser()` and
// `webui_show_wv()` should wait for the window to connect
// before returns or not.
//
// Default: True
show_wait_connection,
// Control if WebUI should block and process the UI events
// one a time in a single thread `True`, or process every
// event in a new non-blocking thread `False`. This updates
// all windows. You can use `webui_set_event_blocking()` for
// a specific single window update.
//
// Default: False
ui_event_blocking,
// Automatically refresh the window UI when any file in the
// root folder gets changed.
//
// Default: False
folder_monitor,
// Allow multiple clients to connect to the same window,
// This is helpful for web apps (non-desktop software),
// Please see the documentation for more details.
//
// Default: False
multi_client,
// Allow or prevent WebUI from adding `webui_auth` cookies.
// WebUI uses these cookies to identify clients and block
// unauthorized access to the window content using a URL.
// Please keep this option to `True` if you want only a single
// client to access the window content.
//
// Default: True
use_cookies,
// If the backend uses asynchronous operations, set this
// option to `True`. This will make webui wait until the
// backend sets a response using `webui_return_x()`.
asynchronous_response
}
// == WebUI C Structs =========================================================
// C-version: webui_event_t
Event :: struct {
window: c.size_t,
event_type: EventType,
element: cstring,
event_number: c.size_t,
bind_id: c.size_t,
client_id: c.size_t,
connection_id: c.size_t,
cookies: cstring,
}
// == WebUI C functions =======================================================
// == Definitions =============================================================
foreign webui {
/**
* @brief Create a new WebUI window object.
*
* @return Returns the window number.
*
* @example myWindow: c.size_t = ui.new_window()
*/
@(link_name="webui_new_window")
new_window :: proc() -> c.size_t ---
/**
* @brief Create a new webui window object using a specified window number.
*
* @param window_number The window number (should be > 0, and < WEBUI_MAX_IDS)
*
* @return Returns the same window number if success.
*
* @example myWindow: c.size_t = ui.new_window_id(123)
*/
@(link_name="webui_new_window_id")
new_window_id :: proc(window_number: c.size_t ) -> c.size_t ---
/**
* @brief Get a free window number that can be used with
* `webui_new_window_id()`.
*
* @return Returns the first available free window number. Starting from 1.
*
* @example myWindowNumber: c.size_t = ui.get_new_window_id()
*/
@(link_name="webui_get_new_window_id")
get_new_window_id :: proc() -> c.size_t ---
/**
* @brief Bind an HTML element and a JavaScript object with a backend function. Empty
* element name means all events.
*
* @param window The window number
* @param element The HTML element / JavaScript object
* @param func The callback function
*
* @return Returns a unique bind ID.
*
* @example ui.bind(myWindow, "myFunction", myFunction)
*/
@(link_name="webui_bind")
bind :: proc(window: c.size_t, element: cstring, func: proc(e: ^Event)) -> c.size_t ---
/**
* @brief Get the recommended web browser ID to use. If you
* are already using one, this function will return the same ID.
*
* @param window The window number
*
* @return Returns a web browser ID.
*
* @example browserID: c.size_t = ui.get_best_browser(myWindow)
*/
@(link_name="webui_get_best_browser")
get_best_browser :: proc(window: c.size_t) -> c.size_t ---
/**
* @brief Show a window using embedded HTML, or a file. If the window is already
* open, it will be refreshed. This will refresh all windows in multi-client mode.
*
* @param window The window number
* @param content The HTML, URL, Or a local file
*
* @return Returns True if showing the window is successed.
*
* @example ui.show(myWindow, "<html>...</html>") |
* ui.show(myWindow, "index.html") | ui.show(myWindow, "http://...")
*/
@(link_name="webui_show")
webui_show :: proc(window: c.size_t, content: cstring) -> c.bool ---
/**
* @brief Show a window using embedded HTML, or a file. If the window is already
* open, it will be refreshed. Single client.
*
* @param e The event struct
* @param content The HTML, URL, Or a local file
*
* @return Returns True if showing the window is successed.
*
* @example ui.show_client(e, "<html>...</html>") |
* ui.show_client(e, "index.html") | ui.show_client(e, "http://...")
*/
@(link_name="webui_show_client")
show_client :: proc(e: ^Event, content: cstring) -> c.bool ---
/**
* @brief Same as `show()`. But using a specific web browser.
*
* @param window The window number
* @param content The HTML, Or a local file
* @param browser The web browser to be used
*
* @return Returns True if showing the window is successed.
*
* @example ui.show_browser(myWindow, "<html>...</html>", .Chrome) |
* ui.show(myWindow, "index.html", .Firefox)
*/
@(link_name="webui_show_browser")
show_browser :: proc(window: c.size_t, content: cstring, browser: Browser) -> c.bool ---
/**
* @brief Same as `show()`. But start only the web server and return the URL.
* No window will be shown.
*
* @param window The window number
* @param content The HTML, Or a local file
*
* @return Returns the url of this window server.
*
* @example url: cstring = ui.start_server(myWindow, "/full/root/path")
*/
@(link_name="webui_start_server")
start_server:: proc(window: c.size_t, content: cstring) -> cstring ---
/**
* @brief Show a WebView window using embedded HTML, or a file. If the window is already
* open, it will be refreshed. Note: Win32 need `WebView2Loader.dll`.
*
* @param window The window number
* @param content The HTML, URL, Or a local file
*
* @return Returns True if showing the WebView window is successed.
*
* @example ui.show_wv(myWindow, "<html>...</html>") | webui_show_wv(myWindow,
* "index.html") | ui.show_wv(myWindow, "http://...")
*/
@(link_name="webui_show_wv")
show_wv :: proc(window: c.size_t, content: cstring) -> c.bool ---
/**
* @brief Set the window in Kiosk mode (Full screen).
*
* @param window The window number
* @param status True or False
*
* @example ui.set_kiosk(myWindow, true)
*/
@(link_name="webui_set_kisok")
set_kiosk :: proc(window: c.size_t, status: c.bool) ---
/**
* @brief Add a user-defined web browser's CLI parameters.
*
* @param window The window number
* @param params Command line parameters
*
* @example ui.set_custom_parameters(myWindow, "--remote-debugging-port=9222")
*/
@(link_name="webui_set_custom_parameters")
set_custom_parameters :: proc(window: c.size_t, params: cstring) ---
/**
* @brief Set the window with high-contrast support. Useful when you want to
* build a better high-contrast theme with CSS.
*
* @param window The window number
* @param status True or False
*
* @example ui.set_high_contrast(myWindow, true)
*/
@(link_name="webui_set_high_contrast")
set_high_contrast :: proc(window: c.size_t, status: c.bool) ---
/**
* @brief Get OS high contrast preference.
*
* @return Returns True if OS is using high contrast theme
*
* @example hc: bool = ui.is_high_contrast()
*/
@(link_name="webui_is_high_contrast")
is_high_contrast :: proc() -> c.bool ---
/**
* @brief Check if a web browser is installed.
*
* @return Returns True if the specified browser is available
*
* @example status: bool = ui.browser_exist(.Chrome)
*/
@(link_name="webui_browser_exist")
browser_exist :: proc(browser: Browser) -> c.bool ---
/**
* @brief Wait until all opened windows get closed.
*
* @example ui.wait()
*/
@(link_name="webui_wait")
wait :: proc() ---
/**
* @brief Close a specific window only. The window object will still exist.
* All clients.
*
* @param window The window number
*
* @example ui.close(myWindow)
*/
@(link_name="webui_close")
close :: proc(window: c.size_t) ---
/**
* @brief Close a specific client.
*
* @param e The event struct
*
* @example ui.close_client(e)
*/
@(link_name="webui_close_client")
close_client :: proc(e: ^Event) ---
/**
* @brief Close a specific window and free all memory resources.
*
* @param window The window number
*
* @example ui.destroy(myWindow)
*/
@(link_name="webui_destroy")
destroy :: proc(window: c.size_t) ---
/**
* @brief Close all open windows. `webui_wait()` will return (Break).
*
* @example ui.exit()
*/
@(link_name="webui_exit")
exit :: proc() ---
/**
* @brief Set the web-server root folder path for a specific window.
*
* @param window The window number
* @param path The local folder full path
*
* @example ui.set_root_folder(myWindow, "/home/Foo/Bar/")
*/
@(link_name="webui_set_root_folder")
set_root_folder :: proc(window: c.size_t, path: cstring) -> c.bool ---
/**
* @brief Set the web-server root folder path for all windows. Should be used
* before `show()`.
*
* @param path The local folder full path
*
* @example ui.set_default_root_folder("/home/Foo/Bar/")
*/
@(link_name="webui_set_default_root_folder")
set_default_root_folder :: proc(path: cstring) -> c.bool ---
/**
* @brief Set a custom handler to serve files. This custom handler should
* return full HTTP header and body.
* This deactivates any previous handler set with `set_file_handler_window`
*
* @param window The window number
* @param handler The handler function: `handler: proc(filename: cstring,
* length: ^c.int) -> rawptr`
*
* @example ui.set_file_handler(myWindow, myHandlerFunction)
*/
@(link_name="webui_set_file_handler")
set_file_handler :: proc(window: c.size_t, handler: proc(filename: cstring, length: ^c.int) -> rawptr) ---
/**
* @brief Set a custom handler to serve files. This custom handler should
* return full HTTP header and body.
* This deactivates any previous handler set with `set_file_handler`
*
* @param window The window number
* @param handler The handler function: `handler: proc(window: c.size_t, filename: cstring,
* length: ^c.int) -> rawptr`
*
* @example ui.set_file_handler_window(myWindow, myHandlerFunction)
*/
@(link_name="webui_set_file_handler_window")
set_file_handler_window :: proc(window: c.size_t, handler: proc(window: c.size_t, filename: cstring, length: ^c.int) -> rawptr) ---
/**
* @brief Check if the specified window is still running.
*
* @param window The window number
*
* @example ui.is_shown(myWindow)
*/
@(link_name="webui_is_shown")
is_shown :: proc(window: c.size_t) -> c.bool ---
/**
* @brief Set the maximum time in seconds to wait for the window to connect.
* This effect `show()` and `wait()`. Value of `0` means wait forever.
*
* @param second The timeout in seconds
*
* @example ui.set_timeout(30)
*/
@(link_name="webui_set_timeout")
set_timeout :: proc(second: c.size_t) ---
/**
* @brief Set the default embedded HTML favicon.
*
* @param window The window number
* @param icon The icon as string: `<svg>...</svg>`
* @param icon_type The icon type: `image/svg+xml`
*
* @example ui.set_icon(myWindow, "<svg>...</svg>", "image/svg+xml")
*/
@(link_name="webui_set_icon")
set_icon :: proc(window: c.size_t, icon: cstring, icon_type: cstring) ---
/**
* @brief Encode text to Base64. The returned buffer need to be freed.
*
* @param str The string to encode (Should be null terminated)
*
* @return Returns the base64 encoded string
*
* @example base64: cstring = ui.encode("Foo Bar")
*/
@(link_name="webui_encode")
encode :: proc(str: cstring) -> cstring ---
/**
* @brief Decode a Base64 encoded text. The returned buffer need to be freed.
*
* @param str The string to decode (Should be null terminated)
*
* @return Returns the base64 decoded string
*
* @example str: cstring = ui.decode("SGVsbG8=")
*/
@(link_name="webui_decode")
decode :: proc(str: cstring) -> cstring ---
/**
* @brief Safely free a buffer allocated by WebUI using `malloc()`.
*
* @param ptr The buffer to be freed
*
* @example ui.free(myBuffer)
*/
@(link_name="webui_free")
free :: proc(ptr: rawptr) ---
/**
* @brief Safely allocate memory using the WebUI memory management system. It
* can be safely freed using `free()` at any time.
*
* @param size The size of memory in bytes
*
* @example myBuffer := cast(^u8)malloc(1024)
*/
@(link_name="webui_malloc")
malloc :: proc(size: c.size_t) -> rawptr ---
/**
* @brief Safely send raw data to the UI. All clients.
*
* @param window The window number
* @param function The JavaScript function to receive raw data: `function
* myFunc(myData){}`
* @param raw The raw data buffer
* @param size The raw data size in bytes
*
* @example ui.send_raw(myWindow, "myJavaScriptFunc", myBuffer, 64)
*/
@(link_name="webui_send_raw")
send_raw :: proc(window: c.size_t, function: cstring, raw: rawptr, size: c.size_t) ---
/**
* @brief Safely send raw data to the UI. Single client.
*
* @param e The event struct
* @param function The JavaScript function to receive raw data: `function
* myFunc(myData){}`
* @param raw The raw data buffer
* @param size The raw data size in bytes
*
* @example ui.send_raw_client(e, "myJavaScriptFunc", myBuffer, 64)
*/
@(link_name="webui_send_raw_client")
send_raw_client :: proc(e: ^Event, function: cstring, raw: rawptr, size: c.size_t) ---
/**
* @brief Set a window in hidden mode. Should be called before `webui_show()`.
*
* @param window The window number
* @param status The status: True or False
*
* @example ui.set_hide(myWindow, true)
*/
@(link_name="webui_set_hide")
set_hide :: proc(window: c.size_t, status: c.bool) ---
/**
* @brief Set the window size.
*
* @param window The window number
* @param width The window width
* @param height The window height
*
* @example ui.set_size(myWindow, 800, 600)
*/
@(link_name="webui_set_size")
set_size :: proc(window: c.size_t, width: c.uint, height: c.uint) ---
/**
* @brief Set the window minimum size.
*
* @param window The window number
* @param width The window width
* @param height The window height
*
* @example ui.set_minimum_size(myWindow, 800, 600)
*/
@(link_name="webui_set_minimum_size")
set_minimum_size :: proc(window: c.size_t, width: c.uint, height: c.uint) ---
/**
* @brief Set the window position.
*
* @param window The window number
* @param x The window X
* @param y The window Y
*
* @example ui.set_position(myWindow, 100, 100)
*/
@(link_name="webui_set_position")
set_position :: proc(window: c.size_t, x: c.uint, y: c.uint) ---
/**
* @brief Set the web browser profile to use. An empty `name` and `path` means
* the default user profile. Need to be called before `show()`.
*
* @param window The window number
* @param name The web browser profile name
* @param path The web browser profile full path
*
* @example ui.set_profile(myWindow, "Bar", "/Home/Foo/Bar") |
* ui.set_profile(myWindow, "", "")
*/
@(link_name="webui_set_profile")
set_profile :: proc(window: c.size_t, name: cstring, path: cstring) ---
/**
* @brief Set the web browser proxy server to use. Need to be called before `show()`.
*
* @param window The window number
* @param proxy_server The web browser proxy_server
*
* @example ui.set_proxy(myWindow, "http://127.0.0.1:8888")
*/
@(link_name="webui_set_proxy")
set_proxy :: proc(window: c.size_t, proxy_server: cstring) ---
/**
* @brief Get current URL of a running window.
*
* @param window The window number
*
* @return Returns the full URL string
*
* @example url: cstring = ui.get_url(myWindow)
*/
@(link_name="webui_get_url")
get_url :: proc(window: c.size_t) -> cstring ---
/**
* @brief Open an URL in the native default web browser.
*
* @param url The URL to open
*
* @example ui.open_url("https://webui.me")
*/
@(link_name="webui_open_url")
open_url :: proc(url: cstring) ---
/**
* @brief Allow a specific window address to be accessible from a public network.
*
* @param window The window number
* @param status True or False
*
* @example ui.set_public(myWindow, true)
*/
@(link_name="webui_set_public")
set_public :: proc(window: c.size_t, status: c.bool) ---
/**
* @brief Navigate to a specific URL. All clients.
*
* @param window The window number
* @param url Full HTTP URL
*
* @example ui.navigate(myWindow, "http://domain.com")
*/
@(link_name="webui_navigate")
webui_navigate :: proc(window: c.size_t, url: cstring) ---
/**
* @brief Navigate to a specific URL. Single client.
*
* @param e The event struct
* @param url Full HTTP URL
*
* @example ui.navigate_client(e, "http://domain.com")
*/
@(link_name="webui_navigate_client")
navigate_client :: proc(e: ^Event, url: cstring) ---
/**
* @brief Free all memory resources. Should be called only at the end.
*
* @example
* ui.wait()
* ui.clean()
*/
@(link_name="webui_clean")
clean :: proc() ---
/**
* @brief Delete all local web-browser profiles folder. It should be called at the
* end.
*
* @example
* ui.wait()
* ui.delete_all_profiles()
* ui.clean()
*/
@(link_name="webui_delete_all_profiles")
delete_all_profiles :: proc() ---
/**
* @brief Delete a specific window web-browser local folder profile.
*
* @param window The window number
*
* @example
* ui.wait()
* ui.delete_profile(myWindow)
* ui.clean()
*
* @note This can break functionality of other windows if using the same
* web-browser.
*/
@(link_name="webui_delete_profile")
delete_profile :: proc(window: c.size_t) ---
/**
* @brief Get the ID of the parent process (The web browser may re-create
* another new process).
*
* @param window The window number
*
* @return Returns the the parent process id as integer
*
* @example id: c.size_t = ui.get_parent_process_id(myWindow)
*/
@(link_name="webui_get_parent_process_id")
get_parent_process_id :: proc(window: c.size_t) -> c.size_t ---
/**
* @brief Get the ID of the last child process.
*
* @param window The window number
*
* @return Returns the the child process id as integer
*
* @example id: c.size_t = ui.get_child_process_id(myWindow)
*/
@(link_name="webui_get_child_process_id")
get_child_process_id :: proc(window: c.size_t) -> c.size_t ---
/**
* @brief Get the network port of a running window.
* This can be useful to determine the HTTP link of `webui.js`
*
* @param window The window number
*
* @return Returns the network port of the window
*
* @example port: c.size_t = ui.get_port(myWindow)
*/
@(link_name="webui_get_port")
get_port :: proc(window: c.size_t) -> c.size_t ---
/**
* @brief Set a custom web-server/websocket network port to be used by WebUI.
* This can be useful to determine the HTTP link of `webui.js` in case
* you are trying to use WebUI with an external web-server like NGNIX.
*
* @param window The window number
* @param port The web-server network port WebUI should use
*
* @return Returns True if the port is free and usable by WebUI
*
* @example ret: bool = ui.set_port(myWindow, 8080)
*/
@(link_name="webui_set_port")
set_port :: proc(window: c.size_t, port: c.size_t) -> c.bool ---
/**
* @brief Get an available usable free network port.
*
* @return Returns a free port
*
* @example port: c.size_t = ui.get_free_port()
*/
@(link_name="webui_get_free_port")
get_free_port :: proc() -> c.size_t ---
/**
* @brief Control the WebUI behaviour. It's recommended to be called at the beginning.
*
* @param option The desired option from `Config` enum
* @param status The status of the option, `true` or `false`
*
* @example ui.set_config(show_wait_connection, false)
*/
@(link_name="webui_set_config")
set_config :: proc(option: Config, status: c.bool) ---
/**
* @brief Control if UI events comming from this window should be processed
* one a time in a single blocking thread `True`, or process every event in
* a new non-blocking thread `False`. This update single window. You can use
* `set_config(ui_event_blocking, ...)` to update all windows.
*
* @param window The window number
* @param status The blocking status `true` or `false`
*
* @example ui.set_event_blocking(myWindow, true)
*/
@(link_name="webui_set_event_blocking")
set_event_blocking :: proc(window: c.size_t, status: c.bool) ---
/**
* @brief Get the HTTP mime type of a file.
*
* @return Returns the HTTP mime string
*
* @example mime: cstring = ui.get_mime_type("foo.png")
*/
@(link_name="webui_get_mime_type")
get_mime_type :: proc(file: cstring) -> cstring ---
// == SSL/TLS =============================================================
/**
* @brief Set the SSL/TLS certificate and the private key content, both in PEM
* format. This works only with `webui-2-secure` library. If set empty WebUI
* will generate a self-signed certificate.
*
* @param certificate_pem The SSL/TLS certificate content in PEM format
* @param private_key_pem The private key content in PEM format
*
* @return Returns True if the certificate and the key are valid.
*
* @example ret: bool = ui.set_tls_certificate("-----BEGIN
* CERTIFICATE-----\n...", "-----BEGIN PRIVATE KEY-----\n...")
*/
@(link_name="webui_set_tls_certificate")
set_tls_certificate :: proc(certificate_pem: cstring, private_key_pem: cstring) -> c.bool ---
// == JavaScript ==========================================================
/**
* @brief Run JavaScript without waiting for the response. All clients.
*
* @param window The window number
* @param script The JavaScript to be run
*
* @example ui.webui_run(myWindow, cstring("alert('Hello');"))
*/
@(link_name="webui_run")
webui_run :: proc(window: c.size_t, script: cstring) ---
/**
* @brief Run JavaScript without waiting for the response. Single client.
*
* @param e The event struct
* @param script The JavaScript to be run
*
* @example ui.run_client(e, cstring("alert('Hello');"))
*/
@(link_name="webui_run_client")
run_client :: proc(e: ^Event, script: cstring) ---
/**
* @brief Run JavaScript and get the response back. Work only in single client mode.
* Make sure your local buffer can hold the response.
*
* @param window The window number
* @param script The JavaScript to be run
* @param timeout The execution timeout in seconds
* @param buffer The local buffer to hold the response
* @param buffer_length The local buffer size
*
* @return Returns True if there is no execution error
*
* @example err: bool = ui.webui_script(myWindow, cstring("return 4 + 6;"), 0, myBuffer, myBufferSize)
*/
@(link_name="webui_script")
webui_script :: proc(window: c.size_t, script: cstring, timeout: c.size_t, buffer: cstring, buffer_length: c.size_t) -> c.bool ---
/**
* @brief Run JavaScript and get the response back. Single client.
* Make sure your local buffer can hold the response.
*
* @param e The event struct
* @param script The JavaScript to be run
* @param timeout The execution timeout in seconds
* @param buffer The local buffer to hold the response
* @param buffer_length The local buffer size
*
* @return Returns True if there is no execution error
*
* @example err: bool = ui.script_client(e, cstring("return 4 + 6;"), 0, myBuffer, myBufferSize)
*/
@(link_name="webui_script_client")
script_client :: proc(e: ^Event, script: cstring, timeout: c.size_t, buffer: cstring, buffer_length: c.size_t) -> c.bool ---
/**
* @brief Chose between Deno and Nodejs as runtime for .js and .ts files.
*
* @param window The window number
* @param runtime Deno | Bun | Nodejs | None
*
* @example ui.set_runtime(myWindow, .Deno)
*/
@(link_name="webui_set_runtime")
set_runtime :: proc(window: c.size_t, runtime: WebuiJSRuntime) ---
/**
* @brief Get how many arguments there are in an event.
*
* @param e The event struct
*
* @return Returns the arguments count.
*
* @example count: c.size_t = ui.get_count(e)
*/
@(link_name="webui_get_count")
get_count :: proc(e: ^Event) -> c.size_t ---
/**
* @brief Get an argument as integer at a specific index.
*
* @param e The event struct
* @param index The argument position starting from 0
*
* @return Returns argument as integer
*
* @example myNum: i64 = ui.get_int_at(e, 0)
*/
@(link_name="webui_get_int_at")
get_int_at :: proc(e: ^Event, index: c.size_t) -> c.longlong ---
/**
* @brief Get the first argument as integer.
*
* @param e The event struct
*
* @return Returns argument as integer
*
* @example myNum: i64 = ui.get_int(e)
*/
@(link_name="webui_get_int")
get_int :: proc(e: ^Event) -> c.longlong ---
/**
* @brief Get an argument as float at a specific index.
*
* @param e The event struct
* @param index The argument position starting from 0
*
* @return Returns argument as float
*
* @example myNum: f64 = ui.get_float_at(e, 0)
*/
@(link_name="webui_get_float_at")
get_float_at :: proc(e: ^Event, index: c.size_t) -> c.double ---
/**
* @brief Get the first argument as float.
*
* @param e The event struct
*
* @return Returns argument as float
*
* @example myNum: f64 = ui.get_float(e)
*/
@(link_name="webui_get_float")
get_float :: proc(e: ^Event) -> c.double ---
/**
* @brief Get an argument as string at a specific index.
*
* @param e The event struct
* @param index The argument position starting from 0
*
* @return Returns argument as string
*
* @example myStr: cstring = ui.get_string_at(e, 0)
*/
@(link_name="webui_get_string_at")
get_string_at :: proc(e: ^Event, index: c.size_t) -> cstring ---
/**
* @brief Get the first argument as string.
*
* @param e The event struct
*
* @return Returns argument as string
*
* @example myStr: cstring = ui.get_string(e)
*/
@(link_name="webui_get_string")
get_string :: proc(e: ^Event) -> cstring ---
/**
* @brief Get an argument as boolean at a specific index.
*
* @param e The event struct
* @param index The argument position starting from 0
*
* @return Returns argument as boolean
*
* @example myBool: bool = ui.get_bool_at(e, 0)
*/
@(link_name="webui_get_bool_at")
get_bool_at :: proc(e: ^Event, index: c.size_t) -> c.bool ---
/**
* @brief Get the first argument as boolean.
*
* @param e The event struct
*
* @return Returns argument as boolean
*
* @example myBool: bool = ui.get_bool(e)
*/
@(link_name="webui_get_bool")
get_bool :: proc(e: ^Event) -> c.bool ---
/**
* @brief Get the size in bytes of an argument at a specific index.
*
* @param e The event struct
* @param index The argument position starting from 0
*
* @return Returns size in bytes
*
* @example argLen: uint = ui.get_size_at(e, 0)
*/
@(link_name="webui_get_size_at")
get_size_at :: proc(e: ^Event, index: c.size_t) -> c.size_t ---