-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.nim
59 lines (46 loc) · 1.38 KB
/
main.nim
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
import webui
proc main =
# Create new windows
let window = newWindow()
# Bind all events
window.bind("") do (e: Event):
# This function gets called every time
# there is an event
case e.eventType
of weConnected:
echo "Connected"
of weDisconnected:
echo "Disconnected"
of weMouseClick:
echo "Click"
of weNavigation:
let url = e.getString()
echo "Starting navigation to: ", url
# Because we used `window.bind("")`
# WebUI will block all `href` link clicks and sent here instead.
# We can then control the behavior of links as needed.
e.window.navigate(url)
else:
discard
# Bind HTML elements with Nim function
window.bind("my_backend_func") do (e: Event):
let
number1 = e.getInt(0)
number2 = e.getInt(1)
number3 = e.getInt(2)
echo "my_backend_func 1: ", number1 # 123
echo "my_backend_func 2: ", number2 # 456
echo "my_backend_func 3: ", number3 # 789
# Set web server network port WebUI should use
# this means `webui.js` will be available at:
# http://localhost:8081/webui.js
window.port = 8081
# Show a new window and show our custom web server
# Assuming the custom web server is running on port
# 8080...
window.show("http://localhost:8080")
# Wait until all windows get closed
wait()
# Free all memory resources (Optional)
clean()
main()