mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-07-26 09:23:50 +00:00
- Add @super-productivity/plugin-api package with TypeScript definitions - Define core plugin interfaces, types, and manifest structure - Add plugin hooks system for event-driven architecture - Create plugin API type definitions and constants - Add documentation and development guidelines
2.8 KiB
2.8 KiB
Plugin Lazy Loading Implementation
Overview
Implemented lazy loading for the plugin system to improve startup performance by deferring plugin code loading until actually needed.
Key Changes
1. Plugin State Management
- Added
PluginStatemodel to track loading status:not-loaded: Plugin discovered but code not loadedloading: Plugin code is being loadedloaded: Plugin fully loaded and readyerror: Plugin failed to load
2. Discovery Phase
initializePlugins()now only discovers plugins without loading code- Built-in plugins: Load manifests from predefined paths
- Uploaded plugins: Parse cached manifests from IndexedDB
- Creates plugin states for all discovered plugins
3. On-Demand Loading
activatePlugin(pluginId): Loads plugin code when needed- Automatically loads plugins with registered hooks at startup
- Lazy loads when plugin is enabled in UI
- Lazy loads when plugin is set as active side panel
4. UI Updates
- Plugin management component shows loading states
- Loading spinner animation while plugins are being activated
- Controls disabled during loading to prevent race conditions
- Real-time updates via plugin states observable
5. Side Panel Integration
setActiveSidePanelPlugin()now async to handle lazy loading- Automatically activates plugins when setting them as side panel
- Transparent lazy loading for side panel activation
Benefits
- Faster Startup: Only manifests loaded initially, not full plugin code
- Memory Efficiency: Plugins only consume memory when actually used
- Better UX: Users see immediate UI with loading states
- Scalability: Can handle many plugins without startup penalty
Migration Notes
- Backward compatible - existing plugins work without changes
setActiveSidePanelPlugin()is now async but handles null synchronously- Plugin instances created on-demand maintain same API
Technical Details
State Flow
Discovery → not-loaded → [user enables] → loading → loaded
↓ ↓
[error] [error]
↓ ↓
error error
Loading Triggers
- User enables plugin in UI
- Plugin has registered hooks (loaded at startup)
- Plugin set as active side panel
- Explicit
activatePlugin()call
Key Files Modified
plugin-state.model.ts: New state modelplugin.service.ts: Lazy loading logicplugin-management.component.ts: UI updatesplugin-management.component.html: Loading indicators
Future Improvements
- Preload plugins in background after initial UI render
- Cache compiled plugin code for faster subsequent loads
- Plugin dependency resolution for ordered loading
- Memory management - unload unused plugins after timeout