Skip to content

Commit

Permalink
Merge pull request #131 from JOTSR/chore/include-js-xxd
Browse files Browse the repository at this point in the history
refactor: split js bridge source code from lib source code
  • Loading branch information
AlbertShown authored Jul 11, 2023
2 parents f71a63f + 45d922f commit 4c9b4fe
Show file tree
Hide file tree
Showing 8 changed files with 389 additions and 297 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
- name: Windows-WebUI
shell: cmd
run: |
cd src
xxd -i client\webui.js client\webui.h
cd ..
cd build\Windows\GCC
mingw32-make
cd ..\..\..
Expand All @@ -27,6 +30,9 @@ jobs:
- uses: actions/checkout@v2
- name: Linux-WebUI
run: |
cd src
xxd -i client/webui.js client/webui.h
cd ..
cd build/Linux/GCC
make
cd ../../..
Expand All @@ -41,5 +47,8 @@ jobs:
- uses: actions/checkout@v2
- name: macOS-WebUI
run: |
cd src
xxd -i client/webui.js client/webui.h
cd ..
cd build/macOS/Clang
make
9 changes: 9 additions & 0 deletions build/linux_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ echo "Compiler: GCC and Clang"
RootPath="$PWD/../"
cd "$RootPath"

echo "";
echo "Converting JS source to C-String using xxd"
echo "";

#Converting JS source to C-String using xxd
cd "$RootPath"
cd "src/client"
xxd -i ./webui.js ./webui.h

echo "";
echo "Building WebUI using GCC...";
echo "";
Expand Down
9 changes: 9 additions & 0 deletions build/macos_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ cd "$RootPath"
cd "build/macOS/Clang"
$CLANG_CMD

echo "";
echo "Converting JS source to C-String using xxd"
echo "";

#Converting JS source to C-String using xxd
cd "$RootPath"
cd "src/client"
xxd -i ./webui.js ./webui.h

echo "";
echo "Copying WebUI libs to the examples folder..."
echo "";
Expand Down
6 changes: 6 additions & 0 deletions build/windows_build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ echo Compiler: MSVC, GCC and TCC
Set RootPath=%CD%\..\
cd "%RootPath%"

REM Converting JS source to C-String using xxd
echo Converting JS source to C-String using xxd
cd "%RootPath%"
cd "src\client"
xxd -i .\webui.js .\webui.h

echo.
echo Building WebUI using MSVC...

Expand Down
3 changes: 3 additions & 0 deletions src/client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Do not track xxd output files
*.c
*.h
47 changes: 47 additions & 0 deletions src/client/webui.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export type B64string = string;

/**
* Call a backend function from the frontend.
* @param fn - Backend bind name.
* @param value - Payload to send.
* @return - Response of the backend callback.
* @example
* ```c
* //Backend (C)
* webui_bind(window, "get_cwd", get_current_working_directory);
* ```
* ```js
* //Frontend (JS)
* const cwd = await webui_fn("get_cwd");
* ```
* @example
* ```c
* //Backend (C)
* webui_bind(window, "write_file", write_file);
* ```
* ```js
* //Frontend (JS)
* webui_fn("write_file", "content to write")
* .then(() => console.log("file writed"))
* .catch(() => console.error("can't write the file"))
* ```
*/
export function webui_fn(fn: string, value?: string): Promise<string | undefined>;

/**
* Active or deactivate webui debug logging.
* @param status - log status to set.
*/
export function webui_log(status: boolean): void;

/**
* Encode a string into base64.
* @param str - string to encode.
*/
export function webui_encode(str: string): B64string;

/**
* Decode a base64 string.
* @param str - base64 string to decode.
*/
export function webui_decode(str: B64string): string;
Loading

0 comments on commit 4c9b4fe

Please sign in to comment.