standard-plugin-sdk 0.1.5

Write Standard Code plugins in Rust: wasm components against standard:plugin@2.0.0
Documentation
//! The links the user clicks in panes, for a UI plugin holding the
//! `links.handle` grant: each arrives as the plugin event [`OPEN_EVENT`]
//! instead of opening in the system browser, as a user gesture (the
//! plugin may open a surface while it handles it).

use alloc::string::String;

use serde::Deserialize;

/// The plugin event a clicked link arrives as.
pub const OPEN_EVENT: &str = "system.link.open";

/// A link clicked in a pane.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Eq)]
pub struct Link {
    /// An `http://` or `https://` URL.
    pub url: String,
    /// The pane it was clicked in.
    #[serde(default)]
    pub pane: Option<String>,
    /// The machine that pane runs on, when the viewer knows it.
    #[serde(default)]
    pub machine: Option<String>,
}

impl Link {
    /// The link an event carries, if it is one.
    pub fn from_event(event: &crate::Event) -> Option<Self> {
        let crate::Event::Plugin { name, payload } = event else {
            return None;
        };
        if name != OPEN_EVENT {
            return None;
        }
        payload.parse().ok()
    }
}