InitializePlugins wires the provided plugins into the application lifecycle.
(ctx context.Context, plugins []Plugin)
| 469 | |
| 470 | // InitializePlugins wires the provided plugins into the application lifecycle. |
| 471 | func (a *App) InitializePlugins(ctx context.Context, plugins []Plugin) error { |
| 472 | if a.pluginRegistry == nil { |
| 473 | a.pluginRegistry = newPluginRegistry() |
| 474 | } |
| 475 | if a.plugins == nil { |
| 476 | a.plugins = make(map[string]Plugin) |
| 477 | } |
| 478 | |
| 479 | for _, pl := range plugins { |
| 480 | if pl == nil { |
| 481 | continue |
| 482 | } |
| 483 | |
| 484 | id := pl.ID() |
| 485 | if id == "" { |
| 486 | return fmt.Errorf("plugin with empty ID cannot be registered") |
| 487 | } |
| 488 | |
| 489 | if _, exists := a.plugins[id]; exists { |
| 490 | return fmt.Errorf("plugin with ID %q already registered", id) |
| 491 | } |
| 492 | |
| 493 | if err := pl.Initialize(ctx, a, a.pluginRegistry); err != nil { |
| 494 | return fmt.Errorf("initialize plugin %q: %w", id, err) |
| 495 | } |
| 496 | |
| 497 | // Register plugin's modal page names for global keyboard handling |
| 498 | if modalPages := pl.ModalPageNames(); len(modalPages) > 0 { |
| 499 | a.pluginRegistry.RegisterModalPageNames(modalPages) |
| 500 | } |
| 501 | |
| 502 | a.plugins[id] = pl |
| 503 | } |
| 504 | |
| 505 | return nil |
| 506 | } |
| 507 | |
| 508 | // IsPluginModal checks if the given page name is registered as a plugin modal. |
| 509 | // This is used by the global keyboard handler to determine if global keybindings |
no test coverage detected