Skip to main content

standard_plugin/
links.rs

1//! The links the user clicks in panes, for a UI plugin holding the
2//! `links.handle` grant: each arrives as the plugin event [`OPEN_EVENT`]
3//! instead of opening in the system browser, as a user gesture (the
4//! plugin may open a surface while it handles it).
5
6use alloc::string::String;
7
8use serde::Deserialize;
9
10/// The plugin event a clicked link arrives as.
11pub const OPEN_EVENT: &str = "system.link.open";
12
13/// A link clicked in a pane.
14#[derive(Clone, Debug, Default, Deserialize, PartialEq, Eq)]
15pub struct Link {
16    /// An `http://` or `https://` URL.
17    pub url: String,
18    /// The pane it was clicked in.
19    #[serde(default)]
20    pub pane: Option<String>,
21    /// The machine that pane runs on, when the viewer knows it.
22    #[serde(default)]
23    pub machine: Option<String>,
24}
25
26impl Link {
27    /// The link an event carries, if it is one.
28    pub fn from_event(event: &crate::Event) -> Option<Self> {
29        let crate::Event::Plugin { name, payload } = event else {
30            return None;
31        };
32        if name != OPEN_EVENT {
33            return None;
34        }
35        payload.parse().ok()
36    }
37}