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;
11pub type JsonObject = serde_json::Map<String, serde_json::Value>;
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct InspectorContext {
15 pub profile_id: ProfileId,
16 pub folder_id: FolderId,
17
18 pub plugin_id: PluginId,
19 pub action_id: ActionId,
20
21 pub tile_id: TileId,
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct DisplayContext {
26 pub device_id: DeviceId,
27 pub plugin_id: PluginId,
28 pub action_id: ActionId,
29 pub tile_id: TileId,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct TileInteractionContext {
34 pub device_id: DeviceId,
35
36 pub plugin_id: PluginId,
37 pub action_id: ActionId,
38
39 pub tile_id: TileId,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct DeepLinkContext {
44 pub url: String,
45 pub host: Option<String>,
46 pub path: String,
47 pub query: Option<String>,
48 pub fragment: Option<String>,
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct TileModel {
53 pub id: TileId,
55
56 pub config: TileConfig,
58
59 pub properties: JsonObject,
61
62 pub folder_id: FolderId,
64
65 pub plugin_id: PluginId,
67 pub action_id: ActionId,
69
70 pub position: TilePosition,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct TileConfig {
76 pub icon: TileIcon,
78 pub label: TileLabel,
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
83pub struct TileIconOptions {
84 pub padding: u32,
85 pub background_color: String,
86 pub border_color: String,
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct TilePosition {
91 pub row: u32,
93 pub column: u32,
95 pub row_span: u32,
97 pub column_span: u32,
99}
100
101#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq)]
102#[serde(tag = "type")]
103pub enum TileIcon {
104 #[default]
106 None,
107
108 PluginIcon {
110 plugin_id: PluginId,
112 icon: String,
114 },
115
116 IconPack {
118 pack_id: String,
120 path: String,
122 },
123
124 Url {
126 src: String,
127 },
128}
129
130#[derive(Default, Debug, Clone, Serialize, Deserialize)]
131#[serde(default)]
132pub struct TileLabel {
133 pub enabled: Option<bool>,
134 pub label: Option<String>,
135 pub align: Option<LabelAlign>,
136
137 pub font: Option<String>,
138 pub font_size: Option<u32>,
139
140 pub bold: Option<bool>,
141 pub italic: Option<bool>,
142 pub underline: Option<bool>,
143 pub outline: Option<bool>,
144
145 pub color: Option<String>,
146 pub outline_color: Option<String>,
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize, Default)]
150pub enum LabelAlign {
151 #[default]
152 Bottom,
153 Middle,
154 Top,
155}
156
157#[derive(Debug, Serialize)]
159#[serde(tag = "type")]
160pub(crate) enum ClientPluginMessage {
161 RegisterPlugin { plugin_id: PluginId },
163
164 GetProperties,
166
167 SetProperties {
169 properties: serde_json::Value,
170
171 partial: bool,
173 },
174
175 SendToInspector {
177 ctx: InspectorContext,
179 message: serde_json::Value,
181 },
182
183 SendToDisplay {
185 ctx: DisplayContext,
187 message: serde_json::Value,
189 },
190
191 OpenUrl { url: String },
193
194 GetTileProperties {
196 tile_id: TileId,
198 },
199
200 SetTileProperties {
202 tile_id: TileId,
204 properties: serde_json::Value,
206 partial: bool,
208 },
209
210 SetTileIcon { tile_id: TileId, icon: TileIcon },
212
213 SetTileLabel { tile_id: TileId, label: TileLabel },
215
216 GetVisibleTiles,
218}
219
220#[derive(Debug, Clone, Deserialize)]
222#[serde(tag = "type")]
223pub(crate) enum ServerPluginMessage {
224 Registered {
226 #[allow(unused)]
227 plugin_id: PluginId,
228 },
229
230 Properties { properties: serde_json::Value },
232
233 TileClicked {
235 ctx: TileInteractionContext,
236 properties: serde_json::Value,
237 },
238
239 RecvFromInspector {
241 ctx: InspectorContext,
242 message: serde_json::Value,
243 },
244
245 RecvFromDisplay {
247 ctx: DisplayContext,
248 message: serde_json::Value,
249 },
250
251 InspectorOpen { ctx: InspectorContext },
253
254 InspectorClose { ctx: InspectorContext },
256
257 DeepLink { ctx: DeepLinkContext },
259
260 TileProperties {
262 tile_id: TileId,
263 properties: serde_json::Value,
264 },
265
266 DeviceTiles {
268 device_id: DeviceId,
270 tiles: Vec<TileModel>,
272 },
273
274 VisibleTiles {
275 tiles: Vec<TileModel>,
277 },
278}