(state: RuntimeState, plugin: PluginEntry, persist: boolean)
| 514 | } |
| 515 | |
| 516 | async function activatePluginEntry(state: RuntimeState, plugin: PluginEntry, persist: boolean) { |
| 517 | plugin.enabled = true |
| 518 | if (persist) writePluginEnabledState(state.api, plugin.id, true) |
| 519 | if (plugin.scope) { |
| 520 | state.view.update({ status: listPluginStatus(state) }) |
| 521 | return true |
| 522 | } |
| 523 | |
| 524 | const scope = createPluginScope(plugin.load, plugin.id, state.dispose_timeout_ms) |
| 525 | const api = pluginApi(state, plugin, scope, plugin.id) |
| 526 | const ok = await Promise.resolve() |
| 527 | .then(async () => { |
| 528 | await syncPluginThemes(plugin) |
| 529 | await plugin.plugin(api, plugin.load.options, plugin.meta) |
| 530 | return true |
| 531 | }) |
| 532 | .catch((error) => { |
| 533 | fail("failed to initialize tui plugin", { |
| 534 | path: plugin.load.spec, |
| 535 | id: plugin.id, |
| 536 | error, |
| 537 | }) |
| 538 | return false |
| 539 | }) |
| 540 | |
| 541 | if (!ok) { |
| 542 | await scope.dispose() |
| 543 | state.view.update({ status: listPluginStatus(state) }) |
| 544 | return false |
| 545 | } |
| 546 | |
| 547 | if (!plugin.enabled) { |
| 548 | await scope.dispose() |
| 549 | state.view.update({ status: listPluginStatus(state) }) |
| 550 | return true |
| 551 | } |
| 552 | |
| 553 | plugin.scope = scope |
| 554 | state.view.update({ status: listPluginStatus(state) }) |
| 555 | return true |
| 556 | } |
| 557 | |
| 558 | async function activatePluginById(state: RuntimeState | undefined, id: string, persist: boolean) { |
| 559 | if (!state) return false |
no test coverage detected