WebUI Documentation
repository·main·Indexed 26 days ago
https://github.com/webui-dev/webuiWebUI is a lightweight, portable library for creating GUI applications using web technologies (HTML/CSS/JS) as the frontend and C/C++ as the backend. It controls existing web browsers or WebViews rather than embedding a heavy engine. The library includes a WebUI Bridge for WebSocket communication, a virtual file system for embedding assets into single executables, and starter kits for C and C++ development across Windows, Linux, and macOS.
What's inside WebUI
- WebUI is a lightweight, portable library that allows you to use any installed web browser or WebView as a GUI for your application. It enables developers to use modern web technologies (HTML5, CSS, JavaScript) for the frontend while using their preferred language (C, C++, etc.) for the backend. Unlike Electron or Tauri, WebUI does not embed a heavy browser engine, making it highly portable and small in size, as it relies on the user's existing web browser.
Available WebUI C examples
mainThe following C examples demonstrate various integration patterns with WebUI:
minimal: A minimal WebUI application.call_c_from_js: Demonstrates calling C functions from JavaScript.call_js_from_c: Demonstrates calling JavaScript functions from C.serve_a_folder: Serves a folder containing.html,.css,.js, or.tsfiles.custom_web_server: Integrates WebUI with an external web server like NGINX or Apache to serve a folder.chatgpt_api: Demonstrates calling the ChatGPT API from C.frameless: Shows how to create a frameless window.public_network_access: Configures the application to allow network access from external devices.react: Demonstrates using React with WebUI.virtual_file_system: Shows how to embed files using a virtual file system.test_index_redirect: Tests index fallback and custom entry behavior for paths like/,/sub, and/sub/foo.web_app_multi_client: Demonstrates handling multiple clients.text-editor: A lightweight, portable text editor written in C using WebUI as the GUI library.
Build the WebUI Bridge on Windows
mainTo build the bridge on Windows, ensure you have Python and Node.js installed. You can either run the manual build steps or use the provided batch file.Customize the C++ Starter Kit
mainYou can customize several aspects of the application:
- App name: Edit
APP_NAMEinMakefileorGNUmakefile. - Frontend: Edit any files in the
ui/directory. Files are automatically re-packed into the executable on every build. - Backend: Add C++ functions in
src/main.cppand expose them usingwin.bind(). Bound functions become globalasyncJavaScript functions. - HTTP Routes: Modify
http_handler()insrc/main.cppto add custom routes, headers, or dynamic responses. Note that using a custom handler disables WebUI's cookie-based client authentication. - Icons:
ui/favicon.ico: The Windows executable icon (used by Explorer, taskbar, and WebView).ui/icon.png: The HTML favicon, Linux window/taskbar/launcher icon, and macOS app icon.
- Window Style: To use a standard OS window instead of a frameless/transparent one, remove the
win.set_frameless()andwin.set_transparent()calls insrc/main.cpp. For browser mode, callwin.show()instead ofwin.show_wv().
- App name: Edit
Ensure interoperability when updating the Civetweb submodule
mainWhen updating the Civetweb submodule in a project that uses wrappers, you must apply specific preprocessor directives to prevent compiler warnings (such as those for
mallocorsnprintf) from being triggered by code usage outside of the Civetweb core. This ensures full direct interoperability for the wrappers.Apply the following header guards at the beginning of the Civetweb source files to treat them as system headers, which suppresses warnings for the compiler (MSVC, Clang, or GCC).
+ // Disable All Warnings + #ifdef _MSC_VER + #pragma warning(push, 0) + #pragma warning(disable: 4996) + #elif defined(__clang__) + #pragma clang system_header + #elif defined(__GNUC__) + #pragma GCC system_header + #endif /* Copyright (c) 2013-2024 the Civetweb developersBuild the WebUI Bridge
mainThe WebUI Bridge connects the UI (Web Browser) with the backend application via WebSocket. To build it, you must transpile the TypeScript source (webui.ts) to JavaScript using ESBuild to producewebui.js, and then use thejs2c.jsNode script to convert that JavaScript into the C headerwebui_bridge.h.Install EventToken.h
mainTo include the
EventToken.hheader, you must extract it from your local Windows SDK installation:- Ensure the Windows SDK is installed (available at learn.microsoft.com/en-us/windows/apps/windows-sdk/downloads).
- Locate the file at:
C:\Program Files (x86)\Windows Kits\10\Include\10.x.xxxx.x\winrt\EventToken.h. - Copy and paste
EventToken.hinto thewebui\src\webviewdirectory.
Build the WebUI Library
mainYou can build the WebUI library from source using various compilers depending on your operating system.
Windows
- GCC: Use
mingw32-make. - MSVC: Use
nmake.
Linux
- GCC: Use
make. - Clang: Use
make CC=clang.
macOS
- Default: Use
make.
- GCC: Use
Build WebUI C examples
mainTo build any of the C examples, navigate to the specific example's directory and use the appropriate build command for your operating system and compiler:
Windows
- GCC (MinGW): Use
mingw32-make. - MSVC: Use
nmake.
Linux
- GCC: Use
make. - Clang: Use
make CC=clang.
macOS
- Use
make.
- GCC (MinGW): Use
Build the WebUI Bridge on Linux
mainTo build the bridge on Linux, ensure you have Python and Node.js installed. You can use the manual build commands or the provided shell script.Customize the WebUI C Starter Kit
mainYou can customize several aspects of the application:
- App Name: Edit the
APP_NAMEvariable at the top ofMakefileorGNUmakefile. - Frontend: Add or modify files in the
ui/directory. These are automatically re-packed into the executable on every build. - Backend (C Bindings): Add C functions in
src/main.cand expose them usingwebui_bind(). Bound functions are accessible in JavaScript as globalasyncfunctions (e.g.,const reply = await my_c_function('arg');). - Icons:
ui/favicon.ico: Used as the Windows executable icon (viaicon.rc).ui/icon.png: Used as the HTML favicon, the Linux window/launcher icon, and the macOS app icon.
- HTTP Handling: Custom routes, headers, or dynamic responses can be added by modifying
http_handler()insrc/main.c. Note that using a custom file handler disables WebUI's built-in cookie-based client authentication. - Window Appearance: By default,
src/main.copens a frameless, transparent WebView. To use a standard OS window, remove thewebui_set_frameless()andwebui_set_transparent()calls. To run in browser mode, callwebui_show()instead ofwebui_show_wv().
- App Name: Edit the
Use the React WebUI Example
mainThe React WebUI example demonstrates how to use WebUI with React to create a portable single executable program. WebUI runs an internal web server and uses the system's installed web browser as the GUI.
To rebuild the React project and compile the C source code, run the provided build script: