-
Notifications
You must be signed in to change notification settings - Fork 0
Plugin API
Here all the functionality of the plugin api, all params are displayed
App = ({ config, setConfig }) => JSX
The App component is renderd on the screen when the plugin is selected, this should have all your config and setting the user can control.
name | Type | Description |
---|---|---|
config | object |
The config you set by the setConfig function |
setConfig | fn(Object) |
Set any user config, merge the old config via ...config to prevent overwrites |
Here a basic example
const App = ({ config, setConfig }) => {
return (
<div>
<label htmlFor="link">link: </label>
<input
name="link"
onChange={(e) => setConfig({ ...config, myLink: e.target.value }) }
value={config.myLink|| ""}
/>
</div>
)
};
export default App;
manifest = Object
The manifest file will have all you plugin settings, used to tell webdeck how to consume this plugin.
name | Type | Description |
---|---|---|
version | number |
(optional) The manifest version, current only 1 is available. If no value is provided, falls back to 1 |
icons | Object |
(optional) Setup for you icons that will be used. "default" is required and is the default icon set |
bespoke | boolean |
(optional) If you plan to create a bespoke experience. Default drawing to key of icon/text/etc is disabled. |
The basic manifest:
export const manifest = {
version: 1,
icons: {
["default"]: {
icon: ".....svg path string....",
},
},
};
To add more icons, for example when user interacts with the plugin (e.g in this case turn on and off) you can provide additional icons.
export const manifest = {
version: 1,
icons: {
["default"]: {
icon: ".....svg path string....",
},
["on"]: {
icon: ".....svg path string....",,
},
["off"]: {
icon: ".....svg path string....",,
},
},
};
init = (params) => function<destructor>
The init function is called when the plugin is initialized. The definition of initialized is "plugin is loaded AND used on a key". The function is called once per initialization, and a return function can be provided as a destruction. This pattern is very common in react-hooks.
export const init = (params) => {
const interval = setInterval(() => {
console.log("hello world every 1 second";
}, 1000);
return () => clearInterval(interval )
};
params: Object
name | Type | Description |
---|---|---|
drawkey | function<callback> |
see draw function bellow |
config | string |
The configration |
keyIndex | number |
The current index of key this plugin is assigned |
drawkey : fn({ ctx, canvas}) => void
This function allows you to draw directly to the canvas:
export const init = ({ drawKey, config }) => {
drawKey(({ ctx, canvas }) => {
ctx.beginPath();
ctx.arc(15, 15, 10, 0, 2 * Math.PI);
ctx.strokeStyle = "yellow";
ctx.stroke();
});
};
onPress = (params) => void
This function fire when user click the button, this is the main piece of code to trigger something to happen, you can put anything here to trigger. The most basic hello world example:
export const onPress = () => {
else alert("hello world");
};
params: Object
name | Type | Description |
---|---|---|
config | object |
see config example bellow |
icon | string |
Icon string e.g "on" or "default" |
keyIndex | number |
The current index of key this plugin is assigned |
plugin | string |
Your plugin name as seen by webdeck |
setIcon | fn(string) |
see setIcon example bellow. |
title | string |
Subtitle given to you plugin. |
config: Object
The config is an object, and value can be set via the App controller. Example:
export const onPress = ({ config }) => {
if(config.myText) alert(config.myText);
else alert("no text provided");
};
export const App = ({ config, setConfig }) => {
return <input onChange={(e) => setConfig({ myText: e.target.value }) } value={config.myText|| ""} />
};
setIcon: fn(string) => void
🟡 INFO- This requires icons to be configured in
manifest
first.
This function set an icon to display, usually based on a condition:
export const onPress = ({ setIcon }) => {
if(true) setIcon("on");
};
onPressDown = (config) => void
{description}
onPressUp = (config) => void
{description}