-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmc_webview.nim
91 lines (77 loc) · 1.91 KB
/
mc_webview.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
static:
const WEBVIEW_DIR: string = currentSourcePath().substr(0, high(currentSourcePath()) - 14)
discard staticExec "g++ --std=c++11 $(pkg-config --cflags gtk+-3.0 webkit2gtk-4.0) -c " & WEBVIEW_DIR & "webview/webview.cc"
{.passL: WEBVIEW_DIR & "webview.o".}
when defined(linux):
#Required so the string is considered static.
const libs: string = staticExec "pkg-config --libs gtk+-3.0 webkit2gtk-4.0"
{.passL: libs.}
elif defined(windows):
when sizeof(int) == 4:
{.passL: "-mwindows -L./dll/x86 -lwebview -lWebView2Loader".}
elif sizeof(int) == 8:
{.passL: "-mwindows -L./dll/x64 -lwebview -lWebView2Loader".}
else:
panic("WebView must be run on a 32-bit or 64-bit architecture.")
elif defined(macosx):
{.passL: "-framework WebKit".}
type SizeHint* = enum
None = 0,
Minimum = 1,
Maximum = 2,
Fixed = 3
type Webview* = pointer
proc newWebview*(
debug: bool
): Webview {.importc: "webview_create".}
proc setTitle*(
w: Webview,
title: cstring
) {.importc: "webview_set_title".}
proc setSize*(
w: Webview,
width: cint,
height: cint,
hints: SizeHint
) {.importc: "webview_set_size".}
proc bindProc*(
w: Webview,
name: cstring,
p: proc (
id: cstring,
jsonArgs: cstring,
carriedArgs: pointer
) {.cdecl.},
carriedArgs: pointer
) {.importc: "webview_bind".}
proc returnProc*(
w: Webview,
id: cstring,
status: cint,
resultJSON: cstring
) {.importc: "webview_return".}
proc navigate*(
w: Webview,
url: cstring
) {.importc: "webview_navigate".}
proc eval*(
w: Webview,
js: cstring
) {.importc: "webview_eval".}
proc dispatch*(
w: Webview,
fn: proc (
w: Webview,
arg: pointer
) {.cdecl.},
arg: pointer
) {.importc: "webview_dispatch".}
proc run*(
w: Webview
) {.importc: "webview_run".}
proc terminate*(
w: Webview
) {.importc: "webview_terminate".}
proc destroy*(
w: Webview
) {.importc: "webview_destroy".}