Skip to content

PluginNoticeComponent

Manages showing plugin notices. Automatically hides the previous notice when a new one is shown.

Import:

import { PluginNoticeComponent } from 'obsidian-dev-utils/obsidian/components/plugin-notice-component';

Signature:

export class PluginNoticeComponent extends ComponentEx

Extends: ComponentEx

Constructor

new PluginNoticeComponent(params: PluginNoticeComponentConstructorParams)

Creates a new plugin notice component.

Properties

PropertyTypeDescription
appAppThe Obsidian app instance.
pluginNamestringThe plugin name (shown as prefix in notices).

Methods

MethodReturnsDescription
[Symbol.dispose]()voidDisposes of the component.
(Inherited from ComponentEx)
addChild(component)TComponentAdds a child component.

Mirrors the native Component.addChild contract: if this component is already loaded, the child is loaded immediately, so child._loaded is set before this method returns even when this component has async load logic. The child's async tail (if any) is sequenced into the load promise so a later loadWithPromises call awaits it.
(Inherited from ComponentEx)
ensureLoaded()voidEnsures the component is loaded, throwing if it is not.

Use this to guard public methods that register teardown-bearing resources (via Component.register, Component.registerEvent, Component.registerDomEvent, etc.). Registering before load is unsafe: Component.unload is a no-op while the component is not loaded, so any teardown registered beforehand would never run if the component is unloaded without first being loaded.
(Inherited from ComponentEx)
load()voidLoads the component.
(Inherited from ComponentEx)
loadWithPromises()null | Promise<void>Loads the component with promises.

Unlike load, this method never rejects with an individual error: every failure raised by onloadAsync or a child's load is collected, and once everything settles the returned Promise rejects with a single AggregateError holding all of them. Non-Error throwables are normalized via ErrorWrapper.create.
(Inherited from ComponentEx)
onload()voidDismisses the permanent notice left over from a previous load (e.g. a previous plugin session) on load.
onloadAsync()Promise<void>Asynchronously loads the component.

Override to add async load logic, which is executed after Component.onload.
(Inherited from ComponentEx)
onunload()voidHides the current notice on unload, unless it is the permanent notice (which is meant to outlive the plugin).
registerDisposable(disposable)TDisposableRegisters a Disposable so it is disposed when this component unloads, and returns it unchanged.

The recurring "tie a disposable to the component's lifecycle, then keep using it" idiom: the disposable is disposed on Component.unload (or earlier, if the caller disposes it directly — dispose is expected to be idempotent). Guard with ensureLoaded at the call site when registering before load would be unsafe.
(Inherited from ComponentEx)
removeChild(component)TComponentRemoves a child component.
(Inherited from ComponentEx)
showNotice(message, options?)NoticeDisplays a notice message to the user.
showNoticeAfterDelay(params)PluginNoticeComponentDelayedNoticeShows a notice describing a long-running operation, but only once the operation has run for longer than PluginNoticeComponentShowNoticeAfterDelayParams.delayInMilliseconds — so operations that finish sooner never flash a notice. The notice stays until the returned Disposable is disposed (which also cancels the pending timer if it has not fired yet), so it can be used with using. When an PluginNoticeComponentShowNoticeAfterDelayParams.abortController is given, a Cancel button that aborts it is appended (and, being interactive, does not dismiss the notice).

Links to this page: