Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Plugins꞉ 1. The basics

Daniel Chýlek edited this page Apr 25, 2018 · 14 revisions

All custom plugins are placed in the plugins/user folder. A plugin is a folder that contains a .meta file, and then either browser.js or notification.js, or both based on where the plugin should run.

Tips

View the official plugin source codes for working examples. When debugging a plugin, download dev tools to use the JavaScript console in the app.


.meta

The metadata file contains information about the plugin, which is displayed in the Plugins screen and used for compatibility checking.

Structure of the .meta file

[name]
Example plugin

[description]
This is an example plugin.
It does stuff.

[author]
chylex

[version]
1.0

[website]
https://chylex.com

[configfile]
configuration.js

[configdefault]
configuration.default.js

[requires]
1.2.3
  • [name] is required, all other tags are optional
    • should use sentence case as shown in the example
  • [description] should contain some text that describes the plugin
    • can have any number of lines, but only up to 3 will be displayed without a scroll bar
  • [configfile] points to the file user can configure
    • if the entry exists, there will be a Configure button (disabled if the file itself does not exist)
  • [configdefault] points to the file with default configuration
    • if both this and [configfile] exist, TweetDuck will copy the default configuration file to the file specified by [configfile], as long as this would not overwrite an existing file
  • [requires] specifies the minimum required version of TweetDuck to run the plugin
    • omit to allow the plugin to run on any version of TweetDuck

browser.js

This file is a script that runs in the main browser window.

Structure of the browser.js file

constructor(){
  super({
    // reloads page when manually enabled or disabled; not recommended, as it's
    // always better when a plugin can be toggled seamlessly without reloading,
    // but the option is available if needed (default: false)
    requiresPageReload: true
  });
}

enabled(){
  // runs immediately after constructor if the plugin is enabled (can modify the
  // head tag or add overlay elements to the body tag), or when manually enabled
  // in the program

  // prepare variables and functions, create stylesheets
}

ready(){
  // runs once the main app (.js-app div element) is displayed (the columns
  // themselves may not be loaded yet); will also be called immediately after
  // enabled() if the plugin is manually enabled after the page has loaded

  // modify the contents as the page has finished loading, add event listeners
}

configure(){
  // if this method is present, the plugin will have a 'Configure' button
  // in the UI, which calls this method when clicked (requires version 1.13+)
}

disabled(){
  // runs when the plugin is manually disabled in the program

  // remove event listeners and revert everything to original state
  // not necessary to use this if 'requiresPageReload' is set to true
}

All functions are optional. If you implement constructor(), please DO NOT run any code in it besides the super call with plugin settings, since the constructor runs even when the plugin is disabled.

Tips

Please, make sure your plugin is functional when disabled and re-enabled in the program, and also does not break if the user logs out and logs in again.

The requiresPageReload property is usually not necessary. Even some changes to the layout are immediate and do not require reloading the page, but it has to be tested individually for each plugin.

If your plugin supports being disabled/enabled without reloading the page, use the $$ prefix for properties you want to remain after the plugin is disabled and re-enabled (for example this.$$property = 10). All other properties are automatically deleted starting from version 1.8.


notification.js

This file is a script that runs in the notification popup window.

Structure of the notification.js file

constructor(){
  super({
    // currently no options
  });
}

run(){
  // runs every time a new notification is displayed
}

Implementing constructor() is not necessary as there are currently no options plugins can use.

Tips

Do not create global variables or functions since the entire page is regenerated, and all plugins are reconstructed every time a new notification is displayed.

View the full collection of tips.