1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 05:40:03 -04:00

Add egui_inspection crate and eframe inspection hooks

New `egui_inspection` crate ships:
- `protocol` (default): wire types + length-prefixed msgpack framing for the
  inspector ↔ egui-peer connection. Transport-neutral (stdio / unix socket / TCP).
- `plugin`: `InspectionPlugin`, an `egui::Plugin` that dials a unix socket from
  `EGUI_INSPECTION_SOCKET`, streams frames + accesskit tree updates, and applies
  inbound `InspectorCommand`s back into the running `egui::Context`.

eframe gains an `inspection` feature that auto-attaches the plugin during native
startup (glow + wgpu integrations) when the env var is set. Connection failures
log via `log::warn!` and do not abort startup.

Lives in its own crate (rather than `egui_kittest`) so eframe can pull the
protocol in without picking up the test harness, and so external tools can
depend on it directly.
This commit is contained in:
lucasmerlin
2026-05-21 10:57:42 +02:00
parent a41bba33a0
commit 622218e94f
11 changed files with 809 additions and 0 deletions

View File

@@ -209,6 +209,33 @@ pub use native::file_storage::storage_dir;
#[cfg(not(target_arch = "wasm32"))]
pub mod icon_data;
// ----------------------------------------------------------------------------
/// Attach an [`egui_inspection::InspectionPlugin`] to `ctx` if the
/// `EGUI_INSPECTION_SOCKET` env var points at a reachable unix socket.
///
/// No-op when:
/// - the `inspection` feature isn't enabled,
/// - the target isn't unix, or
/// - the env var is unset.
///
/// Connection failures are logged via `log::warn!` but do not abort startup — running
/// without an inspector is always valid.
#[cfg(all(feature = "inspection", unix, not(target_arch = "wasm32")))]
pub(crate) fn maybe_attach_inspection_plugin(ctx: &egui::Context, label: Option<String>) {
match egui_inspection::InspectionPlugin::from_env(label) {
Ok(Some(plugin)) => {
log::info!("eframe: attaching egui_inspection plugin");
ctx.add_plugin(plugin);
}
Ok(None) => {}
Err(err) => log::warn!("eframe: egui_inspection attach failed: {err}"),
}
}
#[cfg(not(all(feature = "inspection", unix, not(target_arch = "wasm32"))))]
pub(crate) fn maybe_attach_inspection_plugin(_ctx: &egui::Context, _label: Option<String>) {}
/// This is how you start a native (desktop) app.
///
/// The first argument is name of your app, which is an identifier

View File

@@ -299,6 +299,8 @@ impl<'app> GlowWinitApp<'app> {
let app_creator = std::mem::take(&mut self.app_creator)
.expect("Single-use AppCreator has unexpectedly already been taken");
crate::maybe_attach_inspection_plugin(&integration.egui_ctx, Some(self.app_name.clone()));
let app: Box<dyn 'app + App> = {
// Use latest raw_window_handle for eframe compatibility
use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _};

View File

@@ -291,6 +291,9 @@ impl<'app> WgpuWinitApp<'app> {
let app_creator = std::mem::take(&mut self.app_creator)
.expect("Single-use AppCreator has unexpectedly already been taken");
crate::maybe_attach_inspection_plugin(&egui_ctx, Some(self.app_name.clone()));
let cc = CreationContext {
egui_ctx: egui_ctx.clone(),
integration_info: integration.frame.info().clone(),