v2.0.3 - TypeScript Dynamic Lib

- TypeScript Dynamic Lib
- Incomplete Rus wrapper
- Rename of many API's
- Clean all batch script
This commit is contained in:
Hassan DRAGA 2022-10-29 21:41:20 -04:00
parent d870c5b2cb
commit 8c77d0b056
75 changed files with 954 additions and 337 deletions

3
.gitignore vendored
View File

@ -28,3 +28,6 @@ webui2.egg-info/
# Rust
target/
*.lock
# Broken NTFS
nul

View File

@ -12,7 +12,7 @@ Use any web browser as GUI, with your preferred language in the backend, and HTM
- Lightweight and small memory footprint
- Fast binary communication (*App--WebUI--Browser*)
- One header file
- Multiplatform & Multi Browser
- Multi-platform & Multi-Browser
- Use private browser profile for safety
- Customized app mode look & feel

48
clean_all.bat Normal file
View File

@ -0,0 +1,48 @@
@echo off
Set CurrentPath=%CD%
echo.
echo Clean all...
cd build\Windows\MSVC
nmake clean
cd "%CurrentPath%"
cd build\Windows\GCC
mingw32-make clean
cd "%CurrentPath%"
cd build\Windows\TCC
mingw32-make clean
cd "%CurrentPath%"
cd examples\C\hello_world\Windows\MSVC
nmake clean
cd "%CurrentPath%"
cd examples\C\hello_world\Windows\GCC
mingw32-make clean
cd "%CurrentPath%"
cd examples\C\hello_world\Windows\TCC
mingw32-make clean
cd "%CurrentPath%"
cd examples\C++\hello_world\Windows\MSVC
nmake clean
cd "%CurrentPath%"
cd examples\C++\hello_world\Windows\GCC
mingw32-make clean
cd "%CurrentPath%"
cd examples\Go\hello_world\
go clean -modcache
go clean --cache
go clean
cd "%CurrentPath%"
cd examples\Rust\hello_world
cargo clean
cd "%CurrentPath%"

View File

@ -0,0 +1,42 @@
# WebUI Library 2.x
# C++ Example
# Linux - Clang
LIB=../../../../../build/Linux/Clang
INCLUDE=../../../../../include
SOURCE=../..
all: release
debug:
# Build Lib
@cd "$(LIB)" && $(MAKE) debug
# Static with Debug info
@echo "Build C++ Example (Static Debug)..."
@clang -g -static -m64 -o main "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" -lwebui-2-static-x64 -lpthread
# Dynamic with Debug info
@echo "Build C++ Example (Dynamic Debug)..."
@clang -g -m64 -o main-dyn "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" "$(LIB)/webui-2-x64.so" -lpthread
# Clean
@- rm -f *.o
@echo "Done."
release:
# Build Lib
@cd "$(LIB)" && $(MAKE)
# Static Release
@echo "Build C++ Example (Static Release)..."
@clang -static -Os -m64 -o main "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" -lwebui-2-static-x64 -lpthread
@llvm-strip --strip-all main
# Dynamic Release
@echo "Build C++ Example (Dynamic Release)..."
@clang -m64 -o main-dyn "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" "$(LIB)/webui-2-x64.so" -lpthread
@llvm-strip --strip-all main-dyn
# Clean
@- rm -f *.o
@echo "Done."
clean:
- rm -f *.o
- rm -f *.so
- rm -f *.a

View File

@ -0,0 +1,42 @@
# WebUI Library 2.x
# C++ Example
# Linux - GCC
LIB=../../../../../build/Linux/GCC
INCLUDE=../../../../../include
SOURCE=../..
all: release
debug:
# Build Lib
@cd "$(LIB)" && $(MAKE) debug
# Static with Debug info
@echo "Build C++ Example (Static Debug)..."
@gcc -g -static -m64 -o main "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" -lwebui-2-static-x64 -lpthread
# Dynamic with Debug info
@echo "Build C++ Example (Dynamic Debug)..."
@gcc -g -m64 -o main-dyn "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" "$(LIB)/webui-2-x64.so" -lpthread
# Clean
@- rm -f *.o
@echo "Done."
release:
# Build Lib
@cd "$(LIB)" && $(MAKE)
# Static Release
@echo "Build C++ Example (Static Release)..."
@gcc -static -Os -m64 -o main "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" -lwebui-2-static-x64 -lpthread
@strip --strip-all main
# Dynamic Release
@echo "Build C++ Example (Dynamic Release)..."
@gcc -m64 -o main-dyn "$(SOURCE)/main.cpp" -I "$(INCLUDE)" -L "$(LIB)" "$(LIB)/webui-2-x64.so" -lpthread
@strip --strip-all main-dyn
# Clean
@- rm -f *.o
@echo "Done."
clean:
- rm -f *.o
- rm -f *.so
- rm -f *.a

View File

@ -3,8 +3,8 @@
# Windows - GCC
SHELL=CMD
LIB=../../../../build/Windows/GCC
INCLUDE=../../../../include
LIB=../../../../../build/Windows/GCC
INCLUDE=../../../../../include
SOURCE=../..
all: release

View File

Before

Width:  |  Height:  |  Size: 105 KiB

After

Width:  |  Height:  |  Size: 105 KiB

View File

@ -3,8 +3,8 @@
# Windows - Microsoft Visual C
SHELL=CMD
_LIB=../../../../build/Windows/MSVC/
_INCLUDE=../../../../include/
_LIB=../../../../../build/Windows/MSVC/
_INCLUDE=../../../../../include/
_SOURCE=../../
all: release

View File

Before

Width:  |  Height:  |  Size: 105 KiB

After

Width:  |  Height:  |  Size: 105 KiB

View File

@ -33,12 +33,12 @@ void check_the_password(webui_event_t* e) {
// This function get called every time the user click on "MyButton1"
webui_javascript_t js;
webui_script_t js;
js.script = " return document.getElementById(\"MyInput\").value; ";
js.timeout = 3;
// Run the JavaScript on the UI (Web Browser)
webui_run_js(my_window, &js);
webui_script(my_window, &js);
// Check if there is any JavaScript error
if (js.result.error) {
@ -56,17 +56,17 @@ void check_the_password(webui_event_t* e) {
// Correct password
js.script = "alert('Good. Password is correct.')";
webui_run_js(my_window, &js);
webui_script(my_window, &js);
}
else {
// Wrong password
js.script = "alert('Sorry. Wrong password.')";
webui_run_js(my_window, &js);
webui_script(my_window, &js);
}
// Free data resources
webui_free_js(&js);
webui_free_script(&js);
}
void close_the_application(webui_event_t* e) {
@ -89,7 +89,7 @@ int main() {
webui_show(my_window, my_html, webui.browser.any); // If not, run on any other installed web browser
// Wait until all windows get closed
webui_loop();
webui_wait();
return 0;
}

View File

@ -72,22 +72,22 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\..\..\..\..\include;..\..\..\..\..\include;$(IncludePath)</IncludePath>
<IncludePath>..\..\..\..\..\..\include;..\..\..\..\..\..\include;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\..\..\..\..\include;..\..\..\..\..\include;$(IncludePath)</IncludePath>
<IncludePath>..\..\..\..\..\..\include;..\..\..\..\..\..\include;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>..\..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>$(OutDir);$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>..\..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>$(OutDir);$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">

View File

@ -72,19 +72,19 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\..\..\..\..\include;..\..\..\..\..\include;$(IncludePath)</IncludePath>
<IncludePath>..\..\..\..\..\..\include;..\..\..\..\..\..\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\..\..\..\..\include;..\..\..\..\..\include;$(IncludePath)</IncludePath>
<IncludePath>..\..\..\..\..\..\include;..\..\..\..\..\..\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>..\..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>..\..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@ -155,12 +155,12 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\..\include\mongoose.h" />
<ClInclude Include="..\..\..\..\..\include\webui.h" />
<ClInclude Include="..\..\..\..\..\..\include\mongoose.h" />
<ClInclude Include="..\..\..\..\..\..\include\webui.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\..\src\mongoose.c" />
<ClCompile Include="..\..\..\..\..\src\webui.c" />
<ClCompile Include="..\..\..\..\..\..\src\mongoose.c" />
<ClCompile Include="..\..\..\..\..\..\src\webui.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -15,18 +15,18 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\..\include\webui.h">
<ClInclude Include="..\..\..\..\..\..\include\webui.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\..\include\mongoose.h">
<ClInclude Include="..\..\..\..\..\..\include\mongoose.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\..\src\webui.c">
<ClCompile Include="..\..\..\..\..\..\src\webui.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\..\src\mongoose.c">
<ClCompile Include="..\..\..\..\..\..\src\mongoose.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>

View File

@ -33,12 +33,12 @@ void check_the_password(webui_event_t* e) {
// This function get called every time the user click on "MyButton1"
webui_javascript_t js;
webui_script_t js;
js.script = " return document.getElementById(\"MyInput\").value; ";
js.timeout = 3;
// Run the JavaScript on the UI (Web Browser)
webui_run_js(my_window, &js);
webui_script(my_window, &js);
// Check if there is any JavaScript error
if (js.result.error) {
@ -56,17 +56,17 @@ void check_the_password(webui_event_t* e) {
// Correct password
js.script = "alert('Good. Password is correct.')";
webui_run_js(my_window, &js);
webui_script(my_window, &js);
}
else {
// Wrong password
js.script = "alert('Sorry. Wrong password.')";
webui_run_js(my_window, &js);
webui_script(my_window, &js);
}
// Free data resources
webui_free_js(&js);
webui_free_script(&js);
}
void close_the_application(webui_event_t* e) {
@ -89,7 +89,7 @@ int main() {
webui_show(my_window, my_html, webui.browser.any); // If not, run on any other installed web browser
// Wait until all windows get closed
webui_loop();
webui_wait();
return 0;
}

View File

@ -72,22 +72,22 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\..\..\..\..\include;..\..\..\..\..\include;$(IncludePath)</IncludePath>
<IncludePath>..\..\..\..\..\..\include;..\..\..\..\..\..\include;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\..\..\..\..\include;..\..\..\..\..\include;$(IncludePath)</IncludePath>
<IncludePath>..\..\..\..\..\..\include;..\..\..\..\..\..\include;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>..\..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>$(OutDir);$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>..\..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>$(OutDir);$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">

View File

@ -72,19 +72,19 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\..\..\..\..\include;..\..\..\..\..\include;$(IncludePath)</IncludePath>
<IncludePath>..\..\..\..\..\..\include;..\..\..\..\..\..\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\..\..\..\..\include;..\..\..\..\..\include;$(IncludePath)</IncludePath>
<IncludePath>..\..\..\..\..\..\include;..\..\..\..\..\..\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>..\..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>..\..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@ -155,12 +155,12 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\..\include\mongoose.h" />
<ClInclude Include="..\..\..\..\..\include\webui.h" />
<ClInclude Include="..\..\..\..\..\..\include\mongoose.h" />
<ClInclude Include="..\..\..\..\..\..\include\webui.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\..\src\mongoose.c" />
<ClCompile Include="..\..\..\..\..\src\webui.c" />
<ClCompile Include="..\..\..\..\..\..\src\mongoose.c" />
<ClCompile Include="..\..\..\..\..\..\src\webui.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -15,18 +15,18 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\..\include\webui.h">
<ClInclude Include="..\..\..\..\..\..\include\webui.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\..\include\mongoose.h">
<ClInclude Include="..\..\..\..\..\..\include\mongoose.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\..\src\webui.c">
<ClCompile Include="..\..\..\..\..\..\src\webui.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\..\src\mongoose.c">
<ClCompile Include="..\..\..\..\..\..\src\mongoose.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>

View File

@ -33,12 +33,12 @@ void check_the_password(webui_event_t* e) {
// This function get called every time the user click on "MyButton1"
webui_javascript_t js;
webui_script_t js;
js.script = " return document.getElementById(\"MyInput\").value; ";
js.timeout = 3;
// Run the JavaScript on the UI (Web Browser)
webui_run_js(my_window, &js);
webui_script(my_window, &js);
// Check if there is any JavaScript error
if(js.result.error) {
@ -56,17 +56,17 @@ void check_the_password(webui_event_t* e) {
// Correct password
js.script = "alert('Good. Password is correct.')";
webui_run_js(my_window, &js);
webui_script(my_window, &js);
}
else {
// Wrong password
js.script = "alert('Sorry. Wrong password.')";
webui_run_js(my_window, &js);
webui_script(my_window, &js);
}
// Free data resources
webui_free_js(&js);
webui_free_script(&js);
}
void close_the_application(webui_event_t* e){
@ -89,7 +89,7 @@ int main() {
webui_show(my_window, my_html, webui.browser.any); // If not, run on any other installed web browser
// Wait until all windows get closed
webui_loop();
webui_wait();
return 0;
}

View File

@ -2,8 +2,8 @@
# C99 Example
# Linux - Clang
LIB=../../../../build/Linux/Clang
INCLUDE=../../../../include
LIB=../../../../../build/Linux/Clang
INCLUDE=../../../../../include
SOURCE=../..
all: release

View File

@ -2,8 +2,8 @@
# C99 Example
# Linux - GCC
LIB=../../../../build/Linux/GCC
INCLUDE=../../../../include
LIB=../../../../../build/Linux/GCC
INCLUDE=../../../../../include
SOURCE=../..
all: release

View File

@ -3,8 +3,8 @@
# Windows - GCC
SHELL=CMD
LIB=../../../../build/Windows/GCC
INCLUDE=../../../../include
LIB=../../../../../build/Windows/GCC
INCLUDE=../../../../../include
SOURCE=../..
all: release

View File

Before

Width:  |  Height:  |  Size: 105 KiB

After

Width:  |  Height:  |  Size: 105 KiB

View File

@ -3,8 +3,8 @@
# Windows - Microsoft Visual C
SHELL=CMD
_LIB=../../../../build/Windows/MSVC/
_INCLUDE=../../../../include/
_LIB=../../../../../build/Windows/MSVC/
_INCLUDE=../../../../../include/
_SOURCE=../../
all: release

View File

Before

Width:  |  Height:  |  Size: 105 KiB

After

Width:  |  Height:  |  Size: 105 KiB

View File

@ -3,8 +3,8 @@
# Windows - Tiny C Compiler
SHELL=CMD
LIB=../../../../build/Windows/TCC/
INCLUDE=../../../../include/
LIB=../../../../../build/Windows/TCC/
INCLUDE=../../../../../include/
SOURCE=../../
all: release

View File

@ -31,13 +31,13 @@ void check_the_password(webui_event_t* e) {
// This function get called every time the user click on "MyButton1"
webui_javascript_t js = {
webui_script_t js = {
.script = " return document.getElementById(\"MyInput\").value; ",
.timeout = 3
};
// Run the JavaScript on the UI (Web Browser)
webui_run_js(my_window, &js);
webui_script(my_window, &js);
// Check if there is any JavaScript error
if (js.result.error) {
@ -55,17 +55,17 @@ void check_the_password(webui_event_t* e) {
// Correct password
js.script = "alert('Good. Password is correct.')";
webui_run_js(my_window, &js);
webui_script(my_window, &js);
}
else {
// Wrong password
js.script = "alert('Sorry. Wrong password.')";
webui_run_js(my_window, &js);
webui_script(my_window, &js);
}
// Free data resources
webui_free_js(&js);
webui_free_script(&js);
}
void close_the_application(webui_event_t* e) {
@ -88,7 +88,7 @@ int main() {
webui_show(my_window, my_html, webui.browser.any); // If not, run on any other installed web browser
// Wait until all windows get closed
webui_loop();
webui_wait();
return 0;
}

View File

@ -72,22 +72,22 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\..\..\..\..\include;..\..\..\..\..\include;$(IncludePath)</IncludePath>
<IncludePath>..\..\..\..\..\..\include;..\..\..\..\..\..\include;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\..\..\..\..\include;..\..\..\..\..\include;$(IncludePath)</IncludePath>
<IncludePath>..\..\..\..\..\..\include;..\..\..\..\..\..\include;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir);$(OutDir);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>..\..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>$(OutDir);$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>..\..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<LibraryPath>$(OutDir);$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">

View File

@ -72,19 +72,19 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\..\..\..\..\include;..\..\..\..\..\include;$(IncludePath)</IncludePath>
<IncludePath>..\..\..\..\..\..\include;..\..\..\..\..\..\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\..\..\..\..\include;..\..\..\..\..\include;$(IncludePath)</IncludePath>
<IncludePath>..\..\..\..\..\..\include;..\..\..\..\..\..\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>..\..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>..\..\..\..\..\..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@ -155,12 +155,12 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\..\include\mongoose.h" />
<ClInclude Include="..\..\..\..\..\include\webui.h" />
<ClInclude Include="..\..\..\..\..\..\include\mongoose.h" />
<ClInclude Include="..\..\..\..\..\..\include\webui.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\..\src\mongoose.c" />
<ClCompile Include="..\..\..\..\..\src\webui.c" />
<ClCompile Include="..\..\..\..\..\..\src\mongoose.c" />
<ClCompile Include="..\..\..\..\..\..\src\webui.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -15,18 +15,18 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\..\include\webui.h">
<ClInclude Include="..\..\..\..\..\..\include\webui.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\..\include\mongoose.h">
<ClInclude Include="..\..\..\..\..\..\include\mongoose.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\..\src\webui.c">
<ClCompile Include="..\..\..\..\..\..\src\webui.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\..\src\mongoose.c">
<ClCompile Include="..\..\..\..\..\..\src\mongoose.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>

View File

@ -31,13 +31,13 @@ void check_the_password(webui_event_t* e) {
// This function get called every time the user click on "MyButton1"
webui_javascript_t js = {
webui_script_t js = {
.script = " return document.getElementById(\"MyInput\").value; ",
.timeout = 3
};
// Run the JavaScript on the UI (Web Browser)
webui_run_js(my_window, &js);
webui_script(my_window, &js);
// Check if there is any JavaScript error
if (js.result.error) {
@ -55,17 +55,17 @@ void check_the_password(webui_event_t* e) {
// Correct password
js.script = "alert('Good. Password is correct.')";
webui_run_js(my_window, &js);
webui_script(my_window, &js);
}
else {
// Wrong password
js.script = "alert('Sorry. Wrong password.')";
webui_run_js(my_window, &js);
webui_script(my_window, &js);
}
// Free data resources
webui_free_js(&js);
webui_free_script(&js);
}
void close_the_application(webui_event_t* e) {
@ -88,7 +88,7 @@ int main() {
webui_show(my_window, my_html, webui.browser.any); // If not, run on any other installed web browser
// Wait until all windows get closed
webui_loop();
webui_wait();
return 0;
}

View File

@ -31,13 +31,13 @@ void check_the_password(webui_event_t* e) {
// This function get called every time the user click on "MyButton1"
webui_javascript_t js = {
webui_script_t js = {
.script = " return document.getElementById(\"MyInput\").value; ",
.timeout = 3
};
// Run the JavaScript on the UI (Web Browser)
webui_run_js(my_window, &js);
webui_script(my_window, &js);
// Check if there is any JavaScript error
if(js.result.error) {
@ -55,17 +55,17 @@ void check_the_password(webui_event_t* e) {
// Correct password
js.script = "alert('Good. Password is correct.')";
webui_run_js(my_window, &js);
webui_script(my_window, &js);
}
else {
// Wrong password
js.script = "alert('Sorry. Wrong password.')";
webui_run_js(my_window, &js);
webui_script(my_window, &js);
}
// Free data resources
webui_free_js(&js);
webui_free_script(&js);
}
void close_the_application(webui_event_t* e){
@ -88,7 +88,7 @@ int main() {
webui_show(my_window, my_html, webui.browser.any); // If not, run on any other installed web browser
// Wait until all windows get closed
webui_loop();
webui_wait();
return 0;
}

View File

@ -30,9 +30,9 @@ const login_html string = `<!DOCTYPE html>
<br>
<input type="password" id="MyInput" OnKeyUp="document.getElementById('err').innerHTML='&nbsp;';" autocomplete="off">
<br>
<h3 id="err" style="color: #dbdd52">&nbsp;</h3>
<h3 id="err" style="color: #dbdd52">&nbsp;</h3>
<br>
<button id="CheckPassword">Check Password</button> - <button id="Exit">Exit</button>
<button id="CheckPassword">Check Password</button> - <button id="Exit">Exit</button>
</body>
</html>`
@ -56,7 +56,7 @@ const dashboard_html string = `<!DOCTYPE html>
<h1>Welcome !</h1>
<br>
<br>
<button id="Exit">Exit</button>
<button id="Exit">Exit</button>
</body>
</html>`
@ -110,7 +110,7 @@ func main() {
webui.Show(my_window, login_html, webui.AnyBrowser)
// Loop
webui.Loop()
webui.Wait()
fmt.Println("Bye.")
}

View File

@ -1,6 +1,6 @@
package webui
// WebUI Library 2.0.2
// WebUI Library 2.0.3
//
// http://webui.me
// https://github.com/alifcommunity/webui
@ -76,7 +76,7 @@ func webui_go_handler(_window *C.webui_window_t, _element_id C.uint, _window_id
func RunJavaScript(window *C.webui_window_t, js *JavaScript) {
// Interface
c_js := C.webui_javascript_int_t{
c_js := C.webui_script_interface_t{
script: C.CString(js.Script),
timeout: 30, // uint(js.Timeout),
error: C.bool(false),
@ -84,7 +84,7 @@ func RunJavaScript(window *C.webui_window_t, js *JavaScript) {
// data: C.CString(nil),
}
C.webui_run_js_int_struct(window, &c_js)
C.webui_script_interface_struct(window, &c_js)
js.Error = bool(c_js.error)
js.Data = C.GoString(c_js.data)
@ -106,9 +106,9 @@ func Show(window *C.webui_window_t, html string, browser uint) {
C.webui_show(window, c_html, C.uint(browser))
}
func Loop() {
func Wait() {
C.webui_loop()
C.webui_wait()
}
func Bind(window *C.webui_window_t, element string, callback func(Event)) {

View File

@ -10,7 +10,9 @@
# Install WebUI 2
# pip install --upgrade webui2
from webui import webui
# from webui import webui
import webui
# Create a global window object
MyWindow = webui.window()
@ -108,7 +110,7 @@ def main():
MyWindow.show(login_html)
# Wait until all windows are closed
webui.loop()
webui.wait()
print('Bye.')

View File

@ -1,5 +1,5 @@
/*
WebUI Library 2.0.2
WebUI Library 2.0.3
http://webui.me
https://github.com/alifcommunity/webui
@ -18,4 +18,5 @@ fn main() {
// WebUI static library name
println!("cargo:rustc-link-lib=webui-2-static-x64");
println!("cargo:rustc-link-lib=user32");
}

View File

@ -1,5 +1,5 @@
/*
WebUI Library 2.0.2
WebUI Library 2.0.3
http://webui.me
https://github.com/alifcommunity/webui
@ -21,26 +21,22 @@ use std::os::raw::c_char;
use std::ffi::CString;
use std::ffi::CStr;
// --[WebUI Library References]-------------------------------
// --[WebUI Library References]--------
pub type size_t = ::std::os::raw::c_ulonglong;
pub const WEBUI_MAX_ARRAY: u32 = 32;
pub const __bool_true_false_are_defined: u32 = 1;
pub const true_: u32 = 1;
pub const false_: u32 = 0;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct webui_event_t {
pub window: *mut webui_window_t,
pub window_id: ::std::os::raw::c_uint,
pub element_id: ::std::os::raw::c_uint,
pub element_name: *mut ::std::os::raw::c_char,
pub window: *mut webui_window_t,
}
#[repr(C)]
pub struct webui_custom_browser_t {
pub app: *mut ::std::os::raw::c_char,
pub arg: *mut ::std::os::raw::c_char,
pub auto_link: bool,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct webui_window_core_t {
pub window_number: ::std::os::raw::c_uint,
pub server_running: bool,
@ -51,8 +47,11 @@ pub struct webui_window_core_t {
pub server_port: ::std::os::raw::c_uint,
pub is_bind_all: bool,
pub url: *mut ::std::os::raw::c_char,
pub cb_all: [::std::option::Option<unsafe extern "C" fn(e: webui_event_t)>; 1usize],
pub cb_all: [::std::option::Option<
unsafe extern "C" fn(e: *mut webui_event_t),
>; 1usize],
pub html: *const ::std::os::raw::c_char,
pub html_cpy: *const ::std::os::raw::c_char,
pub icon: *const ::std::os::raw::c_char,
pub icon_type: *const ::std::os::raw::c_char,
pub CurrentBrowser: ::std::os::raw::c_uint,
@ -61,37 +60,67 @@ pub struct webui_window_core_t {
pub connections: ::std::os::raw::c_uint,
pub runtime: ::std::os::raw::c_uint,
pub detect_process_close: bool,
pub server_thread: ::std::os::raw::c_int,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct webui_window_t {
pub core: webui_window_core_t,
pub path: *mut ::std::os::raw::c_char,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct webui_javascript_result_t {
pub error: bool,
pub length: ::std::os::raw::c_uint,
pub data: *const ::std::os::raw::c_char,
}
#[repr(C)]
pub struct webui_javascript_t {
pub script: *mut ::std::os::raw::c_char,
#[derive(Debug, Copy, Clone)]
pub struct webui_script_t {
pub script: *const ::std::os::raw::c_char,
pub timeout: ::std::os::raw::c_uint,
pub result: webui_javascript_result_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct webui_cb_t {
pub win: *mut webui_window_t,
pub element_id: *mut ::std::os::raw::c_char,
pub element_name: *mut ::std::os::raw::c_char,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct webui_cmd_async_t {
pub win: *mut webui_window_t,
pub cmd: *mut ::std::os::raw::c_char,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct webui_custom_browser_t {
pub app: *mut ::std::os::raw::c_char,
pub arg: *mut ::std::os::raw::c_char,
pub auto_link: bool,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct webui_browser_t {
pub any: ::std::os::raw::c_uint,
pub chrome: ::std::os::raw::c_uint,
pub firefox: ::std::os::raw::c_uint,
pub edge: ::std::os::raw::c_uint,
pub safari: ::std::os::raw::c_uint,
pub chromium: ::std::os::raw::c_uint,
pub custom: ::std::os::raw::c_uint,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct webui_runtime_t {
pub none: ::std::os::raw::c_uint,
pub deno: ::std::os::raw::c_uint,
pub nodejs: ::std::os::raw::c_uint,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct webui_t {
pub servers: ::std::os::raw::c_uint,
pub connections: ::std::os::raw::c_uint,
@ -104,50 +133,46 @@ pub struct webui_t {
pub use_timeout: bool,
pub timeout_extra: bool,
pub exit_now: bool,
pub run_responses: [*mut ::std::os::raw::c_char; 32usize],
pub run_responses: [*const ::std::os::raw::c_char; 32usize],
pub run_done: [bool; 32usize],
pub run_error: [bool; 32usize],
pub run_last_id: ::std::os::raw::c_uint,
pub browser: webui_browser_t,
pub runtime: webui_runtime_t,
pub initialized: bool,
pub cb: [::std::option::Option<unsafe extern "C" fn(e: webui_event_t)>; 32usize],
pub cb: [::std::option::Option<unsafe extern "C" fn(e: *mut webui_event_t)>;
32usize],
pub cb_int: [::std::option::Option<
unsafe extern "C" fn(
arg1: ::std::os::raw::c_uint,
arg2: ::std::os::raw::c_uint,
arg3: *mut ::std::os::raw::c_char,
element_id: ::std::os::raw::c_uint,
window_id: ::std::os::raw::c_uint,
element_name: *mut ::std::os::raw::c_char,
window: *mut webui_window_t,
),
>; 32usize],
pub executable_path: *mut ::std::os::raw::c_char,
pub ptr_list: [*mut ::std::os::raw::c_void; 32usize],
pub ptr_position: size_t,
pub ptr_size: [size_t; 32usize],
pub ptr_position: ::std::os::raw::c_uint,
pub ptr_size: [usize; 32usize],
}
extern "C" {
pub static mut webui: webui_t;
}
extern "C" {
pub fn webui_loop();
pub fn webui_wait();
}
extern "C" {
pub fn webui_exit();
}
extern "C" {
pub fn webui_any_window_is_open() -> bool;
pub fn webui_is_any_window_running() -> bool;
}
extern "C" {
pub fn webui_set_timeout(second: ::std::os::raw::c_uint);
}
extern "C" {
pub fn webui_new_window() -> *mut webui_window_t;
}
extern "C" {
pub fn webui_show(
win: *mut webui_window_t,
@ -155,15 +180,13 @@ extern "C" {
browser: ::std::os::raw::c_uint,
) -> bool;
}
extern "C" {
pub fn webui_copy_show(
pub fn webui_show_cpy(
win: *mut webui_window_t,
html: *const ::std::os::raw::c_char,
browser: ::std::os::raw::c_uint,
) -> bool;
}
extern "C" {
pub fn webui_set_icon(
win: *mut webui_window_t,
@ -171,18 +194,15 @@ extern "C" {
type_s: *const ::std::os::raw::c_char,
);
}
extern "C" {
pub fn webui_allow_multi_access(win: *mut webui_window_t, status: bool);
}
extern "C" {
pub fn webui_set_root_folder(
win: *mut webui_window_t,
path: *const ::std::os::raw::c_char,
) -> bool;
}
extern "C" {
pub fn webui_new_server(
win: *mut webui_window_t,
@ -190,21 +210,86 @@ extern "C" {
index_html: *const ::std::os::raw::c_char,
) -> *const ::std::os::raw::c_char;
}
extern "C" {
pub fn webui_close(win: *mut webui_window_t);
}
extern "C" {
pub fn webui_is_show(win: *mut webui_window_t) -> bool;
}
extern "C" {
pub fn webui_run_js(win: *mut webui_window_t, javascript: *mut webui_javascript_t);
pub fn webui_script(
win: *mut webui_window_t,
script: *mut webui_script_t,
);
}
extern "C" {
pub fn webui_run_js_int(
pub fn webui_bind(
win: *mut webui_window_t,
element: *const ::std::os::raw::c_char,
func: ::std::option::Option<
// unsafe extern "C" fn(e: *mut webui_event_t),
unsafe fn(e: *mut webui_event_t),
>,
) -> ::std::os::raw::c_uint;
}
extern "C" {
pub fn webui_bind_all(
win: *mut webui_window_t,
func: ::std::option::Option<
unsafe extern "C" fn(e: *mut webui_event_t),
>,
);
}
extern "C" {
pub fn webui_open(
win: *mut webui_window_t,
url: *const ::std::os::raw::c_char,
browser: ::std::os::raw::c_uint,
) -> bool;
}
extern "C" {
pub fn webui_free_script(script: *mut webui_script_t);
}
extern "C" {
pub fn webui_script_runtime(
win: *mut webui_window_t,
runtime: ::std::os::raw::c_uint,
);
}
extern "C" {
pub fn webui_wait_process(win: *mut webui_window_t, status: bool);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct webui_script_interface_t {
pub script: *mut ::std::os::raw::c_char,
pub timeout: ::std::os::raw::c_uint,
pub error: bool,
pub length: ::std::os::raw::c_uint,
pub data: *const ::std::os::raw::c_char,
}
extern "C" {
pub fn webui_bind_interface(
win: *mut webui_window_t,
element: *const ::std::os::raw::c_char,
func: ::std::option::Option<
// unsafe extern "C" fn(
// element_id: ::std::os::raw::c_uint,
// window_id: ::std::os::raw::c_uint,
// element_name: *mut ::std::os::raw::c_char,
// window: *mut webui_window_t,
// ),
unsafe fn(
element_id: ::std::os::raw::c_uint,
window_id: ::std::os::raw::c_uint,
element_name: *mut ::std::os::raw::c_char,
window: *mut webui_window_t,
),
>,
) -> ::std::os::raw::c_uint;
}
extern "C" {
pub fn webui_script_interface(
win: *mut webui_window_t,
script: *const ::std::os::raw::c_char,
timeout: ::std::os::raw::c_uint,
@ -213,43 +298,159 @@ extern "C" {
data: *mut ::std::os::raw::c_char,
);
}
extern "C" {
pub fn webui_bind(
pub fn webui_script_interface_struct(
win: *mut webui_window_t,
element: *const ::std::os::raw::c_char,
func: ::std::option::Option<unsafe fn(e: webui_event_t) -> ()>,
) -> ::std::os::raw::c_uint;
}
extern "C" {
pub fn webui_bind_all(
win: *mut webui_window_t,
func: ::std::option::Option<unsafe extern "C" fn(e: webui_event_t)>,
js_int: *mut webui_script_interface_t,
);
}
extern "C" {
pub fn webui_open(
pub fn webui_TEST(win: *mut webui_window_t);
}
extern "C" {
pub fn _webui_ini();
}
extern "C" {
pub fn _webui_get_cb_index(
element: *mut ::std::os::raw::c_char,
) -> ::std::os::raw::c_uint;
}
extern "C" {
pub fn _webui_set_cb_index(
element: *mut ::std::os::raw::c_char,
) -> ::std::os::raw::c_uint;
}
extern "C" {
pub fn _webui_get_free_port() -> ::std::os::raw::c_uint;
}
extern "C" {
pub fn _webui_get_new_window_number() -> ::std::os::raw::c_uint;
}
extern "C" {
pub fn _webui_wait_for_startup();
}
extern "C" {
pub fn _webui_free_port(port: ::std::os::raw::c_uint);
}
extern "C" {
pub fn _webui_set_custom_browser(p: *mut webui_custom_browser_t);
}
extern "C" {
pub fn _webui_get_current_path() -> *mut ::std::os::raw::c_char;
}
extern "C" {
pub fn _webui_window_receive(
win: *mut webui_window_t,
packet: *const ::std::os::raw::c_char,
len: usize,
);
}
extern "C" {
pub fn _webui_window_send(
win: *mut webui_window_t,
packet: *mut ::std::os::raw::c_char,
packets_size: usize,
);
}
extern "C" {
pub fn _webui_window_event(
win: *mut webui_window_t,
element_id: *mut ::std::os::raw::c_char,
element: *mut ::std::os::raw::c_char,
);
}
extern "C" {
pub fn _webui_window_get_number(
win: *mut webui_window_t,
) -> ::std::os::raw::c_uint;
}
extern "C" {
pub fn _webui_window_open(
win: *mut webui_window_t,
link: *mut ::std::os::raw::c_char,
browser: ::std::os::raw::c_uint,
);
}
extern "C" {
pub fn _webui_cmd_sync(
cmd: *mut ::std::os::raw::c_char,
show: bool,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn _webui_cmd_async(
cmd: *mut ::std::os::raw::c_char,
show: bool,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn _webui_run_browser(
win: *mut webui_window_t,
cmd: *mut ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn _webui_browser_clean();
}
extern "C" {
pub fn _webui_browser_exist(
win: *mut webui_window_t,
url: *const ::std::os::raw::c_char,
browser: ::std::os::raw::c_uint,
) -> bool;
}
extern "C" {
pub fn webui_free_js(javascript: *mut webui_javascript_t);
pub fn _webui_browser_get_temp_path(
browser: ::std::os::raw::c_uint,
) -> *const ::std::os::raw::c_char;
}
extern "C" {
pub fn _webui_folder_exist(folder: *mut ::std::os::raw::c_char) -> bool;
}
extern "C" {
pub fn _webui_browser_create_profile_folder(
win: *mut webui_window_t,
browser: ::std::os::raw::c_uint,
) -> bool;
}
extern "C" {
pub fn _webui_browser_start_edge(
win: *mut webui_window_t,
address: *const ::std::os::raw::c_char,
) -> bool;
}
extern "C" {
pub fn _webui_browser_start_firefox(
win: *mut webui_window_t,
address: *const ::std::os::raw::c_char,
) -> bool;
}
extern "C" {
pub fn _webui_browser_start_custom(
win: *mut webui_window_t,
address: *const ::std::os::raw::c_char,
) -> bool;
}
extern "C" {
pub fn _webui_browser_start_chrome(
win: *mut webui_window_t,
address: *const ::std::os::raw::c_char,
) -> bool;
}
extern "C" {
pub fn _webui_browser_start(
win: *mut webui_window_t,
address: *const ::std::os::raw::c_char,
browser: ::std::os::raw::c_uint,
) -> bool;
}
extern "C" {
pub fn _webui_system_win32(
cmd: *mut ::std::os::raw::c_char,
show: bool,
) -> ::std::os::raw::c_int;
}
extern "C" {
pub fn webui_runtime(win: *mut webui_window_t, runtime: ::std::os::raw::c_uint);
}
extern "C" {
pub fn webui_detect_process_close(win: *mut webui_window_t, status: bool);
}
// --[Tools]--------------------------------------------------
// --[Tools]---------------------------
// fn char_to_string(c : *mut ::std::os::raw::c_char) -> String {
// let cstr = unsafe {CStr::from_ptr(c)};
@ -270,7 +471,7 @@ fn cstr_to_string(c : CString) -> String {
return s;
}
// --[Wrapper]------------------------------------------------
// --[Wrapper]-------------------------
pub const AnyBrowser: u32 = 0;
pub const Chrome: u32 = 1;
@ -287,6 +488,16 @@ pub struct JavaScript {
pub data: String,
}
pub struct Event {
pub ElementId: u32,
pub WindowId: u32,
pub ElementName: String,
pub Window: *mut webui_window_t,
}
// TODO: Create list of function (2-dimensional array)
// pub mut func_list: [[Option::<fn(e: Event) -> ()>; 64]; 64] = [[None; 64]; 64];
pub fn RunJavaScript(win: *mut webui_window_t, js: &mut JavaScript) {
unsafe {
@ -308,7 +519,7 @@ pub fn RunJavaScript(win: *mut webui_window_t, js: &mut JavaScript) {
let length_ptr: *mut ::std::os::raw::c_uint = &mut length;
let data_ptr = data.into_raw();
webui_run_js_int(win, script, timeout, error_ptr, length_ptr, data_ptr);
webui_script_interface(win, script, timeout, error_ptr, length_ptr, data_ptr);
js.error = error;
js.data = char_to_string(data_ptr);
@ -323,11 +534,11 @@ pub fn NewWindow() -> *mut webui_window_t {
}
}
pub fn Loop() {
pub fn Wait() {
unsafe {
webui_loop();
webui_wait();
}
}
@ -347,24 +558,50 @@ pub fn Show(win: *mut webui_window_t, html: &str, b: u32) -> bool {
let html_c_str = CString::new(html).unwrap();
let html_c_char: *const c_char = html_c_str.as_ptr() as *const c_char;
return webui_copy_show(win, html_c_char, b);
return webui_show_cpy(win, html_c_char, b);
}
}
pub fn Bind(win: *mut webui_window_t, element: &str, func: fn(e: webui_event_t)) -> u32 {
fn events_handler (element_id: ::std::os::raw::c_uint, window_id: ::std::os::raw::c_uint, element_name: *mut ::std::os::raw::c_char, window: *mut webui_window_t) {
let ElementId: u32 = element_id;
let WindowId: u32 = window_id;
let ElementName: String = char_to_string(element_name);
let Window: *mut webui_window_t = window;
let E = Event {
ElementId: ElementId,
WindowId: WindowId,
ElementName: ElementName,
Window: Window,
};
println!("You clicked on this element:");
println!("element_id = {}", E.ElementId);
println!("window_id = {}", E.WindowId);
println!("element_name = {}", E.ElementName);
println!("The Rust wrapper still under development... ");
// TODO: Call user cb
// (func_list[WindowId][ElementId]).expect("non-null function pointer")(E);
}
pub fn Bind(win: *mut webui_window_t, element: &str, func: fn(e: Event)) {
// Element String to i8/u8
let element_c_str = CString::new(element).unwrap();
let element_c_char: *const c_char = element_c_str.as_ptr() as *const c_char;
// Func to Option
let f: Option<unsafe fn(e: webui_event_t)> = Some(func);
// Bind
unsafe {
let f: Option<unsafe fn(element_id: ::std::os::raw::c_uint, window_id: ::std::os::raw::c_uint, element_name: *mut ::std::os::raw::c_char, window: *mut webui_window_t)> = Some(events_handler);
webui_bind(win, element_c_char, f);
let window_id: ::std::os::raw::c_uint = _webui_window_get_number(win);
let cb_index: ::std::os::raw::c_uint = webui_bind_interface(win, element_c_char, f);
// TODO: Add user cb to the list
// let uf: Option<fn(e: Event)> = Some(func);
// func_list[window_id][cb_index] = uf;
}
return 0;
}

View File

@ -11,13 +11,20 @@
mod Webui;
fn close_the_application (_e: Webui::webui_event_t) {
fn close_the_application (e: Webui::Event) {
// The Rust wrapper still under development...
/*
Webui::Exit();
*/
}
fn check_the_password (e: Webui::webui_event_t) {
fn check_the_password (e: Webui::Event) {
// The Rust wrapper still under development...
/*
// Script to get the text value
let mut js = Webui::JavaScript {
@ -29,7 +36,7 @@ fn check_the_password (e: Webui::webui_event_t) {
};
// Run the script
Webui::RunJavaScript(e.window, &mut js);
Webui::RunJavaScript(e.Window, &mut js);
// Check if any error
if !js.error {
@ -42,6 +49,7 @@ fn check_the_password (e: Webui::webui_event_t) {
// There is an error in our script
println!("JavaScript Error: {}", js.data);
}
*/
}
fn main() {
@ -69,7 +77,7 @@ fn main() {
Webui::Show(my_window, my_html, Webui::Chrome);
// Wait until all windows get closed
Webui::Loop();
Webui::Wait();
println!("Bye.");
}

View File

@ -25,14 +25,14 @@ int main(int argc, char* argv[]) {
my_window = webui_new_window();
// Stop when the browser process get closed.
webui_detect_process_close(my_window, true);
webui_wait_process(my_window, true);
// Show the window
if(!webui_open(my_window, url, webui.browser.chrome)) // Run the window on Chrome
webui_open(my_window, url, webui.browser.any); // If not, run on any other installed web browser
// Wait until all windows get closed
webui_loop();
webui_wait();
return 0;
}

View File

@ -0,0 +1,68 @@
/*
WebUI Library 2.x
TypeScript Dynamic Lib Example
http://webui.me
https://github.com/alifcommunity/webui
Licensed under GNU General Public License v3.0.
Copyright (C)2022 Hassan DRAGA <https://github.com/hassandraga>.
*/
import * as webui from "./webui.ts";
// Optional: Set the library path
webui.set_lib_path('../../../../build/Windows/MSVC/webui-2-x64.dll');
function check_password() {
console.log("You clicked on the check password button...");
// ...
}
const my_html = `
<!DOCTYPE html>
<html>
<head>
<title>WebUI 2 - Deno Dynamic Lib Example</title>
<style>
body {
color: white;
background: #0F2027;
background: -webkit-linear-gradient(to right, #101314, #0f1c20, #061f2a);
background: linear-gradient(to right, #101314, #0f1c20, #061f2a);
text-align: center;
font-size: 18px;
font-family: sans-serif;
}
</style>
</head>
<body>
<h1>WebUI 2 - Deno Dynamic Lib Example</h1>
<br>
<input type="password" id="MyInput" OnKeyUp="document.getElementById('err').innerHTML='&nbsp;';" autocomplete="off">
<br>
<h3 id="err" style="color: #dbdd52">&nbsp;</h3>
<br>
<button id="CheckPassword">Check Password</button> - <button id="Exit">Exit</button>
</body>
</html>
`;
// Create new window
const my_window = webui.new_window();
// Bind
webui.bind(my_window, "Exit", function(){
console.log("You clicked on the exit button...");
webui.exit();
});
webui.bind(my_window, "CheckPassword", check_password);
// Show the window
if(!webui.show(my_window, my_html, webui.browser.chrome))
webui.show(my_window, my_html, webui.browser.any);
// Wait until all windows get closed
await webui.wait();
console.log("Bye");

View File

@ -0,0 +1,163 @@
// WebUI Library 2.0.3
//
// http://webui.me
// https://github.com/alifcommunity/webui
//
// Licensed under GNU General Public License v3.0.
// Copyright (C)2022 Hassan DRAGA <https://github.com/hassandraga>.
import { existsSync } from "https://deno.land/std/fs/mod.ts";
const version = '2.0.3';
const encoder = new TextEncoder();
const decoder = new TextDecoder();
let lib_loaded = false;
var webui_lib;
export const browser = {};
browser.any = 0;
browser.chrome = 1;
browser.firefox = 2;
browser.edge = 3;
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
var fun_list:number[][]
interface event {
element_id: number;
window_id: number;
element_name_ptr: string;
win: Deno.Pointer;
}
// Determine the library name based
// on the current OS
var lib_name;
if (Deno.build.os === 'windows')
lib_name = 'webui-2-x64x.dll';
if (Deno.build.os === 'linux')
lib_name = 'webui-2-x64x.so';
else
lib_name = 'webui-2-x64x.dyn';
// Full path to the library name
var lib_path = './' + lib_name;
// Check if a file exist
function is_file_exist(path): boolean {
return existsSync(path);
}
// Convert String to C-String
function string_to_uint8array(value: string) {
return encoder.encode(value + '\0');
}
// Convert C-String to String
function uint8array_to_string(value: ArrayBuffer) {
return decoder.decode(value);
}
// Load the library
function load_lib() {
if(lib_loaded)
return;
// Check if the library file exist
if(!is_file_exist(lib_path)) {
console.log('WebUI Error: File not found (' + lib_path + ')');
Deno.exit(1);
}
// Load the library
// FFI
webui_lib = Deno.dlopen(
lib_path,
{
webui_wait: {
parameters: [],
result: 'void',
nonblocking: false,
},
webui_new_window: {
parameters: [],
result: 'pointer',
nonblocking: false,
},
webui_show: {
parameters: ['pointer', 'buffer', 'u32'],
result: 'i32',
nonblocking: false,
},
webui_bind_interface: {
parameters: ['pointer', 'buffer', 'function'],
result: 'u32',
nonblocking: false,
},
webui_is_app_running: {
parameters: [],
result: 'i32',
nonblocking: false,
},
webui_exit: {
parameters: [],
result: 'void',
nonblocking: false,
},
} as const,
);
// Make sure we don't load twice
lib_loaded = true;
}
export function set_lib_path(path) {
lib_path = path;
}
export function new_window() : number {
load_lib();
return webui_lib.symbols.webui_new_window();
}
export function show(win, html, browser) : number {
load_lib();
return webui_lib.symbols.webui_show(win, string_to_uint8array(html), browser);
}
export function exit() {
load_lib();
webui_lib.symbols.webui_exit();
}
export async function wait() {
load_lib();
while(true) {
await sleep(100);
if(!webui_lib.symbols.webui_is_app_running())
break;
}
}
export function bind(win, element, func) : number {
load_lib();
const callbackResource = new Deno.UnsafeCallback(
{
parameters: ['u32', 'u32', 'pointer', 'pointer'],
result: 'void',
} as const,
(
element_id: Deno.u32,
window_id: Deno.u32,
element_name_ptr: Deno.PointerValue,
win: Deno.Pointer,
) => {
const element_name = new Deno.UnsafePointerView(BigInt(element_name_ptr)).getCString();
const e: event = {
element_id: element_id,
window_id: window_id,
element_name: element_name,
win: win,
};
func(e);
},
);
webui_lib.symbols.webui_bind_interface(win, string_to_uint8array(element), callbackResource.pointer);
return 0;
}

View File

@ -20,20 +20,20 @@ int main() {
// Chose your preferable runtime for .js files
// Deno: webui.runtime.deno
// Node.js: webui.runtime.nodejs
webui_runtime(my_window, webui.runtime.deno);
webui_script_runtime(my_window, webui.runtime.deno);
// Create a new web server using WebUI
const char* url = webui_new_server(my_window, "", NULL);
// Stop when the browser process get closed.
webui_detect_process_close(my_window, true);
webui_wait_process(my_window, true);
// Show the window
if(!webui_open(my_window, url, webui.browser.chrome)) // Run the window on Chrome
webui_open(my_window, url, webui.browser.any); // If not, run on any other installed web browser
// Wait until all windows get closed
webui_loop();
webui_wait();
return 0;
}

View File

@ -25,14 +25,14 @@ int main(int argc, char* argv[]) {
my_window = webui_new_window();
// Stop when the browser process get closed.
webui_detect_process_close(my_window, true);
webui_wait_process(my_window, true);
// Show the window
if(!webui_open(my_window, url, webui.browser.chrome)) // Run the window on Chrome
webui_open(my_window, url, webui.browser.any); // If not, run on any other installed web browser
// Wait until all windows get closed
webui_loop();
webui_wait();
return 0;
}

View File

@ -20,20 +20,20 @@ int main() {
// Chose your preferable runtime for .js files
// Deno: webui.runtime.deno
// Node.js: webui.runtime.nodejs
webui_runtime(my_window, webui.runtime.nodejs);
webui_script_runtime(my_window, webui.runtime.nodejs);
// Create a new web server using WebUI
const char* url = webui_new_server(my_window, "", NULL);
// Stop when the browser process get closed.
webui_detect_process_close(my_window, true);
webui_wait_process(my_window, true);
// Show the window
if(!webui_open(my_window, url, webui.browser.chrome)) // Run the window on Chrome
webui_open(my_window, url, webui.browser.any); // If not, run on any other installed web browser
// Wait until all windows get closed
webui_loop();
webui_wait();
return 0;
}

View File

@ -1,5 +1,5 @@
/*
WebUI Library 2.0.2
WebUI Library 2.0.3
http://webui.me
https://github.com/alifcommunity/webui
@ -75,27 +75,14 @@
#define WEBUI_PCLOSE pclose
#define WEBUI_MAX_PATH PATH_MAX
#endif
// -- macOS ---------------------------
// ...
struct webui_window_t;
// -- Structs -------------------------
struct webui_event_t;
typedef struct webui_timer_t {
struct timespec start;
struct timespec now;
} webui_timer_t;
typedef struct webui_event_t {
unsigned int window_id;
unsigned int element_id;
char* element_name;
struct webui_window_t* window;
} webui_event_t;
typedef struct webui_window_core_t {
unsigned int window_number;
bool server_running;
bool connected;
@ -105,7 +92,7 @@ typedef struct webui_window_core_t {
unsigned int server_port;
bool is_bind_all;
char* url;
void (*cb_all[1]) (webui_event_t* e);
void (*cb_all[1]) (struct webui_event_t* e);
const char* html;
const char* html_cpy;
const char* icon;
@ -122,49 +109,41 @@ typedef struct webui_window_core_t {
pthread_t server_thread;
#endif
} webui_window_core_t;
typedef struct webui_window_t {
webui_window_core_t core;
char* path;
} webui_window_t;
typedef struct webui_event_t {
unsigned int window_id;
unsigned int element_id;
char* element_name;
webui_window_t* window;
} webui_event_t;
typedef struct webui_javascript_result_t {
bool error;
unsigned int length;
const char* data;
} webui_javascript_result_t;
typedef struct webui_javascript_t {
typedef struct webui_script_t {
const char* script;
unsigned int timeout;
webui_javascript_result_t result;
} webui_javascript_t;
} webui_script_t;
typedef struct webui_cb_t {
webui_window_t* win;
char* element_id;
char* element_name;
} webui_cb_t;
typedef struct webui_cmd_async_t {
webui_window_t* win;
char* cmd;
} webui_cmd_async_t;
typedef struct webui_custom_browser_t {
char* app;
char* arg;
bool auto_link;
} webui_custom_browser_t;
typedef struct webui_browser_t {
unsigned int any; // 0
unsigned int chrome; // 1
unsigned int firefox; // 2
@ -173,16 +152,12 @@ typedef struct webui_browser_t {
unsigned int chromium; // 5
unsigned int custom; // 99
} webui_browser_t;
typedef struct webui_runtime_t {
unsigned int none; // 0
unsigned int deno; // 1
unsigned int nodejs; // 2
} webui_runtime_t;
typedef struct webui_t {
unsigned int servers;
unsigned int connections;
webui_custom_browser_t *custom_browser;
@ -204,7 +179,7 @@ typedef struct webui_t {
webui_runtime_t runtime;
bool initialized;
void (*cb[WEBUI_MAX_ARRAY]) (webui_event_t* e);
void (*cb_int[WEBUI_MAX_ARRAY])(unsigned int, unsigned int, char*);
void (*cb_int[WEBUI_MAX_ARRAY])(unsigned int, unsigned int, char*, webui_window_t*);
char* executable_path;
void *ptr_list[WEBUI_MAX_ARRAY];
unsigned int ptr_position;
@ -212,42 +187,41 @@ typedef struct webui_t {
} webui_t;
// -- Definitions ---------------------
EXPORT webui_t webui;
EXPORT void webui_loop();
EXPORT void webui_wait();
EXPORT void webui_exit();
EXPORT bool webui_any_window_is_open();
EXPORT bool webui_is_any_window_running();
EXPORT bool webui_is_app_running();
EXPORT void webui_set_timeout(unsigned int second);
EXPORT webui_window_t* webui_new_window();
EXPORT bool webui_show(webui_window_t* win, const char* html, unsigned int browser);
EXPORT bool webui_copy_show(webui_window_t* win, const char* html, unsigned int browser);
EXPORT bool webui_show_cpy(webui_window_t* win, const char* html, unsigned int browser);
EXPORT void webui_set_icon(webui_window_t* win, const char* icon_s, const char* type_s);
EXPORT void webui_allow_multi_access(webui_window_t* win, bool status);
EXPORT bool webui_set_root_folder(webui_window_t* win, const char* path);
EXPORT const char* webui_new_server(webui_window_t* win, const char* path, const char* index_html);
EXPORT void webui_close(webui_window_t* win);
EXPORT bool webui_is_show(webui_window_t* win);
EXPORT void webui_run_js(webui_window_t* win, webui_javascript_t* javascript);
EXPORT void webui_script(webui_window_t* win, webui_script_t* script);
EXPORT unsigned int webui_bind(webui_window_t* win, const char* element, void (*func) (webui_event_t* e));
EXPORT void webui_bind_all(webui_window_t* win, void (*func) (webui_event_t* e));
EXPORT bool webui_open(webui_window_t* win, const char* url, unsigned int browser);
EXPORT void webui_free_js(webui_javascript_t* javascript);
EXPORT void webui_runtime(webui_window_t* win, unsigned int runtime);
EXPORT void webui_detect_process_close(webui_window_t* win, bool status);
EXPORT void webui_free_script(webui_script_t* script);
EXPORT void webui_script_runtime(webui_window_t* win, unsigned int runtime);
EXPORT void webui_wait_process(webui_window_t* win, bool status);
// -- Interface -----------------------
// To help other languages to use WebUI
typedef struct webui_javascript_int_t {
// Used by other languages to create WebUI wrappers
typedef struct webui_script_interface_t {
char* script;
unsigned int timeout;
bool error;
unsigned int length;
const char* data;
} webui_javascript_int_t;
EXPORT unsigned int webui_bind_int(webui_window_t* win, const char* element, void (*func)(unsigned int, unsigned int, char*));
EXPORT void webui_run_js_int(webui_window_t* win, const char* script, unsigned int timeout, bool* error, unsigned int* length, char* data);
EXPORT void webui_run_js_int_struct(webui_window_t* win, webui_javascript_int_t* js_int);
} webui_script_interface_t;
EXPORT unsigned int webui_bind_interface(webui_window_t* win, const char* element, void (*func)(unsigned int, unsigned int, char*, webui_window_t*));
EXPORT void webui_script_interface(webui_window_t* win, const char* script, unsigned int timeout, bool* error, unsigned int* length, char* data);
EXPORT void webui_script_interface_struct(webui_window_t* win, webui_script_interface_t* js_int);
// Core
EXPORT void _webui_ini();

View File

@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "webui2"
version = "2.0.2"
version = "2.0.3"
authors = [
{ name="Hassan Draga" },
]

View File

@ -1,4 +1,4 @@
# WebUI Library 2.0.2
# WebUI Library 2.0.3
#
# http://webui.me
# https://github.com/alifcommunity/webui
@ -21,9 +21,10 @@ class event:
element_id = 0
window_id = 0
element_name = ""
window = None
# WebUI C-Struct
class webui_javascript_int_t(ctypes.Structure):
class webui_script_interface_t(ctypes.Structure):
_fields_ = [
("script", c_char_p),
("timeout", c_uint),
@ -62,7 +63,7 @@ class window:
webui_wrapper.restype = c_void_p
self.window = c_void_p(webui_wrapper())
# Initializing events() to be called from WebUI Library
py_fun = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_uint, ctypes.c_uint, ctypes.c_char_p)
py_fun = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_uint, ctypes.c_uint, ctypes.c_char_p, ctypes.c_void_p)
self.c_events = py_fun(self.events)
except OSError as e:
print("WebUI Exception: %s" % e)
@ -73,7 +74,7 @@ class window:
if self.window is not None and WebUI is not None:
WebUI.webui_close(self.window)
def events(self, element_id, window_id, element_name):
def events(self, element_id, window_id, element_name, window):
if self.cb_fun_list[int(element_id)] is None:
print('WebUI Error: Callback is None.')
return
@ -81,6 +82,7 @@ class window:
e.element_id = element_id
e.window_id = window_id
e.element_name = element_name
e.window = window
self.cb_fun_list[element_id](e)
def bind(self, element, func):
@ -91,7 +93,7 @@ class window:
if WebUI is None:
err_library_not_found('bind')
return
cb_index = int(WebUI.webui_bind_int(self.window, element.encode('utf-8'), self.c_events))
cb_index = int(WebUI.webui_bind_interface(self.window, element.encode('utf-8'), self.c_events))
self.cb_fun_list.insert(cb_index, func)
def show(self, html):
@ -120,7 +122,7 @@ class window:
err_library_not_found('show')
return
# Create Struct
js = webui_javascript_int_t()
js = webui_script_interface_t()
# Initializing
js.script = ctypes.c_char_p(script.encode('utf-8'))
js.timeout = ctypes.c_uint(timeout)
@ -135,7 +137,7 @@ class window:
res.length = 7
res.data = "UNKNOWN"
# Run JavaScript
WebUI.webui_run_js_int_struct(self.window, ctypes.byref(js))
WebUI.webui_script_interface_struct(self.window, ctypes.byref(js))
res.length = int(js.length)
res.data = js.data.decode('utf-8')
res.error = js.error
@ -208,12 +210,12 @@ def exit():
WebUI.webui_exit()
# Wait until all windows get closed
def loop():
def wait():
global WebUI
if WebUI is None:
err_library_not_found('loop')
err_library_not_found('wait')
return
WebUI.webui_loop()
WebUI.webui_wait()
try:
shutil.rmtree(os.getcwd() + '/__intcache__/')
except OSError:

View File

@ -1,5 +1,5 @@
/*
WebUI Library 2.0.2
WebUI Library 2.0.3
http://webui.me
https://github.com/alifcommunity/webui
@ -24,7 +24,7 @@ webui_t webui;
// This is a uncompressed version to make the debugging
// more easy in the browser using the builtin dev-tools
static const char* webui_javascript_bridge =
"const _webui_log = false; \n"
"var _webui_log = false; \n"
"var _webui_ws; \n"
"var _webui_ws_status = false; \n"
"var _webui_action8 = new Uint8Array(1); \n"
@ -75,7 +75,7 @@ static const char* webui_javascript_bridge =
" buffer8[1] + \" 0x\" + buffer8[2]); \n"
" var len = buffer8.length - 3; \n"
" if(buffer8[buffer8.length - 1] === 0) \n"
" len--; // Null terminated byte can break eval() \n"
" len--; // Null byte (0x00) can break eval() \n"
" data8 = new Uint8Array(len); \n"
" for (i = 0; i < len; i++) data8[i] = buffer8[i + 3]; \n"
" var data8utf8 = new TextDecoder(\"utf-8\").decode(data8); \n"
@ -1711,7 +1711,7 @@ void _webui_browser_clean() {
int _webui_system_win32(char* cmd, bool show) {
#ifdef WEBUI_LOG
printf("[0] _webui_system_win32([%s], [%d])... \n", cmd, show);
printf("[0] _webui_system_win32()... \n");
#endif
DWORD Return = 0;
@ -1757,7 +1757,7 @@ void _webui_browser_clean() {
int _webui_cmd_sync(char* cmd, bool show) {
#ifdef WEBUI_LOG
printf("[0] _webui_cmd_sync([%s], [%d])... \n", cmd, show);
printf("[0] _webui_cmd_sync()... \n");
#endif
// Run sync command and
@ -1767,9 +1767,15 @@ int _webui_cmd_sync(char* cmd, bool show) {
#ifdef _WIN32
sprintf(buf, "cmd /c \"%s\" > nul 2>&1 ", cmd);
#ifdef WEBUI_LOG
printf("[0] _webui_cmd_sync() -> Running [%s] \n", buf);
#endif
return _webui_system_win32(buf, show);
#else
sprintf(buf, "%s >>/dev/null 2>>/dev/null ", cmd);
#ifdef WEBUI_LOG
printf("[0] _webui_cmd_sync() -> Running [%s] \n", buf);
#endif
int r = system(buf);
r = (r != -1 && r != 127 && WIFEXITED(r)) ? WEXITSTATUS(r) : -1;
return r;
@ -1779,7 +1785,7 @@ int _webui_cmd_sync(char* cmd, bool show) {
int _webui_cmd_async(char* cmd, bool show) {
#ifdef WEBUI_LOG
printf("[0] _webui_cmd_async([%s])... \n", cmd);
printf("[0] _webui_cmd_async()... \n");
#endif
// Run a async command
@ -1831,7 +1837,7 @@ int _webui_cmd_async(char* cmd, bool show) {
int _webui_run_browser(webui_window_t* win, char* cmd) {
#ifdef WEBUI_LOG
printf("[%d] _webui_run_browser([%s])... \n", win->core.window_number, cmd);
printf("[%d] _webui_run_browser()... \n", win->core.window_number);
#endif
int res = 0;
@ -2073,35 +2079,35 @@ void _webui_window_open(webui_window_t* win, char* link, unsigned int browser) {
_webui_browser_start(win, link, browser);
}
void webui_free_js(webui_javascript_t* javascript) {
void webui_free_script(webui_script_t* script) {
_webui_free_mem((void *) &javascript->result.data);
_webui_free_mem((void *) &javascript->script);
memset(javascript, 0x00, sizeof(webui_javascript_t));
_webui_free_mem((void *) &script->result.data);
_webui_free_mem((void *) &script->script);
memset(script, 0x00, sizeof(webui_script_t));
}
void webui_run_js(webui_window_t* win, webui_javascript_t* javascript) {
void webui_script(webui_window_t* win, webui_script_t* script) {
#ifdef WEBUI_LOG
printf("[%d] webui_run_js([%s])... \n", win->core.window_number, javascript->script);
printf("[%d] webui_script([%s])... \n", win->core.window_number, script->script);
#endif
size_t js_len = strlen(javascript->script);
size_t js_len = strlen(script->script);
if(js_len < 1) {
_webui_free_mem((void *) &javascript->result.data);
javascript->result.data = webui_js_empty;
javascript->result.length = (unsigned int) strlen(webui_js_empty);
javascript->result.error = true;
_webui_free_mem((void *) &script->result.data);
script->result.data = webui_js_empty;
script->result.length = (unsigned int) strlen(webui_js_empty);
script->result.error = true;
return;
}
// Initializing js result
_webui_free_mem((void *) &javascript->result.data);
javascript->result.data = webui_js_timeout;
javascript->result.length = (unsigned int) strlen(webui_js_timeout);
javascript->result.error = true;
_webui_free_mem((void *) &script->result.data);
script->result.data = webui_js_timeout;
script->result.length = (unsigned int) strlen(webui_js_timeout);
script->result.error = true;
// Initializing pipe
unsigned int run_id = _webui_get_run_id();
@ -2116,14 +2122,14 @@ void webui_run_js(webui_window_t* win, webui_javascript_t* javascript) {
packet[1] = WEBUI_HEADER_JS; // Type
packet[2] = run_id; // ID
for(unsigned int i = 0; i < js_len; i++) // Data
packet[i + 3] = javascript->script[i];
packet[i + 3] = script->script[i];
// Send packets
_webui_window_send(win, packet, packet_len);
_webui_free_mem((void *) &packet);
// Wait for UI response
if(javascript->timeout < 1 || javascript->timeout > 86400) {
if(script->timeout < 1 || script->timeout > 86400) {
for(;;) {
@ -2135,7 +2141,7 @@ void webui_run_js(webui_window_t* win, webui_javascript_t* javascript) {
}
else {
for(unsigned int n = 0; n <= (javascript->timeout * 1000); n++) {
for(unsigned int n = 0; n <= (script->timeout * 1000); n++) {
if(webui.run_done[run_id])
break;
@ -2146,9 +2152,9 @@ void webui_run_js(webui_window_t* win, webui_javascript_t* javascript) {
if(webui.run_responses[run_id] != NULL) {
javascript->result.data = webui.run_responses[run_id];
javascript->result.length = (unsigned int) strlen(webui.run_responses[run_id]);
javascript->result.error = webui.run_error[run_id];
script->result.data = webui.run_responses[run_id];
script->result.length = (unsigned int) strlen(webui.run_responses[run_id]);
script->result.error = webui.run_error[run_id];
}
}
@ -2205,10 +2211,10 @@ bool webui_is_show(webui_window_t* win) {
return win->core.connected;
}
bool webui_any_window_is_open() {
bool webui_is_any_window_running() {
#ifdef WEBUI_LOG
printf("[0] webui_any_window_is_open()... \n");
printf("[0] webui_is_any_window_running()... \n");
#endif
if(webui.connections > 0)
@ -2296,7 +2302,7 @@ void webui_set_icon(webui_window_t* win, const char* icon_s, const char* type_s)
bool webui_show(webui_window_t* win, const char* html, unsigned int browser) {
#ifdef WEBUI_LOG
printf("[%d] webui_show([%.*s..], [%d])... \n", win->core.window_number, 3, html, browser);
printf("[%d] webui_show([%.*s...], [%d])... \n", win->core.window_number, 4, html, browser);
#endif
// Initializing
@ -2356,7 +2362,7 @@ bool webui_show(webui_window_t* win, const char* html, unsigned int browser) {
return true;
}
bool webui_copy_show(webui_window_t* win, const char* html, unsigned int browser) {
bool webui_show_cpy(webui_window_t* win, const char* html, unsigned int browser) {
// Copy HTML, And show the window
@ -2605,7 +2611,7 @@ void _webui_window_receive(webui_window_t* win, const char* packet, size_t len)
// Fatal.
// The pipe ID is not valid
// we can't send the ready signal to webui_run_js()
// we can't send the ready signal to webui_script()
return;
}
@ -2636,7 +2642,7 @@ void _webui_window_receive(webui_window_t* win, const char* packet, size_t len)
webui.run_responses[run_id] = webui_empty_string;
}
// Send ready signal to webui_run_js()
// Send ready signal to webui_script()
webui.run_done[run_id] = true;
}
}
@ -2649,14 +2655,14 @@ bool webui_open(webui_window_t* win, const char* url, unsigned int browser) {
// Just open an app-mode window using the link
webui_set_timeout(0);
webui_detect_process_close(win, true);
webui_wait_process(win, true);
return _webui_browser_start(win, url, browser);
}
void webui_detect_process_close(webui_window_t* win, bool status) {
void webui_wait_process(webui_window_t* win, bool status) {
#ifdef WEBUI_LOG
printf("[%d] webui_detect_process_close()... \n", win->core.window_number);
printf("[%d] webui_wait_process()... \n", win->core.window_number);
#endif
win->core.detect_process_close = status;
@ -2695,16 +2701,37 @@ void webui_exit() {
webui.exit_now = true;
}
void webui_loop() {
bool webui_is_app_running() {
#ifdef WEBUI_LOG
printf("[L] webui_loop()... \n");
printf("[0] webui_app_exit()... \n");
#endif
if(webui.use_timeout) {
if(webui.wait_for_socket_window) {
if(webui.servers > 0)
return true;
return false;
}
}
else {
if(!webui.exit_now)
return true;
return false;
}
return false;
}
void webui_wait() {
#ifdef WEBUI_LOG
printf("[L] webui_wait()... \n");
#endif
if(webui.use_timeout) {
#ifdef WEBUI_LOG
printf("[L] webui_loop() -> Using timeout %d second\n", webui.startup_timeout);
printf("[L] webui_wait() -> Using timeout %d second\n", webui.startup_timeout);
#endif
// TODO: Loop trough all win
@ -2717,7 +2744,7 @@ void webui_loop() {
if(webui.wait_for_socket_window) {
#ifdef WEBUI_LOG
printf("[L] webui_loop() -> Wait for connected socket window...\n");
printf("[L] webui_wait() -> Wait for connected socket window...\n");
#endif
while(webui.servers > 0) {
@ -2729,14 +2756,14 @@ void webui_loop() {
else {
#ifdef WEBUI_LOG
printf("[L] webui_loop() -> Ignore connected socket window.\n");
printf("[L] webui_wait() -> Ignore connected socket window.\n");
#endif
}
}
else {
#ifdef WEBUI_LOG
printf("[L] webui_loop() -> Infinite loop...\n");
printf("[L] webui_wait() -> Infinite loop...\n");
#endif
// Infinite wait
@ -2745,7 +2772,7 @@ void webui_loop() {
}
#ifdef WEBUI_LOG
printf("[L] webui_loop() -> Loop finished.\n");
printf("[L] webui_wait() -> Loop finished.\n");
#endif
_webui_browser_clean();
@ -2855,7 +2882,7 @@ unsigned int _webui_get_free_port() {
return port;
}
void webui_runtime(webui_window_t* win, unsigned int runtime) {
void webui_script_runtime(webui_window_t* win, unsigned int runtime) {
if(runtime != webui.runtime.deno && runtime != webui.runtime.nodejs)
win->core.runtime = webui.runtime.none;
@ -2935,10 +2962,10 @@ void webui_bind_int_handler(webui_event_t* e) {
unsigned int cb_index = e->element_id;
if(cb_index > 0 && webui.cb_int[cb_index] != NULL)
webui.cb_int[cb_index](e->element_id, e->window_id, e->element_name);
webui.cb_int[cb_index](e->element_id, e->window_id, e->element_name, e->window);
}
unsigned int webui_bind_int(webui_window_t* win, const char* element, void (*func)(unsigned int, unsigned int, char*)) {
unsigned int webui_bind_interface(webui_window_t* win, const char* element, void (*func)(unsigned int, unsigned int, char*, webui_window_t*)) {
unsigned int cb_index = webui_bind(win, element, webui_bind_int_handler);
webui.cb_int[cb_index] = func;
@ -2946,36 +2973,36 @@ unsigned int webui_bind_int(webui_window_t* win, const char* element, void (*fun
return cb_index;
}
void webui_run_js_int(webui_window_t* win, const char* script, unsigned int timeout, bool* error, unsigned int* length, char* data) {
void webui_script_interface(webui_window_t* win, const char* script, unsigned int timeout, bool* error, unsigned int* length, char* data) {
#ifdef WEBUI_LOG
printf("[%d] webui_run_js_int()... \n", win->core.window_number);
printf("[%d] webui_script_interface()... \n", win->core.window_number);
#endif
webui_javascript_t js = {
webui_script_t js = {
.script = script,
.timeout = timeout
};
webui_run_js(win, &js);
webui_script(win, &js);
data = (char*) js.result.data;
*error = js.result.error;
*length = js.result.length;
}
void webui_run_js_int_struct(webui_window_t* win, webui_javascript_int_t* js_int) {
void webui_script_interface_struct(webui_window_t* win, webui_script_interface_t* js_int) {
#ifdef WEBUI_LOG
printf("[%d] webui_run_js_int_struct()... \n", win->core.window_number);
printf("[%d] webui_script_interface_struct()... \n", win->core.window_number);
#endif
webui_javascript_t js = {
webui_script_t js = {
.script = js_int->script,
.timeout = js_int->timeout
};
webui_run_js(win, &js);
webui_script(win, &js);
js_int->data = js.result.data;
js_int->error = js.result.error;

View File

@ -61,7 +61,7 @@ webui_show(my_window, my_html, webui.browser.any);
### Loop
It's very important to call `webui_loop()` at the end of your main function after you created/shows all your windows.
It's very important to call `webui_wait()` at the end of your main function after you created/shows all your windows.
```c
int main() {
@ -71,7 +71,7 @@ int main() {
// Show the windows...
// Wait until all windows get closed
webui_loop();
webui_wait();
return 0;
}

View File

@ -148,8 +148,8 @@
</div>
<div class="flex-none mt-auto bg-white rounded-b rounded-t-none overflow-hidden shadow p-6">
<div class="flex items-center justify-center">
<a href="#" target="_blank" class="mx-auto lg:mx-0 hover:underline gradient-button text-white font-bold my-6 py-2 px-4 shadow-lg no-underline">
Download Windows WebUI v2.0.2
<a href="https://github.com/alifcommunity/webui/releases/download/2.0.3/webui_2.0.3.zip" target="_blank" class="mx-auto lg:mx-0 hover:underline gradient-button text-white font-bold my-6 py-2 px-4 shadow-lg no-underline">
Download Windows WebUI v2.0.3
</a>
</div>
</div>
@ -169,8 +169,8 @@
</div>
<div class="flex-none mt-auto bg-white rounded-b rounded-t-none overflow-hidden shadow p-6">
<div class="flex items-center justify-center">
<a href="#" target="_blank" class="mx-auto lg:mx-0 hover:underline gradient-button text-white font-bold my-6 py-2 px-4 shadow-lg no-underline">
Download Linux WebUI v2.0.2
<a href="https://github.com/alifcommunity/webui/releases/download/2.0.3/webui_2.0.3.zip" target="_blank" class="mx-auto lg:mx-0 hover:underline gradient-button text-white font-bold my-6 py-2 px-4 shadow-lg no-underline">
Download Linux WebUI v2.0.3
</a>
</div>
</div>