Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 50 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,64 @@ if (WEBUI_BUILD_EXAMPLES)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

add_executable(minimal ${CMAKE_CURRENT_SOURCE_DIR}/examples/C++/minimal/main.cpp)
# C++ examples
add_executable(minimal_cpp ${CMAKE_CURRENT_SOURCE_DIR}/examples/C++/minimal/main.cpp)
add_executable(call_js_from_cpp ${CMAKE_CURRENT_SOURCE_DIR}/examples/C++/call_js_from_cpp/main.cpp)
add_executable(call_js_from_cpp_class ${CMAKE_CURRENT_SOURCE_DIR}/examples/C++/call_js_from_cpp_class/main.cpp)
add_executable(serve_a_folder ${CMAKE_CURRENT_SOURCE_DIR}/examples/C++/serve_a_folder/main.cpp)
add_executable(call_js_from_c ${CMAKE_CURRENT_SOURCE_DIR}/examples/C/call_js_from_c/main.c)
add_executable(call_cpp_from_js ${CMAKE_CURRENT_SOURCE_DIR}/examples/C++/call_cpp_from_js/main.cpp)
add_executable(serve_a_folder_cpp ${CMAKE_CURRENT_SOURCE_DIR}/examples/C++/serve_a_folder/main.cpp)
add_executable(virtual_file_system_cpp ${CMAKE_CURRENT_SOURCE_DIR}/examples/C++/virtual_file_system/main.cpp)

target_link_libraries(minimal webui)
# C examples
add_executable(minimal_c ${CMAKE_CURRENT_SOURCE_DIR}/examples/C/minimal/main.c)
add_executable(call_js_from_c ${CMAKE_CURRENT_SOURCE_DIR}/examples/C/call_js_from_c/main.c)
add_executable(call_c_from_js ${CMAKE_CURRENT_SOURCE_DIR}/examples/C/call_c_from_js/main.c)
add_executable(serve_a_folder_c ${CMAKE_CURRENT_SOURCE_DIR}/examples/C/serve_a_folder/main.c)
add_executable(virtual_file_system_c ${CMAKE_CURRENT_SOURCE_DIR}/examples/C/virtual_file_system/main.c)
add_executable(public_network_access ${CMAKE_CURRENT_SOURCE_DIR}/examples/C/public_network_access/main.c)
add_executable(web_app_multi_client ${CMAKE_CURRENT_SOURCE_DIR}/examples/C/web_app_multi_client/main.c)
add_executable(chatgpt_api ${CMAKE_CURRENT_SOURCE_DIR}/examples/C/chatgpt_api/main.c)
add_executable(custom_web_server ${CMAKE_CURRENT_SOURCE_DIR}/examples/C/custom_web_server/main.c)
add_executable(react ${CMAKE_CURRENT_SOURCE_DIR}/examples/C/react/main.c)
add_executable(frameless ${CMAKE_CURRENT_SOURCE_DIR}/examples/C/frameless/main.c)
add_executable(text_editor ${CMAKE_CURRENT_SOURCE_DIR}/examples/C/text-editor/main.c)

target_link_libraries(minimal_cpp webui)
target_link_libraries(call_js_from_cpp webui)
target_link_libraries(call_js_from_cpp_class webui)
target_link_libraries(serve_a_folder webui)
target_link_libraries(call_cpp_from_js webui)
target_link_libraries(serve_a_folder_cpp webui)
target_link_libraries(virtual_file_system_cpp webui)

target_link_libraries(minimal_c webui)
target_link_libraries(call_js_from_c webui)
target_link_libraries(call_c_from_js webui)
target_link_libraries(serve_a_folder_c webui)
target_link_libraries(virtual_file_system_c webui)
target_link_libraries(public_network_access webui)
target_link_libraries(web_app_multi_client webui)
target_link_libraries(chatgpt_api webui)
target_link_libraries(custom_web_server webui)
target_link_libraries(react webui)
target_link_libraries(frameless webui)
target_link_libraries(text_editor webui)

if (MSVC)
set_target_properties(minimal PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(minimal_cpp PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(call_js_from_cpp PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(call_js_from_cpp_class PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(serve_a_folder PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(call_cpp_from_js PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(serve_a_folder_cpp PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(virtual_file_system_cpp PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(minimal_c PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(call_js_from_c PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(call_c_from_js PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(serve_a_folder_c PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(virtual_file_system_c PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(public_network_access PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(web_app_multi_client PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(chatgpt_api PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(custom_web_server PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(react PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(frameless PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
set_target_properties(text_editor PROPERTIES LINK_FLAGS "/SubSystem:\"Windows\"" VS_DPI_AWARE "ON")
endif()

if (MSVC)
Expand Down
8 changes: 4 additions & 4 deletions bridge/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# WebUI Bridge

The WebUI Bridge connects the UI (_Web Browser_) with the backend application through WebSocket. This bridge is written in TypeScript, and it needs to be transpiled to JavaScript using [ESBuild](https://esbuild.github.io/) to produce `webui.js`, then converted to C header using the Python script `js2c.py` to generate `webui_bridge.h`.
The WebUI Bridge connects the UI (_Web Browser_) with the backend application through WebSocket. This bridge is written in TypeScript, and it needs to be transpiled to JavaScript using [ESBuild](https://esbuild.github.io/) to produce `webui.js`, then converted to C header using the Node script `js2c.js` to generate `webui_bridge.h`.

### Windows

Expand All @@ -9,7 +9,7 @@ The WebUI Bridge connects the UI (_Web Browser_) with the backend application th
- cd `webui\bridge`
- `npm install esbuild`
- `.\node_modules\.bin\esbuild --bundle --target="chrome90,firefox90,safari15" --format=esm --tree-shaking=false --outdir=.\ .\webui.ts`
- `python js2c.py`
- `node js2c.js`

### Windows PowerShell

Expand All @@ -25,7 +25,7 @@ The WebUI Bridge connects the UI (_Web Browser_) with the backend application th
- cd `webui/bridge`
- `npm install esbuild`
- `./node_modules/.bin/esbuild --bundle --target="chrome90,firefox90,safari15" --format=esm --tree-shaking=false --outdir=./ ./webui.ts`
- `python js2c.py`
- `node js2c.js`

### Linux Bash

Expand All @@ -39,7 +39,7 @@ The WebUI Bridge connects the UI (_Web Browser_) with the backend application th
- cd `webui/bridge`
- `npm install esbuild`
- `./node_modules/.bin/esbuild --bundle --target="chrome90,firefox90,safari15" --format=esm --tree-shaking=false --outdir=./ ./webui.ts`
- `python js2c.py`
- `node js2c.js`

### macOS Bash

Expand Down
6 changes: 3 additions & 3 deletions examples/C++/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Examples of how to create a WebUI application in C++.
The only requirement to build the examples is a a C++11 compiler.

- `minimal`: Creates a minimal WebUI application.
- `call_c_from_js`: Calls C++ from JavaScript.
- `call_js_from_c`: Calls JavaScript from C++.
- `call_js_from_cpp_class`: Calls JavaScript from C++ using class methods and member-function bind.
- `call_cpp_from_js`: Calls C++ from JavaScript.
- `call_js_from_cpp`: Calls JavaScript from C++ using class methods and member-function bind.
- `serve_a_folder`: Uses WebUI to serve a folder with multiple files (class-based example using member-function bind).
- `virtual_file_system`: Embeds files using a virtual file system.

To build an example, cd into its directory and run the make command.

Expand Down
6 changes: 6 additions & 0 deletions examples/C/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ The only requirement to build the examples is a C compiler.
- `call_js_from_c`: Calls JavaScript from C.
- `serve_a_folder`: Use WebUI to serve a folder that contains `.html`, `.css`, `.js`, or `.ts` files.
- `custom_web_server`: Use your preferred web server like NGINX/Apache... with WebUI to serve a folder.
- `chatgpt_api`: Calls ChatGPT API from C.
- `frameless`: Frameless window example.
- `public_network_access`: Allows network access to external devices.
- `react`: React + WebUI example.
- `virtual_file_system`: Embeds files using a virtual file system.
- `web_app_multi_client`: Multiple clients example.

To build an example, cd into its directory and run the make command.

Expand Down
Loading