wef: Fix doc and warnings. (#972)

![20250617-191859](https://github.com/user-attachments/assets/f677ecb4-dbff-4e0d-86b9-203f6e1004a4)
This commit is contained in:
Jason Lee 2025-06-17 20:10:34 +08:00 committed by GitHub
parent b70b229370
commit 8762e3482a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 31 deletions

View file

@ -14,6 +14,7 @@ UI components for building fantastic desktop applications using [GPUI](https://g
- **Content Rendering**: Native support for Markdown and simple HTML. - **Content Rendering**: Native support for Markdown and simple HTML.
- **Charting**: Built-in charts for visualization your data. - **Charting**: Built-in charts for visualization your data.
- **Code Highlighting**: Code Editor and Syntax highlighting. - **Code Highlighting**: Code Editor and Syntax highlighting.
- **Wef**: (Experimental) Offscreen rendering webview based on [CEF](https://github.com/chromiumembedded/cef).
## Showcase ## Showcase

View file

@ -12,5 +12,5 @@ cargo wef init
## Run example ## Run example
```bash ```bash
cargo run -p wef-example cargo wef run -p wef-example
``` ```

View file

@ -1,9 +1,3 @@
use embed_manifest::{embed_manifest, new_manifest};
fn main() { fn main() {
// if std::env::var_os("CARGO_CFG_WINDOWS").is_some() {
// embed_manifest(new_manifest("Wef.Example.GpuiExample"))
// .expect("unable to embed manifest file");
// }
println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=build.rs");
} }

View file

@ -1,5 +1,9 @@
# Wef is a Rust library for embedding WebView functionality using Chromium Embedded Framework (CEF3) with offscreen rendering support. # Wef is a Rust library for embedding WebView functionality using Chromium Embedded Framework (CEF3) with offscreen rendering support.
> The `Wef` name is abbreviation of "Web Embedding Framework", it also inspires by Wry.
![Wef Example](https://github.com/user-attachments/assets/f677ecb4-dbff-4e0d-86b9-203f6e1004a4)
## Contents ## Contents
- [Introduction](#introduction) - [Introduction](#introduction)
@ -8,11 +12,11 @@
- [Application Layout](#application-layout) - [Application Layout](#application-layout)
- [Windows](#windows) - [Windows](#windows)
- [Linux](#linux) - [Linux](#linux)
- [MacOS](#macos) - [macOS](#macos)
- [Application Structure](#application-structure) - [Application Structure](#application-structure)
- [Entry-Point Function](#entry-point-function) - [Entry-Point Function](#entry-point-function)
- [Single Executable](#single-executable) - [Single Executable](#single-executable)
- [Separate Sub-Process Executable](#separate-sub-process-executable) - [Separate Sub-Process Executable](#separate-sub-process-executable)
- [Examples](#examples) - [Examples](#examples)
- [JS Bridge](#js-bridge) - [JS Bridge](#js-bridge)
- [Call Rust functions from JavaScript](#call-rust-functions-from-javascript) - [Call Rust functions from JavaScript](#call-rust-functions-from-javascript)
@ -20,7 +24,7 @@
- [Cargo-wef](#cargo-wef) - [Cargo-wef](#cargo-wef)
- [Installation Cargo-wef](#installation-cargo-wef) - [Installation Cargo-wef](#installation-cargo-wef)
- [Build Wef application](#build-wef-application) - [Build Wef application](#build-wef-application)
- [MacOS Bundle Settings](#macos-bundle-settings) - [macOS Bundle Settings](#macos-bundle-settings)
- [Run Wef application](#run-wef-application) - [Run Wef application](#run-wef-application)
- [Add CEF3 Framework to the application](#add-cef3-framework-to-the-application) - [Add CEF3 Framework to the application](#add-cef3-framework-to-the-application)
@ -32,7 +36,7 @@
## Getting Started ## Getting Started
To use Wef, you need to download the CEF binary distribution. You can find the latest version of CEF on the [CEF Download page](https://cef-builds.spotifycdn.com/index.html). Make sure to download the appropriate version for your platform (Windows, macOS, or Linux). To use Wef, you need to download the CEF binary distribution. You can find the latest version of CEF on the [CEF Download page](https://cef-builds.spotifycdn.com/index.html). Make sure to download the appropriate version for your platform (Windows, macOS or Linux).
After downloading the CEF binary distribution, extract it to a directory of your choice. After downloading the CEF binary distribution, extract it to a directory of your choice.
@ -77,9 +81,9 @@ Application/
en-US.pak, ... <= locale-specific resources and strings en-US.pak, ... <= locale-specific resources and strings
``` ```
### MacOS ### macOS
The application (app bundle) layout on MacOS is mandated by the Chromium implementation and consequently is not very flexible. The application (app bundle) layout on macOS is mandated by the Chromium implementation and consequently is not very flexible.
```plain ```plain
cefclient.app/ cefclient.app/
@ -137,7 +141,7 @@ As described in the `Important Concepts` section a CEF3 application will run mul
#### Single Executable #### Single Executable
When running as a single executable the entry-point function is required to differentiate between the different process types. The single executable structure is supported on Windows and Linux but not on MacOS. When running as a single executable the entry-point function is required to differentiate between the different process types. The single executable structure is supported on Windows and Linux but not on macOS.
```rust, no_run ```rust, no_run
use wef::Settings; use wef::Settings;
@ -212,9 +216,9 @@ let browser = Browser::builder()
The Rust results are returned as promises in JavaScript. You can use the `Promise.then` method to handle the result, and the `Promise.catch` method to handle errors. The Rust results are returned as promises in JavaScript. You can use the `Promise.then` method to handle the result, and the `Promise.catch` method to handle errors.
```javascript ```javascript
jsBridge.addInt(1, 2).then(result => { jsBridge.addInt(1, 2).then((result) => {
console.log("Result of addInt:", result); console.log("Result of addInt:", result);
// Result of addInt: 3 // Result of addInt: 3
}); });
``` ```
@ -248,8 +252,8 @@ let Some(frame) = browser.main_frame() {
```javascript ```javascript
jsBridge.addEventListener((message) => { jsBridge.addEventListener((message) => {
console.log("Message from Rust:", message); console.log("Message from Rust:", message);
// Message from Rust: ok // Message from Rust: ok
}); });
``` ```
@ -272,7 +276,7 @@ cargo install cargo-wef
The `init` command used to init and download CEF into your system, default download path is `~/.cef`, you can change it by passing the path to the command. The `init` command used to init and download CEF into your system, default download path is `~/.cef`, you can change it by passing the path to the command.
```bash ```bash
cargo wef init [/path/to/cef] cargo wef init
``` ```
### Build Wef application ### Build Wef application
@ -283,11 +287,11 @@ Like cargo build, but it will also copy the CEF3 framework to the target directo
cargo wef build cargo wef build
``` ```
On MacOS, this command will also create an application bundle with the CEF3 framework inside. On macOS, this command will also create an application bundle with the CEF3 framework inside.
On Windows and Linux, it will copy the CEF3 framework to the target directory. On Windows and Linux, it will copy the CEF3 framework to the target directory.
```bash ````bash
If on MacOS, this command also create application bundle with the CEF3 framework inside. If on macOS, this command also create application bundle with the CEF3 framework inside.
### Run Wef application ### Run Wef application
@ -295,9 +299,9 @@ Like cargo run, but it will also copy the CEF3 framework to the target directory
```bash ```bash
cargo wef run cargo wef run
``` ````
#### MacOS Bundle Settings #### macOS Bundle Settings
You can specify the application bundle settings in your `Cargo.toml` file under the `package.metadata.bundle` section, otherwise it will use the default settings. You can specify the application bundle settings in your `Cargo.toml` file under the `package.metadata.bundle` section, otherwise it will use the default settings.
@ -324,7 +328,7 @@ identifier = "my.wef.app"
``` ```
| name | type | optional | description | | name | type | optional | description |
|------------------------|----------|----------|--------------------------------------------------------------------------------------------------------------------------| | ---------------------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------ |
| name | String | No | Bundle name | | name | String | No | Bundle name |
| identifier | String | No | Bundle identifier | | identifier | String | No | Bundle identifier |
| display_name | String | Yes | Display name, If is `None` then use `name` | | display_name | String | Yes | Display name, If is `None` then use `name` |
@ -340,13 +344,13 @@ identifier = "my.wef.app"
### Add CEF3 Framework to the application ### Add CEF3 Framework to the application
MacOS For macOS
```bash ```bash
cargo wef add-framework /path/to/your/app.bundle cargo wef add-framework /path/to/your/app.bundle
``` ```
Windows/Linux For Windows or Linux
```bash ```bash
cargo wef add-framework /path/to/app cargo wef add-framework /path/to/app