tilepad_plugin_sdk/plugin.rs
1use crate::{
2 display::Display,
3 inspector::Inspector,
4 protocol::{DeepLinkContext, DeviceId, TileId, TileInteractionContext, TileModel},
5 session::PluginSessionHandle,
6};
7
8/// Trait implemented by your plugin
9#[allow(unused_variables)]
10pub trait Plugin {
11 /// Invoked when the plugin is successfully registered with the
12 /// Tilepad application and has a usable session
13 ///
14 /// # Arguments
15 /// * `session` - The current session
16 fn on_registered(&mut self, session: &PluginSessionHandle) {}
17
18 /// Invoked when the plugin properties are received from Tilepad,
19 /// this will occur when the plugin calls `session.request_properties` or `session.get_properties`
20 /// but also once when the plugin is first registered
21 ///
22 /// # Arguments
23 /// * `session` - The current session
24 /// * `properties` - The current plugin properties
25 fn on_properties(&mut self, session: &PluginSessionHandle, properties: serde_json::Value) {}
26
27 /// Invoked when a tiles properties are received from Tilepad,
28 /// this will occur when the plugin calls [PluginSessionHandle::request_tile_properties] or [PluginSessionHandle::get_tile_properties]
29 ///
30 /// # Arguments
31 /// * `session` - The current session
32 /// * `tile_id` - ID of the tile that the properties are for
33 /// * `properties` - The current plugin properties
34 fn on_tile_properties(
35 &mut self,
36 session: &PluginSessionHandle,
37 tile_id: TileId,
38 properties: serde_json::Value,
39 ) {
40 }
41
42 /// Invoked when the plugin receives a message from the inspector,
43 /// this message structure is defined by the developer
44 ///
45 /// # Arguments
46 /// * `session` - The current session
47 /// * `inspector - Inspector to send messages back
48 /// * `message` - The message sent from the inspector
49 fn on_inspector_message(
50 &mut self,
51 session: &PluginSessionHandle,
52 inspector: Inspector,
53 message: serde_json::Value,
54 ) {
55 }
56 /// Invoked when the plugin receives a message from a display,
57 /// this message structure is defined by the developer
58 ///
59 /// # Arguments
60 /// * `session` - The current session
61 /// * `display` - Display to send messages back
62 /// * `message` - The message sent from the inspector
63 fn on_display_message(
64 &mut self,
65 session: &PluginSessionHandle,
66 display: Display,
67 message: serde_json::Value,
68 ) {
69 }
70
71 /// Invoked when the inspector is opened for a tile
72 ///
73 /// # Arguments
74 /// * `session` - The current session
75 /// * `inspector - Inspector to send messages back
76 fn on_inspector_open(&mut self, session: &PluginSessionHandle, inspector: Inspector) {}
77
78 /// Invoked when the inspector is closed for a tile
79 ///
80 /// # Arguments
81 /// * `session` - The current session
82 /// * `inspector - Inspector to send messages back
83 fn on_inspector_close(&mut self, session: &PluginSessionHandle, inspector: Inspector) {}
84
85 /// Invoked when a deep link is received for the plugin
86 ///
87 /// # Arguments
88 /// * `session` - The current session
89 /// * `ctx` - Information about the deep-link
90 fn on_deep_link(&mut self, session: &PluginSessionHandle, ctx: DeepLinkContext) {}
91
92 /// Invoked when a tile is clicked on a device
93 ///
94 /// # Arguments
95 /// * `session` - The current session
96 /// * `ctx` - Contextual information about tile clicked tile (Device, action, etc)
97 /// * `properties` - The current tile properties at the time of clicking
98 fn on_tile_clicked(
99 &mut self,
100 session: &PluginSessionHandle,
101 ctx: TileInteractionContext,
102 properties: serde_json::Value,
103 ) {
104 }
105
106 /// Invoked when the visible tiles on a device change
107 ///
108 /// # Arguments
109 /// * `session` - The current session
110 /// * `device_id` - ID of the device the tiles are for
111 /// * `tiles` - The current tiles of the device
112 fn on_device_tiles(
113 &mut self,
114 session: &PluginSessionHandle,
115 device_id: DeviceId,
116 tiles: Vec<TileModel>,
117 ) {
118 }
119 /// Invoked when the list of visible tiles is received
120 /// this will occur when the plugin calls [PluginSessionHandle::request_visible_tiles] or [PluginSessionHandle::get_visible_tiles]
121 ///
122 /// # Arguments
123 /// * `session` - The current session
124 /// * `tiles` - The current visible tiles
125 fn on_visible_tiles(&mut self, session: &PluginSessionHandle, tiles: Vec<TileModel>) {}
126}