tilepad_plugin_sdk/plugin.rs
1use crate::{
2 inspector::Inspector,
3 protocol::{DeepLinkContext, TileId, TileInteractionContext},
4 session::PluginSessionHandle,
5};
6
7/// Trait implemented by your plugin
8#[allow(unused_variables)]
9pub trait Plugin {
10 /// Invoked when the plugin is successfully registered with the
11 /// Tilepad application and has a usable session
12 ///
13 /// # Arguments
14 /// * `session` - The current session
15 fn on_registered(&mut self, session: &PluginSessionHandle) {}
16
17 /// Invoked when the plugin properties are received from Tilepad,
18 /// this will occur when the plugin calls `session.request_properties` or `session.get_properties`
19 /// but also once when the plugin is first registered
20 ///
21 /// # Arguments
22 /// * `session` - The current session
23 /// * `properties` - The current plugin properties
24 fn on_properties(&mut self, session: &PluginSessionHandle, properties: serde_json::Value) {}
25
26 /// Invoked when a tiles properties are received from Tilepad,
27 /// this will occur when the plugin calls `session.request_tile_properties` or `session.get_tile_properties`
28 ///
29 /// # Arguments
30 /// * `session` - The current session
31 /// * `tile_id` - ID of the tile that the properties are for
32 /// * `properties` - The current plugin properties
33 fn on_tile_properties(
34 &mut self,
35 session: &PluginSessionHandle,
36 tile_id: TileId,
37 properties: serde_json::Value,
38 ) {
39 }
40
41 /// Invoked when the plugin receives a message from the inspector,
42 /// this message structure is defined by the developer
43 ///
44 /// # Arguments
45 /// * `session` - The current session
46 /// * `ctx` - Contextual information about the inspector (Which tile is selected, which folder, which profile etc)
47 /// * `message` - The message sent from the inspector
48 fn on_inspector_message(
49 &mut self,
50 session: &PluginSessionHandle,
51 inspector: Inspector,
52 message: serde_json::Value,
53 ) {
54 }
55
56 /// Invoked when the inspector is opened for a tile
57 ///
58 /// # Arguments
59 /// * `session` - The current session
60 /// * `ctx` - Contextual information about the inspector (Which tile is selected, which folder, which profile etc)
61 fn on_inspector_open(&mut self, session: &PluginSessionHandle, inspector: Inspector) {}
62
63 /// Invoked when the inspector is closed for a tile
64 ///
65 /// # Arguments
66 /// * `session` - The current session
67 /// * `ctx` - Contextual information about the inspector (Which tile is selected, which folder, which profile etc)
68 fn on_inspector_close(&mut self, session: &PluginSessionHandle, inspector: Inspector) {}
69
70 /// Invoked when a deep link is received for the plugin
71 ///
72 /// # Arguments
73 /// * `session` - The current session
74 /// * `ctx` - Information about the deep-link
75 fn on_deep_link(&mut self, session: &PluginSessionHandle, ctx: DeepLinkContext) {}
76
77 /// Invoked when a tile is clicked on a device
78 ///
79 /// # Arguments
80 /// * `session` - The current session
81 /// * `ctx` - Contextual information about tile clicked tile (Device, action, etc)
82 /// * `properties` - The current tile properties at the time of clicking
83 fn on_tile_clicked(
84 &mut self,
85 session: &PluginSessionHandle,
86 ctx: TileInteractionContext,
87 properties: serde_json::Value,
88 ) {
89 }
90}