mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
3.6 KiB
3.6 KiB
Flow.Launcher.Plugin Codemap
Responsibility
The Flow.Launcher.Plugin module serves as the Plugin SDK for Flow.Launcher. It defines the essential building blocks, interfaces, and models required for developers to create plugins. It acts as the formal contract between the Flow.Launcher core application and its extensibility layer, ensuring a stable and consistent API for search results, UI interaction, and system integration across different plugin languages (C#, Python, JavaScript, etc.).
Design
The SDK is built on several key architectural patterns:
- Interface-based Extensibility: The core functionality is driven by interfaces (
IPlugin,IAsyncPlugin) that define how plugins are queried. Optional features are exposed via specialized interfaces likeIContextMenu,ISettingProvider, andIReloadable. - Command/Action Pattern: The
Resultclass encapsulates its own execution logic throughActionandAsyncActiondelegates. This decouples the search engine from the specific logic of what happens when a result is clicked. - Contextual Initialization: Plugins receive their environment data and a reference to the application's capabilities via
PluginInitContextand theIPublicAPIinterface during theInitphase. - Marker Interfaces: The
IFeaturesinterface serves as a base for all optional capability interfaces, allowing the core system to dynamically discover and invoke plugin features.
Key Components:
Result: The primary model for search results, containing display data (Title, SubTitle, Icons) and execution delegates.Query: Represents the user's input, providing parsed search terms and action keywords.IPublicAPI: The interface providing plugins with access to global functions (logging, UI control, settings storage, HTTP utilities).PluginMetadata: Identity and configuration data extracted from the plugin'splugin.jsonmanifest.
Flow
The lifecycle and data flow of a plugin within Flow.Launcher follow a strictly defined sequence:
- Discovery & Load: The
PluginManager(in Core) scans thePluginsdirectory, parsesplugin.jsonintoPluginMetadata, and instantiates the plugin class. - Initialization: The
Init(PluginInitContext)method is called. The plugin stores theIPublicAPIreference for future use. - Query Loop: When the user types, the system constructs a
Queryobject. It then callsQuery(Query)(Sync) orQueryAsync(Query, CancellationToken)(Async) on all relevant plugins. - Result Aggregation: Plugins return a
List<Result>. The Core sorts these results based onScoreand displays them in the UI. - Action Execution: When a result is selected, the Core invokes
Result.ExecuteAsync(), which runs the plugin-defined delegate. - Feedback: Plugins use
IPublicAPIto trigger side-effects, such as changing the current query, showing notifications, or saving persistent settings.
Integration
- Search Integration: Plugins hook into the main launcher window by providing results that match user queries.
- UI Integration: Plugins provide custom settings panels via
ISettingProviderand additional context menu options viaIContextMenu. - Storage Integration: Plugins persist their state using
LoadSettingJsonStorage<T>(for configuration) orLoadCacheBinaryStorageAsync<T>(for high-performance data caching) provided by the API. - System Integration: Through
IPublicAPI, plugins can execute shell commands, manage the clipboard, download files, and subscribe to system-wide events like theme changes or keyboard hooks.