janela 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -0
  3. package/bin/janela.mjs +271 -0
  4. package/package.json +43 -0
  5. package/runtime/janela.ts +193 -0
  6. package/shim/wvshim.cc +201 -0
  7. package/templates/index.html +48 -0
  8. package/templates/janela.conf.json +10 -0
  9. package/templates/main.ts +37 -0
  10. package/vendor-webview/LICENSE +22 -0
  11. package/vendor-webview/core/include/webview/api.h +251 -0
  12. package/vendor-webview/core/include/webview/backends.hh +40 -0
  13. package/vendor-webview/core/include/webview/c_api_impl.hh +258 -0
  14. package/vendor-webview/core/include/webview/detail/backends/cocoa_webkit.hh +626 -0
  15. package/vendor-webview/core/include/webview/detail/backends/gtk_webkitgtk.hh +355 -0
  16. package/vendor-webview/core/include/webview/detail/backends/win32_edge.hh +909 -0
  17. package/vendor-webview/core/include/webview/detail/basic_result.hh +119 -0
  18. package/vendor-webview/core/include/webview/detail/engine_base.hh +382 -0
  19. package/vendor-webview/core/include/webview/detail/exceptions.hh +42 -0
  20. package/vendor-webview/core/include/webview/detail/json.hh +337 -0
  21. package/vendor-webview/core/include/webview/detail/native_library.hh +170 -0
  22. package/vendor-webview/core/include/webview/detail/optional.hh +118 -0
  23. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSApplication.hh +107 -0
  24. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSBundle.hh +56 -0
  25. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSEvent.hh +71 -0
  26. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSInvocation.hh +66 -0
  27. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSMethodSignature.hh +52 -0
  28. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSNotification.hh +51 -0
  29. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSNumber.hh +53 -0
  30. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSObject.hh +51 -0
  31. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSOpenPanel.hh +71 -0
  32. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSPoint.hh +53 -0
  33. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSRect.hh +53 -0
  34. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSSavePanel.hh +52 -0
  35. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSSize.hh +53 -0
  36. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSString.hh +87 -0
  37. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSURL.hh +63 -0
  38. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSURLRequest.hh +52 -0
  39. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSValue.hh +56 -0
  40. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSView.hh +91 -0
  41. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSWindow.hh +137 -0
  42. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/cocoa.hh +59 -0
  43. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/types.hh +49 -0
  44. package/vendor-webview/core/include/webview/detail/platform/darwin/objc/Class.hh +55 -0
  45. package/vendor-webview/core/include/webview/detail/platform/darwin/objc/autoreleasepool.hh +70 -0
  46. package/vendor-webview/core/include/webview/detail/platform/darwin/objc/invoke.hh +75 -0
  47. package/vendor-webview/core/include/webview/detail/platform/darwin/objc/memory.hh +57 -0
  48. package/vendor-webview/core/include/webview/detail/platform/darwin/objc/objc.hh +47 -0
  49. package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKOpenPanelParameters.hh +57 -0
  50. package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKScriptMessage.hh +51 -0
  51. package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKUserContentController.hh +61 -0
  52. package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKUserScript.hh +71 -0
  53. package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKWebView.hh +108 -0
  54. package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKWebViewConfiguration.hh +60 -0
  55. package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/webkit.hh +46 -0
  56. package/vendor-webview/core/include/webview/detail/platform/linux/gtk/compat.hh +137 -0
  57. package/vendor-webview/core/include/webview/detail/platform/linux/webkitgtk/compat.hh +142 -0
  58. package/vendor-webview/core/include/webview/detail/platform/linux/webkitgtk/dmabuf.hh +167 -0
  59. package/vendor-webview/core/include/webview/detail/platform/windows/com_init_wrapper.hh +126 -0
  60. package/vendor-webview/core/include/webview/detail/platform/windows/dpi.hh +161 -0
  61. package/vendor-webview/core/include/webview/detail/platform/windows/dwmapi.hh +67 -0
  62. package/vendor-webview/core/include/webview/detail/platform/windows/iid.hh +78 -0
  63. package/vendor-webview/core/include/webview/detail/platform/windows/ntdll.hh +58 -0
  64. package/vendor-webview/core/include/webview/detail/platform/windows/reg_key.hh +135 -0
  65. package/vendor-webview/core/include/webview/detail/platform/windows/shcore.hh +59 -0
  66. package/vendor-webview/core/include/webview/detail/platform/windows/theme.hh +76 -0
  67. package/vendor-webview/core/include/webview/detail/platform/windows/user32.hh +90 -0
  68. package/vendor-webview/core/include/webview/detail/platform/windows/version.hh +151 -0
  69. package/vendor-webview/core/include/webview/detail/platform/windows/webview2/loader.hh +391 -0
  70. package/vendor-webview/core/include/webview/detail/user_script.hh +76 -0
  71. package/vendor-webview/core/include/webview/detail/utility/string.hh +99 -0
  72. package/vendor-webview/core/include/webview/errors.h +67 -0
  73. package/vendor-webview/core/include/webview/errors.hh +85 -0
  74. package/vendor-webview/core/include/webview/json_deprecated.hh +61 -0
  75. package/vendor-webview/core/include/webview/macros.h +123 -0
  76. package/vendor-webview/core/include/webview/types.h +81 -0
  77. package/vendor-webview/core/include/webview/types.hh +48 -0
  78. package/vendor-webview/core/include/webview/version.h +67 -0
  79. package/vendor-webview/core/include/webview/webview.h +32 -0
  80. package/vendor-webview/core/include/webview.h +15 -0
package/shim/wvshim.cc ADDED
@@ -0,0 +1,201 @@
1
+ // wvshim.cc — a C-ABI shim over webview.h shaped to scriptc's FFI format 2.
2
+ //
3
+ // Three constraints drive every design decision here:
4
+ // 1. scriptc has no pointer/u64 type, so webview_t can never cross the
5
+ // boundary. We keep a handle table and hand out int32 indices.
6
+ // 2. Callback params/returns are numeric scalars only, so the request JSON
7
+ // cannot be passed as a callback argument. We stage it in a shim-side
8
+ // buffer and let TS drain it byte-at-a-time via re-entrant FFI calls.
9
+ // 3. Callbacks are lifetime:"call" only. webview_bind wants a retained
10
+ // callback, which is not expressible. Instead the TS callback is handed
11
+ // to wv_run(), which blocks for the whole app lifetime — so "call scope"
12
+ // and "app lifetime" coincide, and bind dispatch happens inside it.
13
+
14
+ #include "webview.h"
15
+
16
+ #include <cstdint>
17
+ #include <cstring>
18
+ #include <string>
19
+ #include <vector>
20
+
21
+ namespace {
22
+
23
+ struct Bind {
24
+ std::string name;
25
+ };
26
+
27
+ struct App {
28
+ webview_t w = nullptr;
29
+ bool used = false;
30
+ std::vector<Bind> binds;
31
+
32
+ // Callback supplied by TS for the duration of wv_run().
33
+ int32_t (*cb)(uint32_t, uint32_t, void *) = nullptr;
34
+ void *cb_ctx = nullptr;
35
+
36
+ // Staging for the in-flight request.
37
+ std::string req; // JSON args array from JS
38
+ std::string cur_id; // webview's call id, needed by webview_return
39
+ std::string reply; // response body assembled by TS
40
+ uint32_t seq = 0;
41
+ };
42
+
43
+ // Fixed-size table: handles are indices, never pointers.
44
+ App g_apps[8];
45
+
46
+ App *app_at(int32_t h) {
47
+ if (h < 0 || h >= 8 || !g_apps[h].used) return nullptr;
48
+ return &g_apps[h];
49
+ }
50
+
51
+ // scriptc passes strings as (ptr, len) and does NOT NUL-terminate.
52
+ std::string to_str(const uint8_t *p, size_t n) {
53
+ return std::string(reinterpret_cast<const char *>(p), n);
54
+ }
55
+
56
+ // The single C trampoline registered with webview_bind for every binding.
57
+ // `arg` encodes the app index and bind index.
58
+ void trampoline(const char *id, const char *req, void *arg) {
59
+ uintptr_t packed = reinterpret_cast<uintptr_t>(arg);
60
+ App *a = &g_apps[packed >> 32];
61
+ uint32_t bind_index = static_cast<uint32_t>(packed & 0xffffffffu);
62
+
63
+ if (!a->cb) return; // no TS handler installed
64
+
65
+ a->req = req ? req : "";
66
+ a->cur_id = id ? id : "";
67
+ a->reply.clear();
68
+ a->seq++;
69
+
70
+ // Re-entrancy: this call lands back in TS, which will call wv_req_byte()
71
+ // etc. back into this shim before returning.
72
+ int32_t status = a->cb(bind_index, a->seq, a->cb_ctx);
73
+
74
+ webview_return(a->w, a->cur_id.c_str(), status,
75
+ a->reply.empty() ? "null" : a->reply.c_str());
76
+ }
77
+
78
+ } // namespace
79
+
80
+ extern "C" {
81
+
82
+ int32_t wv_create(int32_t debug) {
83
+ for (int32_t i = 0; i < 8; i++) {
84
+ if (g_apps[i].used) continue;
85
+ webview_t w = webview_create(debug, nullptr);
86
+ if (!w) return -1;
87
+ g_apps[i] = App{};
88
+ g_apps[i].w = w;
89
+ g_apps[i].used = true;
90
+ return i;
91
+ }
92
+ return -1;
93
+ }
94
+
95
+ int32_t wv_set_title(int32_t h, const uint8_t *p, size_t n) {
96
+ App *a = app_at(h);
97
+ if (!a) return -1;
98
+ return webview_set_title(a->w, to_str(p, n).c_str());
99
+ }
100
+
101
+ int32_t wv_set_size(int32_t h, int32_t width, int32_t height, int32_t hint) {
102
+ App *a = app_at(h);
103
+ if (!a) return -1;
104
+ return webview_set_size(a->w, width, height,
105
+ static_cast<webview_hint_t>(hint));
106
+ }
107
+
108
+ int32_t wv_set_html(int32_t h, const uint8_t *p, size_t n) {
109
+ App *a = app_at(h);
110
+ if (!a) return -1;
111
+ return webview_set_html(a->w, to_str(p, n).c_str());
112
+ }
113
+
114
+ int32_t wv_navigate(int32_t h, const uint8_t *p, size_t n) {
115
+ App *a = app_at(h);
116
+ if (!a) return -1;
117
+ return webview_navigate(a->w, to_str(p, n).c_str());
118
+ }
119
+
120
+ int32_t wv_init(int32_t h, const uint8_t *p, size_t n) {
121
+ App *a = app_at(h);
122
+ if (!a) return -1;
123
+ return webview_init(a->w, to_str(p, n).c_str());
124
+ }
125
+
126
+ int32_t wv_eval(int32_t h, const uint8_t *p, size_t n) {
127
+ App *a = app_at(h);
128
+ if (!a) return -1;
129
+ return webview_eval(a->w, to_str(p, n).c_str());
130
+ }
131
+
132
+ // Returns the bind index that wv_run's callback will receive.
133
+ int32_t wv_bind(int32_t h, const uint8_t *p, size_t n) {
134
+ App *a = app_at(h);
135
+ if (!a) return -1;
136
+ uint32_t idx = static_cast<uint32_t>(a->binds.size());
137
+ a->binds.push_back(Bind{to_str(p, n)});
138
+ uintptr_t packed = (static_cast<uintptr_t>(h) << 32) | idx;
139
+ int rc = webview_bind(a->w, a->binds[idx].name.c_str(), trampoline,
140
+ reinterpret_cast<void *>(packed));
141
+ if (rc != WEBVIEW_ERROR_OK) return -1;
142
+ return static_cast<int32_t>(idx);
143
+ }
144
+
145
+ // ---- request payload, drained byte-at-a-time from inside the TS callback ----
146
+ int32_t wv_req_len(int32_t h) {
147
+ App *a = app_at(h);
148
+ if (!a) return -1;
149
+ return static_cast<int32_t>(a->req.size());
150
+ }
151
+
152
+ int32_t wv_req_byte(int32_t h, int32_t i) {
153
+ App *a = app_at(h);
154
+ if (!a || i < 0 || static_cast<size_t>(i) >= a->req.size()) return -1;
155
+ return static_cast<uint8_t>(a->req[i]);
156
+ }
157
+
158
+ // ---- reply payload, pushed byte-at-a-time from inside the TS callback ----
159
+ int32_t wv_reply_reset(int32_t h) {
160
+ App *a = app_at(h);
161
+ if (!a) return -1;
162
+ a->reply.clear();
163
+ return 0;
164
+ }
165
+
166
+ int32_t wv_reply_push(int32_t h, int32_t byte) {
167
+ App *a = app_at(h);
168
+ if (!a) return -1;
169
+ a->reply.push_back(static_cast<char>(byte & 0xff));
170
+ return 0;
171
+ }
172
+
173
+ // Blocks for the app's lifetime; dispatches bind calls into `cb`.
174
+ int32_t wv_run(int32_t h, int32_t (*cb)(uint32_t, uint32_t, void *),
175
+ void *cb_ctx) {
176
+ App *a = app_at(h);
177
+ if (!a) return -1;
178
+ a->cb = cb;
179
+ a->cb_ctx = cb_ctx;
180
+ int rc = webview_run(a->w);
181
+ a->cb = nullptr; // callback must not outlive the call, per lifetime:"call"
182
+ a->cb_ctx = nullptr;
183
+ return rc;
184
+ }
185
+
186
+ int32_t wv_terminate(int32_t h) {
187
+ App *a = app_at(h);
188
+ if (!a) return -1;
189
+ return webview_terminate(a->w);
190
+ }
191
+
192
+ int32_t wv_destroy(int32_t h) {
193
+ App *a = app_at(h);
194
+ if (!a) return -1;
195
+ webview_destroy(a->w);
196
+ a->used = false;
197
+ a->w = nullptr;
198
+ return 0;
199
+ }
200
+
201
+ } // extern "C"
@@ -0,0 +1,48 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <style>
6
+ body { font: 16px -apple-system, sans-serif; padding: 2rem; }
7
+ input[type="number"] { width: 5em; }
8
+ #events { color: #666; font-size: 13px; }
9
+ </style>
10
+ </head>
11
+ <body>
12
+ <h1>__NAME__</h1>
13
+ <p>
14
+ <input id="a" type="number" value="2" /> +
15
+ <input id="b" type="number" value="40" />
16
+ <button id="add">add</button>
17
+ <button id="quit">Quit</button>
18
+ </p>
19
+ <pre id="out">booting…</pre>
20
+ <ul id="events"></ul>
21
+
22
+ <script>
23
+ // `janela.invoke(name, args)` and `janela.listen(event, cb)` are injected by
24
+ // janela before the page loads — the Tauri-shaped frontend API.
25
+ window.onload = async () => {
26
+ const out = document.getElementById("out");
27
+ const events = document.getElementById("events");
28
+
29
+ janela.listen("added", (sum) => {
30
+ const li = document.createElement("li");
31
+ li.textContent = "event 'added' from host: " + sum;
32
+ events.prepend(li);
33
+ });
34
+
35
+ out.textContent = await janela.invoke("greet", { name: "__NAME__" });
36
+ await janela.invoke("log", "page loaded");
37
+
38
+ document.getElementById("add").onclick = async () => {
39
+ const a = Number(document.getElementById("a").value);
40
+ const b = Number(document.getElementById("b").value);
41
+ const sum = await janela.invoke("add", { a, b });
42
+ out.textContent = `add(${a}, ${b}) -> ${sum}`;
43
+ };
44
+ document.getElementById("quit").onclick = () => janela.invoke("quit");
45
+ };
46
+ </script>
47
+ </body>
48
+ </html>
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "__NAME__",
3
+ "identifier": "dev.janela.__NAME__",
4
+ "version": "0.1.0",
5
+ "window": {
6
+ "title": "__NAME__",
7
+ "width": 640,
8
+ "height": 420
9
+ }
10
+ }
@@ -0,0 +1,37 @@
1
+ // src-host/main.ts — your app's backend, compiled to native code by scriptc.
2
+ //
3
+ // Register commands here; the page calls them with `await janela.invoke(name, args)`.
4
+ // Handlers receive the args as JSON text and return JSON text (what the
5
+ // frontend promise resolves with).
6
+ //
7
+ // Gotcha inherited from scriptc 0.0.32: never use a bare FFI-backed call as a
8
+ // complete variable initializer — wrap it in any expression (`+ 0`). Plain
9
+ // TypeScript like everything in this file is unaffected.
10
+
11
+ import type { JanelaApp } from "./janela";
12
+
13
+ export function setup(app: JanelaApp): void {
14
+ app.command("add", (argsJson) => {
15
+ const a = JSON.parse(argsJson) as { a: number; b: number };
16
+ const sum = a.a + a.b;
17
+ // Backend→frontend event, just to show the channel exists.
18
+ app.emit("added", JSON.stringify(sum));
19
+ return JSON.stringify(sum);
20
+ });
21
+
22
+ app.command("greet", (argsJson) => {
23
+ const a = JSON.parse(argsJson) as { name: string };
24
+ return JSON.stringify("Hello, " + a.name + " — from the native TS binary");
25
+ });
26
+
27
+ app.command("log", (argsJson) => {
28
+ const a = JSON.parse(argsJson) as string;
29
+ console.log("[host] page says:", a);
30
+ return "null";
31
+ });
32
+
33
+ app.command("quit", (_argsJson) => {
34
+ app.quit();
35
+ return "null";
36
+ });
37
+ }
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Serge Zaitsev
4
+ Copyright (c) 2022 Steffen André Langnes
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,251 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2017 Serge Zaitsev
5
+ * Copyright (c) 2022 Steffen André Langnes
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ #ifndef WEBVIEW_API_H
27
+ #define WEBVIEW_API_H
28
+
29
+ #include "errors.h"
30
+ #include "macros.h"
31
+ #include "types.h"
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ /**
38
+ * Creates a new webview instance.
39
+ *
40
+ * @param debug Enable developer tools if supported by the backend.
41
+ * @param window Optional native window handle, i.e. @c GtkWindow pointer
42
+ * @c NSWindow pointer (Cocoa) or @c HWND (Win32). If non-null,
43
+ * the webview widget is embedded into the given window, and the
44
+ * caller is expected to assume responsibility for the window as
45
+ * well as application lifecycle. If the window handle is null,
46
+ * a new window is created and both the window and application
47
+ * lifecycle are managed by the webview instance.
48
+ * @remark Win32: The function also accepts a pointer to @c HWND (Win32) in the
49
+ * window parameter for backward compatibility.
50
+ * @remark Win32/WebView2: @c CoInitializeEx should be called with
51
+ * @c COINIT_APARTMENTTHREADED before attempting to call this function
52
+ * with an existing window. Omitting this step may cause WebView2
53
+ * initialization to fail.
54
+ * @return @c NULL on failure. Creation can fail for various reasons such
55
+ * as when required runtime dependencies are missing or when window
56
+ * creation fails.
57
+ * @retval WEBVIEW_ERROR_MISSING_DEPENDENCY
58
+ * May be returned if WebView2 is unavailable on Windows.
59
+ */
60
+ WEBVIEW_API webview_t webview_create(int debug, void *window);
61
+
62
+ /**
63
+ * Destroys a webview instance and closes the native window.
64
+ *
65
+ * @param w The webview instance.
66
+ */
67
+ WEBVIEW_API webview_error_t webview_destroy(webview_t w);
68
+
69
+ /**
70
+ * Runs the main loop until it's terminated.
71
+ *
72
+ * @param w The webview instance.
73
+ */
74
+ WEBVIEW_API webview_error_t webview_run(webview_t w);
75
+
76
+ /**
77
+ * Stops the main loop. It is safe to call this function from another
78
+ * background thread.
79
+ *
80
+ * @param w The webview instance.
81
+ */
82
+ WEBVIEW_API webview_error_t webview_terminate(webview_t w);
83
+
84
+ /**
85
+ * Schedules a function to be invoked on the thread with the run/event loop.
86
+ *
87
+ * Since library functions generally do not have thread safety guarantees,
88
+ * this function can be used to schedule code to execute on the main/GUI
89
+ * thread and thereby make that execution safe in multi-threaded applications.
90
+ *
91
+ * @param w The webview instance.
92
+ * @param fn The function to be invoked.
93
+ * @param arg An optional argument passed along to the callback function.
94
+ */
95
+ WEBVIEW_API webview_error_t webview_dispatch(webview_t w,
96
+ void (*fn)(webview_t w, void *arg),
97
+ void *arg);
98
+
99
+ /**
100
+ * Returns the native handle of the window associated with the webview instance.
101
+ * The handle can be a @c GtkWindow pointer (GTK), @c NSWindow pointer (Cocoa)
102
+ * or @c HWND (Win32).
103
+ *
104
+ * @param w The webview instance.
105
+ * @return The handle of the native window.
106
+ */
107
+ WEBVIEW_API void *webview_get_window(webview_t w);
108
+
109
+ /**
110
+ * Get a native handle of choice.
111
+ *
112
+ * @param w The webview instance.
113
+ * @param kind The kind of handle to retrieve.
114
+ * @return The native handle or @c NULL.
115
+ * @since 0.11
116
+ */
117
+ WEBVIEW_API void *webview_get_native_handle(webview_t w,
118
+ webview_native_handle_kind_t kind);
119
+
120
+ /**
121
+ * Updates the title of the native window.
122
+ *
123
+ * @param w The webview instance.
124
+ * @param title The new title.
125
+ */
126
+ WEBVIEW_API webview_error_t webview_set_title(webview_t w, const char *title);
127
+
128
+ /**
129
+ * Updates the size of the native window.
130
+ *
131
+ * Remarks:
132
+ * - Subsequent calls to this function may behave inconsistently across
133
+ * different versions of GTK and windowing systems (X11/Wayland).
134
+ * - Using WEBVIEW_HINT_MAX for setting the maximum window size is not
135
+ * supported with GTK 4 because X11-specific functions such as
136
+ * gtk_window_set_geometry_hints were removed. This option has no effect
137
+ * when using GTK 4.
138
+ *
139
+ * @param w The webview instance.
140
+ * @param width New width.
141
+ * @param height New height.
142
+ * @param hints Size hints.
143
+ */
144
+ WEBVIEW_API webview_error_t webview_set_size(webview_t w, int width, int height,
145
+ webview_hint_t hints);
146
+
147
+ /**
148
+ * Navigates webview to the given URL. URL may be a properly encoded data URI.
149
+ *
150
+ * Example:
151
+ * @code{.c}
152
+ * webview_navigate(w, "https://github.com/webview/webview");
153
+ * webview_navigate(w, "data:text/html,%3Ch1%3EHello%3C%2Fh1%3E");
154
+ * webview_navigate(w, "data:text/html;base64,PGgxPkhlbGxvPC9oMT4=");
155
+ * @endcode
156
+ *
157
+ * @param w The webview instance.
158
+ * @param url URL.
159
+ */
160
+ WEBVIEW_API webview_error_t webview_navigate(webview_t w, const char *url);
161
+
162
+ /**
163
+ * Load HTML content into the webview.
164
+ *
165
+ * Example:
166
+ * @code{.c}
167
+ * webview_set_html(w, "<h1>Hello</h1>");
168
+ * @endcode
169
+ *
170
+ * @param w The webview instance.
171
+ * @param html HTML content.
172
+ */
173
+ WEBVIEW_API webview_error_t webview_set_html(webview_t w, const char *html);
174
+
175
+ /**
176
+ * Injects JavaScript code to be executed immediately upon loading a page.
177
+ * The code will be executed before @c window.onload.
178
+ *
179
+ * @param w The webview instance.
180
+ * @param js JS content.
181
+ */
182
+ WEBVIEW_API webview_error_t webview_init(webview_t w, const char *js);
183
+
184
+ /**
185
+ * Evaluates arbitrary JavaScript code.
186
+ *
187
+ * Use bindings if you need to communicate the result of the evaluation.
188
+ *
189
+ * @param w The webview instance.
190
+ * @param js JS content.
191
+ */
192
+ WEBVIEW_API webview_error_t webview_eval(webview_t w, const char *js);
193
+
194
+ /**
195
+ * Binds a function pointer to a new global JavaScript function.
196
+ *
197
+ * Internally, JS glue code is injected to create the JS function by the
198
+ * given name. The callback function is passed a request identifier,
199
+ * a request string and a user-provided argument. The request string is
200
+ * a JSON array of the arguments passed to the JS function.
201
+ *
202
+ * @param w The webview instance.
203
+ * @param name Name of the JS function.
204
+ * @param fn Callback function.
205
+ * @param arg User argument.
206
+ * @retval WEBVIEW_ERROR_DUPLICATE
207
+ * A binding already exists with the specified name.
208
+ */
209
+ WEBVIEW_API webview_error_t webview_bind(webview_t w, const char *name,
210
+ void (*fn)(const char *id,
211
+ const char *req, void *arg),
212
+ void *arg);
213
+
214
+ /**
215
+ * Removes a binding created with webview_bind().
216
+ *
217
+ * @param w The webview instance.
218
+ * @param name Name of the binding.
219
+ * @retval WEBVIEW_ERROR_NOT_FOUND No binding exists with the specified name.
220
+ */
221
+ WEBVIEW_API webview_error_t webview_unbind(webview_t w, const char *name);
222
+
223
+ /**
224
+ * Responds to a binding call from the JS side.
225
+ *
226
+ * This function is safe to call from another thread.
227
+ *
228
+ * @param w The webview instance.
229
+ * @param id The identifier of the binding call. Pass along the value received
230
+ * in the binding handler (see webview_bind()).
231
+ * @param status A status of zero tells the JS side that the binding call was
232
+ * successful; any other value indicates an error.
233
+ * @param result The result of the binding call to be returned to the JS side.
234
+ * This must either be a valid JSON value or an empty string for
235
+ * the primitive JS value @c undefined.
236
+ */
237
+ WEBVIEW_API webview_error_t webview_return(webview_t w, const char *id,
238
+ int status, const char *result);
239
+
240
+ /**
241
+ * Get the library's version information.
242
+ *
243
+ * @since 0.10
244
+ */
245
+ WEBVIEW_API const webview_version_info_t *webview_version(void);
246
+
247
+ #ifdef __cplusplus
248
+ }
249
+ #endif
250
+
251
+ #endif // WEBVIEW_API_H
@@ -0,0 +1,40 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2017 Serge Zaitsev
5
+ * Copyright (c) 2022 Steffen André Langnes
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ #ifndef WEBVIEW_BACKENDS_HH
27
+ #define WEBVIEW_BACKENDS_HH
28
+
29
+ #if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
30
+
31
+ #include "detail/backends/cocoa_webkit.hh"
32
+ #include "detail/backends/gtk_webkitgtk.hh"
33
+ #include "detail/backends/win32_edge.hh"
34
+
35
+ namespace webview {
36
+ using webview = browser_engine;
37
+ }
38
+
39
+ #endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
40
+ #endif // WEBVIEW_BACKENDS_HH