-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathserve_folder.nim
105 lines (77 loc) · 2.31 KB
/
serve_folder.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
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
import std/strformat
import std/os
import webui
var
window: Window
window2: Window
count: int
proc exitApp(_: Event) =
exit()
proc main =
# Create new windows
window = newWindow(1)
window2 = newWindow(2)
window.bind("SwitchToSecondPage") do (e: Event):
# This function gets called every
# time the user clicks on "SwitchToSecondPage"
# Switch to `./second.html` in the same opened window.
e.window.show("second.html")
window.bind("OpenNewWindow") do (e: Event):
# This function gets called every
# time the user clicks on "OpenNewWindow"
# Show a new window, and navigate to `/second.html`
# if it's already open, then switch in the same window
window2.show("second.html")
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:
echo "Starting navigation to: ", e.getString()
else:
discard
window.setFileHandler() do (filename: string) -> string:
echo "File: ", filename
case filename
of "/test.txt":
# Const static file example
# Note: The connection will drop if the content
# does not have `<script src="/webui.js"></script>`
return "This is a embedded file content example."
of "/dynamic.html":
# Dynamic file example
inc count
return fmt"""
<html>
This is a dynamic file content example.
<br>
Count: {count} <a href="dynamic.html">[Refresh]</a>
<br>
<script src="/webui.js"></script>
</html>
"""
# By default, this function returns an empty string
# returning an empty string will make WebUI look for
# the requested file locally
window.bind("Exit", exitApp)
window2.bind("Exit", exitApp)
# Make Deno as the `.ts` and `.js` interpreter
window.runtime = wrDeno
# Set root folder to current directory
window.rootFolder = currentSourcePath().parentDir()
window2.rootFolder = currentSourcePath().parentDir()
# Set window size
window.setSize(800, 600)
# Set window position
window.setPosition(100, 100)
# Show a new window
window.show("index.html")
# Wait until all windows get closed
wait()
main()