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, PartialEq, Eq)]
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, PartialEq, Eq)]
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, PartialEq, Eq)]
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, PartialEq, Eq)]
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, PartialEq, Eq)]
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 DisplayIndicator {
221 device_id: Uuid,
223 tile_id: Uuid,
225 indicator: DeviceIndicator,
227 duration: u32,
230 },
231}
232
233#[derive(Debug, Clone, Deserialize)]
235#[serde(tag = "type")]
236pub(crate) enum ServerPluginMessage {
237 Registered {
239 #[allow(unused)]
240 plugin_id: PluginId,
241 },
242
243 Properties { properties: serde_json::Value },
245
246 TileClicked {
248 ctx: TileInteractionContext,
249 properties: serde_json::Value,
250 },
251
252 RecvFromInspector {
254 ctx: InspectorContext,
255 message: serde_json::Value,
256 },
257
258 RecvFromDisplay {
260 ctx: DisplayContext,
261 message: serde_json::Value,
262 },
263
264 InspectorOpen { ctx: InspectorContext },
266
267 InspectorClose { ctx: InspectorContext },
269
270 DeepLink { ctx: DeepLinkContext },
272
273 TileProperties {
275 tile_id: TileId,
276 properties: serde_json::Value,
277 },
278
279 DeviceTiles {
281 device_id: DeviceId,
283 tiles: Vec<TileModel>,
285 },
286
287 VisibleTiles {
288 tiles: Vec<TileModel>,
290 },
291}
292
293#[derive(Debug, Serialize, Deserialize)]
294pub enum DeviceIndicator {
295 Error,
296 Success,
297 Warning,
298 Loading,
299 None,
301}