Skip to content

Commit c40bb03

Browse files
not-elmnot-elm
and
not-elm
authored
Changed IPC communication to use triggers. (#50)
* update: change ipc-event to ipc-trigger Switched IPC event handling to use Bevy’s Trigger instead of Event. This commit implements the pathway from the WebView to Bevy. * update: emit event method Change to emit an event via trigger * clippy * update: add comment * update: move examples directory * update: event reader * fix: doc lint * fix: doc lint * fix: docs --------- Co-authored-by: not-elm <elmgameinfo@gmail.com>
1 parent a4599df commit c40bb03

File tree

37 files changed

+395
-416
lines changed

37 files changed

+395
-416
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
resolver = "2"
33
members = [
44
"crates/*",
5-
"examples/*",
65
]
76
exclude = [
87
"tool",
@@ -13,7 +12,7 @@ version = "0.3.0"
1312
authors = ["notelm <elmprograminfo@gmail.com>"]
1413
repository = "https://github.com/not-elm/bevy_webview_projects"
1514
license = "MIT OR Apache-2.0"
16-
edition = "2021"
15+
edition = "2024"
1716

1817
[workspace.dependencies]
1918
bevy = { version = "0.16", default-features = false }

crates/bevy_flurx_api/src/log.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
//! Provides mechanism to output the logs.
22
3-
use bevy::app::Update;
43
use bevy::log;
5-
use bevy::prelude::{App, EventReader, Plugin};
6-
use bevy_flurx_ipc::ipc_events::IpcEventExt;
7-
use bevy_flurx_ipc::prelude::IpcEvent;
4+
use bevy::prelude::{App, Event, Plugin, Trigger};
5+
use bevy_flurx_ipc::ipc_trigger::IpcTriggerExt;
86
use serde::Deserialize;
97

108
/// You will be able to output a massage to the console of the aa process.
@@ -19,21 +17,19 @@ pub struct AllLogPlugins;
1917
impl Plugin for AllLogPlugins {
2018
fn build(&self, app: &mut App) {
2119
app
22-
.add_ipc_event::<RequestPrintln>("FLURX|log::println")
23-
.add_ipc_event::<RequestLog>("FLURX|log::log")
24-
.add_systems(Update, (
25-
println_event,
26-
log_event,
27-
));
20+
.add_ipc_trigger::<RequestPrintln>("FLURX|log::println")
21+
.add_ipc_trigger::<RequestLog>("FLURX|log::log")
22+
.add_observer(apply_println_api)
23+
.add_observer(apply_log_api);
2824
}
2925
}
3026

31-
#[derive(Deserialize)]
27+
#[derive(Deserialize, Event)]
3228
struct RequestPrintln {
3329
message: String,
3430
}
3531

36-
#[derive(Deserialize)]
32+
#[derive(Deserialize, Event)]
3733
struct RequestLog {
3834
message: String,
3935
level: RequestLogLevel,
@@ -49,21 +45,17 @@ enum RequestLogLevel {
4945
Error,
5046
}
5147

52-
fn println_event(mut er: EventReader<IpcEvent<RequestPrintln>>) {
53-
for event in er.read() {
54-
println!("{}", event.payload.message);
55-
}
48+
fn apply_println_api(trigger: Trigger<RequestPrintln>) {
49+
println!("{}", trigger.message);
5650
}
5751

58-
fn log_event(mut er: EventReader<IpcEvent<RequestLog>>) {
59-
for event in er.read() {
60-
let message = &event.payload.message;
61-
match event.payload.level {
62-
RequestLogLevel::Trace => log::trace!(message),
63-
RequestLogLevel::Debug => log::debug!(message),
64-
RequestLogLevel::Info => log::info!(message),
65-
RequestLogLevel::Warn => log::warn!(message),
66-
RequestLogLevel::Error => log::error!(message),
67-
}
52+
fn apply_log_api(trigger: Trigger<RequestLog>) {
53+
let message = &trigger.message;
54+
match trigger.level {
55+
RequestLogLevel::Trace => log::trace!(message),
56+
RequestLogLevel::Debug => log::debug!(message),
57+
RequestLogLevel::Info => log::info!(message),
58+
RequestLogLevel::Warn => log::warn!(message),
59+
RequestLogLevel::Error => log::error!(message),
6860
}
6961
}

crates/bevy_flurx_ipc/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ serde_json = { workspace = true }
2323

2424
[dev-dependencies]
2525
trybuild = "1"
26-
bevy = { workspace = true }
26+
bevy = { workspace = true, features = ["bevy_log"] }
27+
bevy_test_helper = { git = "https://github.com/not-elm/bevy_test_helper", branch = "v0.16" }
2728

2829
[lints]
2930
workspace = true

examples/ipc/simple.rs renamed to crates/bevy_flurx_ipc/examples/simple.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! This example demonstrates how to use `bevy_flurx_ipc`.
22
3+
use bevy::log::LogPlugin;
34
use bevy::prelude::*;
45
use bevy_flurx::prelude::*;
56
use bevy_flurx_ipc::prelude::*;
@@ -11,6 +12,7 @@ fn main() {
1112
App::new()
1213
.add_plugins((
1314
MinimalPlugins,
15+
LogPlugin::default(),
1416
FlurxPlugin,
1517
FlurxIpcPlugin,
1618
))

crates/bevy_flurx_ipc/src/ipc_events.rs

Lines changed: 0 additions & 154 deletions
This file was deleted.

0 commit comments

Comments
 (0)