Plugin
Official
Base class for all plugins.
Import:
import { Plugin } from 'obsidian';Signature:
export class Plugin extends ComponentExtends: Component
Constructor
new Plugin(app: App, manifest: PluginManifest)Constructor.
To extract the constructor type, use ExtractConstructor<Plugin>.
Properties
| Property | Type | Description | |
|---|---|---|---|
| _children | Component[] | Child Components attached to current component, will be unloaded on unloading parent component. (Inherited from Component) | |
| _events | EventRef[] | Events that are attached to the current component, will be detached on unloading parent component. (Inherited from Component) | |
| _lastDataModifiedTime | number | The last time the plugin's data was modified. | |
| _loaded | boolean | Whether the component and its children are loaded. (Inherited from Component) | |
| _userDisabled | boolean | Whether the plugin was disabled by the user. | |
| app | App | The Obsidian app instance. | |
| manifest | PluginManifest | The plugin manifest. | |
| onConfigFileChange | Debouncer<[], Promise<void>> | Debounced handler for config file changes. | |
| settings? | unknown | obsidian#Plugin settings. Assign loaded data here in onload. Declare a concrete type on your subclass to type it. | |
| settingTab? | SettingTab | The plugin's registered setting tab, if any. |
Methods
| Method | Returns | Description | |
|---|---|---|---|
| _onConfigFileChange() | Promise<void> | Internal handler invoked when the plugin's config file changes on disk. | |
| addChild(component) | T | Adds a child component, loading it if this component is loaded. (Inherited from Component) | |
| addCommand(command) | Command | Register a command globally. Registered commands will be available from the https://help.obsidian.md/Plugins/Command+palette Command palette. The command id and name will be automatically prefixed with this plugin's id and name. | |
| addRibbonIcon(icon, title, callback) | HTMLElement | Adds a ribbon icon to the left bar. | |
| addSettingTab(settingTab) | void | Register a settings tab, which allows users to change settings. | |
| addStatusBarItem() | HTMLElement | Adds a status bar item to the bottom of the app. Not available on mobile. | |
| getModifiedTime() | Promise<number> | Gets the latest modification time across the plugin's files. | |
| load() | void | Load this component and its children. (Inherited from Component) | |
| loadCSS() | Promise<void> | Loads the plugin's styles.css into the document. | |
| loadData() | Promise<any> | Load settings data from disk. Data is stored in data.json in the plugin folder. | |
| onExternalSettingsChange() | any | Called when the data.json file is modified on disk externally from Obsidian. This usually means that a Sync service or external program has modified the plugin settings.Implement this method to reload plugin settings when they have changed externally. | |
| onload() | Promise<void> | void | Called when the plugin is loaded. | |
| onunload() | void | Override this to unload your component (Inherited from Component) | |
| onUserEnable() | void | Perform any initial setup code. The user has explicitly interacted with the plugin so its safe to engage with the user. If your plugin registers a custom view, you can open it here. | |
| register(cb) | void | Registers a callback to be called when unloading. (Inherited from Component) | |
| registerBasesView(viewId, registration) | boolean | Register a Base view handler that can be used to render data from property queries. | |
| registerCliHandler(command, description, flags, handler) | void | Register a CLI handler to handle a command from the CLI. obsidian#Command IDs must be globally unique. Attempting to register a command that is already registered will throw an Error.Use the format <plugin-id> for your default command, and <plugin-id>:<action> for sub-commands and actions. | |
| registerCodeMirror(callback) | void | Registers a legacy CodeMirror 5 callback. No-op in current Obsidian versions. | |
| registerDomEvent(el, type, callback, options?) | void | Registers a DOM event to be detached when unloading. (Inherited from Component) | |
| registerDomEvent(el, type, callback, options?) | void | Registers a DOM event to be detached when unloading (Inherited from Component) | |
| registerDomEvent(el, type, callback, options?) | void | Registers a DOM event to be detached when unloading (Inherited from Component) | |
| registerEditorExtension(extension) | void | Registers a CodeMirror 6 extension. To reconfigure cm6 extensions for a plugin on the fly, an array should be passed in, and modified dynamically. Once this array is modified, calling obsidian#Workspace.updateOptions will apply the changes. | |
| registerEditorSuggest(editorSuggest) | void | Register an obsidian#EditorSuggest which can provide live suggestions while the user is typing. | |
| registerEvent(eventRef) | void | Registers an event to be detached when unloading. (Inherited from Component) | |
| registerExtensions(extensions, viewType) | void | Register a set of extensions for a view type. | |
| registerGlobalFunc(func) | void | Registers a global Bases formula function, unregistered automatically on unload. | |
| registerHoverLinkSource(id, info) | void | Registers a view with the 'Page preview' core plugin as an emitter of the 'hover-link' event. | |
| registerInstanceFunc(type, func) | void | Registers a Bases formula function for a specific value type, unregistered automatically on unload. | |
| registerInterval(id) | number | Registers an interval (from setInterval) to be cancelled when unloading. Use window.setInterval instead of setInterval to avoid TypeScript confusing between NodeJS vs Browser API(Inherited from Component) | |
| registerMarkdownCodeBlockProcessor(language, handler, sortOrder?) | MarkdownPostProcessor | Register a special post processor that handles fenced code given a language and a handler. This special post processor takes care of removing the <pre><code> and create a <div> that will be passed to the handler, and is expected to be filled with custom elements. | |
| registerMarkdownPostProcessor(postProcessor, sortOrder?) | MarkdownPostProcessor | Registers a post processor, to change how the document looks in reading mode. | |
| registerObsidianProtocolHandler(action, handler) | void | Register a handler for obsidian:// URLs. | |
| registerScopeEvent(keymapEventHandler) | void | Register a scope keymap event handler to be removed on unload. (Inherited from Component) | |
| registerView(type, viewCreator) | void | Register a custom view. | |
| removeChild(component) | T | Removes a child component, unloading it. (Inherited from Component) | |
| removeCommand(commandId) | void | Manually remove a command from the list of global commands. This should not be needed unless your plugin registers commands dynamically. | |
| saveData(data) | Promise<void> | Write settings data to disk. Data is stored in data.json in the plugin folder. | |
| unload() | void | Override this to unload your component. (Inherited from Component) |
Links to this page: