-
Notifications
You must be signed in to change notification settings - Fork 1
Plugins
TMCP supports custom plugins, and includes a few which you can reference as an example. The included plugins also serve to give TMCP enough base functionality to make it a useful tool out of the box. Without plugins, TMCP would have no results to search for, and would thus be pretty useless.
Plugins are powered by JavaScript, and optionally some CSS.
Plugins are located in the plugins folder that exists next to the application executable. When you download the program, it will come with this folder inside of the zip file already. You can easily access this folder by clicking on the "Open plugins folder" button in the "Extras" section of the settings page.
Each folder inside plugins represents a theme, with the structure looking something like this:
plugins
└─── plugin-name
├── config.json
├── my-plugin-script.js
├── my-plugin-styles.css
└── my-plugin-icon.png
TMCP will automatically detect plugins placed here whenever it loads.
Every plugin must have a config.json file and at least one JS file. Your config file should look like this:
{
"name": "My Plugin",
"description": "This plugin is really great because I said so.",
"icon": "./my-plugin-icon.png",
"scripts": [
"my-plugin-script.js"
],
"styles": [
"my-plugin-styles.css"
]
}Every plugin requires a name, a description, and at least one JS file in the scripts array. The styles array and icon are optional.
Your icon will appear next to your plugin in the settings page, and will be the default icon that appears next to search results that your plugin has provided. No matter what size the image is, it will only ever be displayed at 16x16, so no need to make one that is overly detailed.
You'll want to have the dev tools open in order to effectively develop your plugin.
If you want to have TMCP recognize changes to your plugin without having to restart, you can click on "Reload TMCP" in the "Extras" section of the settings page.
To add a new item that can show up in the results of TMCP's search, you can use tmcp.addItem() like so:
tmcp.addItem({
text: 'Search result',
action: () => {
console.log('You hit enter on me!')
},
display: {
type: 'markdown',
content: 'Hey there! *Thanks* for searching!'
}
});This defines a static search result to be added to TMCP, and is good method for adding static information, tools, and anything else that won't change later on.
If you want to have dynamic search results in your plugin, you'll need to use the tmcp.onQuery() method:
tmcp.onQuery((query, addItem) => {
if (query.includes('hello')) {
addItem({
text: 'Hello World',
action: () => console.log('Hello World!')
});
}
});The tmcp.onQuery() method allows you to register a callback (one per plugin) that gets called whenever the user updates their query. This will then allow you to react to that query, and dynamically add items to the result with the provided callback. The first argument (query) is a string containing whatever the user currently has typed in. The second argument (addItem) is a special function that allows you to add a volatile item to the search results. Items added this way will be removed whenever the user updates their search query.
Continue reading about advanced topics or check out the plugin API page.