Skip to content

The purpose of this crate is integrate bevy and wry using bevy_flurx.

License

Apache-2.0, Apache-2.0 licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
Apache-2.0
LICENSE-MIT
Notifications You must be signed in to change notification settings

not-elm/bevy_flurx_wry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

bevy_flurx_wry

Crates.io MIT/Apache 2.0 Crates.io

Caution

This crate is in the early stages of development and is subject to disruptive changes.

Purpose

The purpose of this crate is integrate bevy and wry using bevy_flurx.

In addition to that, I would like to take advantage of bevy's extensibility and discover bevy's potential to transcend the framework of existing game engines.

Platform Support

The operation has been confirmed on Windows and MacOS.

Linux is currently not supported.

Usage

There are two ways to create a webview:

Converts an existing window into a webview window.

simple

examples/simple.rs

use bevy::prelude::*;
use bevy::window::PrimaryWindow;
use bevy_flurx_wry::prelude::*;

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(
        WryWebViewBundle {
            uri: WebviewUri::new("https://bevyengine.org/"),
            ..default()
        }
    );
}

Create a webview as child inside a window.

child_view examples/child_view.rs

use bevy::prelude::*;
use bevy::window::PrimaryWindow;
use bevy_flurx_wry::prelude::*;

fn spawn_webview(
    mut commands: Commands,
    window: Query<Entity, With<PrimaryWindow>>,
) {
    commands.spawn((
        WryWebViewBundle {
            ..default()
        },
        AsChildBundle {
            // Here, create a webview as child inside a given window.
            parent: ParentWindow(window.single()),
            bounds: Bounds {
                position: Vec2::new(100., 100.),
                size: Vec2::new(500., 500.),
                min_size: Vec2::new(100., 100.),
            },
            ..default()
        },
    ));
}

Ipc

IpcEvent

You can listen events from the webview and, conversely, emit events to the webview.

Webview(javascript) -> bevy

examples/event_listen.rs

javascript

// you can use any type.
const event = {
    message: "message"
};
window.__FLURX__.emit("event_id", event);

rust

use bevy::prelude::*;
use bevy_flurx_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() {
        println!("webview message: {}", e.payload.message);
    }
}

bevy -> Webview(javascript)

examples/event_emit.rs

javascript

window.__FLURX__.listen("event_id", ({message}) => {
    console.log(message);
});

rust

use bevy::prelude::*;
use bevy_flurx_wry::prelude::*;
use serde_json::json;

fn emit_event(
    mut views: Query<&mut EventEmitter>
) {
    for mut emitter in views.iter_mut() {
        emitter.emit("event_id", &serde_json::json!({
            "message" : "hello world!"
        }));
    }
}

IpcCommand

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/ipc_command.rs for details.

Todo

  • Enhance security
  • Bug fix
  • Add apis
  • Support Linux(X11)
  • Support Linux(Wayland)

ChangeLog

Please see here.

Compatible Bevy versions

bevy_flurx_wry bevy_flurx bevy
0.1.0-alpha1 0.5.2 0.13.2

License

This crate is licensed under the MIT License or the Apache License 2.0.