├── .gitignore
├── src
├── os
│ ├── WebView2Loader.dll
│ ├── Linux
│ │ ├── arm
│ │ │ └── webui-2.so
│ │ ├── x64
│ │ │ └── webui-2.so
│ │ └── arm64
│ │ │ └── webui-2.so
│ ├── Windows
│ │ └── x64
│ │ │ └── webui-2.dll
│ ├── Darwin
│ │ ├── arm64
│ │ │ └── webui-2.dylib
│ │ └── x64
│ │ │ └── webui-2.dylib
│ └── webui.h
├── Cobj.php
├── Base.php
├── JavaScript.php
├── Wrapper.php
├── webui_php.h
└── Webui.php
├── composer.json
├── README.md
└── README-zh-CN.md
/.gitignore:
--------------------------------------------------------------------------------
1 | index.php
2 | index.html
3 | .vscode
4 | .idea
5 | vendor
6 | composer.lock
--------------------------------------------------------------------------------
/src/os/WebView2Loader.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingBes/php-webui-composer/HEAD/src/os/WebView2Loader.dll
--------------------------------------------------------------------------------
/src/os/Linux/arm/webui-2.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingBes/php-webui-composer/HEAD/src/os/Linux/arm/webui-2.so
--------------------------------------------------------------------------------
/src/os/Linux/x64/webui-2.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingBes/php-webui-composer/HEAD/src/os/Linux/x64/webui-2.so
--------------------------------------------------------------------------------
/src/os/Linux/arm64/webui-2.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingBes/php-webui-composer/HEAD/src/os/Linux/arm64/webui-2.so
--------------------------------------------------------------------------------
/src/os/Windows/x64/webui-2.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingBes/php-webui-composer/HEAD/src/os/Windows/x64/webui-2.dll
--------------------------------------------------------------------------------
/src/os/Darwin/arm64/webui-2.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingBes/php-webui-composer/HEAD/src/os/Darwin/arm64/webui-2.dylib
--------------------------------------------------------------------------------
/src/os/Darwin/x64/webui-2.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/KingBes/php-webui-composer/HEAD/src/os/Darwin/x64/webui-2.dylib
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "kingbes/webui",
3 | "description": "webui 绑定 php 实现跨平台桌面应用",
4 | "keywords": [
5 | "composer",
6 | "webui",
7 | "php",
8 | "desktop",
9 | "FFI"
10 | ],
11 | "license": "MIT",
12 | "authors": [
13 | {
14 | "name": "kingbes",
15 | "email": "1164601554@qq.com"
16 | }
17 | ],
18 | "require": {
19 | "php": ">=8.1.0",
20 | "ext-ffi": "*",
21 | "ffi/work-directory": "^1.0"
22 | },
23 | "autoload": {
24 | "psr-4": {
25 | "Kingbes\\": "src/"
26 | }
27 | },
28 | "minimum-stability": "dev",
29 | "prefer-stable": true,
30 | "config": {
31 | "sort-packages": true
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Cobj.php:
--------------------------------------------------------------------------------
1 | new("struct webui_event_t");
25 | }
26 |
27 | /**
28 | * web配置
29 | *
30 | * 控制' webui_show() ', ' webui_show_browser() '和
31 | * ' webui_show_wv() '应该等待窗口连接
32 | * before是否返回。
33 | * 默认值:True
34 | * show_wait_connection = 0,
35 | *
36 | * 控制web是否应该阻塞和处理UI事件
37 | * 在一个线程中一次处理一个' True ',或者处理每一个
38 | * 一个新的非阻塞线程中的事件' False '。这个更新
39 | * 所有窗口。你可以使用' webui_set_event_blocking() '
40 | * 一个特定的单窗口更新。
41 | * 默认值:False
42 | * ui_event_blocking,
43 | *
44 | * 自动刷新窗口UI
45 | * 根目录被更改。
46 | * 默认值:False
47 | * folder_monitor,
48 | *
49 | * 允许多个客户端连接到同一个窗口
50 | * 这对web应用程序(非桌面软件)很有帮助,
51 | * 详细信息请参考文档。
52 | * 默认值:False
53 | * multi_client,
54 | *
55 | * 允许多个客户端连接到同一个窗口
56 | * 这对web应用程序(非桌面软件)很有帮助,
57 | * 详细信息请参考文档。
58 | * 默认值:False
59 | * use_cookies,
60 | *
61 | * @return object
62 | */
63 | public function config(): object
64 | {
65 | return self::$ffi->new("webui_config");
66 | }
67 |
68 | /**
69 | * ffi function
70 | *
71 | * @return mixed
72 | */
73 | public function ffi(): mixed
74 | {
75 | return self::$ffi;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | 
4 |
5 | # WebUI for PHP
6 |
7 | [build-status]: https://img.shields.io/github/actions/workflow/status/webui-dev/webui/ci.yml?branch=main&style=for-the-badge&logo=githubactions&labelColor=414868&logoColor=C0CAF5
8 | [last-commit]: https://img.shields.io/github/last-commit/webui-dev/webui?style=for-the-badge&logo=github&logoColor=C0CAF5&labelColor=414868
9 | [release-version]: https://img.shields.io/github/v/tag/webui-dev/webui?style=for-the-badge&logo=webtrees&logoColor=C0CAF5&labelColor=414868&color=7664C6
10 | [license]: https://img.shields.io/github/license/webui-dev/webui?style=for-the-badge&logo=opensourcehardware&label=License&logoColor=C0CAF5&labelColor=414868&color=8c73cc
11 |
12 | [![][build-status]](https://github.com/webui-dev/webui/actions?query=branch%3Amain)
13 | [![][last-commit]](https://github.com/webui-dev/webui/pulse)
14 | [![][release-version]](https://github.com/webui-dev/webui/releases/latest)
15 | [![][license]](https://github.com/webui-dev/webui/blob/main/LICENSE)
16 |
17 | >Use any web browser or WebView as GUI, with your preferred language in the backend and modern web technologies in the frontend, all in a lightweight portable library.
18 |
19 | 
20 |
21 |
22 |
23 | [中文自述](/README-zh-CN.md)
24 |
25 | # composer
26 |
27 | ```shell
28 | composer require kingbes/webui
29 | ```
30 |
31 | | require | |
32 | | ---- | ---- |
33 | | PHP | 8.1+ |
34 | | FFI | * |
35 | | Windows-x64 | true |
36 | | Linux-x64 | true |
37 | | Linux-arm | To be tested |
38 | | Linux-arm64 | To be tested |
39 | | MacOs-x64 | To be tested |
40 | | MacOs-arm64 | To be tested |
41 |
42 |
43 | # example
44 |
45 | 1. Example I
46 |
47 | index.html
48 |
49 | ```html
50 |
51 |
52 |
53 |
54 |
55 |
56 | Document
57 |
58 |
59 |
60 |
61 |
62 | asd
63 |
70 |
71 |
72 |
73 | ```
74 |
75 | index.php
76 |
77 | ```php
78 | require "./vendor/autoload.php";
79 |
80 | use Kingbes\Webui;
81 | use Kingbes\JavaScript;
82 |
83 | $Webui = new Webui;
84 | $html = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . "index.html");
85 | $window = $Webui->newWindow();
86 | $bind = $Webui->bind($window, "hello", function ($event, JavaScript $js) {
87 | // Gets the first argument as a string
88 | $arg_one = $js->getString($event);
89 | var_dump($arg_one);
90 |
91 | // return string
92 | $js->returnString($event, "nihao");
93 | });
94 | $Webui->show($window, $html);
95 | $Webui->wait();
96 | $Webui->clean();
97 | ```
98 |
99 | ## Various usage instructions
100 |
101 | 1. `Webui` Webui class
102 | 2. `JavaScript` Used to interact with js bindings
103 | 3. `Wrapper` Wrappers that wrap the entire interaction, etc
104 | 4. `Cobj` Wrappers, which wrap the entire interaction with other C object classes, some functions may be required
105 |
106 | # MORE
107 |
108 | [website](https://webui.me/)
109 |
--------------------------------------------------------------------------------
/src/Base.php:
--------------------------------------------------------------------------------
1 | library());
24 | }
25 | }
26 |
27 | /**
28 | * 获取ffi
29 | *
30 | * @return \FFI
31 | */
32 | public function getFfi(): \FFI
33 | {
34 | return self::$ffi;
35 | }
36 |
37 | /**
38 | * 库文件 function
39 | *
40 | * @return string
41 | */
42 | protected function library(): string
43 | {
44 | if ($this->libraryFile !== null) {
45 | return $this->libraryFile;
46 | }
47 | $this->libraryFile = $this->osFamily();
48 | return $this->libraryFile;
49 | }
50 |
51 | /**
52 | * 库文件路径 function
53 | *
54 | * @return string
55 | */
56 | protected function osFamily(): string
57 | {
58 | switch (PHP_OS_FAMILY) {
59 | case "Linux":
60 | $arch = php_uname('m');
61 | if ($arch === 'x86_64') {
62 | return __DIR__ . DIRECTORY_SEPARATOR . "os"
63 | . DIRECTORY_SEPARATOR . "Linux"
64 | . DIRECTORY_SEPARATOR . "x64"
65 | . DIRECTORY_SEPARATOR . "webui-2.so";
66 | } elseif ($arch === 'arm' || $arch === 'armv7l') {
67 | return __DIR__ . DIRECTORY_SEPARATOR . "os"
68 | . DIRECTORY_SEPARATOR . "Linux"
69 | . DIRECTORY_SEPARATOR . "arm"
70 | . DIRECTORY_SEPARATOR . "webui-2.so";
71 | } elseif ($arch === 'aarch64') {
72 | return __DIR__ . DIRECTORY_SEPARATOR . "os"
73 | . DIRECTORY_SEPARATOR . "Linux"
74 | . DIRECTORY_SEPARATOR . "arm64"
75 | . DIRECTORY_SEPARATOR . "webui-2.so";
76 | } else {
77 | throw new \Exception("linux supports only x64, arm, and arm64");
78 | }
79 | break;
80 | case "Darwin":
81 | $unameOutput = '';
82 | exec('uname -m', $unameOutput);
83 | if (in_array(trim($unameOutput[0]), ['X86_64', 'x86_64'])) {
84 | return __DIR__ . DIRECTORY_SEPARATOR . "os"
85 | . DIRECTORY_SEPARATOR . "Darwin"
86 | . DIRECTORY_SEPARATOR . "x64"
87 | . DIRECTORY_SEPARATOR . "webui-2.dylib";
88 | } elseif (in_array(trim($unameOutput[0]), ['ARM64', 'arm64'])) {
89 | return __DIR__ . DIRECTORY_SEPARATOR . "os"
90 | . DIRECTORY_SEPARATOR . "Darwin"
91 | . DIRECTORY_SEPARATOR . "arm64"
92 | . DIRECTORY_SEPARATOR . "webui-2.dylib";
93 | } else {
94 | throw new \Exception("Only macos x64 and arm64 are supported");
95 | }
96 | break;
97 | case "Windows":
98 | if (PHP_INT_SIZE == 8) {
99 | return __DIR__ . DIRECTORY_SEPARATOR . "os"
100 | . DIRECTORY_SEPARATOR . "Windows"
101 | . DIRECTORY_SEPARATOR . "x64"
102 | . DIRECTORY_SEPARATOR . "webui-2.dll";
103 | } else {
104 | throw new \Exception("windows 32-bit system is not supported");
105 | }
106 | break;
107 | default:
108 | throw new \Exception("Os is not supported, Only Linux, MacOs and windows are only supported by default!");
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/src/JavaScript.php:
--------------------------------------------------------------------------------
1 | webui_close_client($event);
22 | }
23 |
24 | /**
25 | * 安全地将原始数据发送到UI。单一的客户端。
26 | *
27 | * @param object $event
28 | * @param string $func js函数名
29 | * @param mixed $raw C的const void *
30 | * @param integer $size 大小
31 | * @return void
32 | */
33 | public function sendRawClient(object $event, string $func, mixed $raw, int $size): void
34 | {
35 | self::$ffi->webui_send_raw_client($event, $func, $raw, $size);
36 | }
37 |
38 | /**
39 | * 导航到特定的URL。单一的客户端。
40 | *
41 | * @param object $event
42 | * @param string $url 链接
43 | * @example 示例 navigateClient($event,"http://domain.com");
44 | * @return void
45 | */
46 | public function navigateClient(object $event, string $url): void
47 | {
48 | self::$ffi->webui_navigate_client($event, $url);
49 | }
50 |
51 | /**
52 | * 运行JavaScript而不等待响应。单一的客户端。
53 | *
54 | * @param object $event
55 | * @param string $js js字符串
56 | * @example 示例 runClient($event,"alert('Hello');");
57 | * @return void
58 | */
59 | public function runClient(object $event, string $js): void
60 | {
61 | self::$ffi->webui_run_client($event, $js);
62 | }
63 |
64 | /**
65 | * 运行JavaScript并获得响应。单一的客户端。确保您的本地缓冲区可以保存响应。
66 | *
67 | * @param object $event
68 | * @param string $js js字符串
69 | * @param integer $timeout 等待时间
70 | * @param mixed $buffer 缓冲对象 C的char *类型
71 | * @param integer $bufferLength 缓冲长度
72 | * @example 示例 scriptClient($window,"return 4 + 6;",$buffer,$bufferLength);
73 | * @return boolean
74 | */
75 | public function scriptClient(object $event, string $js, int $timeout, mixed $buffer, int $bufferLength): bool
76 | {
77 | return self::$ffi->webui_script_client($event, $js, $timeout, $buffer, $bufferLength);
78 | }
79 |
80 | /**
81 | * 得到事件中有多少个参数。
82 | *
83 | * @param object $event
84 | * @return integer
85 | */
86 | public function getCount(object $event): int
87 | {
88 | return self::$ffi->webui_get_count($event);
89 | }
90 |
91 | /**
92 | * 在特定索引处获取参数为整数。
93 | *
94 | * @param object $event
95 | * @param integer $index 索引
96 | * @example 示例 $myNum = getIntAt($event,0);
97 | * @return integer
98 | */
99 | public function getIntAt(object $event, int $index): int
100 | {
101 | return self::$ffi->webui_get_int_at($event, $index);
102 | }
103 |
104 | /**
105 | * 获取第一个参数为整数。
106 | *
107 | * @param object $event
108 | * @example 示例 $myNum = getInt($event);
109 | * @return integer
110 | */
111 | public function getInt(object $event): int
112 | {
113 | return self::$ffi->webui_get_int($event);
114 | }
115 |
116 | /**
117 | * 在特定索引处获取float参数。
118 | *
119 | * @param object $event
120 | * @param integer $index 索引
121 | * @example 示例 $myfloat = getFloatAt($event, 0);
122 | * @return float
123 | */
124 | public function getFloatAt(object $event, int $index): float
125 | {
126 | return self::$ffi->webui_get_float_at($event, $index);
127 | }
128 |
129 | /**
130 | * 获取第一个参数为float。
131 | *
132 | * @param object $event
133 | * @example 示例 $myfloat = getFloat($event);
134 | * @return float
135 | */
136 | public function getFloat(object $event): float
137 | {
138 | return self::$ffi->webui_get_float($event);
139 | }
140 |
141 | /**
142 | * 在特定索引处以字符串形式获取参数。
143 | *
144 | * @param object $event
145 | * @param integer $index 索引
146 | * @example 示例 $myString = getStringAt($event, 0);
147 | * @return string
148 | */
149 | public function getStringAt(object $event, int $index): string
150 | {
151 | return self::$ffi->webui_get_string_at($event, $index);
152 | }
153 |
154 | /**
155 | * 获取第一个参数为字符串。
156 | *
157 | * @param object $event
158 | * @example 示例 $myString = getString($event);
159 | * @return string
160 | */
161 | public function getString(object $event): string
162 | {
163 | return self::$ffi->webui_get_string($event);
164 | }
165 |
166 | /**
167 | * 在特定索引处获取一个布尔参数。
168 | *
169 | * @param object $event
170 | * @param integer $index 索引
171 | * @example 示例 $myBool = getBoolAt($event, 0);
172 | * @return boolean
173 | */
174 | public function getBoolAt(object $event, int $index): bool
175 | {
176 | return self::$ffi->webui_get_bool_at($event, $index);
177 | }
178 |
179 | /**
180 | * 获取第一个参数为布尔值。
181 | *
182 | * @param object $event
183 | * @example 示例 $myBool = getBool($event);
184 | * @return boolean
185 | */
186 | public function getBool(object $event): bool
187 | {
188 | return self::$ffi->webui_get_bool($event);
189 | }
190 |
191 | /**
192 | * 获取特定索引处参数的大小(以字节为单位)。
193 | *
194 | * @param object $event
195 | * @param integer $index 索引
196 | * @example 示例 $mySzie = getSizeAt($event, 0);
197 | * @return integer
198 | */
199 | public function getSizeAt(object $event, int $index): int
200 | {
201 | return self::$ffi->webui_get_size_at($event, $index);
202 | }
203 |
204 | /**
205 | * 获取第一个参数的字节大小。
206 | *
207 | * @param object $event
208 | * @example 示例 $mySzie = getSizeAt($event);
209 | * @return integer
210 | */
211 | public function getSize(object $event): int
212 | {
213 | return self::$ffi->webui_get_size($event);
214 | }
215 |
216 | /**
217 | * 将响应作为整数返回给JavaScript。
218 | *
219 | * @param object $event
220 | * @param integer $num
221 | * @example 示例 returnInt($event, 123);
222 | * @return void
223 | */
224 | public function returnInt(object $event, int $num): void
225 | {
226 | self::$ffi->webui_return_int($event, $num);
227 | }
228 |
229 | /**
230 | * 将响应作为浮点数返回给JavaScript。
231 | *
232 | * @param object $event
233 | * @param float $double 浮点
234 | * @example 示例 returnFloat($event,123.456);
235 | * @return void
236 | */
237 | public function returnFloat(object $event, float $double): void
238 | {
239 | self::$ffi->webui_return_float($event, $double);
240 | }
241 |
242 | /**
243 | * 将响应作为字符串返回给JavaScript。
244 | *
245 | * @param object $event
246 | * @param string $str 字符串
247 | * @example 示例 returnString($event,"hello world");
248 | * @return void
249 | */
250 | public function returnString(object $event, string $str): void
251 | {
252 | self::$ffi->webui_return_string($event, $str);
253 | }
254 |
255 | /**
256 | * 将响应作为布尔值返回给JavaScript。
257 | *
258 | * @param object $event
259 | * @param boolean $bool
260 | * @return void
261 | */
262 | public function returnBool(object $event, bool $boolean): void
263 | {
264 | self::$ffi->webui_return_bool($event, $boolean);
265 | }
266 | }
267 |
--------------------------------------------------------------------------------
/src/Wrapper.php:
--------------------------------------------------------------------------------
1 | new('void (*)(size_t, size_t, char *, size_t, size_t)');
27 | $callback = function ($param1, $param2, $param3, $param4, $param5) use ($func) {
28 | $phpParam3 = self::$ffi->string($param3);
29 | $func($param1, $param2, $phpParam3, $param4, $param5);
30 | };
31 | return self::$ffi->webui_interface_bind($window, $element, $callback);
32 | }
33 |
34 | /**
35 | * 当使用' interfaceBind() '时,你可能需要这个函数来方便地设置响应。
36 | *
37 | * @param integer $window 窗口对象
38 | * @param integer $eventNumber $event对象的event_number
39 | * @param string $response 字符串
40 | * @example 示例 interfaceSetResponse($window,$event[0]->event_number,"Response...");
41 | * @return void
42 | */
43 | public function interfaceSetResponse(int $window, int $eventNumber, string $response): void
44 | {
45 | self::$ffi->webui_interface_set_response($window, $eventNumber, $response);
46 | }
47 |
48 | /**
49 | * 检查应用程序是否仍在运行。
50 | *
51 | * @return boolean
52 | */
53 | public function interfaceIsAppRunning(): bool
54 | {
55 | return self::$ffi->webui_interface_is_app_running();
56 | }
57 |
58 | /**
59 | * 获取唯一的窗口ID。
60 | *
61 | * @param integer $window 窗口对象
62 | * @return integer
63 | */
64 | public function interfaceGetWindowId(int $window): int
65 | {
66 | return self::$ffi->webui_interface_get_window_id($window);
67 | }
68 |
69 | /**
70 | * 在特定索引处以字符串形式获取参数。
71 | *
72 | * @param integer $window 窗口对象
73 | * @param integer $eventNumber $event对象的event_number
74 | * @param integer $index 索引
75 | * @example 示例 $myStr = interfaceGetStringAt($window, $event[0]->event_number, 0);
76 | * @return string
77 | */
78 | public function interfaceGetStringAt(int $window, int $eventNumber, int $index): string
79 | {
80 | return self::webui_interface_get_string_at($window, $eventNumber, $index);
81 | }
82 |
83 | /**
84 | * 在特定索引处获取参数为整数。
85 | *
86 | * @param integer $window 窗口对象
87 | * @param integer $eventNumber $event对象的event_number
88 | * @param integer $index 索引
89 | * @example 示例 $myNum = interfaceGetIntAt($window, $event[0]->event_number, 0);
90 | * @return integer
91 | */
92 | public function interfaceGetIntAt(int $window, int $eventNumber, int $index): int
93 | {
94 | return self::webui_interface_get_int_at($window, $eventNumber, $index);
95 | }
96 |
97 | /**
98 | * 在特定索引处获取float参数。
99 | *
100 | * @param integer $window 窗口对象
101 | * @param integer $eventNumber $event对象的event_number
102 | * @param integer $index 索引
103 | * @example 示例 $myFloat = interfaceGetFloatAt($window, $event[0]->event_number, 0);
104 | * @return float
105 | */
106 | public function interfaceGetFloatAt(int $window, int $eventNumber, int $index): float
107 | {
108 | return self::$ffi->webui_interface_get_float_at($window, $eventNumber, $index);
109 | }
110 |
111 | /**
112 | * 在特定索引处获取一个布尔参数。
113 | *
114 | * @param integer $window 窗口对象
115 | * @param integer $eventNumber $event对象的event_number
116 | * @param integer $index 索引
117 | * @example 示例 $myBool = interfaceGetBoolAt($window, $event[0]->event_number, 0);
118 | * @return boolean
119 | */
120 | public function interfaceGetBoolAt(int $window, int $eventNumber, int $index): bool
121 | {
122 | return self::$ffi->webui_interface_get_bool_at($window, $eventNumber, $index);
123 | }
124 |
125 | /**
126 | * 获取特定索引处参数的大小(以字节为单位)。
127 | *
128 | * @param integer $window 窗口对象
129 | * @param integer $eventNumber $event对象的event_number
130 | * @param integer $index 索引
131 | * @example 示例 $mySize = interfaceGetSizeAt($window, $event[0]->event_number, 0);
132 | * @return integer
133 | */
134 | public function interfaceGetSizeAt(int $window, int $eventNumber, int $index): int
135 | {
136 | return self::$ffi->webui_interface_get_size_at($window, $eventNumber, $index);
137 | }
138 |
139 | /**
140 | * 如果你的后端需要异步,使用这个API来设置一个文件处理程序响应
141 | * 响应‘ setFileHandler() ’。
142 | *
143 | * @param integer $window 窗口对象
144 | * @param string $response 响应缓冲区字符串
145 | * @param integer $length 响应长度
146 | * @example 示例 interfaceSetResponseFileHandler($window, $response, 1024);
147 | * @return void
148 | */
149 | public function interfaceSetResponseFileHandler(int $window, string $response, int $length): void
150 | {
151 | self::$ffi->webui_interface_set_response_file_handler($window, $response, $length);
152 | }
153 |
154 | /**
155 | * 使用嵌入的HTML或文件显示窗口。如果窗口已经
156 | * 打开,会刷新。单一的客户端。
157 | *
158 | * @param integer $window 窗口对象号
159 | * @param integer $eventNumber 事件号
160 | * @param string $content HTML、URL或本地文件
161 | * @return boolean
162 | */
163 | public function interfaceShowClient(int $window, int $eventNumber, string $content): bool
164 | {
165 | return self::$ffi->webui_interface_show_client($window, $eventNumber, $content);
166 | }
167 |
168 | /**
169 | * 关闭特定客户端。
170 | *
171 | * @param integer $window 窗口对象号
172 | * @param integer $eventNumber 事件号
173 | * @return void
174 | */
175 | public function interfaceCloseClient(int $window, int $eventNumber): void
176 | {
177 | self::$ffi->webui_interface_close_client($window, $eventNumber);
178 | }
179 |
180 | /**
181 | * 安全地将原始数据发送到UI。单一的客户端。
182 | *
183 | * @param integer $window 窗口对象
184 | * @param integer $eventNumber 事件号
185 | * @param string $data 接收原始数据的JavaScript函数
186 | * myFunc(myData){}`
187 | * @param mixed $raw 原始数据缓冲区
188 | * @param integer $size 原始数据大小(以字节为单位)
189 | * @return void
190 | */
191 | public function interfaceSendRawClient(int $window, int $eventNumber, string $data, mixed $raw, int $size): void
192 | {
193 | self::$ffi->webui_interface_send_raw_client($window, $eventNumber, $data, $raw, $size);
194 | }
195 |
196 | /**
197 | * 导航到特定的URL。单一的客户端。
198 | *
199 | * @param integer $window 窗口号
200 | * @param integer $eventNumber 事件号
201 | * @param string $url 完整的HTTP URL
202 | * @example navigateClient($e,"http://domain.com")
203 | * @return void
204 | */
205 | public function interfaceNavigateClient(int $window, int $eventNumber, string $url): void
206 | {
207 | self::$ffi->webui_interface_navigate_client($window, $eventNumber, $url);
208 | }
209 |
210 | /**
211 | * 运行JavaScript而不等待响应。单一的客户端。
212 | *
213 | * @param integer $window 窗口对象
214 | * @param integer $eventNumber 事件号
215 | * @param string $js 要运行的JavaScript
216 | * @example 示例 interfaceRunClient($window, $event[0]->event_number, "alert('Hello World!')");
217 | * @return void
218 | */
219 | public function interfaceRunClient(int $window, int $eventNumber, string $js): void
220 | {
221 | self::$ffi->webui_interface_run_client($window, $eventNumber, $js);
222 | }
223 |
224 | /**
225 | * 运行JavaScript并获得响应。单一的客户端。
226 | * 确保您的本地缓冲区可以保存响应。
227 | *
228 | * @param integer $window 窗口对象
229 | * @param integer $eventNumber 事件号
230 | * @param string $js 要运行的JavaScript
231 | * @param integer $timeout 等待时间
232 | * @param mixed $buffer 缓冲对象 C的char *类型
233 | * @param integer $bufferLength 缓冲长度
234 | * @return boolean true表示成功,false表示失败
235 | */
236 | public function interfaceScriptClient(int $window, int $eventNumber, string $js, int $timeout, mixed $buffer, int $bufferLength): bool
237 | {
238 | return self::$ffi->webui_interface_script_client($window, $eventNumber, $js, $timeout, $buffer, $bufferLength);
239 | }
240 | }
241 |
--------------------------------------------------------------------------------
/src/webui_php.h:
--------------------------------------------------------------------------------
1 | // -- Enums ---------------------------
2 | enum webui_browser
3 | { // 浏览器
4 | NoBrowser = 0, // 0. 无浏览器
5 | AnyBrowser = 1, // 1. Default recommended web browser
6 | Chrome, // 2. Google Chrome
7 | Firefox, // 3. Mozilla Firefox
8 | Edge, // 4. Microsoft Edge
9 | Safari, // 5. Apple Safari
10 | Chromium, // 6. The Chromium Project
11 | Opera, // 7. Opera Browser
12 | Brave, // 8. The Brave Browser
13 | Vivaldi, // 9. The Vivaldi Browser
14 | Epic, // 10. The Epic Browser
15 | Yandex, // 11. The Yandex Browser
16 | ChromiumBased, // 12. Any Chromium based browser
17 | Webview, // 13. WebView (Non-web-browser)
18 | };
19 |
20 | enum webui_runtime
21 | {
22 | None = 0, // 0. Prevent WebUI from using any runtime for .js and .ts files
23 | Deno, // 1. Use Deno runtime for .js and .ts files
24 | NodeJS, // 2. Use Nodejs runtime for .js files
25 | Bun, // 3. Use Bun runtime for .js and .ts files
26 | };
27 |
28 | enum webui_event
29 | {
30 | WEBUI_EVENT_DISCONNECTED = 0, // 0. Window disconnection event
31 | WEBUI_EVENT_CONNECTED, // 1. Window connection event
32 | WEBUI_EVENT_MOUSE_CLICK, // 2. Mouse click event
33 | WEBUI_EVENT_NAVIGATION, // 3. Window navigation event
34 | WEBUI_EVENT_CALLBACK, // 4. Function call event
35 | };
36 |
37 | typedef struct webui_event_t
38 | {
39 | size_t window; // 窗口对象号
40 | size_t event_type; // 事件类型
41 | const char *element; // HTML元素ID
42 | size_t event_number; // 内部WebUI
43 | size_t bind_id; // 绑定 id
44 | size_t client_id; // 客户端唯一ID
45 | size_t connection_id; // 客户端连接ID
46 | const char *cookies; // 客户的全部 cookies
47 | } webui_event_t;
48 |
49 | typedef enum
50 | {
51 | // 控制' webui_show() ', ' webui_show_browser() '和
52 | // ' webui_show_wv() '应该等待窗口连接
53 | // before是否返回。
54 | //
55 | // 默认值:True
56 | show_wait_connection = 0,
57 | // 控制web是否应该阻塞和处理UI事件
58 | // 在一个线程中一次处理一个' True ',或者处理每一个
59 | // 一个新的非阻塞线程中的事件' False '。这个更新
60 | // 所有窗口。你可以使用' webui_set_event_blocking() '
61 | // 一个特定的单窗口更新。
62 | //
63 | // 默认值:False
64 | ui_event_blocking,
65 | // 自动刷新窗口UI
66 | // 根目录被更改。
67 | //
68 | // 默认值:False
69 | folder_monitor,
70 | // 允许多个客户端连接到同一个窗口
71 | // 这对web应用程序(非桌面软件)很有帮助,
72 | // 详细信息请参考文档。
73 | //
74 | // 默认值:False
75 | multi_client,
76 | // 允许多个客户端连接到同一个窗口
77 | // 这对web应用程序(非桌面软件)很有帮助,
78 | // 详细信息请参考文档。
79 | //
80 | // 默认值:False
81 | use_cookies,
82 | } webui_config;
83 |
84 | // -- 定义 ---------------------
85 |
86 | // 创建一个新的web窗口对象。
87 | // size_t myWindow = webui_new_window();
88 | size_t webui_new_window(void);
89 |
90 | // 使用指定的窗口号创建新的web窗口对象。
91 | // size_t myWindow = webui_new_window_id(123);
92 | size_t webui_new_window_id(size_t window_number);
93 |
94 | // 获得一个可以使用的免费窗口对象
95 | // size_t myWindowNumber = webui_get_new_window_id();
96 | size_t webui_get_new_window_id(void);
97 |
98 | // 用后端函数绑定一个HTML元素和一个JavaScript对象。空元素名称表示所有事件。
99 | // webui_bind(myWindow, "myFunction", myFunction);
100 | size_t webui_bind(size_t window, const char *element, void (*func)(webui_event_t *e));
101 |
102 | // 获取要使用的推荐web浏览器ID。如果您已经使用了一个ID,则此函数将返回相同的ID。
103 | // size_t browserID = webui_get_best_browser(myWindow);
104 | size_t webui_get_best_browser(size_t window);
105 |
106 | // 使用嵌入的HTML或文件显示窗口。如果窗口已经打开,它将被刷新。这将刷新多客户端模式下的所有窗口。
107 | // webui_show(myWindow, "..."); | webui_show(myWindow, "index.html"); | webui_show(myWindow, "http://...");
108 | bool webui_show(size_t window, const char *content);
109 |
110 | // 使用嵌入的HTML或文件显示窗口。如果窗口已经打开,它将被刷新。单一的客户端。
111 | // webui_show_client(e, "..."); | webui_show_client(e, "index.html"); | webui_show_client(e, "http://...");
112 | bool webui_show_client(webui_event_t *e, const char *content);
113 |
114 | // 与' webui_show() '相同。但是使用特定的网络浏览器。
115 | // webui_show_browser(myWindow, "...", Chrome); | webui_show(myWindow, "index.html", Firefox);
116 | bool webui_show_browser(size_t window, const char *content, size_t browser);
117 |
118 | // 与' webui_show() '相同。但是只启动web服务器并返回URL。不会显示任何窗口。
119 | // const char* url = webui_start_server(myWindow, "/full/root/path");
120 | const char *webui_start_server(size_t window, const char *content);
121 |
122 | // 使用嵌入的HTML或文件显示WebView窗口。如果窗口已经打开,它将被刷新。注意:Win32需要' WebView2Loader.dll '。
123 | // webui_show_wv(myWindow, "..."); | webui_show_wv(myWindow, "index.html"); | webui_show_wv(myWindow, "http://...");
124 | bool webui_show_wv(size_t window, const char *content);
125 |
126 | // 将窗口设置为Kiosk模式(全屏)。
127 | // webui_set_kiosk(myWindow, true);
128 | void webui_set_kiosk(size_t window, bool status);
129 |
130 | // 设置具有高对比度支持的窗口。当你想用CSS构建一个更好的高对比度主题时非常有用。
131 | // webui_set_high_contrast(myWindow, true);
132 | void webui_set_high_contrast(size_t window, bool status);
133 |
134 | // 获得操作系统高对比度偏好。
135 | // bool hc = webui_is_high_contrast();
136 | bool webui_is_high_contrast(void);
137 |
138 | // 检查是否安装了浏览器。
139 | // bool status = webui_browser_exist(Chrome);
140 | bool webui_browser_exist(size_t browser);
141 |
142 | // 等到所有开着的窗户都关上了。
143 | // webui_wait();
144 | void webui_wait(void);
145 |
146 | // 仅关闭特定窗口。窗口对象仍然存在。所有的客户。
147 | // webui_close(myWindow);
148 | void webui_close(size_t window);
149 |
150 | // 关闭特定客户端。
151 | // webui_close_client(e);
152 | void webui_close_client(webui_event_t *e);
153 |
154 | // 关闭特定窗口并释放所有内存资源。
155 | // webui_destroy(myWindow);
156 | void webui_destroy(size_t window);
157 |
158 | // 关闭所有打开的窗口。' webui_wait() '将返回(Break)。
159 | // webui_exit();
160 | void webui_exit(void);
161 |
162 | // 为特定窗口设置web服务器根文件夹路径。
163 | // webui_set_root_folder(myWindow, "/home/Foo/Bar/");
164 | bool webui_set_root_folder(size_t window, const char *path);
165 |
166 | // 设置所有windows的web服务器根文件夹路径。应该使用在' webui_show() '之前。
167 | // webui_set_default_root_folder("/home/Foo/Bar/");
168 | bool webui_set_default_root_folder(const char *path);
169 |
170 | // 设置一个自定义处理程序来提供文件。这个自定义处理程序应该返回完整的HTTP报头和正文。
171 | // webui_set_file_handler(myWindow, myHandlerFunction);
172 | void webui_set_file_handler(size_t window, const void *(*handler)(const char *filename, int *length));
173 |
174 | // 检查指定的窗口是否仍在运行。
175 | // webui_is_shown(myWindow);
176 | bool webui_is_shown(size_t window);
177 |
178 | // 设置等待窗口连接的最大时间(以秒为单位)。这个效果是' show() '和' wait() '。值“0”表示永远等待。
179 | // webui_set_timeout(30);
180 | void webui_set_timeout(size_t second);
181 |
182 | // 设置默认的嵌入HTML图标。
183 | // webui_set_icon(myWindow, "... ", "image/svg+xml");
184 | void webui_set_icon(size_t window, const char *icon, const char *icon_type);
185 |
186 | // 将文本编码为Base64。返回的缓冲区需要被释放。
187 | // char* base64 = webui_encode("Foo Bar");
188 | const char *webui_encode(const char *str);
189 |
190 | // 解码Base64编码的文本。返回的缓冲区需要被释放。
191 | // char* str = webui_decode("SGVsbG8=");
192 | const char *webui_decode(const char *str);
193 |
194 | // 安全地释放由web使用' webui_malloc() '分配的缓冲区。
195 | // webui_free(myBuffer);
196 | void webui_free(void *ptr);
197 |
198 | // 通过web内存管理系统安全分配内存。它可以在任何时候使用' webui_free() '安全地释放。
199 | // char* myBuffer = (char*)webui_malloc(1024);
200 | void *webui_malloc(size_t size);
201 |
202 | // 安全地将原始数据发送到UI。所有的客户。
203 | // webui_send_raw(myWindow, "myJavaScriptFunc", myBuffer, 64);
204 | void webui_send_raw(size_t window, const char *function, const void *raw, size_t size);
205 |
206 | // 安全地将原始数据发送到UI。单一的客户端。
207 | // webui_send_raw_client(e, "myJavaScriptFunc", myBuffer, 64);
208 | void webui_send_raw_client(webui_event_t *e, const char *function, const void *raw, size_t size);
209 |
210 | // 设置窗口为隐藏模式。应该在' webui_show() '之前调用。
211 | // webui_set_hide(myWindow, True);
212 | void webui_set_hide(size_t window, bool status);
213 |
214 | // 设置窗口大小。
215 | // webui_set_size(myWindow, 800, 600);
216 | void webui_set_size(size_t window, unsigned int width, unsigned int height);
217 |
218 | // 设置窗口位置。
219 | // webui_set_position(myWindow, 100, 100);
220 | void webui_set_position(size_t window, unsigned int x, unsigned int y);
221 |
222 | // 设置要使用的web浏览器配置文件。空的“name”和“path”表示默认的用户配置文件。需要在' webui_show() '之前调用。
223 | // webui_set_profile(myWindow, "Bar", "/Home/Foo/Bar"); | webui_set_profile(myWindow, "", "");
224 | void webui_set_profile(size_t window, const char *name, const char *path);
225 |
226 | // 设置使用的web浏览器代理服务器。需要在' webui_show() '之前调用。
227 | // webui_set_proxy(myWindow, "http://127.0.0.1:8888");
228 | void webui_set_proxy(size_t window, const char *proxy_server);
229 |
230 | // 获取正在运行的窗口的当前URL。
231 | // const char* url = webui_get_url(myWindow);
232 | const char *webui_get_url(size_t window);
233 |
234 | // 在本机默认web浏览器中打开URL。
235 | // webui_open_url("https://webui.me");
236 | void webui_open_url(const char *url);
237 |
238 | // 允许从公共网络访问特定的窗口地址。
239 | // webui_set_public(myWindow, true);
240 | void webui_set_public(size_t window, bool status);
241 |
242 | // 导航到特定的URL。所有的客户。
243 | // webui_navigate(myWindow, "http://domain.com");
244 | void webui_navigate(size_t window, const char *url);
245 |
246 | // 导航到特定的URL。单一的客户端。
247 | // webui_navigate_client(e, "http://domain.com");
248 | void webui_navigate_client(webui_event_t *e, const char *url);
249 |
250 | // 释放所有内存资源。应该只在最后调用。
251 | // webui_wait();
252 | // webui_clean();
253 | void webui_clean(void);
254 |
255 | // 删除所有本地web浏览器配置文件文件夹。它应该在最后被调用。
256 | // webui_wait();
257 | // webui_delete_all_profiles();
258 | // webui_clean();
259 | void webui_delete_all_profiles(void);
260 |
261 | // 删除特定窗口web-browser本地文件夹配置文件。
262 | // webui_wait();
263 | // webui_delete_profile(myWindow);
264 | // webui_clean();
265 | // 提示:如果使用相同的web浏览器,这可能会破坏其他窗口的功能。
266 | void webui_delete_profile(size_t window);
267 |
268 | // 获取父进程的ID (web浏览器可能会重新创建另一个新进程)。
269 | // size_t id = webui_get_parent_process_id(myWindow);
270 | size_t webui_get_parent_process_id(size_t window);
271 |
272 | // 获取最后一个子进程的ID。
273 | // size_t id = webui_get_child_process_id(myWindow);
274 | size_t webui_get_child_process_id(size_t window);
275 |
276 | // 获取正在运行的窗口的网口。这对于确定' webui.js '的HTTP链接很有用。
277 | // size_t port = webui_get_port(myWindow);
278 | size_t webui_get_port(size_t window);
279 |
280 | // 设置web服务使用的自定义web-server/websocket网口。这可以用来确定' web .js '的HTTP链接,如果你试图使用web与外部web服务器如NGNIX。
281 | // bool ret = webui_set_port(myWindow, 8080);
282 | bool webui_set_port(size_t window, size_t port);
283 |
284 | // 获取一个可用的空闲网络端口。
285 | // size_t port = webui_get_free_port();
286 | size_t webui_get_free_port(void);
287 |
288 | // 控制web界面行为。建议在开始时调用。
289 | // webui_set_config(show_wait_connection, false);
290 | void webui_set_config(webui_config option, bool status);
291 |
292 | // 控制来自此窗口的UI事件是否应该在单个阻塞线程中一次处理一个' True ',还是在一个新的非阻塞线程中处理每个事件' False '。此更新单窗口。你可以使用' webui_set_config(ui_event_blocking,…)'来更新所有的窗口。
293 | // webui_set_event_blocking(myWindow, true);
294 | void webui_set_event_blocking(size_t window, bool status);
295 |
296 | // 获取文件的HTTP mime类型。
297 | // const char* mime = webui_get_mime_type("foo.png");
298 | const char *webui_get_mime_type(const char *file);
299 |
300 | /**
301 | * @brief 设置窗口的最小大小。
302 | *
303 | * @param window 窗口对象号
304 | * @param width 窗口宽度
305 | * @param height 窗口高度
306 | *
307 | * @example webui_set_minimum_size(myWindow, 800, 600);
308 | */
309 | void webui_set_minimum_size(size_t window, unsigned int width, unsigned int height);
310 |
311 | /**
312 | * @brief 在使用‘ webui_bind() ’之后使用这个API来添加任何用户数据
313 | * 稍后使用‘ webue_get_context() ’读取。
314 | *
315 | * @param window 窗口号
316 | * @param element HTML元素/ JavaScript对象
317 | * @param context 任何用户数据
318 | *
319 | * @example
320 | * webui_bind(myWindow, "myFunction", myFunction);
321 | *
322 | * webui_set_context(myWindow, "myFunction", myData);
323 | *
324 | * void myFunction(webui_event_t* e) {
325 | * void* myData = webui_get_context(e);
326 | * }
327 | */
328 | void webui_set_context(size_t window, const char *element, void *context);
329 |
330 | /**
331 | * @brief 获取使用‘ webui_set_context() ’设置的用户数据。
332 | *
333 | * @param e 事件
334 | *
335 | * @return void* 用户数据
336 | *
337 | * @example
338 | * webui_bind(myWindow, "myFunction", myFunction);
339 | *
340 | * webui_set_context(myWindow, "myFunction", myData);
341 | *
342 | * void myFunction(webui_event_t* e) {
343 | * void* myData = webui_get_context(e);
344 | * }
345 | */
346 | void *webui_get_context(webui_event_t *e);
347 |
348 | /**
349 | * @brief 添加自定义浏览器的CLI参数。
350 | *
351 | * @param window 窗口对象号
352 | * @param params 命令行参数
353 | *
354 | * @example webui_set_custom_parameters(myWindow, "--remote-debugging-port=9222");
355 | */
356 | void webui_set_custom_parameters(size_t window,const char *params);
357 |
358 | /**
359 | * @brief 设置一个自定义处理程序来提供文件。 这个自定义处理程序应该
360 | * 返回完整的HTTP报头和正文。
361 | * 这将禁用任何先前使用‘ webui_set_file_handler ’设置的处理程序。
362 | *
363 | * @param window 窗口对象号
364 | * @param handler The handler function: `void myHandler(size_t window, const char* filename,
365 | * int* length)`
366 | *
367 | * @example webui_set_file_handler_window(myWindow, myHandlerFunction);
368 | */
369 | void webui_set_file_handler_window(size_t window, const void *(*handler)(size_t window, const char *filename, int *length));
370 |
371 | /**
372 | * @brief 复制原始数据。
373 | *
374 | * @param dest 目标内存指针
375 | * @param src 源内存指针
376 | * @param count 要复制的字节
377 | *
378 | * @example webui_memcpy(myBuffer, myData, 64);
379 | */
380 | void webui_memcpy(void *dest, void *src, size_t count);
381 |
382 | /**
383 | * @brief 获取Win32窗口‘ HWND ’。使用WebView更可靠
384 | * 比web浏览器窗口,因为浏览器的pid可能会在启动时改变。
385 | *
386 | * @param window 窗口对象号
387 | *
388 | * @return 返回窗口的 `hwnd` as `void*`
389 | *
390 | * @example HWND hwnd = webui_win32_get_hwnd(myWindow);
391 | */
392 | void *webui_win32_get_hwnd(size_t window);
393 |
394 | // -- JavaScript ----------------------
395 |
396 | // 运行JavaScript而不等待响应。所有的客户。
397 | // webui_run(myWindow, "alert('Hello');");
398 | void webui_run(size_t window, const char *script);
399 |
400 | // 运行JavaScript而不等待响应。单一的客户端。
401 | // webui_run_client(e, "alert('Hello');");
402 | void webui_run_client(webui_event_t *e, const char *script);
403 |
404 | // 运行JavaScript并获得响应。仅在单客户端模式下工作。确保您的本地缓冲区可以保存响应。
405 | // bool err = webui_script(myWindow, "return 4 + 6;", 0, myBuffer, myBufferSize);
406 | bool webui_script(size_t window, const char *script, size_t timeout, char *buffer, size_t buffer_length);
407 |
408 | // 运行JavaScript并获得响应。单一的客户端。确保您的本地缓冲区可以保存响应。
409 | // bool err = webui_script_client(e, "return 4 + 6;", 0, myBuffer, myBufferSize);
410 | bool webui_script_client(webui_event_t *e, const char *script, size_t timeout, char *buffer, size_t buffer_length);
411 |
412 | // 选择Deno和Nodejs作为.js和.ts文件的运行时。
413 | // webui_set_runtime(myWindow, Deno);
414 | void webui_set_runtime(size_t window, size_t runtime);
415 |
416 | // 得到事件中有多少个参数。
417 | // size_t count = webui_get_count(e);
418 | size_t webui_get_count(webui_event_t *e);
419 |
420 | // 在特定索引处获取参数为整数。
421 | // long long int myNum = webui_get_int_at(e, 0);
422 | long long int webui_get_int_at(webui_event_t *e, size_t index);
423 |
424 | // 获取第一个参数为整数。
425 | // long long int myNum = webui_get_int(e);
426 | long long int webui_get_int(webui_event_t *e);
427 |
428 | // 在特定索引处获取float参数。
429 | // double myNum = webui_get_float_at(e, 0);
430 | double webui_get_float_at(webui_event_t *e, size_t index);
431 |
432 | // 获取第一个参数为float。
433 | // double myNum = webui_get_float(e);
434 | double webui_get_float(webui_event_t *e);
435 |
436 | // 在特定索引处以字符串形式获取参数。
437 | // const char* myStr = webui_get_string_at(e, 0);
438 | const char *webui_get_string_at(webui_event_t *e, size_t index);
439 |
440 | // 获取第一个参数为字符串。
441 | // const char* myStr = webui_get_string(e);
442 | const char *webui_get_string(webui_event_t *e);
443 |
444 | // 在特定索引处获取一个布尔参数。
445 | // bool myBool = webui_get_bool_at(e, 0);
446 | bool webui_get_bool_at(webui_event_t *e, size_t index);
447 |
448 | // 获取第一个参数为布尔值。
449 | // bool myBool = webui_get_bool(e);
450 | bool webui_get_bool(webui_event_t *e);
451 |
452 | // 获取特定索引处参数的大小(以字节为单位)。
453 | // size_t argLen = webui_get_size_at(e, 0);
454 | size_t webui_get_size_at(webui_event_t *e, size_t index);
455 |
456 | // 获取第一个参数的字节大小。
457 | // size_t argLen = webui_get_size(e);
458 | size_t webui_get_size(webui_event_t *e);
459 |
460 | // 将响应作为整数返回给JavaScript。
461 | // webui_return_int(e, 123);
462 | void webui_return_int(webui_event_t *e, long long int n);
463 |
464 | // 将响应作为浮点数返回给JavaScript。
465 | // webui_return_float(e, 123.456);
466 | void webui_return_float(webui_event_t *e, double f);
467 |
468 | // 将响应作为字符串返回给JavaScript。
469 | // webui_return_string(e, "Response...");
470 | void webui_return_string(webui_event_t *e, const char *s);
471 |
472 | // 将响应作为布尔值返回给JavaScript。
473 | // webui_return_bool(e, true);
474 | void webui_return_bool(webui_event_t *e, bool b);
475 |
476 | // -- 包装器的接口 -------------
477 |
478 | // 将特定的HTML元素click事件与函数绑定。空元素表示所有事件。
479 | // size_t id = webui_interface_bind(myWindow, "myID", myCallback);
480 | size_t webui_interface_bind(size_t window, const char *element, void (*func)(size_t, size_t, char *, size_t, size_t));
481 |
482 | // 当使用' webui_interface_bind() '时,你可能需要这个函数来方便地设置响应。
483 | // webui_interface_set_response(myWindow, e->event_number, "Response...");
484 | void webui_interface_set_response(size_t window, size_t event_number, const char *response);
485 |
486 | // 检查应用程序是否仍在运行。
487 | // bool status = webui_interface_is_app_running();
488 | bool webui_interface_is_app_running(void);
489 |
490 | // 获取唯一的窗口ID。
491 | // size_t id = webui_interface_get_window_id(myWindow);
492 | size_t webui_interface_get_window_id(size_t window);
493 |
494 | // 在特定索引处以字符串形式获取参数。
495 | // const char* myStr = webui_interface_get_string_at(myWindow, e->event_number, 0);
496 | const char *webui_interface_get_string_at(size_t window, size_t event_number, size_t index);
497 |
498 | // 在特定索引处获取参数为整数。
499 | // long long int myNum = webui_interface_get_int_at(myWindow, e->event_number, 0);
500 | long long int webui_interface_get_int_at(size_t window, size_t event_number, size_t index);
501 |
502 | // 在特定索引处获取float参数。
503 | // double myFloat = webui_interface_get_int_at(myWindow, e->event_number, 0);
504 | double webui_interface_get_float_at(size_t window, size_t event_number, size_t index);
505 |
506 | // 在特定索引处获取一个布尔参数。
507 | // bool myBool = webui_interface_get_bool_at(myWindow, e->event_number, 0);
508 | bool webui_interface_get_bool_at(size_t window, size_t event_number, size_t index);
509 |
510 | // 获取特定索引处参数的大小(以字节为单位)。
511 | // size_t argLen = webui_interface_get_size_at(myWindow, e->event_number, 0);
512 | size_t webui_interface_get_size_at(size_t window, size_t event_number, size_t index);
513 |
514 | /**
515 | * @brief 如果你的后端需要异步,使用这个API来设置一个文件处理程序响应
516 | * 响应‘ webue_set_file_handler() ’。
517 | *
518 | * @param window 窗口对象号
519 | * @param response 响应缓冲区
520 | * @param length 响应长度
521 | *
522 | * @example webui_interface_set_response_file_handler(myWindow, buffer, 1024);
523 | */
524 | void webui_interface_set_response_file_handler(size_t window, const void *response, int length);
525 |
526 | /**
527 | * @brief 使用嵌入的HTML或文件显示窗口。如果窗口已经
528 | * 打开,会刷新。单一的客户端。
529 | *
530 | * @param window 窗口对象号
531 | * @param event_number 事件号
532 | * @param content HTML、URL或本地文件
533 | *
534 | * @return 如果成功显示窗口,返回True。
535 | *
536 | * @example webui_show_client(e, "..."); |
537 | * webui_show_client(e, "index.html"); | webui_show_client(e, "http://...");
538 | */
539 | bool webui_interface_show_client(size_t window, size_t event_number, const char *content);
540 |
541 | /**
542 | * @brief 关闭特定客户端。
543 | *
544 | * @param window 窗口对象号
545 | * @param event_number 事件号
546 | *
547 | * @example webui_close_client(e);
548 | */
549 | void webui_interface_close_client(size_t window, size_t event_number);
550 |
551 | /**
552 | * @brief 安全地将原始数据发送到UI。单一的客户端。
553 | *
554 | * @param window 窗口对象号
555 | * @param event_number 事件号
556 | * @param function 接收原始数据的JavaScript函数
557 | * myFunc(myData){}`
558 | * @param raw 原始数据缓冲区r
559 | * @param size 原始数据大小(以字节为单位)
560 | *
561 | * @example webui_send_raw_client(e, "myJavaScriptFunc", myBuffer, 64);
562 | */
563 | void webui_interface_send_raw_client(size_t window, size_t event_number, const char *function, const void *raw, size_t size);
564 |
565 | /**
566 | * @brief 导航到特定的URL。单一的客户端。
567 | *
568 | * @param window 窗口号
569 | * @param event_number 事件号
570 | * @param url 完整的HTTP URL
571 | *
572 | * @example webui_navigate_client(e, "http://domain.com");
573 | */
574 | void webui_interface_navigate_client(size_t window, size_t event_number, const char *url);
575 |
576 | /**
577 | * @brief 运行JavaScript而不等待响应。单一的客户端。
578 | *
579 | * @param window 窗口号
580 | * @param event_number 事件号
581 | * @param script 要运行的JavaScript脚本
582 | *
583 | * @example webui_run_client(e, "alert('Hello');");
584 | */
585 | void webui_interface_run_client(size_t window, size_t event_number, const char *script);
586 |
587 | /**
588 | * @brief 运行JavaScript并获得响应。单一的客户端。
589 | * 确保你的本地缓冲区可以保存响应。
590 | *
591 | * @param window 窗口号
592 | * @param event_number 事件号
593 | * @param script 要运行的JavaScript脚本
594 | * @param timeout 执行超时时间(以秒为单位)
595 | * @param buffer 本地缓冲区来保存响应
596 | * @param buffer_length 本地缓冲区大小
597 | *
598 | * @return 如果没有执行错误,返回True。
599 | *
600 | * @example bool err = webui_script_client(e, "return 4 + 6;", 0, myBuffer, myBufferSize);
601 | */
602 | bool webui_interface_script_client(size_t window, size_t event_number, const char *script, size_t timeout, char *buffer, size_t buffer_length);
--------------------------------------------------------------------------------
/src/Webui.php:
--------------------------------------------------------------------------------
1 | webui_new_window();
23 | }
24 |
25 | /**
26 | * 使用指定的窗口号创建新的web窗口对象。
27 | *
28 | * @param integer $window web窗口对象
29 | * @return integer
30 | */
31 | public function newWindowId(int $window): int
32 | {
33 | return self::$ffi->webui_new_window_id($window);
34 | }
35 |
36 | /**
37 | * 获得一个可以使用的免费窗口对象
38 | *
39 | * @return integer
40 | */
41 | public function getNewWindowId(): int
42 | {
43 | return self::$ffi->webui_get_new_window_id();
44 | }
45 |
46 | /**
47 | * 用后端函数绑定一个HTML元素和一个JavaScript对象。空元素名称表示所有事件。 function
48 | *
49 | * @param integer $window 窗口对象
50 | * @param string $element 绑定js函数名
51 | * @param Closure $func php函数
52 | * @return boolean
53 | */
54 | public function bind(
55 | int $window,
56 | string $element,
57 | Closure $func
58 | ): mixed {
59 | $callback = self::$ffi->new('void (*)(webui_event_t *)');
60 | $js = new JavaScript();
61 | $callback = function ($event) use ($func, $js) {
62 | return $func((object)$event, $js);
63 | };
64 | return self::$ffi->webui_bind($window, $element, $callback);
65 | }
66 |
67 | /**
68 | * 获取要使用的推荐web浏览器ID。如果您已经使用了一个ID,则此函数将返回相同的ID。
69 | * NoBrowser = 0, // 0. 无浏览器
70 | * AnyBrowser = 1, // 1. 任何浏览器
71 | * Chrome, // 2. Google Chrome
72 | * Firefox, // 3. Mozilla Firefox
73 | * Edge, // 4. Microsoft Edge
74 | * Safari, // 5. Apple Safari
75 | * Chromium, // 6. The Chromium Project
76 | * Opera, // 7. Opera Browser
77 | * Brave, // 8. The Brave Browser
78 | * Vivaldi, // 9. The Vivaldi Browser
79 | * Epic, // 10. The Epic Browser
80 | * Yandex, // 11. The Yandex Browser
81 | * ChromiumBased, // 12. Any Chromium based browser
82 | * WebView, // 13. WebView (Non-web-browser)
83 | * @param integer $window 窗口对象
84 | * @return integer
85 | */
86 | public function getBestBrowser(int $window = 1): int
87 | {
88 | return self::$ffi->webui_get_best_browser($window);
89 | }
90 |
91 | /**
92 | * 使用嵌入的HTML或文件显示窗口。如果窗口已经打开,它将被刷新。这将刷新多客户端模式下的所有窗口。
93 | *
94 | * @param integer $window web窗口对象
95 | * @param string $content html内容
96 | * @example 示例 show($myWindow,"..."); | show($myWindow, "index.html"); | show($myWindow, "http://...");
97 | * @return boolean
98 | */
99 | public function show(int $window, string $content): bool
100 | {
101 | return self::$ffi->webui_show($window, $content);
102 | }
103 |
104 | /**
105 | * 与' webui_show() '相同。但是使用特定的网络浏览器。
106 | *
107 | * @param integer $window 窗口对象
108 | * @param string $content html内容
109 | * @param integer $browser 浏览器对象
110 | * @example 示例 showBrowser($myWindow, "...", $Chrome); | showBrowser($myWindow, "index.html", $Firefox);
111 | * @return boolean
112 | */
113 | public function showBrowser(int $window, string $content, int $browser): bool
114 | {
115 | return self::$ffi->webui_show_browser($window, $content, $browser);
116 | }
117 |
118 | /**
119 | * 与' webui_show() '相同。但是只启动web服务器并返回URL。不会显示任何窗口。
120 | *
121 | * @param integer $window 窗口对象
122 | * @param string $content 路径
123 | * @example 例子 $url = startServer($myWindow,"/full/root/path");
124 | * @return string
125 | */
126 | public function startServer(int $window, string $content): string
127 | {
128 | return self::$ffi->webui_start_server($window, $content);
129 | }
130 |
131 | /**
132 | * 使用嵌入的HTML或文件显示WebView窗口。如果窗口已经打开,它将被刷新。注意:Win32需要' WebView2Loader.dll '。(失败)
133 | *
134 | * @param integer $window 窗口对象
135 | * @param string $content html内容
136 | * @example 示例 showWv($myWindow,"..."); | show($myWindow, "index.html"); | show($myWindow, "http://...");
137 | * @return boolean
138 | */
139 | public function showWv(int $window, string $content): bool
140 | {
141 | return self::$ffi->webui_show_wv($window, $content);
142 | }
143 |
144 | /**
145 | * 将窗口设置为Kiosk模式(全屏)。
146 | * @param integer $window 窗口对象
147 | * @param boolean $status 状态
148 | * @example 示例 setKiosk($window, true);
149 | * @return void
150 | */
151 | public function setKiosk(int $window, bool $status): void
152 | {
153 | self::$ffi->webui_set_kiosk($window, $status);
154 | }
155 |
156 | /**
157 | * 设置具有高对比度支持的窗口。当你想用CSS构建一个更好的高对比度主题时非常有用。
158 | *
159 | * @param integer $window 窗口对象
160 | * @param boolean $status 状态
161 | * @example 示例 setHighContrast($window, true);
162 | * @return void
163 | */
164 | public function setHighContrast(int $window, bool $status): void
165 | {
166 | self::$ffi->set_high_contrast($window, $status);
167 | }
168 |
169 | /**
170 | * 获得操作系统高对比度偏好。
171 | *
172 | * @example 示例 isHighContrast();
173 | * @return boolean
174 | */
175 | public function isHighContrast(): bool
176 | {
177 | return self::$ffi->webui_is_high_contrast();
178 | }
179 |
180 | /**
181 | * 检查是否安装了某浏览器。
182 | *
183 | * @param integer $browser 浏览器对象
184 | * @example 示例 browserExist($browser);
185 | * @return boolean
186 | */
187 | public function browserExist(int $browser): bool
188 | {
189 | return self::$ffi->webui_browser_exist($browser);
190 | }
191 |
192 | /**
193 | * 等到所有开着的窗户都关上了。
194 | *
195 | * @example 示例 wait();
196 | * @return void
197 | */
198 | public function wait(): void
199 | {
200 | self::$ffi->webui_wait();
201 | }
202 |
203 | /**
204 | * 仅关闭特定窗口。窗口对象仍然存在。所有的客户。
205 | *
206 | * @param integer $window 窗口对象
207 | * @example 示例 close($window);
208 | * @return void
209 | */
210 | public function close(int $window): void
211 | {
212 | self::$ffi->webui_close($window);
213 | }
214 |
215 | /**
216 | * 关闭特定窗口并释放所有内存资源。
217 | *
218 | * @param integer $window 窗口对象
219 | * @example 示例 destroy($window);
220 | * @return void
221 | */
222 | public function destroy(int $window): void
223 | {
224 | self::$ffi->webui_destroy($window);
225 | }
226 |
227 | /**
228 | * 关闭所有打开的窗口。' wait() '将返回(Break)。
229 | *
230 | * @example 示例 exit();
231 | * @return void
232 | */
233 | public function exit(): void
234 | {
235 | self::$ffi->webui_exit();
236 | }
237 |
238 | /**
239 | * 为特定窗口设置web服务器根文件夹路径。
240 | *
241 | * @param integer $window 窗口对象
242 | * @param string $path 文件夹路径
243 | * @example 示例 setRootFolder($window,"/home/Foo/Bar/");
244 | * @return boolean
245 | */
246 | public function setRootFolder(int $window, string $path): bool
247 | {
248 | return self::$ffi->webui_set_root_folder($window, $path);
249 | }
250 |
251 | /**
252 | * 设置所有windows的web服务器根文件夹路径。应该使用在' show() '之前。
253 | *
254 | * @param string $path 文件夹路径
255 | * @example 示例 setDefaultRootFolder("/home/Foo/Bar/");webui_show();
256 | * @return boolean
257 | */
258 | public function setDefaultRootFolder(string $path): bool
259 | {
260 | return self::$ffi->webui_set_default_root_folder($path);
261 | }
262 |
263 | /**
264 | * 设置一个自定义处理程序来提供文件。这个自定义处理程序应该返回完整的HTTP报头和正文。
265 | *
266 | * @param integer $window 窗口对象
267 | * @param Closure $func 函数 参数 string $filename,int $length
268 | * @example 示例 setFileHandler($window,function($filename, $length){});
269 | * @return void
270 | */
271 | public function setFileHandler(int $window, Closure $func): void
272 | {
273 | $callback = self::$ffi->new('const void *(*)(const char *, int *)');
274 | $callback = function ($filename, $length) use ($func) {
275 | return $func($filename, $length);
276 | };
277 | self::$ffi->webui_set_file_handler($window, $callback);
278 | }
279 |
280 | /**
281 | * 检查指定的窗口是否仍在运行。
282 | *
283 | * @param integer $window 窗口对象
284 | * @example 示例 isShown($window);
285 | * @return boolean
286 | */
287 | public function isShown(int $window): bool
288 | {
289 | return self::$ffi->webui_is_shown($window);
290 | }
291 |
292 | /**
293 | * 设置等待窗口连接的最大时间(以秒为单位)。这个效果是' show() '和' wait() '。值“0”表示永远等待。
294 | *
295 | * @param integer $second 秒
296 | * @example 示例 setTimeout(30);
297 | * @return void
298 | */
299 | public function setTimeout(int $second): void
300 | {
301 | self::$ffi->webui_set_timeout($second);
302 | }
303 |
304 | /**
305 | * 设置默认的嵌入HTML图标。
306 | *
307 | * @param integer $window 窗口对象
308 | * @param string $icon 字符串
309 | * @param string $iconType mine类型
310 | * @example 示例 setIcon($window,"... ","image/svg+xml");
311 | * @return void
312 | */
313 | public function setIcon(int $window, string $icon, string $iconType): void
314 | {
315 | self::$ffi->webui_set_icon($window, $icon, $iconType);
316 | }
317 |
318 | /**
319 | * 将文本编码为Base64。返回的缓冲区需要被释放。(应该可以用PHP自带的)
320 | *
321 | * @param string $str
322 | * @example 示例 encode("Foo Bar");
323 | * @return string
324 | */
325 | public function encode(string $str): string
326 | {
327 | return self::$ffi->webui_encode($str);
328 | }
329 |
330 | /**
331 | * 解码Base64编码的文本。返回的缓冲区需要被释放。(应该可以用php自带的)
332 | *
333 | * @param string $str
334 | * @example 示例 decode("SGVsbG8=");
335 | * @return string
336 | */
337 | public function decode(string $str): string
338 | {
339 | return self::$ffi->webui_decode($str);
340 | }
341 |
342 | /**
343 | * 安全地释放由web使用' malloc() '分配的缓冲区。
344 | *
345 | * @param mixed $ptr 指针
346 | * @return void
347 | */
348 | public function free(mixed $ptr): void
349 | {
350 | $p = self::$ffi->new('void *');
351 | $p = $ptr;
352 | self::$ffi->webui_free($p);
353 | }
354 |
355 | /**
356 | * 通过web内存管理系统安全分配内存。它可以在任何时候使用' free() '安全地释放。
357 | *
358 | * @param integer $size 内存
359 | * @example 示例 malloc(1024);
360 | * @return mixed
361 | */
362 | public function malloc(int $size): mixed
363 | {
364 | return self::$ffi->webui_malloc($size);
365 | }
366 |
367 | /**
368 | * 安全地将原始数据发送到UI。所有的客户。
369 | *
370 | * @param integer $window 窗口对象
371 | * @param string $func js字符串函数名
372 | * @param mixed $raw c的const void *
373 | * @param integer $size 大小
374 | * @return void
375 | */
376 | public function sendRaw(int $window, string $func, mixed $raw, int $size): void
377 | {
378 | self::$ffi->webui_send_raw($window, $func, $raw, $size);
379 | }
380 |
381 | /**
382 | * 设置窗口为隐藏模式。应该在' show() '之前调用。
383 | *
384 | * @param integer $window 窗口对象
385 | * @param boolean $status 状态
386 | * @example 示例 setHide($window, true);show();
387 | * @return void
388 | */
389 | public function setHide(int $window, bool $status): void
390 | {
391 | self::$ffi->webui_set_hide($window, $status);
392 | }
393 |
394 | /**
395 | * 设置窗口大小。
396 | *
397 | * @param integer $window 窗口对象
398 | * @param integer $width 宽度
399 | * @param integer $height 高度
400 | * @example 示例 setSize($window, 800, 600);
401 | * @return void
402 | */
403 | public function setSize(int $window, int $width, int $height): void
404 | {
405 | self::$ffi->webui_set_size($window, $width, $height);
406 | }
407 |
408 | /**
409 | * 设置窗口位置。
410 | *
411 | * @param integer $window 窗口对象
412 | * @param integer $x
413 | * @param integer $y
414 | * @return void
415 | */
416 | public function setPosition(int $window, int $x, int $y): void
417 | {
418 | self::$ffi->webui_set_position($window, $x, $y);
419 | }
420 |
421 | /**
422 | * 设置要使用的web浏览器配置文件。空的“name”和“path”表示默认的用户配置文件。需要在'show() '之前调用。
423 | *
424 | * @param integer $window 窗口对象
425 | * @param string $name 名称
426 | * @param string $path 文件路径
427 | * @example 示例 setProfile($window,"Bar","/Home/Foo/Bar");show(); | setProfile($window,"","");show();
428 | * @return void
429 | */
430 | public function setProfile(int $window, string $name, string $path): void
431 | {
432 | self::$ffi->webui_set_profile($window, $name, $path);
433 | }
434 |
435 | /**
436 | * 设置使用的web浏览器代理服务器。需要在' show() '之前调用。
437 | *
438 | * @param integer $window 窗口对象
439 | * @param string $proxyServer 链接
440 | * @example 示例 setProxy($window,"http://127.0.0.1:8888");show();
441 | * @return void
442 | */
443 | public function setProxy(int $window, string $proxyServer): void
444 | {
445 | self::$ffi->webui_set_proxy($window, $proxyServer);
446 | }
447 |
448 | /**
449 | * 获取正在运行的窗口的当前URL。
450 | *
451 | * @param integer $window 窗口对象
452 | * @return string
453 | */
454 | public function getUrl(int $window): string
455 | {
456 | return self::$ffi->webui_get_url($window);
457 | }
458 |
459 | /**
460 | * 在本机默认web浏览器中打开URL。
461 | *
462 | * @param string $url 链接
463 | * @example 示例 openUrl("https://webui.me");
464 | * @return void
465 | */
466 | public function openUrl(string $url): void
467 | {
468 | self::$ffi->webui_open_url($url);
469 | }
470 |
471 | /**
472 | * 允许从公共网络访问特定的窗口地址。
473 | *
474 | * @param integer $window 窗口对象
475 | * @param boolean $status 状态
476 | * @example 示例 setPublic($window,true);
477 | * @return void
478 | */
479 | public function setPublic(int $window, bool $status): void
480 | {
481 | self::$ffi->webui_set_public($window, $status);
482 | }
483 |
484 | /**
485 | * 导航到特定的URL。所有的客户。
486 | *
487 | * @param integer $window 窗口对象
488 | * @param string $url 链接
489 | * @example 示例 navigate($window,"http://domain.com");
490 | * @return void
491 | */
492 | public function navigate(int $window, string $url): void
493 | {
494 | self::$ffi->webui_navigate($window, $url);
495 | }
496 |
497 | /**
498 | * 释放所有内存资源。应该只在最后调用。
499 | *
500 | * @example 示例 clean();
501 | * @return void
502 | */
503 | public function clean(): void
504 | {
505 | self::$ffi->webui_clean();
506 | }
507 |
508 | /**
509 | * 删除所有本地web浏览器配置文件文件夹。它应该在最后被调用。
510 | *
511 | * @example 示例 wait();deleteAllProfiles();clean();
512 | * @return void
513 | */
514 | public function deleteAllProfiles(): void
515 | {
516 | self::$ffi->webui_delete_all_profiles();
517 | }
518 |
519 | /**
520 | * 删除特定窗口web-browser本地文件夹配置文件。
521 | *
522 | * @param integer $window 窗口对象
523 | * @example 示例 wait();deleteProfile();clean();
524 | * @return void
525 | */
526 | public function deleteProfile(int $window): void
527 | {
528 | self::$ffi->webui_delete_profile($window);
529 | }
530 |
531 | /**
532 | * 获取父进程的ID (web浏览器可能会重新创建另一个新进程)。
533 | *
534 | * @param integer $window 窗口对象
535 | * @return integer
536 | */
537 | public function getParentProcessId(int $window): int
538 | {
539 | return self::$ffi->webui_get_parent_process_id($window);
540 | }
541 |
542 | /**
543 | * 获取最后一个子进程的ID。
544 | *
545 | * @param integer $window 窗口对象
546 | * @return integer
547 | */
548 | public function getChildProcessId(int $window): int
549 | {
550 | return self::$ffi->webui_get_child_process_id($window);
551 | }
552 |
553 | /**
554 | * 获取正在运行的窗口的网口。这对于确定' webui.js '的HTTP链接很有用。
555 | *
556 | * @param integer $window 窗口对象
557 | * @return integer
558 | */
559 | public function getPort(int $window): int
560 | {
561 | return self::$ffi->webui_get_port($window);
562 | }
563 |
564 | /**
565 | * 设置web服务使用的自定义web-server/websocket网口。这可以用来确定' web .js '的HTTP链接,如果你试图使用web与外部web服务器如NGNIX。
566 | *
567 | * @param integer $window 窗口对象
568 | * @param integer $port 端口号
569 | * @return boolean
570 | */
571 | public function setPort(int $window, int $port): bool
572 | {
573 | return self::$ffi->webui_set_port($window, $port);
574 | }
575 |
576 | /**
577 | * 获取一个可用的空闲网络端口。
578 | *
579 | * @return integer
580 | */
581 | public function getFreePort(): int
582 | {
583 | return self::$ffi->webui_get_free_port();
584 | }
585 |
586 | /**
587 | * 控制web界面行为。建议在开始时调用。
588 | *
589 | * @param object $option C的webui_config
590 | * @param boolean $status 状态
591 | * @example 示例 setConfig($option,false);
592 | * @return void
593 | */
594 | public function setConfig(object $option, bool $status): void
595 | {
596 | self::$ffi->webui_set_config($option, $status);
597 | }
598 |
599 | /**
600 | * 控制来自此窗口的UI事件是否应该在单个阻塞线程中一次处理一个' True ',还是在一个新的非阻塞线程中处理每个事件' False '。此更新单窗口。你可以使用' setConfig(ui_event_blocking,…)'来更新所有的窗口。
601 | *
602 | * @param integer $window 窗口对象
603 | * @param boolean $status 状态
604 | * @example 示例 setEventBlocking($window, true)
605 | * @return void
606 | */
607 | public function setEventBlocking(int $window, bool $status): void
608 | {
609 | self::$ffi->webui_set_event_blocking($window, $status);
610 | }
611 |
612 | /**
613 | * 获取文件的HTTP mime类型。(应该可以用PHP自带的)
614 | *
615 | * @param string $file 文件
616 | * @example 示例 getMimeType("foo.png");
617 | * @return string
618 | */
619 | public function getMimeType(string $file): string
620 | {
621 | return self::$ffi->webui_get_mime_type($file);
622 | }
623 |
624 | /**
625 | * 运行JavaScript而不等待响应。所有的客户。
626 | *
627 | * @param integer $window 窗口对象
628 | * @param string $js js字符串
629 | * @example 示例 run($window,"alert('Hello');");
630 | * @return void
631 | */
632 | public function run(int $window, string $js): void
633 | {
634 | self::$ffi->webui_run($window, $js);
635 | }
636 |
637 | /**
638 | * 运行JavaScript并获得响应。仅在单客户端模式下工作。确保您的本地缓冲区可以保存响应。
639 | *
640 | * @param integer $window 窗口对象
641 | * @param string $js js字符串
642 | * @param integer $timeout 等待时间
643 | * @param mixed $buffer 缓冲对象 C的char *类型
644 | * @param integer $bufferLength 缓冲长度
645 | * @example 示例 script($window,"return 4 + 6;",$buffer,$bufferLength);
646 | * @return boolean
647 | */
648 | public function script(int $window, string $js, int $timeout, mixed $buffer, int $bufferLength): bool
649 | {
650 | return self::$ffi->webui_script($window, $js, $timeout, $buffer, $bufferLength);
651 | }
652 |
653 | /**
654 | * 选择Deno或Nodejs作为.js和.ts文件的运行时。
655 | *
656 | * @param integer $window 窗口对象
657 | * @param integer $runtime 运行时对象
658 | * @example 示例 setRuntime($window,$runtime);
659 | * @return void
660 | */
661 | public function setRuntime(int $window, int $runtime): void
662 | {
663 | self::$ffi->webui_set_runtime($window, $runtime);
664 | }
665 |
666 | /**
667 | * 设置窗口的最小大小。
668 | *
669 | * @param integer $window 窗口对象
670 | * @param integer $width 宽度
671 | * @param integer $height 高度
672 | * @example 示例 setMinimumSize($window, 800, 600);
673 | * @return void
674 | */
675 | public function setMinimumSize(int $window, int $width, int $height): void
676 | {
677 | self::$ffi->webui_set_minimum_size($window, $width, $height);
678 | }
679 |
680 | /**
681 | * 在使用‘ bind() ’之后使用这个API来添加任何用户数据
682 | * 稍后使用‘ setContext() ’读取。
683 | *
684 | * @param integer $window 窗口对象
685 | * @param string $element HTML元素/ JavaScript脚本
686 | * @param mixed $context 任何用户数据
687 | * @example 示例 setContext($window,"myID",$myData);
688 | * @return void
689 | */
690 | public function setContext(int $window, string $element, mixed $context): void
691 | {
692 | self::$ffi->webui_set_context($window, $element, $context);
693 | }
694 |
695 | /**
696 | * 从使用‘ setContext() ’添加的用户数据中获取数据。
697 | *
698 | * @param Closure $func 事件
699 | * @example 示例 $myData = getContext(function($event){});
700 | * @return mixed
701 | */
702 | public function getContext(Closure $func): mixed
703 | {
704 | return self::$ffi->webui_get_context($func);
705 | }
706 |
707 | /**
708 | * 添加自定义浏览器的CLI参数。
709 | *
710 | * @param integer $window 窗口对象
711 | * @param string $parameters 参数
712 | * @example 示例 setCustomParameters($window, "--remote-debugging-port=9222");
713 | * @return void
714 | */
715 | public function setCustomParameters(int $window, string $parameters): void
716 | {
717 | self::$ffi->webui_set_custom_parameters($window, $parameters);
718 | }
719 |
720 | /**
721 | * 设置一个自定义处理程序来提供文件。 这个自定义处理程序应该
722 | * 返回完整的HTTP报头和正文。
723 | * 这将禁用任何先前使用‘ setFileHandler ’设置的处理程序。
724 | *
725 | * @param integer $window 窗口对象号
726 | * @param Closure $func 函数 参数 string $filename,int $length
727 | * @example 示例 setFileHandlerWindow($window,function($filename, $length){});
728 | * @return void
729 | */
730 | public function setFileHandlerWindow(int $window, Closure $func): void
731 | {
732 | $callback = function ($window, $filename, $length) use ($func) {
733 | return $func($window, $filename, $length);
734 | };
735 | self::$ffi->webui_set_file_handler_window($window, $callback);
736 | }
737 |
738 | /**
739 | * 复制原始数据。
740 | *
741 | * @param mixed $dest 目标内存指针
742 | * @param mixed $src 源内存指针
743 | * @param integer $count 要复制的字节
744 | * @return void
745 | */
746 | public function memcpy(mixed $dest, mixed $src, int $count): void
747 | {
748 | self::$ffi->webui_memcpy($dest, $src, $count);
749 | }
750 |
751 | /**
752 | * 获取Win32窗口‘ HWND ’。使用WebView更可靠
753 | * 比web浏览器窗口,因为浏览器的pid可能会在启动时改变。
754 | *
755 | * @param integer $window 窗口对象
756 | * @example 示例 $hwnd = win32GetHwnd($window);
757 | * @return mixed HWND
758 | */
759 | public function win32GetHwnd(int $window): mixed
760 | {
761 | return self::$ffi->webui_win32_get_hwnd($window);
762 | }
763 | }
764 |
--------------------------------------------------------------------------------
/README-zh-CN.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | 
4 |
5 | # WebUI for PHP
6 |
7 | [build-status]: https://img.shields.io/github/actions/workflow/status/webui-dev/webui/ci.yml?branch=main&style=for-the-badge&logo=githubactions&labelColor=414868&logoColor=C0CAF5
8 | [last-commit]: https://img.shields.io/github/last-commit/webui-dev/webui?style=for-the-badge&logo=github&logoColor=C0CAF5&labelColor=414868
9 | [release-version]: https://img.shields.io/github/v/tag/webui-dev/webui?style=for-the-badge&logo=webtrees&logoColor=C0CAF5&labelColor=414868&color=7664C6
10 | [license]: https://img.shields.io/github/license/webui-dev/webui?style=for-the-badge&logo=opensourcehardware&label=License&logoColor=C0CAF5&labelColor=414868&color=8c73cc
11 |
12 | [![][build-status]](https://github.com/webui-dev/webui/actions?query=branch%3Amain)
13 | [![][last-commit]](https://github.com/webui-dev/webui/pulse)
14 | [![][release-version]](https://github.com/webui-dev/webui/releases/latest)
15 | [![][license]](https://github.com/webui-dev/webui/blob/main/LICENSE)
16 |
17 | >使用任何web浏览器或WebView作为GUI,后端使用您喜欢的语言,前端使用现代web技术,所有这些都在一个轻量级的便携式库中。
18 |
19 | 
20 |
21 |
22 |
23 | Q群:515415726
24 |
25 | # composer
26 |
27 | ```shell
28 | composer require kingbes/webui
29 | ```
30 |
31 | | 要求 | 状态 |
32 | | ---- | ---- |
33 | | PHP | 8.1+ |
34 | | FFI | * |
35 | | Windows-x64 | true |
36 | | Linux-x64 | true |
37 | | Linux-arm | 待测试 |
38 | | Linux-arm64 | 待测试 |
39 | | MacOs-x64 | 待测试 |
40 | | MacOs-arm64 | 待测试 |
41 |
42 |
43 | # 示例
44 |
45 | 1. 示例一
46 |
47 | index.html
48 |
49 | ```html
50 |
51 |
52 |
53 |
54 |
55 |
56 | Document
57 |
58 |
59 |
60 |
61 |
62 | asd
63 |
70 |
71 |
72 |
73 | ```
74 |
75 | index.php
76 |
77 | ```php
78 | require "./vendor/autoload.php";
79 |
80 | use Kingbes\Webui;
81 | use Kingbes\JavaScript;
82 |
83 | // 实例
84 | $Webui = new Webui;
85 | // html字符串
86 | $html = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . "index.html");
87 | // 创建一个窗口
88 | $window = $Webui->newWindow();
89 | // 绑定js函数
90 | $bind = $Webui->bind($window, "hello", function ($event, JavaScript $js) {
91 | // 获取第一个参数为字符串
92 | $arg_one = $js->getString($event);
93 | var_dump($arg_one);
94 |
95 | // 返回字符串
96 | $js->returnString($event, "nihao");
97 | });
98 | // 显示窗口
99 | $Webui->show($window, $html);
100 | // 等待
101 | $Webui->wait();
102 | // 释放所有
103 | $Webui->clean();
104 | ```
105 |
106 | ## 各类用法说明
107 |
108 | 1. `Webui` 窗口的方法类
109 | 2. `JavaScript` 用于与js绑定交互用
110 | 3. `Wrapper` 包装器,对整个交互进行包装等
111 | 4. `Cobj` C的对象类,部分功能可能需要
112 |
113 | ## 类`Kingbes\Webui`
114 |
115 | ```php
116 | /**
117 | * 创建一个新的web窗口对象。 function
118 | *
119 | * @return int
120 | */
121 | public function newWindow(): int
122 | {}
123 |
124 | /**
125 | * 使用指定的窗口号创建新的web窗口对象。
126 | *
127 | * @param integer $window web窗口对象
128 | * @return integer
129 | */
130 | public function newWindowId(int $window): int
131 | {}
132 |
133 | /**
134 | * 获得一个可以使用的免费窗口对象
135 | *
136 | * @return integer
137 | */
138 | public function getNewWindowId(): int
139 | {}
140 |
141 | /**
142 | * 用后端函数绑定一个HTML元素和一个JavaScript对象。空元素名称表示所有事件。 function
143 | *
144 | * @param integer $window 窗口对象
145 | * @param string $element 绑定js函数名
146 | * @param Closure $func php函数
147 | * @return boolean
148 | */
149 | public function bind(
150 | int $window,
151 | string $element,
152 | Closure $func
153 | ): mixed {}
154 |
155 | /**
156 | * 获取要使用的推荐web浏览器ID。如果您已经使用了一个ID,则此函数将返回相同的ID。
157 | *
158 | * @param integer $window 窗口对象
159 | * @return integer
160 | */
161 | public function getBestBrowser(int $window): int
162 | {}
163 |
164 | /**
165 | * 使用嵌入的HTML或文件显示窗口。如果窗口已经打开,它将被刷新。这将刷新多客户端模式下的所有窗口。
166 | *
167 | * @param integer $window web窗口对象
168 | * @param string $content html内容
169 | * @example 示例 show($myWindow,"..."); | show($myWindow, "index.html"); | show($myWindow, "http://...");
170 | * @return boolean
171 | */
172 | public function show(int $window, string $content): bool
173 | {}
174 |
175 | /**
176 | * 与' webui_show() '相同。但是使用特定的网络浏览器。
177 | *
178 | * @param integer $window 窗口对象
179 | * @param string $content html内容
180 | * @param integer $browser 浏览器对象
181 | * @example 示例 showBrowser($myWindow, "...", $Chrome); | showBrowser($myWindow, "index.html", $Firefox);
182 | * @return boolean
183 | */
184 | public function showBrowser(int $window, string $content, int $browser): bool
185 | {}
186 |
187 | /**
188 | * 与' webui_show() '相同。但是只启动web服务器并返回URL。不会显示任何窗口。
189 | *
190 | * @param integer $window 窗口对象
191 | * @param string $content 路径
192 | * @example 例子 $url = startServer($myWindow,"/full/root/path");
193 | * @return string
194 | */
195 | public function startServer(int $window, string $content): string
196 | {}
197 |
198 | /**
199 | * 使用嵌入的HTML或文件显示WebView窗口。如果窗口已经打开,它将被刷新。注意:Win32需要' WebView2Loader.dll '。(失败)
200 | *
201 | * @param integer $window 窗口对象
202 | * @param string $content html内容
203 | * @example 示例 showWv($myWindow,"..."); | show($myWindow, "index.html"); | show($myWindow, "http://...");
204 | * @return boolean
205 | */
206 | public function showWv(int $window, string $content): bool
207 | {}
208 |
209 | /**
210 | * 将窗口设置为Kiosk模式(全屏)。
211 | * @param integer $window 窗口对象
212 | * @param boolean $status 状态
213 | * @example 示例 setKiosk($window, true);
214 | * @return void
215 | */
216 | public function setKiosk(int $window, bool $status): void
217 | {}
218 |
219 | /**
220 | * 设置具有高对比度支持的窗口。当你想用CSS构建一个更好的高对比度主题时非常有用。
221 | *
222 | * @param integer $window 窗口对象
223 | * @param boolean $status 状态
224 | * @example 示例 setHighContrast($window, true);
225 | * @return void
226 | */
227 | public function setHighContrast(int $window, bool $status): void
228 | {}
229 |
230 | /**
231 | * 获得操作系统高对比度偏好。
232 | *
233 | * @example 示例 isHighContrast();
234 | * @return boolean
235 | */
236 | public function isHighContrast(): bool
237 | {}
238 |
239 | /**
240 | * 检查是否安装了某浏览器。
241 | *
242 | * @param integer $browser 浏览器对象
243 | * @example 示例 browserExist($browser);
244 | * @return boolean
245 | */
246 | public function browserExist(int $browser): bool
247 | {}
248 |
249 | /**
250 | * 等到所有开着的窗户都关上了。
251 | *
252 | * @example 示例 wait();
253 | * @return void
254 | */
255 | public function wait(): void
256 | {}
257 |
258 | /**
259 | * 仅关闭特定窗口。窗口对象仍然存在。所有的客户。
260 | *
261 | * @param integer $window 窗口对象
262 | * @example 示例 close($window);
263 | * @return void
264 | */
265 | public function close(int $window): void
266 | {}
267 |
268 | /**
269 | * 关闭特定窗口并释放所有内存资源。
270 | *
271 | * @param integer $window 窗口对象
272 | * @example 示例 destroy($window);
273 | * @return void
274 | */
275 | public function destroy(int $window): void
276 | {}
277 |
278 | /**
279 | * 关闭所有打开的窗口。' wait() '将返回(Break)。
280 | *
281 | * @example 示例 exit();
282 | * @return void
283 | */
284 | public function exit(): void
285 | {}
286 |
287 | /**
288 | * 为特定窗口设置web服务器根文件夹路径。
289 | *
290 | * @param integer $window 窗口对象
291 | * @param string $path 文件夹路径
292 | * @example 示例 setRootFolder($window,"/home/Foo/Bar/");
293 | * @return boolean
294 | */
295 | public function setRootFolder(int $window, string $path): bool
296 | {}
297 |
298 | /**
299 | * 设置所有windows的web服务器根文件夹路径。应该使用在' show() '之前。
300 | *
301 | * @param string $path 文件夹路径
302 | * @example 示例 setDefaultRootFolder("/home/Foo/Bar/");webui_show();
303 | * @return boolean
304 | */
305 | public function setDefaultRootFolder(string $path): bool
306 | {}
307 |
308 | /**
309 | * 设置一个自定义处理程序来提供文件。这个自定义处理程序应该返回完整的HTTP报头和正文。
310 | *
311 | * @param integer $window 窗口对象
312 | * @param Closure $func 函数 参数 string $filename,int $length
313 | * @example 示例 setFileHandler($window,function($filename, $length){});
314 | * @return void
315 | */
316 | public function setFileHandler(int $window, Closure $func): void
317 | {}
318 |
319 | /**
320 | * 检查指定的窗口是否仍在运行。
321 | *
322 | * @param integer $window 窗口对象
323 | * @example 示例 isShown($window);
324 | * @return boolean
325 | */
326 | public function isShown(int $window): bool
327 | {}
328 |
329 | /**
330 | * 设置等待窗口连接的最大时间(以秒为单位)。这个效果是' show() '和' wait() '。值“0”表示永远等待。
331 | *
332 | * @param integer $second 秒
333 | * @example 示例 setTimeout(30);
334 | * @return void
335 | */
336 | public function setTimeout(int $second): void
337 | {}
338 |
339 | /**
340 | * 设置默认的嵌入HTML图标。
341 | *
342 | * @param integer $window 窗口对象
343 | * @param string $icon 字符串
344 | * @param string $iconType mine类型
345 | * @example 示例 setIcon($window,"... ","image/svg+xml");
346 | * @return void
347 | */
348 | public function setIcon(int $window, string $icon, string $iconType): void
349 | {}
350 |
351 | /**
352 | * 将文本编码为Base64。返回的缓冲区需要被释放。(应该可以用PHP自带的)
353 | *
354 | * @param string $str
355 | * @example 示例 encode("Foo Bar");
356 | * @return string
357 | */
358 | public function encode(string $str): string
359 | {}
360 |
361 | /**
362 | * 解码Base64编码的文本。返回的缓冲区需要被释放。(应该可以用php自带的)
363 | *
364 | * @param string $str
365 | * @example 示例 decode("SGVsbG8=");
366 | * @return string
367 | */
368 | public function decode(string $str): string
369 | {}
370 |
371 | /**
372 | * 安全地释放由web使用' malloc() '分配的缓冲区。
373 | *
374 | * @param mixed $ptr 指针
375 | * @return void
376 | */
377 | public function free(mixed $ptr): void
378 | {}
379 |
380 | /**
381 | * 通过web内存管理系统安全分配内存。它可以在任何时候使用' free() '安全地释放。
382 | *
383 | * @param integer $size 内存
384 | * @example 示例 malloc(1024);
385 | * @return mixed
386 | */
387 | public function malloc(int $size): mixed
388 | {}
389 |
390 | /**
391 | * 安全地将原始数据发送到UI。所有的客户。
392 | *
393 | * @param integer $window 窗口对象
394 | * @param string $func js字符串函数名
395 | * @param mixed $raw c的const void *
396 | * @param integer $size 大小
397 | * @return void
398 | */
399 | public function sendRaw(int $window, string $func, mixed $raw, int $size): void
400 | {}
401 |
402 | /**
403 | * 设置窗口为隐藏模式。应该在' show() '之前调用。
404 | *
405 | * @param integer $window 窗口对象
406 | * @param boolean $status 状态
407 | * @example 示例 setHide($window, true);show();
408 | * @return void
409 | */
410 | public function setHide(int $window, bool $status): void
411 | {}
412 |
413 | /**
414 | * 设置窗口大小。
415 | *
416 | * @param integer $window 窗口对象
417 | * @param integer $width 宽度
418 | * @param integer $height 高度
419 | * @example 示例 setSize($window, 800, 600);
420 | * @return void
421 | */
422 | public function setSize(int $window, int $width, int $height): void
423 | {}
424 |
425 | /**
426 | * 设置窗口位置。
427 | *
428 | * @param integer $window 窗口对象
429 | * @param integer $x
430 | * @param integer $y
431 | * @return void
432 | */
433 | public function setPosition(int $window, int $x, int $y): void
434 | {}
435 |
436 | /**
437 | * 设置要使用的web浏览器配置文件。空的“name”和“path”表示默认的用户配置文件。需要在'show() '之前调用。
438 | *
439 | * @param integer $window 窗口对象
440 | * @param string $name 名称
441 | * @param string $path 文件路径
442 | * @example 示例 setProfile($window,"Bar","/Home/Foo/Bar");show(); | setProfile($window,"","");show();
443 | * @return void
444 | */
445 | public function setProfile(int $window, string $name, string $path): void
446 | {}
447 |
448 | /**
449 | * 设置使用的web浏览器代理服务器。需要在' show() '之前调用。
450 | *
451 | * @param integer $window 窗口对象
452 | * @param string $proxyServer 链接
453 | * @example 示例 setProxy($window,"http://127.0.0.1:8888");show();
454 | * @return void
455 | */
456 | public function setProxy(int $window, string $proxyServer): void
457 | {}
458 |
459 | /**
460 | * 获取正在运行的窗口的当前URL。
461 | *
462 | * @param integer $window 窗口对象
463 | * @return string
464 | */
465 | public function getUrl(int $window): string
466 | {}
467 |
468 | /**
469 | * 在本机默认web浏览器中打开URL。
470 | *
471 | * @param string $url 链接
472 | * @example 示例 openUrl("https://webui.me");
473 | * @return void
474 | */
475 | public function openUrl(string $url): void
476 | {}
477 |
478 | /**
479 | * 允许从公共网络访问特定的窗口地址。
480 | *
481 | * @param integer $window 窗口对象
482 | * @param boolean $status 状态
483 | * @example 示例 setPublic($window,true);
484 | * @return void
485 | */
486 | public function setPublic(int $window, bool $status): void
487 | {}
488 |
489 | /**
490 | * 导航到特定的URL。所有的客户。
491 | *
492 | * @param integer $window 窗口对象
493 | * @param string $url 链接
494 | * @example 示例 navigate($window,"http://domain.com");
495 | * @return void
496 | */
497 | public function navigate(int $window, string $url): void
498 | {}
499 |
500 | /**
501 | * 释放所有内存资源。应该只在最后调用。
502 | *
503 | * @example 示例 clean();
504 | * @return void
505 | */
506 | public function clean(): void
507 | {}
508 |
509 | /**
510 | * 删除所有本地web浏览器配置文件文件夹。它应该在最后被调用。
511 | *
512 | * @example 示例 wait();deleteAllProfiles();clean();
513 | * @return void
514 | */
515 | public function deleteAllProfiles(): void
516 | {}
517 |
518 | /**
519 | * 删除特定窗口web-browser本地文件夹配置文件。
520 | *
521 | * @param integer $window 窗口对象
522 | * @example 示例 wait();deleteProfile();clean();
523 | * @return void
524 | */
525 | public function deleteProfile(int $window): void
526 | {}
527 |
528 | /**
529 | * 获取父进程的ID (web浏览器可能会重新创建另一个新进程)。
530 | *
531 | * @param integer $window 窗口对象
532 | * @return integer
533 | */
534 | public function getParentProcessId(int $window): int
535 | {}
536 |
537 | /**
538 | * 获取最后一个子进程的ID。
539 | *
540 | * @param integer $window 窗口对象
541 | * @return integer
542 | */
543 | public function getChildProcessId(int $window): int
544 | {}
545 |
546 | /**
547 | * 获取正在运行的窗口的网口。这对于确定' webui.js '的HTTP链接很有用。
548 | *
549 | * @param integer $window 窗口对象
550 | * @return integer
551 | */
552 | public function getPort(int $window): int
553 | {}
554 |
555 | /**
556 | * 设置web服务使用的自定义web-server/websocket网口。这可以用来确定' web .js '的HTTP链接,如果你试图使用web与外部web服务器如NGNIX。
557 | *
558 | * @param integer $window 窗口对象
559 | * @param integer $port 端口号
560 | * @return boolean
561 | */
562 | public function setPort(int $window, int $port): bool
563 | {}
564 |
565 | /**
566 | * 获取一个可用的空闲网络端口。
567 | *
568 | * @return integer
569 | */
570 | public function getFreePort(): int
571 | {}
572 |
573 | /**
574 | * 控制web界面行为。建议在开始时调用。
575 | *
576 | * @param object $option C的webui_config
577 | * @param boolean $status 状态
578 | * @example 示例 setConfig($option,false);
579 | * @return void
580 | */
581 | public function setConfig(object $option, bool $status): void
582 | {}
583 |
584 | /**
585 | * 控制来自此窗口的UI事件是否应该在单个阻塞线程中一次处理一个' True ',还是在一个新的非阻塞线程中处理每个事件' False '。此更新单窗口。你可以使用' setConfig(ui_event_blocking,…)'来更新所有的窗口。
586 | *
587 | * @param integer $window 窗口对象
588 | * @param boolean $status 状态
589 | * @example 示例 setEventBlocking($window, true)
590 | * @return void
591 | */
592 | public function setEventBlocking(int $window, bool $status): void
593 | {}
594 |
595 | /**
596 | * 获取文件的HTTP mime类型。(应该可以用PHP自带的)
597 | *
598 | * @param string $file 文件
599 | * @example 示例 getMimeType("foo.png");
600 | * @return string
601 | */
602 | public function getMimeType(string $file): string
603 | {}
604 |
605 | /**
606 | * 运行JavaScript而不等待响应。所有的客户。
607 | *
608 | * @param integer $window 窗口对象
609 | * @param string $js js字符串
610 | * @example 示例 run($window,"alert('Hello');");
611 | * @return void
612 | */
613 | public function run(int $window, string $js): void
614 | {}
615 |
616 | /**
617 | * 运行JavaScript并获得响应。仅在单客户端模式下工作。确保您的本地缓冲区可以保存响应。
618 | *
619 | * @param integer $window 窗口对象
620 | * @param string $js js字符串
621 | * @param integer $timeout 等待时间
622 | * @param mixed $buffer 缓冲对象 C的char *类型
623 | * @param integer $bufferLength 缓冲长度
624 | * @example 示例 script($window,"return 4 + 6;",$buffer,$bufferLength);
625 | * @return boolean
626 | */
627 | public function script(int $window, string $js, int $timeout, mixed $buffer, int $bufferLength): bool
628 | {}
629 |
630 | /**
631 | * 选择Deno或Nodejs作为.js和.ts文件的运行时。
632 | *
633 | * @param integer $window 窗口对象
634 | * @param integer $runtime 运行时对象
635 | * @example 示例 setRuntime($window,$runtime);
636 | * @return void
637 | */
638 | public function setRuntime(int $window, int $runtime): void
639 | {}
640 | ```
641 |
642 | ## 类`Kingbes\JavaScript`
643 |
644 | ```php
645 | /**
646 | * 关闭特定客户端。
647 | *
648 | * @param object $event
649 | * @example 示例 closeClient($event);
650 | * @return void
651 | */
652 | public function closeClient(object $event): void
653 | {}
654 |
655 | /**
656 | * 安全地将原始数据发送到UI。单一的客户端。
657 | *
658 | * @param object $event
659 | * @param string $func js函数名
660 | * @param mixed $raw C的const void *
661 | * @param integer $size 大小
662 | * @return void
663 | */
664 | public function sendRawClient(object $event, string $func, mixed $raw, int $size): void
665 | {}
666 |
667 | /**
668 | * 导航到特定的URL。单一的客户端。
669 | *
670 | * @param object $event
671 | * @param string $url 链接
672 | * @example 示例 navigateClient($event,"http://domain.com");
673 | * @return void
674 | */
675 | public function navigateClient(object $event, string $url): void
676 | {}
677 |
678 | /**
679 | * 运行JavaScript而不等待响应。单一的客户端。
680 | *
681 | * @param object $event
682 | * @param string $js js字符串
683 | * @example 示例 runClient($event,"alert('Hello');");
684 | * @return void
685 | */
686 | public function runClient(object $event, string $js): void
687 | {}
688 |
689 | /**
690 | * 运行JavaScript并获得响应。单一的客户端。确保您的本地缓冲区可以保存响应。
691 | *
692 | * @param object $event
693 | * @param string $js js字符串
694 | * @param integer $timeout 等待时间
695 | * @param mixed $buffer 缓冲对象 C的char *类型
696 | * @param integer $bufferLength 缓冲长度
697 | * @example 示例 scriptClient($window,"return 4 + 6;",$buffer,$bufferLength);
698 | * @return boolean
699 | */
700 | public function scriptClient(object $event, string $js, int $timeout, mixed $buffer, int $bufferLength): bool
701 | {}
702 |
703 | /**
704 | * 得到事件中有多少个参数。
705 | *
706 | * @param object $event
707 | * @return integer
708 | */
709 | public function getCount(object $event): int
710 | {}
711 |
712 | /**
713 | * 在特定索引处获取参数为整数。
714 | *
715 | * @param object $event
716 | * @param integer $index 索引
717 | * @example 示例 $myNum = getIntAt($event,0);
718 | * @return integer
719 | */
720 | public function getIntAt(object $event, int $index): int
721 | {}
722 |
723 | /**
724 | * 获取第一个参数为整数。
725 | *
726 | * @param object $event
727 | * @example 示例 $myNum = getInt($event);
728 | * @return integer
729 | */
730 | public function getInt(object $event): int
731 | {}
732 |
733 | /**
734 | * 在特定索引处获取float参数。
735 | *
736 | * @param object $event
737 | * @param integer $index 索引
738 | * @example 示例 $myfloat = getFloatAt($event, 0);
739 | * @return float
740 | */
741 | public function getFloatAt(object $event, int $index): float
742 | {}
743 |
744 | /**
745 | * 获取第一个参数为float。
746 | *
747 | * @param object $event
748 | * @example 示例 $myfloat = getFloat($event);
749 | * @return float
750 | */
751 | public function getFloat(object $event): float
752 | {}
753 |
754 | /**
755 | * 在特定索引处以字符串形式获取参数。
756 | *
757 | * @param object $event
758 | * @param integer $index 索引
759 | * @example 示例 $myString = getStringAt($event, 0);
760 | * @return string
761 | */
762 | public function getStringAt(object $event, int $index): string
763 | {}
764 |
765 | /**
766 | * 获取第一个参数为字符串。
767 | *
768 | * @param object $event
769 | * @example 示例 $myString = getString($event);
770 | * @return string
771 | */
772 | public function getString(object $event): string
773 | {}
774 |
775 | /**
776 | * 在特定索引处获取一个布尔参数。
777 | *
778 | * @param object $event
779 | * @param integer $index 索引
780 | * @example 示例 $myBool = getBoolAt($event, 0);
781 | * @return boolean
782 | */
783 | public function getBoolAt(object $event, int $index): bool
784 | {}
785 |
786 | /**
787 | * 获取第一个参数为布尔值。
788 | *
789 | * @param object $event
790 | * @example 示例 $myBool = getBool($event);
791 | * @return boolean
792 | */
793 | public function getBool(object $event): bool
794 | {}
795 |
796 | /**
797 | * 获取特定索引处参数的大小(以字节为单位)。
798 | *
799 | * @param object $event
800 | * @param integer $index 索引
801 | * @example 示例 $mySzie = getSizeAt($event, 0);
802 | * @return integer
803 | */
804 | public function getSizeAt(object $event, int $index): int
805 | {}
806 |
807 | /**
808 | * 获取第一个参数的字节大小。
809 | *
810 | * @param object $event
811 | * @example 示例 $mySzie = getSizeAt($event);
812 | * @return integer
813 | */
814 | public function getSize(object $event): int
815 | {}
816 |
817 | /**
818 | * 将响应作为整数返回给JavaScript。
819 | *
820 | * @param object $event
821 | * @param integer $num
822 | * @example 示例 returnInt($event, 123);
823 | * @return void
824 | */
825 | public function returnInt(object $event, int $num): void
826 | {}
827 |
828 | /**
829 | * 将响应作为浮点数返回给JavaScript。
830 | *
831 | * @param object $event
832 | * @param float $double 浮点
833 | * @example 示例 returnFloat($event,123.456);
834 | * @return void
835 | */
836 | public function returnFloat(object $event, float $double): void
837 | {}
838 |
839 | /**
840 | * 将响应作为字符串返回给JavaScript。
841 | *
842 | * @param object $event
843 | * @param string $str 字符串
844 | * @example 示例 returnString($event,"hello world");
845 | * @return void
846 | */
847 | public function returnString(object $event, string $str): void
848 | {}
849 |
850 | /**
851 | * 将响应作为布尔值返回给JavaScript。
852 | *
853 | * @param object $event
854 | * @param boolean $bool
855 | * @return void
856 | */
857 | public function returnBool(object $event, bool $boolean): void
858 | {}
859 | ```
860 |
861 | ## 类`Kingbes\Wrapper`
862 |
863 | ```php
864 | /**
865 | * 将特定的HTML元素click事件与函数绑定。空元素表示所有事件。
866 | *
867 | * @param integer $window 窗口对象
868 | * @param string $element html元素
869 | * @param Closure $func 函数 参数 int $param1, int $param2, string $phpParam3, int $param4, int $param5
870 | * @example 示例 interfaceBind($window,"myID",function($param1, $param2, $phpParam3, $param4, $param5){});
871 | * @return integer
872 | */
873 | public function interfaceBind(int $window, string $element, Closure $func): int
874 | {}
875 |
876 | /**
877 | * 当使用' interfaceBind() '时,你可能需要这个函数来方便地设置响应。
878 | *
879 | * @param integer $window 窗口对象
880 | * @param integer $eventNumber $event对象的event_number
881 | * @param string $response 字符串
882 | * @example 示例 interfaceSetResponse($window,$event[0]->event_number,"Response...");
883 | * @return void
884 | */
885 | public function interfaceSetResponse(int $window, int $eventNumber, string $response): void
886 | {}
887 |
888 | /**
889 | * 检查应用程序是否仍在运行。
890 | *
891 | * @return boolean
892 | */
893 | public function interfaceIsAppRunning(): bool
894 | {}
895 |
896 | /**
897 | * 获取唯一的窗口ID。
898 | *
899 | * @param integer $window 窗口对象
900 | * @return integer
901 | */
902 | public function interfaceGetWindowId(int $window): int
903 | {}
904 |
905 | /**
906 | * 在特定索引处以字符串形式获取参数。
907 | *
908 | * @param integer $window 窗口对象
909 | * @param integer $eventNumber $event对象的event_number
910 | * @param integer $index 索引
911 | * @example 示例 $myStr = interfaceGetStringAt($window, $event[0]->event_number, 0);
912 | * @return string
913 | */
914 | public function interfaceGetStringAt(int $window, int $eventNumber, int $index): string
915 | {}
916 |
917 | /**
918 | * 在特定索引处获取参数为整数。
919 | *
920 | * @param integer $window 窗口对象
921 | * @param integer $eventNumber $event对象的event_number
922 | * @param integer $index 索引
923 | * @example 示例 $myNum = interfaceGetIntAt($window, $event[0]->event_number, 0);
924 | * @return integer
925 | */
926 | public function interfaceGetIntAt(int $window, int $eventNumber, int $index): int
927 | {}
928 |
929 | /**
930 | * 在特定索引处获取float参数。
931 | *
932 | * @param integer $window 窗口对象
933 | * @param integer $eventNumber $event对象的event_number
934 | * @param integer $index 索引
935 | * @example 示例 $myFloat = interfaceGetFloatAt($window, $event[0]->event_number, 0);
936 | * @return float
937 | */
938 | public function interfaceGetFloatAt(int $window, int $eventNumber, int $index): float
939 | {}
940 |
941 | /**
942 | * 在特定索引处获取一个布尔参数。
943 | *
944 | * @param integer $window 窗口对象
945 | * @param integer $eventNumber $event对象的event_number
946 | * @param integer $index 索引
947 | * @example 示例 $myBool = interfaceGetBoolAt($window, $event[0]->event_number, 0);
948 | * @return boolean
949 | */
950 | public function interfaceGetBoolAt(int $window, int $eventNumber, int $index): bool
951 | {}
952 |
953 | /**
954 | * 获取特定索引处参数的大小(以字节为单位)。
955 | *
956 | * @param integer $window 窗口对象
957 | * @param integer $eventNumber $event对象的event_number
958 | * @param integer $index 索引
959 | * @example 示例 $mySize = interfaceGetSizeAt($window, $event[0]->event_number, 0);
960 | * @return integer
961 | */
962 | public function interfaceGetSizeAt(int $window, int $eventNumber, int $index): int
963 | {}
964 | ```
965 |
966 | ## 类`Kingbes\Cobj`
967 |
968 | ```php
969 | /**
970 | * 获取event对象结构
971 | *
972 | * int window 窗口对象号;
973 | * int event_type 事件类型;
974 | * char *element HTML元素ID;
975 | * int event_number 内部WebUI;
976 | * int bind_id 绑定 id;
977 | * int client_id 客户端唯一ID;
978 | * int connection_id 客户端连接ID;
979 | * char *cookies 客户的全部 cookies;
980 | * @return object
981 | */
982 | public function event(): object
983 | {}
984 |
985 | /**
986 | * web配置
987 | *
988 | * 控制' webui_show() ', ' webui_show_browser() '和
989 | * ' webui_show_wv() '应该等待窗口连接
990 | * before是否返回。
991 | * 默认值:True
992 | * show_wait_connection = 0,
993 | *
994 | * 控制web是否应该阻塞和处理UI事件
995 | * 在一个线程中一次处理一个' True ',或者处理每一个
996 | * 一个新的非阻塞线程中的事件' False '。这个更新
997 | * 所有窗口。你可以使用' webui_set_event_blocking() '
998 | * 一个特定的单窗口更新。
999 | * 默认值:False
1000 | * ui_event_blocking,
1001 | *
1002 | * 自动刷新窗口UI
1003 | * 根目录被更改。
1004 | * 默认值:False
1005 | * folder_monitor,
1006 | *
1007 | * 允许多个客户端连接到同一个窗口
1008 | * 这对web应用程序(非桌面软件)很有帮助,
1009 | * 详细信息请参考文档。
1010 | * 默认值:False
1011 | * multi_client,
1012 | *
1013 | * 允许多个客户端连接到同一个窗口
1014 | * 这对web应用程序(非桌面软件)很有帮助,
1015 | * 详细信息请参考文档。
1016 | * 默认值:False
1017 | * use_cookies,
1018 | *
1019 | * @return object
1020 | */
1021 | public function config():object
1022 | {}
1023 |
1024 | /**
1025 | * 用于调用c的枚举
1026 | *
1027 | * @example 示例 ffi()->Chrome; // Chrome浏览器
1028 | * @return mixed
1029 | */
1030 | public function ffi(): mixed
1031 | {}
1032 | ```
1033 |
--------------------------------------------------------------------------------
/src/os/webui.h:
--------------------------------------------------------------------------------
1 | /*
2 | WebUI Library
3 | https://webui.me
4 | https://github.com/webui-dev/webui
5 | Copyright (c) 2020-2025 Hassan Draga.
6 | Licensed under MIT License.
7 | All rights reserved.
8 | Canada.
9 | */
10 |
11 | #ifndef _WEBUI_H
12 | #define _WEBUI_H
13 |
14 | #define WEBUI_VERSION "2.5.0-beta.3"
15 |
16 | // Max windows, servers and threads
17 | #define WEBUI_MAX_IDS (256)
18 |
19 | // Max allowed argument's index
20 | #define WEBUI_MAX_ARG (16)
21 |
22 | // Dynamic Library Exports
23 | #if defined(_WIN32) && (defined(_MSC_VER) || defined(__TINYC__))
24 | #ifndef WEBUI_EXPORT
25 | #define WEBUI_EXPORT __declspec(dllexport)
26 | #endif
27 | #else
28 | #ifndef WEBUI_EXPORT
29 | #define WEBUI_EXPORT extern
30 | #endif
31 | #endif
32 |
33 | #if defined(_MSC_VER)
34 | #define strdup _strdup
35 | #endif
36 |
37 | // -- C STD ---------------------------
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 | #include
45 | #include
46 | #include
47 | #include
48 | #include
49 | #include
50 |
51 | // -- Windows -------------------------
52 | #ifdef _WIN32
53 | #include
54 | #include
55 | #ifndef WIN32_LEAN_AND_MEAN
56 | #define WIN32_LEAN_AND_MEAN
57 | #endif
58 | #ifndef CGO
59 | #if defined(__GNUC__) || defined(__TINYC__)
60 | #include
61 | #endif
62 | #endif
63 | #include
64 | #include
65 | #include
66 | #include
67 | #include
68 | #include
69 | #define WEBUI_GET_CURRENT_DIR _getcwd
70 | #define WEBUI_FILE_EXIST _access
71 | #define WEBUI_POPEN _popen
72 | #define WEBUI_PCLOSE _pclose
73 | #define WEBUI_MAX_PATH MAX_PATH
74 | #endif
75 |
76 | // -- Linux ---------------------------
77 | #ifdef __linux__
78 | #include
79 | #include
80 | #include
81 | #include
82 | #include
83 | #include
84 | #include
85 | #include
86 | #include
87 | #include
88 | #define WEBUI_GET_CURRENT_DIR getcwd
89 | #define WEBUI_FILE_EXIST access
90 | #define WEBUI_POPEN popen
91 | #define WEBUI_PCLOSE pclose
92 | #define WEBUI_MAX_PATH PATH_MAX
93 | #endif
94 |
95 | // -- Apple ---------------------------
96 | #ifdef __APPLE__
97 | #include
98 | #include
99 | #include
100 | #include
101 | #include
102 | #include
103 | #include
104 | #include
105 | #include
106 | #include
107 | #include
108 | #include
109 | #include
110 | #define WEBUI_GET_CURRENT_DIR getcwd
111 | #define WEBUI_FILE_EXIST access
112 | #define WEBUI_POPEN popen
113 | #define WEBUI_PCLOSE pclose
114 | #define WEBUI_MAX_PATH PATH_MAX
115 | #endif
116 |
117 | // -- Enums ---------------------------
118 | enum webui_browser {
119 | NoBrowser = 0, // 0. No web browser
120 | AnyBrowser = 1, // 1. Default recommended web browser
121 | Chrome, // 2. Google Chrome
122 | Firefox, // 3. Mozilla Firefox
123 | Edge, // 4. Microsoft Edge
124 | Safari, // 5. Apple Safari
125 | Chromium, // 6. The Chromium Project
126 | Opera, // 7. Opera Browser
127 | Brave, // 8. The Brave Browser
128 | Vivaldi, // 9. The Vivaldi Browser
129 | Epic, // 10. The Epic Browser
130 | Yandex, // 11. The Yandex Browser
131 | ChromiumBased, // 12. Any Chromium based browser
132 | Webview, // 13. WebView (Non-web-browser)
133 | };
134 |
135 | enum webui_runtime {
136 | None = 0, // 0. Prevent WebUI from using any runtime for .js and .ts files
137 | Deno, // 1. Use Deno runtime for .js and .ts files
138 | NodeJS, // 2. Use Nodejs runtime for .js files
139 | Bun, // 3. Use Bun runtime for .js and .ts files
140 | };
141 |
142 | enum webui_event {
143 | WEBUI_EVENT_DISCONNECTED = 0, // 0. Window disconnection event
144 | WEBUI_EVENT_CONNECTED, // 1. Window connection event
145 | WEBUI_EVENT_MOUSE_CLICK, // 2. Mouse click event
146 | WEBUI_EVENT_NAVIGATION, // 3. Window navigation event
147 | WEBUI_EVENT_CALLBACK, // 4. Function call event
148 | };
149 |
150 | typedef enum {
151 | // Control if `webui_show()`, `webui_show_browser()` and
152 | // `webui_show_wv()` should wait for the window to connect
153 | // before returns or not.
154 | //
155 | // Default: True
156 | show_wait_connection = 0,
157 | // Control if WebUI should block and process the UI events
158 | // one a time in a single thread `True`, or process every
159 | // event in a new non-blocking thread `False`. This updates
160 | // all windows. You can use `webui_set_event_blocking()` for
161 | // a specific single window update.
162 | //
163 | // Default: False
164 | ui_event_blocking,
165 | // Automatically refresh the window UI when any file in the
166 | // root folder gets changed.
167 | //
168 | // Default: False
169 | folder_monitor,
170 | // Allow multiple clients to connect to the same window,
171 | // This is helpful for web apps (non-desktop software),
172 | // Please see the documentation for more details.
173 | //
174 | // Default: False
175 | multi_client,
176 | // Allow or prevent WebUI from adding `webui_auth` cookies.
177 | // WebUI uses these cookies to identify clients and block
178 | // unauthorized access to the window content using a URL.
179 | // Please keep this option to `True` if you want only a single
180 | // client to access the window content.
181 | //
182 | // Default: True
183 | use_cookies,
184 | // If the backend uses asynchronous operations, set this
185 | // option to `True`. This will make webui wait until the
186 | // backend sets a response using `webui_return_x()`.
187 | asynchronous_response
188 | } webui_config;
189 |
190 | // -- Structs -------------------------
191 | typedef struct webui_event_t {
192 | size_t window; // The window object number
193 | size_t event_type; // Event type
194 | char* element; // HTML element ID
195 | size_t event_number; // Internal WebUI
196 | size_t bind_id; // Bind ID
197 | size_t client_id; // Client's unique ID
198 | size_t connection_id; // Client's connection ID
199 | char* cookies; // Client's full cookies
200 | } webui_event_t;
201 |
202 | // -- Definitions ---------------------
203 |
204 | /**
205 | * @brief Create a new WebUI window object.
206 | *
207 | * @return Returns the window number.
208 | *
209 | * @example size_t myWindow = webui_new_window();
210 | */
211 | WEBUI_EXPORT size_t webui_new_window(void);
212 |
213 | /**
214 | * @brief Create a new webui window object using a specified window number.
215 | *
216 | * @param window_number The window number (should be > 0, and < WEBUI_MAX_IDS)
217 | *
218 | * @return Returns the same window number if success.
219 | *
220 | * @example size_t myWindow = webui_new_window_id(123);
221 | */
222 | WEBUI_EXPORT size_t webui_new_window_id(size_t window_number);
223 |
224 | /**
225 | * @brief Get a free window number that can be used with
226 | * `webui_new_window_id()`.
227 | *
228 | * @return Returns the first available free window number. Starting from 1.
229 | *
230 | * @example size_t myWindowNumber = webui_get_new_window_id();
231 | */
232 | WEBUI_EXPORT size_t webui_get_new_window_id(void);
233 |
234 | /**
235 | * @brief Bind an HTML element and a JavaScript object with a backend function. Empty
236 | * element name means all events.
237 | *
238 | * @param window The window number
239 | * @param element The HTML element / JavaScript object
240 | * @param func The callback function
241 | *
242 | * @return Returns a unique bind ID.
243 | *
244 | * @example webui_bind(myWindow, "myFunction", myFunction);
245 | */
246 | WEBUI_EXPORT size_t webui_bind(size_t window, const char* element, void (*func)(webui_event_t* e));
247 |
248 | /**
249 | * @brief Use this API after using `webui_bind()` to add any user data to it that can be
250 | * read later using `webui_get_context()`.
251 | *
252 | * @param window The window number
253 | * @param element The HTML element / JavaScript object
254 | * @param context Any user data
255 | *
256 | * @example
257 | * webui_bind(myWindow, "myFunction", myFunction);
258 | *
259 | * webui_set_context(myWindow, "myFunction", myData);
260 | *
261 | * void myFunction(webui_event_t* e) {
262 | * void* myData = webui_get_context(e);
263 | * }
264 | */
265 | WEBUI_EXPORT void webui_set_context(size_t window, const char* element, void* context);
266 |
267 | /**
268 | * @brief Get user data that is set using `webui_set_context()`.
269 | *
270 | * @param e The event struct
271 | *
272 | * @return Returns user data pointer.
273 | *
274 | * @example
275 | * webui_bind(myWindow, "myFunction", myFunction);
276 | *
277 | * webui_set_context(myWindow, "myFunction", myData);
278 | *
279 | * void myFunction(webui_event_t* e) {
280 | * void* myData = webui_get_context(e);
281 | * }
282 | */
283 | WEBUI_EXPORT void* webui_get_context(webui_event_t* e);
284 |
285 | /**
286 | * @brief Get the recommended web browser ID to use. If you
287 | * are already using one, this function will return the same ID.
288 | *
289 | * @param window The window number
290 | *
291 | * @return Returns a web browser ID.
292 | *
293 | * @example size_t browserID = webui_get_best_browser(myWindow);
294 | */
295 | WEBUI_EXPORT size_t webui_get_best_browser(size_t window);
296 |
297 | /**
298 | * @brief Show a window using embedded HTML, or a file. If the window is already
299 | * open, it will be refreshed. This will refresh all windows in multi-client mode.
300 | *
301 | * @param window The window number
302 | * @param content The HTML, URL, Or a local file
303 | *
304 | * @return Returns True if showing the window is successed.
305 | *
306 | * @example webui_show(myWindow, "..."); |
307 | * webui_show(myWindow, "index.html"); | webui_show(myWindow, "http://...");
308 | */
309 | WEBUI_EXPORT bool webui_show(size_t window, const char* content);
310 |
311 | /**
312 | * @brief Show a window using embedded HTML, or a file. If the window is already
313 | * open, it will be refreshed. Single client.
314 | *
315 | * @param e The event struct
316 | * @param content The HTML, URL, Or a local file
317 | *
318 | * @return Returns True if showing the window is successed.
319 | *
320 | * @example webui_show_client(e, "..."); |
321 | * webui_show_client(e, "index.html"); | webui_show_client(e, "http://...");
322 | */
323 | WEBUI_EXPORT bool webui_show_client(webui_event_t* e, const char* content);
324 |
325 | /**
326 | * @brief Same as `webui_show()`. But using a specific web browser.
327 | *
328 | * @param window The window number
329 | * @param content The HTML, Or a local file
330 | * @param browser The web browser to be used
331 | *
332 | * @return Returns True if showing the window is successed.
333 | *
334 | * @example webui_show_browser(myWindow, "...", Chrome); |
335 | * webui_show(myWindow, "index.html", Firefox);
336 | */
337 | WEBUI_EXPORT bool webui_show_browser(size_t window, const char* content, size_t browser);
338 |
339 | /**
340 | * @brief Same as `webui_show()`. But start only the web server and return the URL.
341 | * No window will be shown.
342 | *
343 | * @param window The window number
344 | * @param content The HTML, Or a local file
345 | *
346 | * @return Returns the url of this window server.
347 | *
348 | * @example const char* url = webui_start_server(myWindow, "/full/root/path");
349 | */
350 | WEBUI_EXPORT const char* webui_start_server(size_t window, const char* content);
351 |
352 | /**
353 | * @brief Show a WebView window using embedded HTML, or a file. If the window is already
354 | * open, it will be refreshed. Note: Win32 need `WebView2Loader.dll`.
355 | *
356 | * @param window The window number
357 | * @param content The HTML, URL, Or a local file
358 | *
359 | * @return Returns True if showing the WebView window is successed.
360 | *
361 | * @example webui_show_wv(myWindow, "..."); | webui_show_wv(myWindow,
362 | * "index.html"); | webui_show_wv(myWindow, "http://...");
363 | */
364 | WEBUI_EXPORT bool webui_show_wv(size_t window, const char* content);
365 |
366 | /**
367 | * @brief Set the window in Kiosk mode (Full screen).
368 | *
369 | * @param window The window number
370 | * @param status True or False
371 | *
372 | * @example webui_set_kiosk(myWindow, true);
373 | */
374 | WEBUI_EXPORT void webui_set_kiosk(size_t window, bool status);
375 |
376 | /**
377 | * @brief Add a user-defined web browser's CLI parameters.
378 | *
379 | * @param window The window number
380 | * @param params Command line parameters
381 | *
382 | * @example webui_set_custom_parameters(myWindow, "--remote-debugging-port=9222");
383 | */
384 | WEBUI_EXPORT void webui_set_custom_parameters(size_t window, char *params);
385 |
386 | /**
387 | * @brief Set the window with high-contrast support. Useful when you want to
388 | * build a better high-contrast theme with CSS.
389 | *
390 | * @param window The window number
391 | * @param status True or False
392 | *
393 | * @example webui_set_high_contrast(myWindow, true);
394 | */
395 | WEBUI_EXPORT void webui_set_high_contrast(size_t window, bool status);
396 |
397 | /**
398 | * @brief Get OS high contrast preference.
399 | *
400 | * @return Returns True if OS is using high contrast theme
401 | *
402 | * @example bool hc = webui_is_high_contrast();
403 | */
404 | WEBUI_EXPORT bool webui_is_high_contrast(void);
405 |
406 | /**
407 | * @brief Check if a web browser is installed.
408 | *
409 | * @return Returns True if the specified browser is available
410 | *
411 | * @example bool status = webui_browser_exist(Chrome);
412 | */
413 | WEBUI_EXPORT bool webui_browser_exist(size_t browser);
414 |
415 | /**
416 | * @brief Wait until all opened windows get closed.
417 | *
418 | * @example webui_wait();
419 | */
420 | WEBUI_EXPORT void webui_wait(void);
421 |
422 | /**
423 | * @brief Close a specific window only. The window object will still exist.
424 | * All clients.
425 | *
426 | * @param window The window number
427 | *
428 | * @example webui_close(myWindow);
429 | */
430 | WEBUI_EXPORT void webui_close(size_t window);
431 |
432 | /**
433 | * @brief Close a specific client.
434 | *
435 | * @param e The event struct
436 | *
437 | * @example webui_close_client(e);
438 | */
439 | WEBUI_EXPORT void webui_close_client(webui_event_t* e);
440 |
441 | /**
442 | * @brief Close a specific window and free all memory resources.
443 | *
444 | * @param window The window number
445 | *
446 | * @example webui_destroy(myWindow);
447 | */
448 | WEBUI_EXPORT void webui_destroy(size_t window);
449 |
450 | /**
451 | * @brief Close all open windows. `webui_wait()` will return (Break).
452 | *
453 | * @example webui_exit();
454 | */
455 | WEBUI_EXPORT void webui_exit(void);
456 |
457 | /**
458 | * @brief Set the web-server root folder path for a specific window.
459 | *
460 | * @param window The window number
461 | * @param path The local folder full path
462 | *
463 | * @example webui_set_root_folder(myWindow, "/home/Foo/Bar/");
464 | */
465 | WEBUI_EXPORT bool webui_set_root_folder(size_t window, const char* path);
466 |
467 | /**
468 | * @brief Set the web-server root folder path for all windows. Should be used
469 | * before `webui_show()`.
470 | *
471 | * @param path The local folder full path
472 | *
473 | * @example webui_set_default_root_folder("/home/Foo/Bar/");
474 | */
475 | WEBUI_EXPORT bool webui_set_default_root_folder(const char* path);
476 |
477 | /**
478 | * @brief Set a custom handler to serve files. This custom handler should
479 | * return full HTTP header and body.
480 | * This deactivates any previous handler set with `webui_set_file_handler_window`
481 | *
482 | * @param window The window number
483 | * @param handler The handler function: `void myHandler(const char* filename,
484 | * int* length)`
485 | *
486 | * @example webui_set_file_handler(myWindow, myHandlerFunction);
487 | */
488 | WEBUI_EXPORT void webui_set_file_handler(size_t window, const void* (*handler)(const char* filename, int* length));
489 |
490 | /**
491 | * @brief Set a custom handler to serve files. This custom handler should
492 | * return full HTTP header and body.
493 | * This deactivates any previous handler set with `webui_set_file_handler`
494 | *
495 | * @param window The window number
496 | * @param handler The handler function: `void myHandler(size_t window, const char* filename,
497 | * int* length)`
498 | *
499 | * @example webui_set_file_handler_window(myWindow, myHandlerFunction);
500 | */
501 | WEBUI_EXPORT void webui_set_file_handler_window(size_t window, const void* (*handler)(size_t window, const char* filename, int* length));
502 |
503 | /**
504 | * @brief Use this API to set a file handler response if your backend need async
505 | * response for `webui_set_file_handler()`.
506 | *
507 | * @param window The window number
508 | * @param response The response buffer
509 | * @param length The response size
510 | *
511 | * @example webui_interface_set_response_file_handler(myWindow, buffer, 1024);
512 | */
513 | WEBUI_EXPORT void webui_interface_set_response_file_handler(size_t window, const void* response, int length);
514 |
515 | /**
516 | * @brief Check if the specified window is still running.
517 | *
518 | * @param window The window number
519 | *
520 | * @example webui_is_shown(myWindow);
521 | */
522 | WEBUI_EXPORT bool webui_is_shown(size_t window);
523 |
524 | /**
525 | * @brief Set the maximum time in seconds to wait for the window to connect.
526 | * This effect `show()` and `wait()`. Value of `0` means wait forever.
527 | *
528 | * @param second The timeout in seconds
529 | *
530 | * @example webui_set_timeout(30);
531 | */
532 | WEBUI_EXPORT void webui_set_timeout(size_t second);
533 |
534 | /**
535 | * @brief Set the default embedded HTML favicon.
536 | *
537 | * @param window The window number
538 | * @param icon The icon as string: `... `
539 | * @param icon_type The icon type: `image/svg+xml`
540 | *
541 | * @example webui_set_icon(myWindow, "... ", "image/svg+xml");
542 | */
543 | WEBUI_EXPORT void webui_set_icon(size_t window, const char* icon, const char* icon_type);
544 |
545 | /**
546 | * @brief Encode text to Base64. The returned buffer need to be freed.
547 | *
548 | * @param str The string to encode (Should be null terminated)
549 | *
550 | * @return Returns the base64 encoded string
551 | *
552 | * @example char* base64 = webui_encode("Foo Bar");
553 | */
554 | WEBUI_EXPORT char* webui_encode(const char* str);
555 |
556 | /**
557 | * @brief Decode a Base64 encoded text. The returned buffer need to be freed.
558 | *
559 | * @param str The string to decode (Should be null terminated)
560 | *
561 | * @return Returns the base64 decoded string
562 | *
563 | * @example char* str = webui_decode("SGVsbG8=");
564 | */
565 | WEBUI_EXPORT char* webui_decode(const char* str);
566 |
567 | /**
568 | * @brief Safely free a buffer allocated by WebUI using `webui_malloc()`.
569 | *
570 | * @param ptr The buffer to be freed
571 | *
572 | * @example webui_free(myBuffer);
573 | */
574 | WEBUI_EXPORT void webui_free(void* ptr);
575 |
576 | /**
577 | * @brief Safely allocate memory using the WebUI memory management system. It
578 | * can be safely freed using `webui_free()` at any time.
579 | *
580 | * @param size The size of memory in bytes
581 | *
582 | * @example char* myBuffer = (char*)webui_malloc(1024);
583 | */
584 | WEBUI_EXPORT void* webui_malloc(size_t size);
585 |
586 | /**
587 | * @brief Copy raw data.
588 | *
589 | * @param dest Destination memory pointer
590 | * @param src Source memory pointer
591 | * @param count Bytes to copy
592 | *
593 | * @example webui_memcpy(myBuffer, myData, 64);
594 | */
595 | WEBUI_EXPORT void webui_memcpy(void* dest, void* src, size_t count);
596 |
597 | /**
598 | * @brief Safely send raw data to the UI. All clients.
599 | *
600 | * @param window The window number
601 | * @param function The JavaScript function to receive raw data: `function
602 | * myFunc(myData){}`
603 | * @param raw The raw data buffer
604 | * @param size The raw data size in bytes
605 | *
606 | * @example webui_send_raw(myWindow, "myJavaScriptFunc", myBuffer, 64);
607 | */
608 | WEBUI_EXPORT void webui_send_raw(size_t window, const char* function, const void* raw, size_t size);
609 |
610 | /**
611 | * @brief Safely send raw data to the UI. Single client.
612 | *
613 | * @param e The event struct
614 | * @param function The JavaScript function to receive raw data: `function
615 | * myFunc(myData){}`
616 | * @param raw The raw data buffer
617 | * @param size The raw data size in bytes
618 | *
619 | * @example webui_send_raw_client(e, "myJavaScriptFunc", myBuffer, 64);
620 | */
621 | WEBUI_EXPORT void webui_send_raw_client(webui_event_t* e, const char* function,
622 | const void* raw, size_t size);
623 |
624 | /**
625 | * @brief Set a window in hidden mode. Should be called before `webui_show()`.
626 | *
627 | * @param window The window number
628 | * @param status The status: True or False
629 | *
630 | * @example webui_set_hide(myWindow, True);
631 | */
632 | WEBUI_EXPORT void webui_set_hide(size_t window, bool status);
633 |
634 | /**
635 | * @brief Set the window size.
636 | *
637 | * @param window The window number
638 | * @param width The window width
639 | * @param height The window height
640 | *
641 | * @example webui_set_size(myWindow, 800, 600);
642 | */
643 | WEBUI_EXPORT void webui_set_size(size_t window, unsigned int width, unsigned int height);
644 |
645 | /**
646 | * @brief Set the window minimum size.
647 | *
648 | * @param window The window number
649 | * @param width The window width
650 | * @param height The window height
651 | *
652 | * @example webui_set_minimum_size(myWindow, 800, 600);
653 | */
654 | WEBUI_EXPORT void webui_set_minimum_size(size_t window, unsigned int width, unsigned int height);
655 |
656 | /**
657 | * @brief Set the window position.
658 | *
659 | * @param window The window number
660 | * @param x The window X
661 | * @param y The window Y
662 | *
663 | * @example webui_set_position(myWindow, 100, 100);
664 | */
665 | WEBUI_EXPORT void webui_set_position(size_t window, unsigned int x, unsigned int y);
666 |
667 | /**
668 | * @brief Set the web browser profile to use. An empty `name` and `path` means
669 | * the default user profile. Need to be called before `webui_show()`.
670 | *
671 | * @param window The window number
672 | * @param name The web browser profile name
673 | * @param path The web browser profile full path
674 | *
675 | * @example webui_set_profile(myWindow, "Bar", "/Home/Foo/Bar"); |
676 | * webui_set_profile(myWindow, "", "");
677 | */
678 | WEBUI_EXPORT void webui_set_profile(size_t window, const char* name, const char* path);
679 |
680 | /**
681 | * @brief Set the web browser proxy server to use. Need to be called before `webui_show()`.
682 | *
683 | * @param window The window number
684 | * @param proxy_server The web browser proxy_server
685 | *
686 | * @example webui_set_proxy(myWindow, "http://127.0.0.1:8888");
687 | */
688 | WEBUI_EXPORT void webui_set_proxy(size_t window, const char* proxy_server);
689 |
690 | /**
691 | * @brief Get current URL of a running window.
692 | *
693 | * @param window The window number
694 | *
695 | * @return Returns the full URL string
696 | *
697 | * @example const char* url = webui_get_url(myWindow);
698 | */
699 | WEBUI_EXPORT const char* webui_get_url(size_t window);
700 |
701 | /**
702 | * @brief Open an URL in the native default web browser.
703 | *
704 | * @param url The URL to open
705 | *
706 | * @example webui_open_url("https://webui.me");
707 | */
708 | WEBUI_EXPORT void webui_open_url(const char* url);
709 |
710 | /**
711 | * @brief Allow a specific window address to be accessible from a public network.
712 | *
713 | * @param window The window number
714 | * @param status True or False
715 | *
716 | * @example webui_set_public(myWindow, true);
717 | */
718 | WEBUI_EXPORT void webui_set_public(size_t window, bool status);
719 |
720 | /**
721 | * @brief Navigate to a specific URL. All clients.
722 | *
723 | * @param window The window number
724 | * @param url Full HTTP URL
725 | *
726 | * @example webui_navigate(myWindow, "http://domain.com");
727 | */
728 | WEBUI_EXPORT void webui_navigate(size_t window, const char* url);
729 |
730 | /**
731 | * @brief Navigate to a specific URL. Single client.
732 | *
733 | * @param e The event struct
734 | * @param url Full HTTP URL
735 | *
736 | * @example webui_navigate_client(e, "http://domain.com");
737 | */
738 | WEBUI_EXPORT void webui_navigate_client(webui_event_t* e, const char* url);
739 |
740 | /**
741 | * @brief Free all memory resources. Should be called only at the end.
742 | *
743 | * @example
744 | * webui_wait();
745 | * webui_clean();
746 | */
747 | WEBUI_EXPORT void webui_clean(void);
748 |
749 | /**
750 | * @brief Delete all local web-browser profiles folder. It should be called at the
751 | * end.
752 | *
753 | * @example
754 | * webui_wait();
755 | * webui_delete_all_profiles();
756 | * webui_clean();
757 | */
758 | WEBUI_EXPORT void webui_delete_all_profiles(void);
759 |
760 | /**
761 | * @brief Delete a specific window web-browser local folder profile.
762 | *
763 | * @param window The window number
764 | *
765 | * @example
766 | * webui_wait();
767 | * webui_delete_profile(myWindow);
768 | * webui_clean();
769 | *
770 | * @note This can break functionality of other windows if using the same
771 | * web-browser.
772 | */
773 | WEBUI_EXPORT void webui_delete_profile(size_t window);
774 |
775 | /**
776 | * @brief Get the ID of the parent process (The web browser may re-create
777 | * another new process).
778 | *
779 | * @param window The window number
780 | *
781 | * @return Returns the the parent process id as integer
782 | *
783 | * @example size_t id = webui_get_parent_process_id(myWindow);
784 | */
785 | WEBUI_EXPORT size_t webui_get_parent_process_id(size_t window);
786 |
787 | /**
788 | * @brief Get the ID of the last child process.
789 | *
790 | * @param window The window number
791 | *
792 | * @return Returns the the child process id as integer
793 | *
794 | * @example size_t id = webui_get_child_process_id(myWindow);
795 | */
796 | WEBUI_EXPORT size_t webui_get_child_process_id(size_t window);
797 |
798 | /**
799 | * @brief Gets Win32 window `HWND`. More reliable with WebView
800 | * than web browser window, as browser PIDs may change on launch.
801 | *
802 | * @param window The window number
803 | *
804 | * @return Returns the window `hwnd` as `void*`
805 | *
806 | * @example HWND hwnd = webui_win32_get_hwnd(myWindow);
807 | */
808 | WEBUI_EXPORT void* webui_win32_get_hwnd(size_t window);
809 |
810 | /**
811 | * @brief Get the network port of a running window.
812 | * This can be useful to determine the HTTP link of `webui.js`
813 | *
814 | * @param window The window number
815 | *
816 | * @return Returns the network port of the window
817 | *
818 | * @example size_t port = webui_get_port(myWindow);
819 | */
820 | WEBUI_EXPORT size_t webui_get_port(size_t window);
821 |
822 | /**
823 | * @brief Set a custom web-server/websocket network port to be used by WebUI.
824 | * This can be useful to determine the HTTP link of `webui.js` in case
825 | * you are trying to use WebUI with an external web-server like NGNIX.
826 | *
827 | * @param window The window number
828 | * @param port The web-server network port WebUI should use
829 | *
830 | * @return Returns True if the port is free and usable by WebUI
831 | *
832 | * @example bool ret = webui_set_port(myWindow, 8080);
833 | */
834 | WEBUI_EXPORT bool webui_set_port(size_t window, size_t port);
835 |
836 | /**
837 | * @brief Get an available usable free network port.
838 | *
839 | * @return Returns a free port
840 | *
841 | * @example size_t port = webui_get_free_port();
842 | */
843 | WEBUI_EXPORT size_t webui_get_free_port(void);
844 |
845 | /**
846 | * @brief Control the WebUI behaviour. It's recommended to be called at the beginning.
847 | *
848 | * @param option The desired option from `webui_config` enum
849 | * @param status The status of the option, `true` or `false`
850 | *
851 | * @example webui_set_config(show_wait_connection, false);
852 | */
853 | WEBUI_EXPORT void webui_set_config(webui_config option, bool status);
854 |
855 | /**
856 | * @brief Control if UI events comming from this window should be processed
857 | * one a time in a single blocking thread `True`, or process every event in
858 | * a new non-blocking thread `False`. This update single window. You can use
859 | * `webui_set_config(ui_event_blocking, ...)` to update all windows.
860 | *
861 | * @param window The window number
862 | * @param status The blocking status `true` or `false`
863 | *
864 | * @example webui_set_event_blocking(myWindow, true);
865 | */
866 | WEBUI_EXPORT void webui_set_event_blocking(size_t window, bool status);
867 |
868 | /**
869 | * @brief Get the HTTP mime type of a file.
870 | *
871 | * @return Returns the HTTP mime string
872 | *
873 | * @example const char* mime = webui_get_mime_type("foo.png");
874 | */
875 | WEBUI_EXPORT const char* webui_get_mime_type(const char* file);
876 |
877 | // -- SSL/TLS -------------------------
878 |
879 | /**
880 | * @brief Set the SSL/TLS certificate and the private key content, both in PEM
881 | * format. This works only with `webui-2-secure` library. If set empty WebUI
882 | * will generate a self-signed certificate.
883 | *
884 | * @param certificate_pem The SSL/TLS certificate content in PEM format
885 | * @param private_key_pem The private key content in PEM format
886 | *
887 | * @return Returns True if the certificate and the key are valid.
888 | *
889 | * @example bool ret = webui_set_tls_certificate("-----BEGIN
890 | * CERTIFICATE-----\n...", "-----BEGIN PRIVATE KEY-----\n...");
891 | */
892 | WEBUI_EXPORT bool webui_set_tls_certificate(const char* certificate_pem, const char* private_key_pem);
893 |
894 | // -- JavaScript ----------------------
895 |
896 | /**
897 | * @brief Run JavaScript without waiting for the response. All clients.
898 | *
899 | * @param window The window number
900 | * @param script The JavaScript to be run
901 | *
902 | * @example webui_run(myWindow, "alert('Hello');");
903 | */
904 | WEBUI_EXPORT void webui_run(size_t window, const char* script);
905 |
906 | /**
907 | * @brief Run JavaScript without waiting for the response. Single client.
908 | *
909 | * @param e The event struct
910 | * @param script The JavaScript to be run
911 | *
912 | * @example webui_run_client(e, "alert('Hello');");
913 | */
914 | WEBUI_EXPORT void webui_run_client(webui_event_t* e, const char* script);
915 |
916 | /**
917 | * @brief Run JavaScript and get the response back. Work only in single client mode.
918 | * Make sure your local buffer can hold the response.
919 | *
920 | * @param window The window number
921 | * @param script The JavaScript to be run
922 | * @param timeout The execution timeout in seconds
923 | * @param buffer The local buffer to hold the response
924 | * @param buffer_length The local buffer size
925 | *
926 | * @return Returns True if there is no execution error
927 | *
928 | * @example bool err = webui_script(myWindow, "return 4 + 6;", 0, myBuffer, myBufferSize);
929 | */
930 | WEBUI_EXPORT bool webui_script(size_t window, const char* script, size_t timeout,
931 | char* buffer, size_t buffer_length);
932 |
933 | /**
934 | * @brief Run JavaScript and get the response back. Single client.
935 | * Make sure your local buffer can hold the response.
936 | *
937 | * @param e The event struct
938 | * @param script The JavaScript to be run
939 | * @param timeout The execution timeout in seconds
940 | * @param buffer The local buffer to hold the response
941 | * @param buffer_length The local buffer size
942 | *
943 | * @return Returns True if there is no execution error
944 | *
945 | * @example bool err = webui_script_client(e, "return 4 + 6;", 0, myBuffer, myBufferSize);
946 | */
947 | WEBUI_EXPORT bool webui_script_client(webui_event_t* e, const char* script, size_t timeout,
948 | char* buffer, size_t buffer_length);
949 |
950 | /**
951 | * @brief Chose between Deno and Nodejs as runtime for .js and .ts files.
952 | *
953 | * @param window The window number
954 | * @param runtime Deno | Bun | Nodejs | None
955 | *
956 | * @example webui_set_runtime(myWindow, Deno);
957 | */
958 | WEBUI_EXPORT void webui_set_runtime(size_t window, size_t runtime);
959 |
960 | /**
961 | * @brief Get how many arguments there are in an event.
962 | *
963 | * @param e The event struct
964 | *
965 | * @return Returns the arguments count.
966 | *
967 | * @example size_t count = webui_get_count(e);
968 | */
969 | WEBUI_EXPORT size_t webui_get_count(webui_event_t* e);
970 |
971 | /**
972 | * @brief Get an argument as integer at a specific index.
973 | *
974 | * @param e The event struct
975 | * @param index The argument position starting from 0
976 | *
977 | * @return Returns argument as integer
978 | *
979 | * @example long long int myNum = webui_get_int_at(e, 0);
980 | */
981 | WEBUI_EXPORT long long int webui_get_int_at(webui_event_t* e, size_t index);
982 |
983 | /**
984 | * @brief Get the first argument as integer.
985 | *
986 | * @param e The event struct
987 | *
988 | * @return Returns argument as integer
989 | *
990 | * @example long long int myNum = webui_get_int(e);
991 | */
992 | WEBUI_EXPORT long long int webui_get_int(webui_event_t* e);
993 |
994 | /**
995 | * @brief Get an argument as float at a specific index.
996 | *
997 | * @param e The event struct
998 | * @param index The argument position starting from 0
999 | *
1000 | * @return Returns argument as float
1001 | *
1002 | * @example double myNum = webui_get_float_at(e, 0);
1003 | */
1004 | WEBUI_EXPORT double webui_get_float_at(webui_event_t* e, size_t index);
1005 |
1006 | /**
1007 | * @brief Get the first argument as float.
1008 | *
1009 | * @param e The event struct
1010 | *
1011 | * @return Returns argument as float
1012 | *
1013 | * @example double myNum = webui_get_float(e);
1014 | */
1015 | WEBUI_EXPORT double webui_get_float(webui_event_t* e);
1016 |
1017 | /**
1018 | * @brief Get an argument as string at a specific index.
1019 | *
1020 | * @param e The event struct
1021 | * @param index The argument position starting from 0
1022 | *
1023 | * @return Returns argument as string
1024 | *
1025 | * @example const char* myStr = webui_get_string_at(e, 0);
1026 | */
1027 | WEBUI_EXPORT const char* webui_get_string_at(webui_event_t* e, size_t index);
1028 |
1029 | /**
1030 | * @brief Get the first argument as string.
1031 | *
1032 | * @param e The event struct
1033 | *
1034 | * @return Returns argument as string
1035 | *
1036 | * @example const char* myStr = webui_get_string(e);
1037 | */
1038 | WEBUI_EXPORT const char* webui_get_string(webui_event_t* e);
1039 |
1040 | /**
1041 | * @brief Get an argument as boolean at a specific index.
1042 | *
1043 | * @param e The event struct
1044 | * @param index The argument position starting from 0
1045 | *
1046 | * @return Returns argument as boolean
1047 | *
1048 | * @example bool myBool = webui_get_bool_at(e, 0);
1049 | */
1050 | WEBUI_EXPORT bool webui_get_bool_at(webui_event_t* e, size_t index);
1051 |
1052 | /**
1053 | * @brief Get the first argument as boolean.
1054 | *
1055 | * @param e The event struct
1056 | *
1057 | * @return Returns argument as boolean
1058 | *
1059 | * @example bool myBool = webui_get_bool(e);
1060 | */
1061 | WEBUI_EXPORT bool webui_get_bool(webui_event_t* e);
1062 |
1063 | /**
1064 | * @brief Get the size in bytes of an argument at a specific index.
1065 | *
1066 | * @param e The event struct
1067 | * @param index The argument position starting from 0
1068 | *
1069 | * @return Returns size in bytes
1070 | *
1071 | * @example size_t argLen = webui_get_size_at(e, 0);
1072 | */
1073 | WEBUI_EXPORT size_t webui_get_size_at(webui_event_t* e, size_t index);
1074 |
1075 | /**
1076 | * @brief Get size in bytes of the first argument.
1077 | *
1078 | * @param e The event struct
1079 | *
1080 | * @return Returns size in bytes
1081 | *
1082 | * @example size_t argLen = webui_get_size(e);
1083 | */
1084 | WEBUI_EXPORT size_t webui_get_size(webui_event_t* e);
1085 |
1086 | /**
1087 | * @brief Return the response to JavaScript as integer.
1088 | *
1089 | * @param e The event struct
1090 | * @param n The integer to be send to JavaScript
1091 | *
1092 | * @example webui_return_int(e, 123);
1093 | */
1094 | WEBUI_EXPORT void webui_return_int(webui_event_t* e, long long int n);
1095 |
1096 | /**
1097 | * @brief Return the response to JavaScript as float.
1098 | *
1099 | * @param e The event struct
1100 | * @param f The float number to be send to JavaScript
1101 | *
1102 | * @example webui_return_float(e, 123.456);
1103 | */
1104 | WEBUI_EXPORT void webui_return_float(webui_event_t* e, double f);
1105 |
1106 | /**
1107 | * @brief Return the response to JavaScript as string.
1108 | *
1109 | * @param e The event struct
1110 | * @param n The string to be send to JavaScript
1111 | *
1112 | * @example webui_return_string(e, "Response...");
1113 | */
1114 | WEBUI_EXPORT void webui_return_string(webui_event_t* e, const char* s);
1115 |
1116 | /**
1117 | * @brief Return the response to JavaScript as boolean.
1118 | *
1119 | * @param e The event struct
1120 | * @param n The boolean to be send to JavaScript
1121 | *
1122 | * @example webui_return_bool(e, true);
1123 | */
1124 | WEBUI_EXPORT void webui_return_bool(webui_event_t* e, bool b);
1125 |
1126 | // -- Wrapper's Interface -------------
1127 |
1128 | /**
1129 | * @brief Bind a specific HTML element click event with a function. Empty element means all events.
1130 | *
1131 | * @param window The window number
1132 | * @param element The element ID
1133 | * @param func The callback as myFunc(Window, EventType, Element, EventNumber, BindID)
1134 | *
1135 | * @return Returns unique bind ID
1136 | *
1137 | * @example size_t id = webui_interface_bind(myWindow, "myID", myCallback);
1138 | */
1139 | WEBUI_EXPORT size_t webui_interface_bind(size_t window, const char* element,
1140 | void (*func)(size_t, size_t, char*, size_t, size_t));
1141 |
1142 | /**
1143 | * @brief When using `webui_interface_bind()`, you may need this function to easily set a response.
1144 | *
1145 | * @param window The window number
1146 | * @param event_number The event number
1147 | * @param response The response as string to be send to JavaScript
1148 | *
1149 | * @example webui_interface_set_response(myWindow, e->event_number, "Response...");
1150 | */
1151 | WEBUI_EXPORT void webui_interface_set_response(size_t window, size_t event_number, const char* response);
1152 |
1153 | /**
1154 | * @brief Check if the app still running.
1155 | *
1156 | * @return Returns True if app is running
1157 | *
1158 | * @example bool status = webui_interface_is_app_running();
1159 | */
1160 | WEBUI_EXPORT bool webui_interface_is_app_running(void);
1161 |
1162 | /**
1163 | * @brief Get a unique window ID.
1164 | *
1165 | * @param window The window number
1166 | *
1167 | * @return Returns the unique window ID as integer
1168 | *
1169 | * @example size_t id = webui_interface_get_window_id(myWindow);
1170 | */
1171 | WEBUI_EXPORT size_t webui_interface_get_window_id(size_t window);
1172 |
1173 | /**
1174 | * @brief Get an argument as string at a specific index.
1175 | *
1176 | * @param window The window number
1177 | * @param event_number The event number
1178 | * @param index The argument position
1179 | *
1180 | * @return Returns argument as string
1181 | *
1182 | * @example const char* myStr = webui_interface_get_string_at(myWindow, e->event_number, 0);
1183 | */
1184 | WEBUI_EXPORT const char* webui_interface_get_string_at(size_t window, size_t event_number, size_t index);
1185 |
1186 | /**
1187 | * @brief Get an argument as integer at a specific index.
1188 | *
1189 | * @param window The window number
1190 | * @param event_number The event number
1191 | * @param index The argument position
1192 | *
1193 | * @return Returns argument as integer
1194 | *
1195 | * @example long long int myNum = webui_interface_get_int_at(myWindow, e->event_number, 0);
1196 | */
1197 | WEBUI_EXPORT long long int webui_interface_get_int_at(size_t window, size_t event_number, size_t index);
1198 |
1199 | /**
1200 | * @brief Get an argument as float at a specific index.
1201 | *
1202 | * @param window The window number
1203 | * @param event_number The event number
1204 | * @param index The argument position
1205 | *
1206 | * @return Returns argument as float
1207 | *
1208 | * @example double myFloat = webui_interface_get_int_at(myWindow, e->event_number, 0);
1209 | */
1210 | WEBUI_EXPORT double webui_interface_get_float_at(size_t window, size_t event_number, size_t index);
1211 |
1212 | /**
1213 | * @brief Get an argument as boolean at a specific index.
1214 | *
1215 | * @param window The window number
1216 | * @param event_number The event number
1217 | * @param index The argument position
1218 | *
1219 | * @return Returns argument as boolean
1220 | *
1221 | * @example bool myBool = webui_interface_get_bool_at(myWindow, e->event_number, 0);
1222 | */
1223 | WEBUI_EXPORT bool webui_interface_get_bool_at(size_t window, size_t event_number, size_t index);
1224 |
1225 | /**
1226 | * @brief Get the size in bytes of an argument at a specific index.
1227 | *
1228 | * @param window The window number
1229 | * @param event_number The event number
1230 | * @param index The argument position
1231 | *
1232 | * @return Returns size in bytes
1233 | *
1234 | * @example size_t argLen = webui_interface_get_size_at(myWindow, e->event_number, 0);
1235 | */
1236 | WEBUI_EXPORT size_t webui_interface_get_size_at(size_t window, size_t event_number, size_t index);
1237 |
1238 | /**
1239 | * @brief Show a window using embedded HTML, or a file. If the window is already
1240 | * open, it will be refreshed. Single client.
1241 | *
1242 | * @param window The window number
1243 | * @param event_number The event number
1244 | * @param content The HTML, URL, Or a local file
1245 | *
1246 | * @return Returns True if showing the window is successed.
1247 | *
1248 | * @example webui_show_client(e, "..."); |
1249 | * webui_show_client(e, "index.html"); | webui_show_client(e, "http://...");
1250 | */
1251 | WEBUI_EXPORT bool webui_interface_show_client(size_t window, size_t event_number, const char* content);
1252 |
1253 | /**
1254 | * @brief Close a specific client.
1255 | *
1256 | * @param window The window number
1257 | * @param event_number The event number
1258 | *
1259 | * @example webui_close_client(e);
1260 | */
1261 | WEBUI_EXPORT void webui_interface_close_client(size_t window, size_t event_number);
1262 |
1263 | /**
1264 | * @brief Safely send raw data to the UI. Single client.
1265 | *
1266 | * @param window The window number
1267 | * @param event_number The event number
1268 | * @param function The JavaScript function to receive raw data: `function
1269 | * myFunc(myData){}`
1270 | * @param raw The raw data buffer
1271 | * @param size The raw data size in bytes
1272 | *
1273 | * @example webui_send_raw_client(e, "myJavaScriptFunc", myBuffer, 64);
1274 | */
1275 | WEBUI_EXPORT void webui_interface_send_raw_client(size_t window, size_t event_number, const char* function, const void* raw, size_t size);
1276 |
1277 | /**
1278 | * @brief Navigate to a specific URL. Single client.
1279 | *
1280 | * @param window The window number
1281 | * @param event_number The event number
1282 | * @param url Full HTTP URL
1283 | *
1284 | * @example webui_navigate_client(e, "http://domain.com");
1285 | */
1286 | WEBUI_EXPORT void webui_interface_navigate_client(size_t window, size_t event_number, const char* url);
1287 |
1288 | /**
1289 | * @brief Run JavaScript without waiting for the response. Single client.
1290 | *
1291 | * @param window The window number
1292 | * @param event_number The event number
1293 | * @param script The JavaScript to be run
1294 | *
1295 | * @example webui_run_client(e, "alert('Hello');");
1296 | */
1297 | WEBUI_EXPORT void webui_interface_run_client(size_t window, size_t event_number, const char* script);
1298 |
1299 | /**
1300 | * @brief Run JavaScript and get the response back. Single client.
1301 | * Make sure your local buffer can hold the response.
1302 | *
1303 | * @param window The window number
1304 | * @param event_number The event number
1305 | * @param script The JavaScript to be run
1306 | * @param timeout The execution timeout in seconds
1307 | * @param buffer The local buffer to hold the response
1308 | * @param buffer_length The local buffer size
1309 | *
1310 | * @return Returns True if there is no execution error
1311 | *
1312 | * @example bool err = webui_script_client(e, "return 4 + 6;", 0, myBuffer, myBufferSize);
1313 | */
1314 | WEBUI_EXPORT bool webui_interface_script_client(size_t window, size_t event_number, const char* script, size_t timeout, char* buffer, size_t buffer_length);
1315 |
1316 | #endif /* _WEBUI_H */
1317 |
--------------------------------------------------------------------------------