Compare commits

...

54 Commits

Author SHA1 Message Date
Albert
9dd20b5c98 Update frameless example 2025-03-25 16:12:31 -04:00
Albert
65fd9a8800 Fix out of screen 2025-03-25 16:10:59 -04:00
Albert
3c03d4f45c Fix GCC Warning - ICoreWebView2Controller 2025-03-19 12:20:50 -04:00
Albert
1f80350564 Win32 - Safer WM_EXITSIZEMOVE 2025-03-19 10:54:03 -04:00
Albert
4c8fc25b2d Fix zig warning - Win32 LONG 2025-03-18 19:10:36 -04:00
Albert
b59ddf1c0c Fix zig warning - Win32 LPVOID 2025-03-18 19:02:25 -04:00
Albert
5fafc9b6b6 Improve webkit-app-region precision 2025-03-18 19:00:16 -04:00
Albert
995f1ab25f Frameless + Transparent Screenshot 2025-03-18 17:58:21 -04:00
Albert
d274723ec6 Updating frameless example 2025-03-18 17:46:56 -04:00
Albert
9430e57040 New API - webui_set_transparent 2025-03-18 17:45:34 -04:00
Albert
78b163c350 Win32 - Up WebView Controller Version 2025-03-18 13:52:42 -04:00
Albert
af455d38ee webui_set_center - Linux 2025-03-17 17:22:04 -04:00
Albert
5c52beebfb Fix macOS Build 2025-03-17 15:03:42 -04:00
Albert
ea5e9a57fc Adding webui_set_resizable (macOS) - Not Tested 2025-03-17 14:54:47 -04:00
Albert
c50fcdf5da Adding webui_set_resizable (Linux) 2025-03-17 14:38:13 -04:00
Albert
433dcc25e0 Internal flags rename 2025-03-17 14:07:15 -04:00
Albert
c66b71a98c Renaming webui_wv_set_frameless to webui_set_frameless 2025-03-17 14:01:51 -04:00
Albert
f21f4f14e1 Adding webui_set_resizable (Win32) 2025-03-17 13:59:10 -04:00
Albert
84758f6742 Adding webui_set_center 2025-03-17 13:14:24 -04:00
Hassan DRAGA
aec0f654ba Frameless Example (Not complete) 2025-03-16 00:59:47 -04:00
Hassan DRAGA
ed3aae5790 New webui_minimize and webui_maximize (Not complete) 2025-03-16 00:59:02 -04:00
Hassan DRAGA
d2b40ee7e6 Minor tab spaces cleaning 2025-03-15 23:49:06 -04:00
Hassan DRAGA
25c7e3f16c hwnd check before use 2025-03-15 23:11:21 -04:00
Hassan DRAGA
361237669b macOS frameless window 2025-03-15 18:55:31 -04:00
Hassan DRAGA
c6d5b58352 Custom webkit-app-region implementation 2025-03-15 18:29:28 -04:00
Hassan DRAGA
7e257de1b0 Linux GTK Frameless 2025-03-15 16:13:10 -04:00
Hassan DRAGA
16aec7e181 Renaming webui_wv_set_headless to webui_wv_set_frameless 2025-03-15 15:56:59 -04:00
Hassan DRAGA
5415b19b5f
Merge pull request #570 from eliemichel/patch-2
Fix `WEBUI_STR_CAT_STATIC` on Windows
2025-03-15 15:13:52 -04:00
Hassan DRAGA
c9baba76b7
Merge pull request #568 from eliemichel/patch-1
Remove "index" argument from get_count()
2025-03-15 14:19:37 -04:00
Elie Michel
f4b9043288
Fix WEBUI_STR_CAT_STATIC on Windows
`strcat_s` expects the total destination size as second argument, contrary to `strncat`.
2025-03-15 13:07:28 +01:00
Elie Michel
facd97c107
Remove "index" argument from get_count()
Argument is not used, I suspect it ended up here as part of an abusive copy-paste!
2025-03-15 12:30:42 +01:00
Albert
223608479b macOS - Fix Quick Close WebView 2025-03-14 13:41:53 -04:00
Albert
305070eeb1 macOS - Fix missing symbol build 2025-03-14 12:43:57 -04:00
Albert
7d310a7c1f Fix macOS Build 2025-03-14 12:36:45 -04:00
Albert
d58e04ff05 Safer webui_clean 2025-03-14 12:13:00 -04:00
Albert
1b2f7b637b Fix macOS CPU usage 2025-03-14 12:05:24 -04:00
Albert
dacbfcd257 macOS - Adding _webui_macos_wv_start 2025-03-14 12:00:56 -04:00
Albert
b1595c766c macOS WebView adding exit Timer 2025-03-14 11:37:59 -04:00
Albert
130a26cc21 Remove Linux Tests 2025-03-12 13:35:26 -04:00
Albert
8bf01b0d3e Removing Tests 2025-03-12 13:28:34 -04:00
Albert
3a959d0402 Fix new lib name in macOS 2025-03-12 13:12:50 -04:00
Albert
6cca39ecac Rename examples lib name (Linux and macOS) 2025-03-12 12:42:02 -04:00
Albert
e019f00fad Rename lib name 2025-03-12 11:55:17 -04:00
Albert
fcd903d424 Merge branch 'main' of https://github.com/webui-dev/webui 2025-03-12 10:41:50 -04:00
Showns
6b61f311c8
Merge pull request #306 from iacore/patch-1
fix: add linux dynamic library "lib" prefix
2025-03-12 10:40:03 -04:00
Albert
7dddb64d92 New API - webui_wv_set_headless 2025-03-11 15:09:13 -04:00
Albert
bf1c8ada92 Fix minor warnings 2025-03-11 15:06:20 -04:00
Albert
e558709118 _webui_custom_browser_exist - macOS 2025-03-11 11:51:46 -04:00
Albert
b6457c88bb _webui_custom_browser_exist - Linux 2025-03-11 11:48:01 -04:00
Albert
8d9c6b275b Fix missing Ini _webui_custom_browser_exist 2025-03-11 11:47:25 -04:00
Albert
5ac66da94b _webui_custom_browser_exist - Windows Implementation
We still need macOS and Linux Implementation.
2025-03-10 18:28:37 -04:00
Albert
92324edf6f Adding new API webui_set_browser_folder 2025-03-10 17:50:58 -04:00
Albert
9926908e4b Up to Beta 4 2025-03-10 10:14:39 -04:00
iacore
88bd588905
fix: add linux dynamic library "lib" prefix 2024-01-14 16:01:23 +00:00
33 changed files with 2341 additions and 1366 deletions

View File

@ -85,34 +85,6 @@ jobs:
exit $exit_code
- name: Setup Browser
uses: browser-actions/setup-chrome@v1
- name: Setup Tests
run: |
sudo apt update && sudo apt install xvfb
cd tests
make call_c_from_js.c
make fail_test.c
ls -1
- name: Test Static
timeout-minutes: 2
run: |
cd tests
call_c_from_js=$(pwd)/call_c_from_js
fail_test=$(pwd)/fail_test
xvfb-run "$call_c_from_js"
# Run again and capture its output.
output=$(xvfb-run --auto-servernum --server-num=1 "$call_c_from_js")
[[ "$output" == *"Hello from the backend!"* ]] && true || exit 1
xvfb-run --auto-servernum --server-num=1 "$fail_test" && exit 1 || true
- name: Test Dynamic
timeout-minutes: 2
run: |
cd tests
call_c_from_js=$(pwd)/call_c_from_js-dyn
fail_test=$(pwd)/fail_test-dyn
xvfb-run "$call_c_from_js"
output=$(xvfb-run --auto-servernum --server-num=1 "$call_c_from_js")
[[ "$output" == *"Hello from the backend!"* ]] && true || exit 1
xvfb-run --auto-servernum --server-num=1 "$fail_test" && exit 1 || true
- name: Prepare Artifact
run: |
cp -r include dist
@ -219,33 +191,3 @@ jobs:
fi
done
exit $exit_code
# - name: Setup Browser
# uses: browser-actions/setup-chrome@v1
# - name: Setup Tests
# run: |
# sudo apt update && sudo apt install xvfb
# cd tests
# make call_c_from_js.c
# make fail_test.c
# ls -1
# - name: Test Static
# timeout-minutes: 2
# run: |
# cd tests
# call_c_from_js=$(pwd)/call_c_from_js
# fail_test=$(pwd)/fail_test
# xvfb-run "$call_c_from_js"
# # Run again and capture its output.
# output=$(xvfb-run --auto-servernum --server-num=1 "$call_c_from_js")
# [[ "$output" == *"Hello from the backend!"* ]] && true || exit 1
# xvfb-run --auto-servernum --server-num=1 "$fail_test" && exit 1 || true
# - name: Test Dynamic
# timeout-minutes: 2
# run: |
# cd tests
# call_c_from_js=$(pwd)/call_c_from_js-dyn
# fail_test=$(pwd)/fail_test-dyn
# xvfb-run "$call_c_from_js"
# output=$(xvfb-run --auto-servernum --server-num=1 "$call_c_from_js")
# [[ "$output" == *"Hello from the backend!"* ]] && true || exit 1
# xvfb-run --auto-servernum --server-num=1 "$fail_test" && exit 1 || true

View File

@ -119,41 +119,6 @@ jobs:
# fi
# done
# exit $exit_code
# - name: Setup Browser
# if: matrix.cc == 'arm64'
# uses: browser-actions/setup-chrome@v1
# - name: Setup Tests
# if: matrix.cc == 'arm64'
# run: |
# sudo apt update
# sudo apt install -y xvfb
# cd tests
# make CC=aarch64-linux-gnu-gcc call_c_from_js.c
# make CC=aarch64-linux-gnu-gcc fail_test.c
# ls -1
# - name: Test Static
# if: matrix.cc == 'arm64'
# timeout-minutes: 2
# run: |
# cd tests
# call_c_from_js=$(pwd)/call_c_from_js
# fail_test=$(pwd)/fail_test
# xvfb-run "$call_c_from_js"
# # Run again and capture its output.
# output=$(xvfb-run --auto-servernum --server-num=1 "$call_c_from_js")
# [[ "$output" == *"Hello from the backend!"* ]] && true || exit 1
# xvfb-run --auto-servernum --server-num=1 "$fail_test" && exit 1 || true
# - name: Test Dynamic
# if: matrix.cc == 'arm64'
# timeout-minutes: 2
# run: |
# cd tests
# call_c_from_js=$(pwd)/call_c_from_js-dyn
# fail_test=$(pwd)/fail_test-dyn
# xvfb-run "$call_c_from_js"
# output=$(xvfb-run --auto-servernum --server-num=1 "$call_c_from_js")
# [[ "$output" == *"Hello from the backend!"* ]] && true || exit 1
# xvfb-run --auto-servernum --server-num=1 "$fail_test" && exit 1 || true
- name: Prepare Artifact
run: |
cp -r include dist

View File

@ -68,14 +68,14 @@ else ifeq ($(DETECTED_OS),Darwin)
# MacOS
PLATFORM := macos
CC = clang
LIB_DYN_OUT := $(WEBUI_OUT_LIB_NAME).dylib
LIB_DYN_OUT := lib$(WEBUI_OUT_LIB_NAME).dylib
WEBKIT_OBJ := wkwebview.o
WKWEBKIT_BUILD_FLAGS := -o wkwebview.o -c "$(MAKEFILE_DIR)/src/webview/wkwebview.m"
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
LIB_DYN_OUT := $(WEBUI_OUT_LIB_NAME).so
LIB_DYN_OUT := lib$(WEBUI_OUT_LIB_NAME).so
ifeq ($(CC),clang)
LLVM_OPT := llvm-
endif

View File

@ -2,7 +2,7 @@
![Logo](https://raw.githubusercontent.com/webui-dev/webui-logo/14fd595844f57ce751dfc751297b1468b10de77a/webui_120.svg)
# WebUI v2.5.0-beta.3
# WebUI v2.5.0-beta.4
[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
[last-commit]: https://img.shields.io/github/last-commit/webui-dev/webui?style=for-the-badge&logo=github&logoColor=C0CAF5&labelColor=414868
@ -216,9 +216,9 @@ Think of WebUI like a WebView controller, but instead of embedding the WebView c
| Compiler | Type | Command |
|----------|--------|---------|
| GCC | Static | `gcc -Os my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" -lwebui-2-static -lpthread -lm -ldl -o my_application` |
| GCC | Dynamic | `gcc my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" "./webui-2.so" -lpthread -lm -ldl -o my_application` |
| GCC | Dynamic | `gcc my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" -lwebui-2 -lpthread -lm -ldl -o my_application` |
| Clang | Static | `clang -Os my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" -lwebui-2-static -lpthread -lm -ldl -o my_application` |
| Clang | Dynamic | `clang my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" "./webui-2.so" -lpthread -lm -ldl -o my_application` |
| Clang | Dynamic | `clang my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" -lwebui-2 -lpthread -lm -ldl -o my_application` |
<details>
<summary><strong>Linux With SSL/TLS (Optional)</strong></summary>
@ -226,9 +226,9 @@ Think of WebUI like a WebView controller, but instead of embedding the WebView c
| Compiler | Type | Command |
|----------|--------|---------|
| GCC | Static | `gcc -Os my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" -lwebui-2-secure-static -lpthread -lm -ldl -o my_application` |
| GCC | Dynamic | `gcc my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" "./webui-2-secure.so" -lpthread -lm -ldl -o my_application` |
| GCC | Dynamic | `gcc my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" -lwebui-2-secure -lpthread -lm -ldl -o my_application` |
| Clang | Static | `clang -Os my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" -lwebui-2-secure-static -lpthread -lm -ldl -o my_application` |
| Clang | Dynamic | `clang my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" "./webui-2-secure.so" -lpthread -lm -ldl -o my_application` |
| Clang | Dynamic | `clang my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" -lwebui-2-secure -lpthread -lm -ldl -o my_application` |
</details>
### macOS
@ -236,7 +236,7 @@ Think of WebUI like a WebView controller, but instead of embedding the WebView c
| Compiler | Type | Command |
|----------|--------|---------|
| Clang | Static | `clang -Os my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" -lwebui-2-static -lpthread -lm -framework Cocoa -framework WebKit -o my_application` |
| Clang | Dynamic | `clang my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" "./webui-2.dylib" -lpthread -lm -framework Cocoa -framework WebKit -o my_application` |
| Clang | Dynamic | `clang my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" -lwebui-2 -lpthread -lm -framework Cocoa -framework WebKit -o my_application` |
<details>
<summary><strong>macOS With SSL/TLS (Optional)</strong></summary>
@ -244,7 +244,7 @@ Think of WebUI like a WebView controller, but instead of embedding the WebView c
| Compiler | Type | Command |
|----------|--------|---------|
| Clang | Static | `clang -Os my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" -lwebui-2-secure-static -lpthread -lm -framework Cocoa -framework WebKit -o my_application` |
| Clang | Dynamic | `clang my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" "./webui-2-secure.dylib" -lpthread -lm -framework Cocoa -framework WebKit -o my_application` |
| Clang | Dynamic | `clang my_application.c -I"_PATH_TO_WEBUI_INCLUDE_" -L"_PATH_TO_WEBUI_LIB_" -lwebui-2-secure -lpthread -lm -framework Cocoa -framework WebKit -o my_application` |
</details>
## Wrappers

View File

@ -13,7 +13,7 @@ def js_to_c_header(input_filename, output_filename):
# comment
comment = (
"// WebUI v2.5.0-beta.3\n"
"// WebUI v2.5.0-beta.4\n"
"// https://webui.me\n"
"// https://github.com/webui-dev/webui\n"
"// Copyright (c) 2020-2025 Hassan Draga.\n"

View File

@ -29,6 +29,14 @@ class WebuiBridge {
#winY: number;
#winW: number;
#winH: number;
// Frameless Dragging
#isDragging: boolean = false;
#initialMouseX: number = 0;
#initialMouseY: number = 0;
#initialWindowX: number = window.screenX || window.screenLeft;
#initialWindowY: number = window.screenY || window.screenTop;
#currentWindowX: number = window.screenX || window.screenLeft;
#currentWindowY: number = window.screenY || window.screenTop;
// Internals
#ws: WebSocket;
#wsStayAlive: boolean = true;
@ -56,6 +64,8 @@ class WebuiBridge {
#CMD_NEW_ID: number = 247;
#CMD_MULTI: number = 246;
#CMD_CHECK_TK: number = 245;
#CMD_WINDOW_DRAG: number = 244;
#CMD_WINDOW_RESIZED: number = 243;
#MULTI_CHUNK_SIZE: number = 65500;
#PROTOCOL_SIZE: number = 8; // Protocol header size in bytes
#PROTOCOL_SIGN: number = 0; // Protocol byte position: Signature (1 Byte)
@ -152,6 +162,46 @@ class WebuiBridge {
if (this.#log) return; // Allowed in debug mode
if (event.key === 'F5') event.preventDefault();
});
// Frameless Dragging
document.addEventListener("mousemove", (e) => {
// WebUI `-webkit-app-region: drag;` custom implementation
if (e.buttons !== 1) {
this.#isDragging = false;
return;
}
if (!this.#isDragging) {
let target = e.target;
while (target) {
if (window.getComputedStyle(target).getPropertyValue("-webkit-app-region") === "drag") {
this.#initialMouseX = e.screenX;
this.#initialMouseY = e.screenY;
this.#initialWindowX = this.#currentWindowX;
this.#initialWindowY = this.#currentWindowY;
this.#isDragging = true;
break;
}
target = target.parentElement;
}
return;
}
// Calculate window position relative to cursor movement
const deltaX = e.screenX - this.#initialMouseX;
const deltaY = e.screenY - this.#initialMouseY;
let newX = this.#initialWindowX + deltaX;
let newY = this.#initialWindowY + deltaY;
// Fix out of screen
if (newX < 0) newX = 0;
if (newY < 0) newY = 0;
// Move the window
this.#sendDrag(newX, newY);
// Update the last window position
this.#currentWindowX = newX;
this.#currentWindowY = newY;
});
// Stop frameless dragging on mouse release
document.addEventListener("mouseup", () => {
this.#isDragging = false;
});
onbeforeunload = () => {
this.#close();
};
@ -204,6 +254,19 @@ class WebuiBridge {
if (cmd !== this.#CMD_SEND_RAW) return true;
return false;
}
#parseDimensions(input: string): {x: number; y: number; width: number; height: number} {
try {
const parts = input.split(',');
if (parts.length !== 4) return {x: 0, y: 0, width: 0, height: 0};
const x = parseFloat(parts[0]),
y = parseFloat(parts[1]),
width = parseFloat(parts[2]),
height = parseFloat(parts[3]);
return [x, y, width, height].some(isNaN) ? {x: 0, y: 0, width: 0, height: 0} : {x, y, width, height};
} catch {
return {x: 0, y: 0, width: 0, height: 0};
}
}
#getDataStrFromPacket(buffer: Uint8Array, startIndex: number): string {
let stringBytes: number[] = [];
for (let i = startIndex; i < buffer.length; i++) {
@ -412,6 +475,33 @@ class WebuiBridge {
}
}
}
#sendDrag(x: number, y: number) {
if (this.#wsIsConnected()) {
if (this.#log) console.log(`WebUI -> Send Drag Event [${x}, ${y}]`);
const packet = Uint8Array.of(
// Protocol
// 0: [SIGNATURE]
// 1: [TOKEN]
// 2: [ID]
// 3: [CMD]
// 4: [X]
// 4: [Y]
this.#WEBUI_SIGNATURE,
0,
0,
0,
0, // Token (4 Bytes)
0,
0, // ID (2 Bytes)
this.#CMD_WINDOW_DRAG,
...new Uint8Array(new Int32Array([x]).buffer), // X (4 Bytes)
...new Uint8Array(new Int32Array([y]).buffer), // Y (4 Bytes)
);
this.#addToken(packet, this.#token, this.#PROTOCOL_TOKEN);
// this.#addID(packet, 0, this.#PROTOCOL_ID)
this.#sendData(packet);
}
}
#closeWindowTimer() {
setTimeout(function () {
globalThis.close();
@ -670,6 +760,20 @@ class WebuiBridge {
if (this.#log) console.log(`WebUI -> CMD -> Navigation [${url}]`);
this.#close(this.#CMD_NAVIGATION, url);
break;
case this.#CMD_WINDOW_RESIZED:
// Protocol
// 0: [SIGNATURE]
// 1: [TOKEN]
// 2: [ID]
// 3: [CMD]
// 4: [x,y,width,height]
const widthAndHeight: string = this.#getDataStrFromPacket(buffer8, this.#PROTOCOL_DATA);
const { x, y, width, height } = this.#parseDimensions(widthAndHeight);
// Update drag positions
this.#currentWindowX = x;
this.#currentWindowY = y;
if (this.#log) console.log(`WebUI -> CMD -> Window Resized [x: ${x}, y: ${y}, width: ${width}, height: ${height}]`);
break;
case this.#CMD_NEW_ID:
// Protocol
// 0: [SIGNATURE]

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
.{
.name = .webui,
.version = "2.5.0-beta.3",
.version = "2.5.0-beta.4",
.fingerprint = 0xac5d87f2e5831aa7,
.paths = .{
"src",

View File

@ -48,15 +48,15 @@ else
# MacOS
PLATFORM := macos
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-

View File

@ -48,15 +48,15 @@ else
# MacOS
PLATFORM := macos
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-

View File

@ -48,15 +48,15 @@ else
# MacOS
PLATFORM := macos
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-

View File

@ -48,15 +48,15 @@ else
# MacOS
PLATFORM := macos
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-

View File

@ -48,15 +48,15 @@ else
# MacOS
PLATFORM := macos
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-

View File

@ -48,15 +48,15 @@ else
# MacOS
PLATFORM := macos
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-

View File

@ -48,15 +48,15 @@ else
# MacOS
PLATFORM := macos
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-

View File

@ -48,15 +48,15 @@ else
# MacOS
PLATFORM := macos
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-

View File

@ -1,40 +1,29 @@
# WebUI C Tests
# WebUI C Example
# == 1. VARIABLES =============================================================
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_DIR := $(dir $(MAKEFILE_PATH))/../
TEST_SRC := $(firstword $(MAKECMDGOALS))
TEST_OUT = $(patsubst %.c,%,$(TEST_SRC))
PROJECT_DIR := $(dir $(MAKEFILE_PATH))/../../../
TARGET := $(firstword $(MAKECMDGOALS))
LIB_DIR := $(PROJECT_DIR)/dist
ifeq ($(WEBUI_DEBUG), 1)
ifeq ($(TARGET), debug)
LIB_DIR := $(LIB_DIR)/debug
endif
INCLUDE_DIR := $(PROJECT_DIR)/include
WEBUI_LIB_NAME = webui-2
ifeq ($(WEBUI_USE_TLS), 1)
WEBUI_LIB_NAME = webui-2-secure
endif
# ARGS
# Set a compiler when running on Linux via `make CC=gcc` / `make CC=clang`
CC = gcc
# Build the WebUI library if running via `make BUILD_LIB=true`
CC ?= gcc
BUILD_LIB ?=
ifeq ($(CC), cc)
ifeq ($(shell uname),Darwin)
CC = clang
else
CC = gcc
endif
endif
# BUILD FLAGS
STATIC_BUILD_FLAGS = $(TEST_SRC) -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)"
DYN_BUILD_FLAGS = $(TEST_SRC) -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)"
STATIC_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)"
DYN_BUILD_FLAGS = main.c -I"$(INCLUDE_DIR)" -L"$(LIB_DIR)"
# Platform conditions
ifeq ($(OS),Windows_NT)
@ -44,8 +33,8 @@ ifeq ($(OS),Windows_NT)
STATIC_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)-static -lws2_32 -Wall -luser32 -static
COPY_LIB_CMD := @copy "$(LIB_DIR)\$(WEBUI_LIB_NAME).dll" "$(WEBUI_LIB_NAME).dll"
DYN_BUILD_FLAGS += "$(WEBUI_LIB_NAME).dll" -lws2_32 -Wall -luser32
STATIC_OUT := $(TEST_OUT).exe
DYN_OUT := $(TEST_OUT)-dyn.exe
STATIC_OUT := main.exe
DYN_OUT := main-dyn.exe
LWS2_OPT := -lws2_32 -lole32
STRIP_OPT := --strip-all
CONSOLE_APP := -Wl,-subsystem=console
@ -53,20 +42,21 @@ ifeq ($(OS),Windows_NT)
else
STATIC_BUILD_FLAGS += -lpthread -lm -l$(WEBUI_LIB_NAME)-static
DYN_BUILD_FLAGS += -lpthread -lm
STATIC_OUT := $(TEST_OUT)
DYN_OUT := $(TEST_OUT)-dyn
STATIC_OUT := main
DYN_OUT := main-dyn
ifeq ($(shell uname),Darwin)
# MacOS
PLATFORM := macos
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-
@ -76,23 +66,19 @@ endif
# == 2.TARGETS ================================================================
*.c: all
.PHONY: all
all: release
.PHONY: debug
debug:
debug: --validate-args
ifeq ($(BUILD_LIB),true)
@cd "$(PROJECT_DIR)" && $(MAKE) debug
endif
# Static with Debug info
ifneq ($(WEBUI_USE_TLS), 1)
@echo "Building '$(TEST_SRC)' ($(CC) debug static)..."
@echo "Build C Example ($(CC) debug static)..."
@$(CC) -g $(CONSOLE_APP) $(STATIC_BUILD_FLAGS) $(LWS2_OPT) $(WKWEBKIT_LINK_FLAGS) -o $(STATIC_OUT)
endif
# Dynamic with Debug info
@echo "Building '$(TEST_SRC)' ($(CC) debug dynamic)..."
@echo "Build C Example ($(CC) debug dynamic)..."
$(COPY_LIB_CMD)
@$(CC) -g $(CONSOLE_APP) $(DYN_BUILD_FLAGS) $(LWS2_OPT) $(WKWEBKIT_LINK_FLAGS) -o $(DYN_OUT)
# Clean
@ -104,19 +90,18 @@ else
endif
@echo "Done."
.PHONY: .release
release:
release: --validate-args
ifeq ($(BUILD_LIB),true)
@cd "$(PROJECT_DIR)" && $(MAKE)
endif
# Static Release
ifneq ($(WEBUI_USE_TLS), 1)
@echo "Building '$(TEST_SRC)' ($(CC) static)..."
@echo "Build C Example ($(CC) release static)..."
@$(CC) -Os $(GUI_APP) $(STATIC_BUILD_FLAGS) $(LWS2_OPT) $(WKWEBKIT_LINK_FLAGS) -o $(STATIC_OUT)
@$(LLVM_OPT)strip $(STRIP_OPT) $(STATIC_OUT)
endif
# Dynamic Release
@echo "Building '$(TEST_SRC)' ($(CC) dynamic)..."
@echo "Build C Example ($(CC) release dynamic)..."
$(COPY_LIB_CMD)
@$(CC) $(GUI_APP) $(DYN_BUILD_FLAGS) $(LWS2_OPT) $(WKWEBKIT_LINK_FLAGS) -o $(DYN_OUT)
@$(LLVM_OPT)strip $(STRIP_OPT) $(DYN_OUT)
@ -133,13 +118,15 @@ clean: --clean-$(PLATFORM)
# INTERNAL TARGETS
.PHONY: --clean-linux
--validate-args:
ifneq ($(filter $(CC),gcc clang aarch64-linux-gnu-gcc arm-linux-gnueabihf-gcc musl-gcc),$(CC))
$(error Invalid compiler specified: `$(CC)`)
endif
--clean-linux: --clean-unix
.PHONY: --clean-macos
--clean-macos: clean-unix
--clean-macos: --clean-unix
.PHONY: --clean-unix
--clean-unix:
- rm -f *.o
- rm -f *.a
@ -147,10 +134,8 @@ clean: --clean-$(PLATFORM)
- rm -f *.dylib
- rm -rf *.dSYM
.PHONY: --clean-windows
--clean-windows:
- del *.o >nul 2>&1
- del *.dll >nul 2>&1
- del *.a >nul 2>&1
- del *.exe >nul 2>&1

View File

@ -0,0 +1,64 @@
# WebUI C Example
# Windows - Microsoft Visual C
SHELL = CMD
LIB_DIR = ../../../dist
INCLUDE_DIR = ../../../include
WEBUI_LIB_NAME = webui-2
!IF "$(WEBUI_USE_TLS)" == "1"
WEBUI_LIB_NAME = webui-2-secure
!ENDIF
# Build the WebUI library if running `nmake BUILD_LIB=true`
BUILD_LIB =
all: release
debug:
!IF "$(BUILD_LIB)" == "true"
@cd "$(LIB_DIR)" && cd .. && $(MAKE) debug
!ENDIF
# Static with Debug info
!IF "$(WEBUI_USE_TLS)" != "1"
@echo Build C Example (Static Debug)...
@cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)\debug" /SUBSYSTEM:CONSOLE $(WEBUI_LIB_NAME)-static.lib user32.lib Advapi32.lib Shell32.lib Ole32.lib /OUT:main.exe 1>NUL 2>&1
!ENDIF
# Dynamic with Debug info
@echo Build C Example (Dynamic Debug)...
@copy "$(LIB_DIR)\debug\$(WEBUI_LIB_NAME).dll" "$(WEBUI_LIB_NAME).dll"
@cl /Zi main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)\debug" /SUBSYSTEM:CONSOLE $(WEBUI_LIB_NAME).lib user32.lib Advapi32.lib Shell32.lib Ole32.lib /OUT:main-dyn.exe 1>NUL 2>&1
# Clean
@- del *.exp >nul 2>&1
@- del *.ilk >nul 2>&1
@- del *.lib >nul 2>&1
@- del *.obj >nul 2>&1
@echo Done.
release:
!IF "$(BUILD_LIB)" == "true"
@cd "$(LIB_DIR)" && cd .. && $(MAKE)
!ENDIF
# Static Release
!IF "$(WEBUI_USE_TLS)" != "1"
@echo Build C Example (Static Release)...
@cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /SUBSYSTEM:WINDOWS $(WEBUI_LIB_NAME)-static.lib user32.lib Advapi32.lib Shell32.lib Ole32.lib /OUT:main.exe 1>NUL 2>&1
!ENDIF
# Dynamic Release
@echo Build C Example (Dynamic Release)...
@copy "$(LIB_DIR)\$(WEBUI_LIB_NAME).dll" "$(WEBUI_LIB_NAME).dll"
@cl main.c /I"$(INCLUDE_DIR)" /link /LIBPATH:"$(LIB_DIR)" /SUBSYSTEM:WINDOWS $(WEBUI_LIB_NAME).lib user32.lib Advapi32.lib Shell32.lib Ole32.lib /OUT:main-dyn.exe 1>NUL 2>&1
# Clean
@- del *.exp >nul 2>&1
@- del *.ilk >nul 2>&1
@- del *.lib >nul 2>&1
@- del *.obj >nul 2>&1
@- del *.pdb >nul 2>&1
@echo Done.
clean:
- del *.obj >nul 2>&1
- del *.ilk >nul 2>&1
- del *.pdb >nul 2>&1
- del *.exp >nul 2>&1
- del *.exe >nul 2>&1
- del *.lib >nul 2>&1

105
examples/C/frameless/main.c Normal file
View File

@ -0,0 +1,105 @@
// WebUI C - Frameless Example
#include "webui.h"
const char* html =
"<html>"
" <head>"
" <meta charset='UTF-8'>"
" <script src=\"webui.js\"></script>"
" <style>"
" * { margin: 0; padding: 0; box-sizing: border-box; }"
" html, body { height: 100%; width: 100%; overflow: hidden; background: transparent; }"
" #titlebar {"
" height: 40px;"
" background: linear-gradient(to right, #2c3e50, #34495e);"
" color: white;"
" display: flex;"
" align-items: center;"
" justify-content: space-between;"
" padding: 0 15px;"
" box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);"
" -webkit-app-region: drag;"
" font-family: Arial, sans-serif;"
" }"
" #title { font-size: 16px; font-weight: bold; }"
" #buttons { -webkit-app-region: no-drag; }"
" .button {"
" display: inline-block;"
" width: 24px;"
" height: 24px;"
" margin-left: 8px;"
" border-radius: 50%;"
" text-align: center;"
" line-height: 24px;"
" cursor: pointer;"
" transition: all 0.2s;"
" }"
" .minimize { background: #f1c40f; }"
" .maximize { background: #2ecc71; }"
" .close { background: #e74c3c; }"
" .button:hover { filter: brightness(120%); }"
" #content {"
" height: calc(100% - 40px);"
" background: rgba(0, 0, 0, 0.7);"
" display: flex;"
" align-items: center;"
" justify-content: center;"
" }"
" #message {"
" color: white;"
" font-size: 32px;"
" font-family: Arial, sans-serif;"
" text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);"
" }"
" </style>"
" </head>"
" <body>"
" <div id='titlebar'>"
" <span id='title'>WebUI Frameless Window</span>"
" <div id='buttons'>"
" <span class='button minimize' onclick='minimize()'></span>"
// " <span class='button maximize' onclick='maximize()'>□</span>"
" <span class='button close' onclick='close_win()'>✕</span>"
" </div>"
" </div>"
" <div id='content'>"
" <span id='message'>This is a WebUI frameless example</span>"
" </div>"
" </body>"
"</html>";
void minimize(webui_event_t* e) {
webui_minimize(e->window);
}
void maximize(webui_event_t* e) {
webui_maximize(e->window);
}
void close_win(webui_event_t* e) {
webui_close(e->window);
}
int main() {
size_t my_window = webui_new_window();
webui_bind(my_window, "minimize", minimize);
webui_bind(my_window, "maximize", maximize);
webui_bind(my_window, "close_win", close_win);
webui_set_size(my_window, 800, 600);
webui_set_frameless(my_window, true);
webui_set_transparent(my_window, true);
webui_set_resizable(my_window, false);
webui_set_center(my_window);
webui_show_wv(my_window, html);
webui_wait();
return 0;
}
#if defined(_MSC_VER)
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, PSTR cmdline, int cmdshow) { return main(); }
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 KiB

View File

@ -48,15 +48,15 @@ else
# MacOS
PLATFORM := macos
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-

View File

@ -48,15 +48,15 @@ else
# MacOS
PLATFORM := macos
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-

View File

@ -48,15 +48,15 @@ else
# MacOS
PLATFORM := macos
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-

View File

@ -48,15 +48,15 @@ else
# MacOS
PLATFORM := macos
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-

View File

@ -48,15 +48,15 @@ else
# MacOS
PLATFORM := macos
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-

View File

@ -48,15 +48,15 @@ else
# MacOS
PLATFORM := macos
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-

View File

@ -48,15 +48,15 @@ else
# MacOS
PLATFORM := macos
CC = clang
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).dylib" "$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += "./$(WEBUI_LIB_NAME).dylib"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).dylib" "lib$(WEBUI_LIB_NAME).dylib"
DYN_BUILD_FLAGS += -l$(WEBUI_LIB_NAME)
WKWEBKIT_LINK_FLAGS := -framework Cocoa -framework WebKit
else
# Linux
PLATFORM := linux
COPY_LIB_CMD := @cp "$(LIB_DIR)/$(WEBUI_LIB_NAME).so" "$(WEBUI_LIB_NAME).so"
COPY_LIB_CMD := @cp "$(LIB_DIR)/lib$(WEBUI_LIB_NAME).so" "lib$(WEBUI_LIB_NAME).so"
STATIC_BUILD_FLAGS += -ldl
DYN_BUILD_FLAGS += -ldl "./$(WEBUI_LIB_NAME).so"
DYN_BUILD_FLAGS += -ldl -l$(WEBUI_LIB_NAME)
STRIP_OPT := --strip-all
ifeq ($(CC),clang)
LLVM_OPT := llvm-

View File

@ -11,7 +11,7 @@
#ifndef _WEBUI_H
#define _WEBUI_H
#define WEBUI_VERSION "2.5.0-beta.3"
#define WEBUI_VERSION "2.5.0-beta.4"
// Max windows, servers and threads
#define WEBUI_MAX_IDS (256)
@ -107,6 +107,7 @@
#include <sys/types.h>
#include <sys/event.h>
#include <unistd.h>
#include <CoreGraphics/CoreGraphics.h>
#define WEBUI_GET_CURRENT_DIR getcwd
#define WEBUI_FILE_EXIST access
#define WEBUI_POPEN popen
@ -394,6 +395,17 @@ WEBUI_EXPORT void webui_set_custom_parameters(size_t window, char *params);
*/
WEBUI_EXPORT void webui_set_high_contrast(size_t window, bool status);
/**
* @brief Sets whether the window frame is resizable or fixed.
* Works only on WebView window.
*
* @param window The window number
* @param status True or False
*
* @example webui_set_resizable(myWindow, true);
*/
WEBUI_EXPORT void webui_set_resizable(size_t window, bool status);
/**
* @brief Get OS high contrast preference.
*
@ -429,6 +441,24 @@ WEBUI_EXPORT void webui_wait(void);
*/
WEBUI_EXPORT void webui_close(size_t window);
/**
* @brief Minimize a WebView window.
*
* @param window The window number
*
* @example webui_minimize(myWindow);
*/
WEBUI_EXPORT void webui_minimize(size_t window);
/**
* @brief Maximize a WebView window.
*
* @param window The window number
*
* @example webui_maximize(myWindow);
*/
WEBUI_EXPORT void webui_maximize(size_t window);
/**
* @brief Close a specific client.
*
@ -464,6 +494,15 @@ WEBUI_EXPORT void webui_exit(void);
*/
WEBUI_EXPORT bool webui_set_root_folder(size_t window, const char* path);
/**
* @brief Set custom browser folder path.
*
* @param path The browser folder path
*
* @example webui_set_browser_folder("/home/Foo/Bar/");
*/
WEBUI_EXPORT void webui_set_browser_folder(const char* path);
/**
* @brief Set the web-server root folder path for all windows. Should be used
* before `webui_show()`.
@ -664,6 +703,16 @@ WEBUI_EXPORT void webui_set_minimum_size(size_t window, unsigned int width, unsi
*/
WEBUI_EXPORT void webui_set_position(size_t window, unsigned int x, unsigned int y);
/**
* @brief Centers the window on the screen. Works better with
* WebView. Call this function before `webui_show()` for better results.
*
* @param window The window number
*
* @example webui_set_center(myWindow);
*/
WEBUI_EXPORT void webui_set_center(size_t window);
/**
* @brief Set the web browser profile to use. An empty `name` and `path` means
* the default user profile. Need to be called before `webui_show()`.
@ -865,6 +914,26 @@ WEBUI_EXPORT void webui_set_config(webui_config option, bool status);
*/
WEBUI_EXPORT void webui_set_event_blocking(size_t window, bool status);
/**
* @brief Make a WebView window frameless.
*
* @param window The window number
* @param status The frameless status `true` or `false`
*
* @example webui_set_frameless(myWindow, true);
*/
WEBUI_EXPORT void webui_set_frameless(size_t window, bool status);
/**
* @brief Make a WebView window transparent.
*
* @param window The window number
* @param status The transparency status `true` or `false`
*
* @example webui_set_transparent(myWindow, true);
*/
WEBUI_EXPORT void webui_set_transparent(size_t window, bool status);
/**
* @brief Get the HTTP mime type of a file.
*

View File

@ -90,7 +90,7 @@ namespace webui {
// ------ Event methods `e->xxx()` ------
// Get how many arguments there are in an event.
size_t get_count(size_t index = 0) {
size_t get_count() {
return webui_get_count(this);
}

File diff suppressed because it is too large Load Diff

View File

@ -11,12 +11,16 @@
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
#define WEBUI_MAX_IDS (256) // Max windows, servers and threads
extern bool webui_interface_is_app_running(void);
void (*close_callback)(int index) = NULL;
void _webui_macos_wv_check_exit();
@interface AppDelegate : NSObject <NSApplicationDelegate, NSWindowDelegate, WKNavigationDelegate>
{
NSWindow *windows[256];
WKWebView *webViews[256];
NSWindow *windows[WEBUI_MAX_IDS];
WKWebView *webViews[WEBUI_MAX_IDS];
}
- (NSWindow *)windowAtIndex:(int)index;
- (void)setWindow:(NSWindow *)window atIndex:(int)index;
@ -29,14 +33,24 @@ void (*close_callback)(int index) = NULL;
- (instancetype)init {
self = [super init];
if (self) {
for (int i = 0; i < 256; i++) {
for (int i = 0; i < WEBUI_MAX_IDS; i++) {
windows[i] = nil;
webViews[i] = nil;
}
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(_webui_macos_wv_timer)
userInfo:nil
repeats:YES];
}
return self;
}
- (void)_webui_macos_wv_timer {
_webui_macos_wv_check_exit();
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\tapplicationDidFinishLaunching()\n");
@ -50,7 +64,7 @@ void (*close_callback)(int index) = NULL;
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\twindowWillClose()\n");
#endif
for (int i = 0; i < 256; i++) {
for (int i = 0; i < WEBUI_MAX_IDS; i++) {
if (windows[i] == [notification object]) {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\twindowWillClose() -> Index [%d]\n", i);
@ -65,7 +79,7 @@ void (*close_callback)(int index) = NULL;
}
BOOL anyWindowOpen = NO;
for (int i = 0; i < 256; i++) {
for (int i = 0; i < WEBUI_MAX_IDS; i++) {
if (windows[i] != nil) {
anyWindowOpen = YES;
break;
@ -99,7 +113,7 @@ void (*close_callback)(int index) = NULL;
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
NSString *title = webView.title;
for (int i = 0; i < 256; i++) {
for (int i = 0; i < WEBUI_MAX_IDS; i++) {
if (webViews[i] == webView) {
NSWindow *window = windows[i];
[window setTitle:title];
@ -116,12 +130,33 @@ void (*close_callback)(int index) = NULL;
AppDelegate *delegate;
bool _webui_macos_wv_new(int index) {
void _webui_macos_wv_start() {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_new([%d])\n", index);
printf("[ObjC]\t\t\t_webui_macos_wv_start()\n");
#endif
if (index < 0 || index >= 256) {
@autoreleasepool {
NSApplication *app = [NSApplication sharedApplication];
[app setActivationPolicy:NSApplicationActivationPolicyRegular];
// Ensure the event loop keeps running
[app finishLaunching];
// Run the application event loop
[app run];
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_start() -> Exit.\n");
#endif
}
}
bool _webui_macos_wv_new(int index, bool frameless, bool resizable) {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_new([%d], [%d], [%d])\n", index, frameless, resizable);
#endif
if (index < 0 || index >= WEBUI_MAX_IDS) {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_new([%d]) -> Invalid index\n", index);
#endif
@ -138,10 +173,23 @@ bool _webui_macos_wv_new(int index) {
}
NSRect frame = NSMakeRect(0, 0, 800, 600);
// Set window style
NSWindowStyleMask windowStyle;
if (frameless) {
windowStyle = NSWindowStyleMaskBorderless;
if (resizable) {
windowStyle |= NSWindowStyleMaskResizable; // Allows programmatic resizing
}
} else {
windowStyle = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable;
if (resizable) {
windowStyle |= NSWindowStyleMaskResizable; // Allows user resizing
}
}
NSWindow *window = [[NSWindow alloc] initWithContentRect:frame
styleMask:(NSWindowStyleMaskTitled |
NSWindowStyleMaskClosable |
NSWindowStyleMaskResizable)
styleMask:windowStyle
backing:NSBackingStoreBuffered
defer:NO];
if (!window) {
@ -150,7 +198,12 @@ bool _webui_macos_wv_new(int index) {
#endif
return false;
}
if (!frameless) {
[window setTitle:@"Loading..."];
} else {
[window setMovableByWindowBackground:YES]; // Allow moving frameless windows
}
[window setDelegate:delegate];
WKWebView *webView = [[WKWebView alloc] initWithFrame:[[window contentView] bounds]];
@ -170,12 +223,12 @@ bool _webui_macos_wv_new(int index) {
return true;
}
void _webui_macos_wv_new_thread_safe(int index) {
void _webui_macos_wv_new_thread_safe(int index, bool frameless, bool resizable) {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_new_thread_safe([%d])\n", index);
#endif
dispatch_async(dispatch_get_main_queue(), ^{
_webui_macos_wv_new(index);
_webui_macos_wv_new(index, frameless, resizable);
});
}
@ -188,7 +241,7 @@ bool _webui_macos_wv_show(int index, const char* urlString, int x, int y, int wi
printf("[ObjC]\t\t\t_webui_macos_wv_show([%d]) -> width: [%d]\n", index, width);
printf("[ObjC]\t\t\t_webui_macos_wv_show([%d]) -> height: [%d]\n", index, height);
#endif
if (index < 0 || index >= 256) {
if (index < 0 || index >= WEBUI_MAX_IDS) {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_show([%d]) -> Invalid index\n", index);
#endif
@ -258,7 +311,7 @@ void _webui_macos_wv_stop() {
NSApplication *app = [NSApplication sharedApplication];
[app stop:nil];
// Dummy event to immediately break `_webui_macos_wv_process()`
// Dummy event to immediately break `[app run]` in `_webui_macos_wv_start`
NSEvent *event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined
location:NSMakePoint(0, 0)
modifierFlags:0
@ -272,11 +325,17 @@ void _webui_macos_wv_stop() {
});
}
void _webui_macos_wv_check_exit() {
if (!webui_interface_is_app_running()) {
_webui_macos_wv_stop();
}
}
bool _webui_macos_wv_close(int index) {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_close([%d])\n", index);
#endif
if (index < 0 || index >= 256) {
if (index < 0 || index >= WEBUI_MAX_IDS) {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_close([%d]) -> Invalid index\n", index);
#endif
@ -308,7 +367,7 @@ bool _webui_macos_wv_set_position(int index, int x, int y) {
printf("[ObjC]\t\t\t_webui_macos_wv_set_position([%d]) -> x: [%d]\n", index, x);
printf("[ObjC]\t\t\t_webui_macos_wv_set_position([%d]) -> y: [%d]\n", index, y);
#endif
if (index < 0 || index >= 256) {
if (index < 0 || index >= WEBUI_MAX_IDS) {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_set_position([%d]) -> Invalid index\n", index);
#endif
@ -334,13 +393,69 @@ bool _webui_macos_wv_set_position(int index, int x, int y) {
return success;
}
bool _webui_macos_wv_minimize(int index) {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_minimize([%d])\n", index);
#endif
if (index < 0 || index >= WEBUI_MAX_IDS) {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_minimize([%d]) -> Invalid index\n", index);
#endif
return false;
}
__block bool success = false;
dispatch_async(dispatch_get_main_queue(), ^{
NSWindow *window = [delegate windowAtIndex:index];
if (window) {
[window miniaturize:nil];
success = true;
} else {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_minimize([%d]) -> Window not found.\n", index);
#endif
}
});
return success;
}
bool _webui_macos_wv_maximize(int index) {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_maximize([%d])\n", index);
#endif
if (index < 0 || index >= WEBUI_MAX_IDS) {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_maximize([%d]) -> Invalid index\n", index);
#endif
return false;
}
__block bool success = false;
dispatch_async(dispatch_get_main_queue(), ^{
NSWindow *window = [delegate windowAtIndex:index];
if (window) {
[window zoom:nil];
success = true;
} else {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_maximize([%d]) -> Window not found.\n", index);
#endif
}
});
return success;
}
bool _webui_macos_wv_set_size(int index, int width, int height) {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_set_size([%d])\n", index);
printf("[ObjC]\t\t\t_webui_macos_wv_set_size([%d]) -> width: [%d]\n", index, width);
printf("[ObjC]\t\t\t_webui_macos_wv_set_size([%d]) -> height: [%d]\n", index, height);
#endif
if (index < 0 || index >= 256) {
if (index < 0 || index >= WEBUI_MAX_IDS) {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_set_size([%d]) -> Invalid index\n", index);
#endif
@ -371,7 +486,7 @@ bool _webui_macos_wv_navigate(int index, const char* urlString) {
printf("[ObjC]\t\t\t_webui_macos_wv_navigate([%d])\n", index);
printf("[ObjC]\t\t\t_webui_macos_wv_navigate([%d]) -> url: [%s]\n", index, urlString);
#endif
if (index < 0 || index >= 256) {
if (index < 0 || index >= WEBUI_MAX_IDS) {
#ifdef WEBUI_LOG
printf("[ObjC]\t\t\t_webui_macos_wv_navigate([%d]) -> Invalid index\n", index);
#endif

View File

@ -1,113 +0,0 @@
#include "webui.h"
const char *doc =
"<html style=\"background: #654da9; color: #eee\">"
"<head>"
" <script src=\"webui.js\"></script>"
"</head>"
"<body>"
" <script>"
" setTimeout(async () => {"
" await webui.assert_int(1, 23, 345);"
" await webui.assert_float(1.0, 2.3, 3.45);"
" await webui.assert_string('foo', 'bar', 'baz');"
" await webui.assert_bool(true, false, true);"
" await webui.assert_cprint();"
" await webui.assert_close();"
" }, 500)"
" </script>"
"</body>"
"</html>";
void assert_int(webui_event_t *e) {
size_t count = webui_get_count(e);
assert(count == 3);
long long num = webui_get_int(e);
long long num1 = webui_get_int_at(e, 0);
long long num2 = webui_get_int_at(e, 1);
long long num3 = webui_get_int_at(e, 2);
assert(num == 1);
assert(num1 == num);
assert(num2 == 23);
assert(num3 == 345);
}
void assert_float(webui_event_t *e) {
size_t count = webui_get_count(e);
assert(count == 3);
double num = webui_get_float(e);
double num1 = webui_get_float_at(e, 0);
double num2 = webui_get_float_at(e, 1);
double num3 = webui_get_float_at(e, 2);
printf("num1: %f, num2: %f, num3: %f\n", num1, num2, num3);
// TODO: enable asserts after get_float is fixed.
// assert(num == 1.0);
// assert(num1 == num);
// assert(num2 == 2.3);
// assert(num3 == 3.45);
}
void assert_string(webui_event_t *e) {
size_t count = webui_get_count(e);
assert(count == 3);
const char *str = webui_get_string(e);
const char *str1 = webui_get_string_at(e, 0);
const char *str2 = webui_get_string_at(e, 1);
const char *str3 = webui_get_string_at(e, 2);
assert(strcmp(str, "foo") == 0);
assert(strcmp(str1, str) == 0);
assert(strcmp(str2, "bar") == 0);
assert(strcmp(str3, "baz") == 0);
}
void assert_bool(webui_event_t *e) {
size_t count = webui_get_count(e);
assert(count == 3);
long long b = webui_get_bool(e);
long long b1 = webui_get_bool_at(e, 0);
long long b2 = webui_get_bool_at(e, 1);
long long b3 = webui_get_bool_at(e, 2);
assert(b == true);
assert(b1 == b);
assert(b2 == false);
assert(b3 == true);
}
void assert_cprint(webui_event_t *e) {
size_t count = webui_get_count(e);
assert(count == 0);
// The print should be confirmed by checking the program's terminal output.
printf("Hello from the backend!\n");
}
void assert_close(webui_event_t *e) {
// Closing often leads to a seqfault at the moment. Therefore, just a sysexit for now.
// webui_close(e->window);
exit(EXIT_SUCCESS);
}
int main() {
size_t w = webui_new_window();
webui_bind(w, "assert_int", assert_int);
webui_bind(w, "assert_float", assert_float);
webui_bind(w, "assert_string", assert_string);
webui_bind(w, "assert_bool", assert_bool);
webui_bind(w, "assert_cprint", assert_cprint);
webui_bind(w, "assert_close", assert_close);
webui_show(w, doc);
webui_wait();
webui_clean();
return 0;
}

View File

@ -1,30 +0,0 @@
#include "webui.h"
const char *doc =
"<html style=\"background: #654da9; color: #eee\">"
"<head>"
" <script src=\"webui.js\"></script>"
"</head>"
"<body>"
" <script>"
" setTimeout(async () => {"
" await webui.call(\"fail\");"
" }, 500)"
" </script>"
"</body>"
"</html>";
void fail(webui_event_t *e) {
// This test should help to ensure that test failures can be detected from CI.
exit(EXIT_FAILURE);
}
int main() {
size_t w = webui_new_window();
webui_bind(w, "fail", fail);
webui_show(w, doc);
webui_wait();
return 0;
}