Skip to content

Commit bc6c508

Browse files
hassandraganeroist
andauthored
Update to WebUI v2.1.0 (#7)
* Update to WebUI v2.0.7 #New Features * Supporting more web browsers * Search for web browsers in Windows Reg. * Using the same show() function for HTML script, files, and refresh content * Support Chrome on macOS * The `getInt()` and `returnInt()` are now 64bit integer instead of 32bit #Breaking code * Switching from `show(html, browser);` to `show(content);`, and it's used for HTML, files, or reload the window * Removing `showCopy()`, `refresh()`, `refreshCopy()` * link additional depenencies * Add new browsers to `Browser` enum * add `_webui_show_window` * Add the rest of the `_webui_browser_start_xxx` functions * change to clonglong * int64 -> int/clonglong * int64 -> int * int64 -> int * Add `browserStartXXX` funcs * Add `showWindow` and `showBrowser` * update submodule? --------- Co-authored-by: Grave <[email protected]>
1 parent a6a6c87 commit bc6c508

File tree

6 files changed

+104
-51
lines changed

6 files changed

+104
-51
lines changed

README.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,44 @@ be found in WebUI's website [here](https://webui.me/#download).
9191
In addition, you can also enable WebUI's logging via `-d:webuiLog` but that flag
9292
only works for static compilation.
9393

94-
## Supported Browsers
95-
96-
| OS | Browser | Status |
97-
| ------ | ------ | ------ |
98-
| Windows | Firefox | ✔️ |
99-
| Windows | Chrome | ✔️ |
100-
| Windows | Edge | ✔️ |
101-
| Linux | Firefox | ✔️ |
102-
| Linux | Chrome | ✔️ |
103-
| macOS | Firefox | *coming soon* |
104-
| macOS | Chrome | *coming soon* |
105-
| macOS | Safari | *coming soon* |
94+
## Supported Web Browsers
95+
96+
| OS | Browser | Status |
97+
| ------ | ------ | ------ |
98+
| Windows | Mozilla Firefox | ✔️ |
99+
| Windows | Google Chrome | ✔️ |
100+
| Windows | Microsoft Edge | ✔️ |
101+
| Windows | Chromium | ✔️ |
102+
| Windows | Yandex | ✔️ |
103+
| Windows | Brave | ✔️ |
104+
| Windows | Vivaldi | ✔️ |
105+
| Windows | Epic | ✔️ |
106+
| Windows | Opera | *coming soon* |
107+
| - | - | - |
108+
| Linux | Mozilla Firefox | ✔️ |
109+
| Linux | Google Chrome | ✔️ |
110+
| Linux | Microsoft Edge | *coming soon* |
111+
| Linux | Chromium | ✔️ |
112+
| Linux | Yandex | *coming soon* |
113+
| Linux | Brave | *coming soon* |
114+
| Linux | Vivaldi | *coming soon* |
115+
| Linux | Epic | *coming soon* |
116+
| Linux | Opera | *coming soon* |
117+
| - | - | - |
118+
| macOS | Mozilla Firefox | *coming soon* |
119+
| macOS | Google Chrome | ✔️ |
120+
| macOS | Microsoft Edge | *coming soon* |
121+
| macOS | Chromium | *coming soon* |
122+
| macOS | Yandex | *coming soon* |
123+
| macOS | Brave | *coming soon* |
124+
| macOS | Vivaldi | *coming soon* |
125+
| macOS | Epic | *coming soon* |
126+
| macOS | Apple Safari | *coming soon* |
127+
| macOS | Opera | *coming soon* |
106128

107129
## License
108130

109131
MIT License. See [LICENSE](LICENSE)
110132

111-
Original WebUI library is licensed under LGPL-2.1. See
133+
Original WebUI library is licensed under GPLv2.0. See
112134
[LICENSE](https://github.com/alifcommunity/webui/blob/main/LICENSE).

examples/call_nim_from_js.nim

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ proc main =
7979
# result is sent back to Javascript for you
8080

8181
# Show the window
82-
if not window.show(html, BrowserChrome): # Run the window on Chrome
83-
window.show(html, BrowserAny) # If not, run on any other installed web browser
82+
window.show(html)
8483

8584
# Wait until all windows get closed
8685
wait()
8786

88-
main()
87+
main()

examples/hello_world.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ proc main =
110110
webui.exit()
111111

112112
# Show the window
113-
if not window.show(loginHtml, BrowserChrome): # Run the window on Chrome
114-
window.show(loginHtml, BrowserAny) # If not, run on any other installed web browser
113+
window.show(loginHtml)
115114

116115
# Wait until all windows get closed
117116
wait()

examples/hello_world_c.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ proc main =
7878
webui.exit()
7979

8080
# Show the window
81-
if not window.show(html, BrowserChrome): # Run the window on Chrome
82-
window.show(html, BrowserAny) # If not, run on any other installed web browser
81+
window.show(html)
8382

8483
# Wait until all windows get closed
8584
wait()

webui.nim

Lines changed: 36 additions & 19 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.0.7
5+
:WebUI Version: 2.1.0
66
77
# Get Started
88
@@ -400,6 +400,10 @@ type
400400
BrowserEdge = 3
401401
BrowserSafari = 4
402402
BrowserChromium = 5
403+
BrowserOpera = 6
404+
BrowserBrave = 7
405+
BrowserVivaldi = 8
406+
BrowserYandex = 9
403407
BrowserCustom = 99
404408

405409
Runtime* = enum
@@ -616,7 +620,7 @@ proc data*(e: Event): pointer =
616620
proc response*(e: Event): pointer =
617621
e.impl.response
618622

619-
proc getInt*(e: Event): int =
623+
proc getInt*(e: Event): clonglong =
620624
int bindings.getInt(e.impl)
621625

622626
proc getString*(e: Event): string =
@@ -629,7 +633,7 @@ proc getBool*(e: Event): bool =
629633
e.getString() == "true"
630634

631635
proc returnInt*(e: Event; n: int) =
632-
bindings.returnInt(e.impl, cint n)
636+
bindings.returnInt(e.impl, clonglong n)
633637

634638
proc returnString*(e: Event; s: string) =
635639
bindings.returnString(e.impl, cstring s)
@@ -719,22 +723,12 @@ proc core*(win: Window): WindowCore =
719723

720724
{.push discardable.}
721725

722-
proc show*(win: Window; html: string; browser: Browser = BrowserAny): bool =
726+
proc show*(win: Window; content: string): bool =
723727
## Show Window `win`. If the window is already shown, the UI will get
724728
## refreshed in the same window.
729+
## `content` can be a file name, or a static HTML script
725730

726-
bindings.show(win.impl, cstring html, cuint ord(browser))
727-
728-
proc showCopy*(win: Window; html: string; browser: Browser = BrowserAny): bool =
729-
bindings.showCpy(win.impl, cstring html, cuint ord(browser))
730-
731-
proc refresh*(win: Window; html: string): bool =
732-
## Refresh the window UI with any new HTML content.
733-
734-
bindings.refresh(win.impl, cstring html)
735-
736-
proc refreshCopy*(win: Window; html: string): bool =
737-
bindings.refreshCpy(win.impl, cstring html)
731+
bindings.show(win.impl, cstring content)
738732

739733
{.pop.}
740734

@@ -924,20 +918,43 @@ proc browserCreateProfileFolder*(win: Window; browser: Browser): bool {.discarda
924918

925919
{.push discardable.}
926920

921+
proc browserStartChrome*(win: Window; address: string | Uri): bool =
922+
bindings.browserStartChrome(win.impl, cstring $address)
923+
927924
proc browserStartEdge*(win: Window; address: string | Uri): bool =
928925
bindings.browserStartEdge(win.impl, cstring $address)
929926

927+
proc browserStartEpic*(win: Window; address: string | Uri): bool =
928+
bindings.browserStartEpic(win.impl, cstring $address)
929+
930+
proc browserStartVivaldi*(win: Window; address: string | Uri): bool =
931+
bindings.browserStartVivaldi(win.impl, cstring $address)
932+
933+
proc browserStartBrave*(win: Window; address: string | Uri): bool =
934+
bindings.browserStartBrave(win.impl, cstring $address)
935+
930936
proc browserStartFirefox*(win: Window; address: string | Uri): bool =
931937
bindings.browserStartFirefox(win.impl, cstring $address)
932938

939+
proc browserStartYandex*(win: Window; address: string | Uri): bool =
940+
bindings.browserStartYandex(win.impl, cstring $address)
941+
942+
proc browserStartChromium*(win: Window; address: string | Uri): bool =
943+
bindings.browserStartChromium(win.impl, cstring $address)
944+
933945
proc browserStartCustom*(win: Window; address: string | Uri): bool =
934946
bindings.browserStartCustom(win.impl, cstring $address)
935947

936-
proc browserStartChrome*(win: Window; address: string | Uri): bool =
937-
bindings.browserStartChrome(win.impl, cstring $address)
938-
939948
{.pop.}
940949

950+
proc showWindow*(win: Window, html: string, browser: Browser) =
951+
bindings.showWindow(win.impl, cstring html, cuint ord browser)
952+
953+
proc showBrowser*(win: Window, html: string, browser: Browser) =
954+
## Alias of `showWindow`
955+
956+
bindings.showWindow(win.impl, cstring html, cuint ord browser)
957+
941958
proc `rootFolder=`*(win: Window; path: string): bool {.discardable.} =
942959
bindings.setRootFolder(win.impl, cstring path)
943960

webui/bindings.nim

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ when useWebuiStaticLib:
2222
when defined(vcc):
2323
{.link: "user32.lib".}
2424
{.link: "ws2_32.lib".}
25+
{.link: "Advapi32.lib".}
2526

2627
{.link: webuiStaticLib & ".lib".}
2728
else:
@@ -33,6 +34,7 @@ when useWebuiStaticLib:
3334

3435
{.passL: "-luser32".} # link dependencies
3536
{.passL: "-lws2_32".}
37+
{.passL: "-lAdvapi32".}
3638

3739
{.pragma: webui, discardable.}
3840
elif useWebuiDll:
@@ -52,12 +54,14 @@ else:
5254
when defined(vcc):
5355
{.link: "user32.lib".}
5456
{.link: "ws2_32.lib".}
57+
{.link: "Advapi32.lib".}
5558

5659
{.passC: "/I " & currentSourceDir / "webui" / "include".}
5760

5861
elif defined(windows):
5962
{.passL: "-lws2_32".}
6063
{.passL: "-luser32".}
64+
{.passL: "-lAdvapi32".}
6165

6266
{.passC: "-I" & currentSourceDir / "webui" / "include".}
6367

@@ -80,7 +84,7 @@ else:
8084
{.deadCodeElim: on.}
8185

8286
const
83-
WEBUI_VERSION* = "2.0.7" ## Version
87+
WEBUI_VERSION* = "2.1.0" ## Version
8488
WEBUI_HEADER_SIGNATURE* = 0xFF ## All packets should start with this 8bit
8589
WEBUI_HEADER_JS* = 0xFE ## Javascript result in frontend
8690
WEBUI_HEADER_CLICK* = 0xFD ## Click event
@@ -171,6 +175,12 @@ type
171175
edge*: cuint ## 3
172176
safari*: cuint ## 4
173177
chromium*: cuint ## 5
178+
opera*: cuint ## 6
179+
brave*: cuint ## 7
180+
vivaldi*: cuint ## 8
181+
epic*: cuint ## 9
182+
yandex*: cuint ## 10
183+
current*: cuint ## x
174184
custom*: cuint ## 99
175185

176186
Runtime* {.bycopy.} = object
@@ -223,14 +233,8 @@ proc isAnyWindowRunning*(): bool {.cdecl,
223233
proc isAppRunning*(): bool {.cdecl, importc: "webui_is_app_running", webui.}
224234
proc setTimeout*(second: cuint) {.cdecl, importc: "webui_set_timeout", webui.}
225235
proc newWindow*(): ptr Window {.cdecl, importc: "webui_new_window", webui.}
226-
proc show*(win: ptr Window; html: cstring; browser: cuint): bool {.cdecl,
236+
proc show*(win: ptr Window; content: cstring): bool {.cdecl,
227237
importc: "webui_show", webui.}
228-
proc showCpy*(win: ptr Window; html: cstring; browser: cuint): bool {.cdecl,
229-
importc: "webui_show_cpy", webui.}
230-
proc refresh*(win: ptr Window; html: cstring): bool {.cdecl,
231-
importc: "webui_refresh", webui.}
232-
proc refreshCpy*(win: ptr Window; html: cstring): bool {.cdecl,
233-
importc: "webui_refresh_cpy", webui.}
234238
proc setIcon*(win: ptr Window; iconS: cstring; typeS: cstring) {.cdecl,
235239
importc: "webui_set_icon", webui.}
236240
proc multiAccess*(win: ptr Window; status: bool) {.cdecl,
@@ -252,10 +256,10 @@ proc scriptCleanup*(script: ptr Script) {.cdecl,
252256
importc: "webui_script_cleanup", webui.}
253257
proc scriptRuntime*(win: ptr Window; runtime: cuint) {.cdecl,
254258
importc: "webui_script_runtime", webui.}
255-
proc getInt*(e: ptr Event): cint {.cdecl, importc: "webui_get_int", webui.}
259+
proc getInt*(e: ptr Event): clonglong {.cdecl, importc: "webui_get_int", webui.}
256260
proc getString*(e: ptr Event): cstring {.cdecl, importc: "webui_get_string", webui.}
257261
proc getBool*(e: ptr Event): bool {.cdecl, importc: "webui_get_bool", webui.}
258-
proc returnInt*(e: ptr Event; n: cint) {.cdecl, importc: "webui_return_int", webui.}
262+
proc returnInt*(e: ptr Event; n: clonglong) {.cdecl, importc: "webui_return_int", webui.}
259263
proc returnString*(e: ptr Event; s: cstring) {.cdecl,
260264
importc: "webui_return_string", webui.}
261265
proc returnBool*(e: ptr Event; b: bool) {.cdecl, importc: "webui_return_bool", webui.}
@@ -329,14 +333,24 @@ proc folderExist*(folder: cstring): bool {.cdecl,
329333

330334
proc browserCreateProfileFolder*(win: ptr Window; browser: cuint): bool {.cdecl,
331335
importc: "_webui_browser_create_profile_folder", webui.}
336+
proc browserStartChrome*(win: ptr Window; address: cstring): bool {.cdecl,
337+
importc: "_webui_browser_start_chrome", webui.}
332338
proc browserStartEdge*(win: ptr Window; address: cstring): bool {.cdecl,
333339
importc: "_webui_browser_start_edge", webui.}
340+
proc browserStartEpic*(win: ptr Window; address: cstring): bool {.cdecl,
341+
importc: "_webui_browser_start_epic", webui.}
342+
proc browserStartVivaldi*(win: ptr Window; address: cstring): bool {.cdecl,
343+
importc: "_webui_browser_start_vivaldi", webui.}
344+
proc browserStartBrave*(win: ptr Window; address: cstring): bool {.cdecl,
345+
importc: "_webui_browser_start_brave", webui.}
334346
proc browserStartFirefox*(win: ptr Window; address: cstring): bool {.cdecl,
335347
importc: "_webui_browser_start_firefox", webui.}
348+
proc browserStartYandex*(win: ptr Window; address: cstring): bool {.cdecl,
349+
importc: "_webui_browser_start_yandex", webui.}
350+
proc browserStartChromium*(win: ptr Window; address: cstring): bool {.cdecl,
351+
importc: "_webui_browser_start_chromium", webui.}
336352
proc browserStartCustom*(win: ptr Window; address: cstring): bool {.cdecl,
337353
importc: "_webui_browser_start_custom", webui.}
338-
proc browserStartChrome*(win: ptr Window; address: cstring): bool {.cdecl,
339-
importc: "_webui_browser_start_chrome", webui.}
340354
proc browserStart*(win: ptr Window; address: cstring; browser: cuint): bool {.
341355
cdecl, importc: "_webui_browser_start", webui.}
342356

@@ -371,3 +385,6 @@ proc fileExistMg*(evData: pointer): bool {.cdecl,
371385
# use std/os?
372386
proc fileExist*(file: cstring): bool {.cdecl, importc: "_webui_file_exist", webui.}
373387
proc freeAllMem*() {.cdecl, importc: "_webui_free_all_mem", webui.}
388+
389+
proc showWindow*(win: ptr Window; html: cstring; browser: cuint): bool {.cdecl,
390+
importc: "_webui_show_window", webui.}

0 commit comments

Comments
 (0)