From 8762e3482a9e6d9d3cc1fef546e06d27c24f8cb3 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 17 Jun 2025 20:10:34 +0800 Subject: [PATCH] wef: Fix doc and warnings. (#972) ![20250617-191859](https://github.com/user-attachments/assets/f677ecb4-dbff-4e0d-86b9-203f6e1004a4) --- README.md | 1 + crates/webview/README.md | 4 +- crates/webview/examples/wef-example/build.rs | 6 --- crates/wef/README.md | 50 +++++++++++--------- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 70779658..e96f2443 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ UI components for building fantastic desktop applications using [GPUI](https://g - **Content Rendering**: Native support for Markdown and simple HTML. - **Charting**: Built-in charts for visualization your data. - **Code Highlighting**: Code Editor and Syntax highlighting. +- **Wef**: (Experimental) Offscreen rendering webview based on [CEF](https://github.com/chromiumembedded/cef). ## Showcase diff --git a/crates/webview/README.md b/crates/webview/README.md index 849c9021..8fda0a0c 100644 --- a/crates/webview/README.md +++ b/crates/webview/README.md @@ -12,5 +12,5 @@ cargo wef init ## Run example ```bash -cargo run -p wef-example -``` \ No newline at end of file +cargo wef run -p wef-example +``` diff --git a/crates/webview/examples/wef-example/build.rs b/crates/webview/examples/wef-example/build.rs index f3a8266d..c2bce4fe 100644 --- a/crates/webview/examples/wef-example/build.rs +++ b/crates/webview/examples/wef-example/build.rs @@ -1,9 +1,3 @@ -use embed_manifest::{embed_manifest, new_manifest}; - 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"); } diff --git a/crates/wef/README.md b/crates/wef/README.md index 18abe776..2bc3472b 100644 --- a/crates/wef/README.md +++ b/crates/wef/README.md @@ -1,5 +1,9 @@ # 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 - [Introduction](#introduction) @@ -8,11 +12,11 @@ - [Application Layout](#application-layout) - [Windows](#windows) - [Linux](#linux) - - [MacOS](#macos) + - [macOS](#macos) - [Application Structure](#application-structure) - - [Entry-Point Function](#entry-point-function) - - [Single Executable](#single-executable) - - [Separate Sub-Process Executable](#separate-sub-process-executable) + - [Entry-Point Function](#entry-point-function) + - [Single Executable](#single-executable) + - [Separate Sub-Process Executable](#separate-sub-process-executable) - [Examples](#examples) - [JS Bridge](#js-bridge) - [Call Rust functions from JavaScript](#call-rust-functions-from-javascript) @@ -20,7 +24,7 @@ - [Cargo-wef](#cargo-wef) - [Installation Cargo-wef](#installation-cargo-wef) - [Build Wef application](#build-wef-application) - - [MacOS Bundle Settings](#macos-bundle-settings) + - [macOS Bundle Settings](#macos-bundle-settings) - [Run Wef application](#run-wef-application) - [Add CEF3 Framework to the application](#add-cef3-framework-to-the-application) @@ -32,7 +36,7 @@ ## 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. @@ -77,9 +81,9 @@ Application/ 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 cefclient.app/ @@ -137,7 +141,7 @@ As described in the `Important Concepts` section a CEF3 application will run mul #### 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 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. ```javascript -jsBridge.addInt(1, 2).then(result => { - console.log("Result of addInt:", result); - // Result of addInt: 3 +jsBridge.addInt(1, 2).then((result) => { + console.log("Result of addInt:", result); + // Result of addInt: 3 }); ``` @@ -248,8 +252,8 @@ let Some(frame) = browser.main_frame() { ```javascript jsBridge.addEventListener((message) => { - console.log("Message from Rust:", message); - // Message from Rust: ok + console.log("Message from Rust:", message); + // 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. ```bash -cargo wef init [/path/to/cef] +cargo wef init ``` ### 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 ``` -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. -```bash -If on MacOS, this command also create application bundle with the CEF3 framework inside. +````bash +If on macOS, this command also create application bundle with the CEF3 framework inside. ### Run Wef application @@ -295,9 +299,9 @@ Like cargo run, but it will also copy the CEF3 framework to the target directory ```bash 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. @@ -324,7 +328,7 @@ identifier = "my.wef.app" ``` | name | type | optional | description | -|------------------------|----------|----------|--------------------------------------------------------------------------------------------------------------------------| +| ---------------------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------ | | name | String | No | Bundle name | | identifier | String | No | Bundle identifier | | 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 -MacOS +For macOS ```bash cargo wef add-framework /path/to/your/app.bundle ``` -Windows/Linux +For Windows or Linux ```bash cargo wef add-framework /path/to/app