Skip to main content

tilepad_plugin_sdk/
inspector.rs

1use serde::Serialize;
2
3use crate::{
4    protocol::{ClientPluginMessage, InspectorContext},
5    session::{PluginSessionHandle, SessionError},
6};
7
8/// Reference to an inspector window that can be
9/// used to send messages
10#[derive(Clone)]
11pub struct Inspector {
12    /// Plugin session handle the inspector is connected through
13    pub session: PluginSessionHandle,
14    /// Context data for the inspector
15    pub ctx: InspectorContext,
16}
17
18impl Inspector {
19    /// Send a JSON serializable message `msg` to the inspector window
20    pub fn send<M>(&self, msg: M) -> Result<(), SessionError>
21    where
22        M: Serialize,
23    {
24        let message = serde_json::to_value(msg)?;
25        self.session
26            .send_message(ClientPluginMessage::SendToInspector {
27                ctx: self.ctx.clone(),
28                message,
29            })
30    }
31}