Pluggable application framework for building extensible desktop-like web applications with plugin architecture support
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Complete plugin lifecycle management including registration, activation, deactivation, and service resolution. The Application class provides comprehensive plugin management capabilities through its integrated PluginRegistry.
Register individual plugins or multiple plugins with the application.
/**
* Register a plugin with the application.
* @param plugin - The plugin to register
* @throws Error if a plugin with the same ID is already registered or has circular dependencies
*/
registerPlugin(plugin: IPlugin<this, any>): void;
/**
* Register multiple plugins with the application.
* @param plugins - The plugins to register
*/
registerPlugins(plugins: IPlugin<this, any>[]): void;Usage Examples:
import { Application } from "@lumino/application";
import { Widget } from "@lumino/widgets";
const app = new Application({ shell: new Widget() });
// Register a simple plugin
app.registerPlugin({
id: 'logger',
description: 'Logging functionality',
activate: () => {
console.log('Logger plugin activated');
return { log: (msg: string) => console.log(msg) };
}
});
// Register multiple plugins at once
app.registerPlugins([
{
id: 'plugin-a',
activate: () => console.log('Plugin A activated')
},
{
id: 'plugin-b',
activate: () => console.log('Plugin B activated')
}
]);Control when and how plugins are activated within the application.
/**
* Activate the plugin with the given ID.
* @param id - The ID of the plugin of interest
* @returns A promise which resolves when the plugin is activated or rejects if it cannot be activated
*/
activatePlugin(id: string): Promise<void>;
/**
* Activate all the deferred plugins.
* @returns A promise which resolves when each plugin is activated or rejects if one cannot be activated
*/
activateDeferredPlugins(): Promise<void>;Usage Examples:
// Activate a specific plugin
try {
await app.activatePlugin('my-plugin');
console.log('Plugin activated successfully');
} catch (error) {
console.error('Failed to activate plugin:', error);
}
// Activate all deferred plugins
await app.activateDeferredPlugins();
console.log('All deferred plugins activated');Deactivate plugins and their dependents when they support deactivation.
/**
* Deactivate the plugin and its downstream dependents if and only if the
* plugin and its dependents all support deactivate.
* @param id - The ID of the plugin of interest
* @returns A list of IDs of downstream plugins deactivated with this one
*/
deactivatePlugin(id: string): Promise<string[]>;
/**
* Deregister a plugin with the application.
* @param id - The ID of the plugin of interest
* @param force - Whether to deregister the plugin even if it is active
*/
deregisterPlugin(id: string, force?: boolean): void;Usage Example:
// Deactivate a plugin and its dependents
const deactivatedPlugins = await app.deactivatePlugin('my-plugin');
console.log('Deactivated plugins:', deactivatedPlugins);
// Deregister a plugin
app.deregisterPlugin('old-plugin', true); // Force deregistration even if activeQuery the state and properties of registered plugins.
/**
* Test whether a plugin is registered with the application.
* @param id - The ID of the plugin of interest
* @returns true if the plugin is registered, false otherwise
*/
hasPlugin(id: string): boolean;
/**
* Test whether a plugin is activated with the application.
* @param id - The ID of the plugin of interest
* @returns true if the plugin is activated, false otherwise
*/
isPluginActivated(id: string): boolean;
/**
* List the IDs of the plugins registered with the application.
* @returns A new array of the registered plugin IDs
*/
listPlugins(): string[];
/**
* Get a plugin description.
* @param id - The ID of the plugin of interest
* @returns The plugin description or empty string if not found
*/
getPluginDescription(id: string): string;Usage Examples:
// Check if a plugin exists
if (app.hasPlugin('my-plugin')) {
console.log('Plugin is registered');
}
// Check if a plugin is active
if (app.isPluginActivated('my-plugin')) {
console.log('Plugin is currently active');
}
// Get all registered plugins
const pluginIds = app.listPlugins();
console.log('Registered plugins:', pluginIds);
// Get plugin description
const description = app.getPluginDescription('my-plugin');
console.log('Plugin description:', description);The IPlugin interface defines the structure for all plugins registered with the application.
interface IPlugin<T = any, U = any> {
/** Unique identifier for the plugin */
id: string;
/** Optional description of the plugin */
description?: string;
/** Function called when the plugin is activated */
activate: (application: T, ...args: any[]) => U | Promise<U>;
/** Optional function called when the plugin is deactivated */
deactivate?: (application: T, ...args: any[]) => void | Promise<void>;
/** Whether the plugin should be activated automatically on startup */
autoStart?: boolean | 'defer';
/** Token for the service this plugin provides */
provides?: Token<U>;
/** Array of tokens for services this plugin requires */
requires?: Token<any>[];
/** Array of tokens for services this plugin optionally uses */
optional?: Token<any>[];
}Plugin Configuration Examples:
import { Token } from "@lumino/coreutils";
// Service tokens
const ILoggerService = new Token<ILoggerService>('ILoggerService');
const IConfigService = new Token<IConfigService>('IConfigService');
// Plugin providing a service
const loggerPlugin: IPlugin<Application> = {
id: 'logger',
description: 'Application logging service',
provides: ILoggerService,
activate: (app: Application) => {
return {
log: (message: string) => console.log(`[LOG] ${message}`),
error: (message: string) => console.error(`[ERROR] ${message}`)
};
}
};
// Plugin requiring services
const featurePlugin: IPlugin<Application> = {
id: 'feature',
description: 'Feature that uses logging',
requires: [ILoggerService],
optional: [IConfigService],
activate: (app: Application, logger: any, config?: any) => {
logger.log('Feature plugin activated');
if (config) {
logger.log('Configuration available');
}
return {};
}
};
// Deferred plugin (activated later)
const deferredPlugin: IPlugin<Application> = {
id: 'deferred-feature',
autoStart: 'defer',
activate: (app: Application) => {
console.log('Deferred plugin activated');
return {};
}
};