tilepad_plugin_sdk/
protocol.rs

1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3
4pub type PluginId = String;
5pub type ActionId = String;
6
7pub type ProfileId = Uuid;
8pub type FolderId = Uuid;
9pub type DeviceId = Uuid;
10pub type TileId = Uuid;
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct InspectorContext {
14    pub profile_id: ProfileId,
15    pub folder_id: FolderId,
16
17    pub plugin_id: PluginId,
18    pub action_id: ActionId,
19
20    pub tile_id: TileId,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct TileInteractionContext {
25    pub device_id: DeviceId,
26
27    pub plugin_id: PluginId,
28    pub action_id: ActionId,
29
30    pub tile_id: TileId,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct DeepLinkContext {
35    pub url: String,
36    pub host: Option<String>,
37    pub path: String,
38    pub query: Option<String>,
39    pub fragment: Option<String>,
40}
41
42#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq)]
43#[serde(tag = "type")]
44pub enum TileIcon {
45    /// No icon
46    #[default]
47    None,
48
49    /// Icon from a specific plugin path
50    PluginIcon {
51        /// ID of the plugin the icon is from
52        plugin_id: PluginId,
53        /// Path to the icon file
54        icon: String,
55    },
56
57    /// Use an icon from an icon pack
58    IconPack {
59        /// ID of the icon pack
60        pack_id: String,
61        /// Path to the icon file
62        path: String,
63    },
64
65    // Image at some remote URL
66    Url {
67        src: String,
68    },
69}
70
71#[derive(Default, Debug, Clone, Serialize, Deserialize)]
72#[serde(default)]
73pub struct TileLabel {
74    pub enabled: Option<bool>,
75    pub label: Option<String>,
76    pub align: Option<LabelAlign>,
77
78    pub font: Option<String>,
79    pub font_size: Option<u32>,
80
81    pub bold: Option<bool>,
82    pub italic: Option<bool>,
83    pub underline: Option<bool>,
84    pub outline: Option<bool>,
85
86    pub color: Option<String>,
87    pub outline_color: Option<String>,
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize, Default)]
91pub enum LabelAlign {
92    #[default]
93    Bottom,
94    Middle,
95    Top,
96}
97
98/// Plugin message coming from the client side
99#[derive(Debug, Serialize)]
100#[serde(tag = "type")]
101pub(crate) enum ClientPluginMessage {
102    /// Register the current plugin with the server
103    RegisterPlugin { plugin_id: PluginId },
104
105    /// Request the current plugin properties
106    GetProperties,
107
108    /// Set the properties for the plugin (Partial update)
109    SetProperties {
110        properties: serde_json::Value,
111
112        /// Whether to treat the properties update as a partial update
113        partial: bool,
114    },
115
116    /// Send data to the current inspector window
117    SendToInspector {
118        /// Inspector context
119        ctx: InspectorContext,
120        /// Message to send the inspector
121        message: serde_json::Value,
122    },
123
124    /// Open a URL
125    OpenUrl { url: String },
126
127    /// Request the current properties for a tile
128    GetTileProperties {
129        /// ID of the tile to get properties for
130        tile_id: TileId,
131    },
132
133    /// Set the current properties for a tile
134    SetTileProperties {
135        /// ID of the tile to set properties for
136        tile_id: TileId,
137        /// Properties for the tile
138        properties: serde_json::Value,
139        /// Whether to treat the properties update as a partial update
140        partial: bool,
141    },
142
143    /// Set the current icon for a tile
144    SetTileIcon { tile_id: TileId, icon: TileIcon },
145
146    /// Set the current label for a tile
147    SetTileLabel { tile_id: TileId, label: TileLabel },
148}
149
150/// Plugin message coming from the server side
151#[derive(Debug, Clone, Deserialize)]
152#[serde(tag = "type")]
153pub(crate) enum ServerPluginMessage {
154    /// Plugin has registered with the server
155    Registered {
156        #[allow(unused)]
157        plugin_id: PluginId,
158    },
159
160    /// Properties received from the server
161    Properties { properties: serde_json::Value },
162
163    /// Tile was clicked on a remote device
164    TileClicked {
165        ctx: TileInteractionContext,
166        properties: serde_json::Value,
167    },
168
169    /// Got a message from the inspector
170    RecvFromInspector {
171        ctx: InspectorContext,
172        message: serde_json::Value,
173    },
174
175    /// Inspector was opened
176    InspectorOpen { ctx: InspectorContext },
177
178    /// Inspector was closed
179    InspectorClose { ctx: InspectorContext },
180
181    /// Received a deep link message for the plugin
182    DeepLink { ctx: DeepLinkContext },
183
184    /// Properties requested for a tile
185    TileProperties {
186        tile_id: TileId,
187        properties: serde_json::Value,
188    },
189}