1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3
4pub type PluginId = String;
5pub type IconPackId = String;
6pub type ActionId = String;
7
8pub type ProfileId = Uuid;
9pub type FolderId = Uuid;
10pub type DeviceId = Uuid;
11pub type TileId = Uuid;
12pub type JsonObject = serde_json::Map<String, serde_json::Value>;
13
14#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
15pub struct InspectorContext {
16 pub profile_id: ProfileId,
17 pub folder_id: FolderId,
18
19 pub plugin_id: PluginId,
20 pub action_id: ActionId,
21
22 pub tile_id: TileId,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
26pub struct DisplayContext {
27 pub device_id: DeviceId,
28 pub plugin_id: PluginId,
29 pub action_id: ActionId,
30 pub tile_id: TileId,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
34pub struct TileInteractionContext {
35 pub device_id: DeviceId,
36
37 pub plugin_id: PluginId,
38 pub action_id: ActionId,
39
40 pub tile_id: TileId,
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct DeepLinkContext {
45 pub url: String,
46 pub host: Option<String>,
47 pub path: String,
48 pub query: Option<String>,
49 pub fragment: Option<String>,
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct TileModel {
54 pub id: TileId,
56
57 pub config: TileConfig,
59
60 pub properties: JsonObject,
62
63 pub folder_id: FolderId,
65
66 pub plugin_id: PluginId,
68 pub action_id: ActionId,
70
71 pub position: TilePosition,
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct TileConfig {
77 pub icon: TileIcon,
79 pub label: TileLabel,
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct TileIconOptions {
85 pub padding: u32,
86 pub background_color: String,
87 pub border_color: String,
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
91pub struct TilePosition {
92 pub row: u32,
94 pub column: u32,
96 pub row_span: u32,
98 pub column_span: u32,
100}
101
102#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq)]
103#[serde(tag = "type")]
104pub enum TileIcon {
105 #[default]
107 None,
108
109 PluginIcon {
111 plugin_id: PluginId,
113 icon: String,
115 },
116
117 IconPack {
119 pack_id: IconPackId,
121 path: String,
123 },
124
125 Url {
127 src: String,
128 },
129
130 Uploaded {
132 path: String,
134 },
135
136 Display {
138 path: String,
140 },
141
142 #[serde(other)]
143 Unknown,
144}
145
146#[derive(Default, Debug, Clone, Serialize, Deserialize)]
147#[serde(default)]
148pub struct TileLabel {
149 pub enabled: Option<bool>,
150 pub label: Option<String>,
151 pub align: Option<LabelAlign>,
152
153 pub font: Option<String>,
154 pub font_size: Option<u32>,
155
156 pub bold: Option<bool>,
157 pub italic: Option<bool>,
158 pub underline: Option<bool>,
159 pub outline: Option<bool>,
160
161 pub color: Option<String>,
162 pub outline_color: Option<String>,
163}
164
165#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
166pub enum LabelAlign {
167 #[default]
168 Bottom,
169 Middle,
170 Top,
171
172 #[serde(other)]
173 Unknown,
174}
175
176#[derive(Debug, Serialize)]
178#[serde(tag = "type")]
179pub(crate) enum ClientPluginMessage {
180 RegisterPlugin { plugin_id: PluginId },
182
183 GetProperties,
185
186 SetProperties {
188 properties: serde_json::Value,
189
190 partial: bool,
192 },
193
194 SendToInspector {
196 ctx: InspectorContext,
198 message: serde_json::Value,
200 },
201
202 SendToDisplay {
204 ctx: DisplayContext,
206 message: serde_json::Value,
208 },
209
210 OpenUrl { url: String },
212
213 GetTileProperties {
215 tile_id: TileId,
217 },
218
219 SetTileProperties {
221 tile_id: TileId,
223 properties: serde_json::Value,
225 partial: bool,
227 },
228
229 SetTileIcon { tile_id: TileId, icon: TileIcon },
231
232 SetTileLabel { tile_id: TileId, label: TileLabel },
234
235 GetVisibleTiles,
237
238 DisplayIndicator {
240 device_id: Uuid,
242 tile_id: Uuid,
244 indicator: DeviceIndicator,
246 duration: u32,
249 },
250}
251
252#[derive(Debug, Clone, Deserialize)]
254#[serde(tag = "type")]
255pub(crate) enum ServerPluginMessage {
256 Registered {
258 #[allow(unused)]
259 plugin_id: PluginId,
260 },
261
262 Properties { properties: serde_json::Value },
264
265 TileClicked {
267 ctx: TileInteractionContext,
268 properties: serde_json::Value,
269 },
270
271 RecvFromInspector {
273 ctx: InspectorContext,
274 message: serde_json::Value,
275 },
276
277 RecvFromDisplay {
279 ctx: DisplayContext,
280 message: serde_json::Value,
281 },
282
283 InspectorOpen { ctx: InspectorContext },
285
286 InspectorClose { ctx: InspectorContext },
288
289 DeepLink { ctx: DeepLinkContext },
291
292 TileProperties {
294 tile_id: TileId,
295 properties: serde_json::Value,
296 },
297
298 DeviceTiles {
300 device_id: DeviceId,
302 tiles: Vec<TileModel>,
304 },
305
306 VisibleTiles {
307 tiles: Vec<TileModel>,
309 },
310}
311
312#[derive(Debug, Serialize, Deserialize)]
313pub enum DeviceIndicator {
314 Error,
315 Success,
316 Warning,
317 Loading,
318 None,
320
321 #[serde(other)]
322 Unknown,
323}