Crates.io | bevy_webview_wry |
lib.rs | bevy_webview_wry |
version | |
source | src |
created_at | 2025-01-13 12:01:52.7723+00 |
updated_at | 2025-02-24 18:27:48.16467+00 |
description | Allows you to create a webview based on wry |
homepage | |
repository | https://github.com/not-elm/bevy_webview_projects |
max_upload_size | |
id | 1514574 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
[!CAUTION] This crate is in the early stages of development and is subject to breaking changes.
The purpose of this crate is integrate bevy and wry using bevy_flurx.
Platform | usable |
---|---|
Windows | ✅ |
MacOS | ✅ |
Linux(X11) | ✅ |
Linux(Wayland) | ❌ |
Web | ❌ |
Android | ❌ |
iOS | ❌ |
Add this to your Cargo.toml
:
[dependencies]
bevy_webview_wry = { version = "0.3", features = ["api"] }
# necessary if you want to use ipc-command.
bevy_flurx = "0.9"
Execute the following command in the directory where the package.json
is located.
# if you use npm
npm install bevy_flurx_api
# if you use yarn
yarn add bevy_flurx_api
# if you use pnpm
pnpm install bevy_flurx_api
Or, you can also use the API directly from Window.__FLURX__
without installation.
There are two ways to create a webview:
fn spawn_webview(
mut commands: Commands,
window: Query<Entity, With<PrimaryWindow>>,
) {
// Converts the `Window` attached the entity into a webview window.
commands
.entity(window.single())
.insert(Webview::Uri(WebviewUri::new("https://bevyengine.org/")));
}
This feature is required child_window
feature flag.
Please refer here for supported platforms.
You can listen events from the webview and, conversely, emit events to the webview.
javascript
// you can use any type.
const event = {
message: "message"
};
window.__FLURX__.emit("event_id", event);
rust
use bevy::prelude::*;
use bevy_webview_wry::prelude::*;
use serde::Deserialize;
#[derive(Deserialize, Debug)]
struct MessageFromWebview {
message: String,
}
fn read_webview_message(
mut er: EventReader<IpcEvent<MessageFromWebview>>
) {
for e in er.read() {
info!("webview message: {}", e.payload.message);
}
}
javascript
const webviewWindow = window.__FLURX__.WebWindow.current()
webviewWindow.listen("count_event", (event) => {
console.log(event);
});
rust
fn emit_event(
mut timer: ResMut<CountTimer>,
mut views: Query<&mut EventEmitter>,
mut count: Local<usize>,
time: Res<Time>,
) {
if timer.0.tick(time.delta()).finished() {
*count += 1;
for mut emitter in views.iter_mut() {
emitter.emit("count_event", serde_json::json!({
"count" : *count
}));
}
}
}
IpcEvent
can't receive the output value from the other side.
In this case, IpcCommand
can be used.
IpcComamnd
can be divided into two command patterns: action-command, task-command
Please check examples/wry/ipc_command.rs for details.
Please see here.
flag | description | default |
---|---|---|
child_window |
allows you to create embedding child window | true |
api |
provides api plugins for the webview | false |
bevy_webview_wry | bevy_flurx | bevy |
---|---|---|
0.1.0 ~ | 0.9 | 0.15 |
This crate is licensed under the MIT License or the Apache License 2.0.