Initialize plugins in PluginManager::new and fix CLI release deps

This commit is contained in:
Gregory Schier
2026-02-22 15:06:55 -08:00
parent 50c7992b42
commit 4aef826a80
6 changed files with 48 additions and 78 deletions

View File

@@ -27,9 +27,15 @@ jobs:
with:
node-version: lts/*
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: Install dependencies
run: npm ci
- name: Install wasm-pack
run: npm run bootstrap:install-wasm-pack
- name: Build plugin assets
run: |
npm run build-plugins

View File

@@ -8,7 +8,6 @@ use yaak_crypto::manager::EncryptionManager;
use yaak_models::blob_manager::BlobManager;
use yaak_models::db_context::DbContext;
use yaak_models::query_manager::QueryManager;
use yaak_plugins::bootstrap;
use yaak_plugins::events::PluginContext;
use yaak_plugins::manager::PluginManager;
@@ -52,7 +51,7 @@ impl CliContext {
.expect("Failed to prepare embedded plugin runtime")
});
match bootstrap::create_and_initialize_manager(
match PluginManager::new(
vendored_plugin_dir,
installed_plugin_dir,
node_bin_path,
@@ -63,7 +62,7 @@ impl CliContext {
)
.await
{
Ok(plugin_manager) => Some(plugin_manager),
Ok(plugin_manager) => Some(Arc::new(plugin_manager)),
Err(err) => {
eprintln!("Warning: Failed to initialize plugins: {err}");
None

View File

@@ -27,7 +27,6 @@ use yaak_plugins::api::{
PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse, check_plugin_updates,
search_plugins,
};
use yaak_plugins::bootstrap;
use yaak_plugins::events::PluginContext;
use yaak_plugins::install::{delete_and_uninstall, download_and_install};
use yaak_plugins::manager::PluginManager;
@@ -274,7 +273,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
// Create plugin manager asynchronously
let app_handle_clone = app_handle.clone();
tauri::async_runtime::block_on(async move {
let manager = bootstrap::create_and_initialize_manager(
let manager = PluginManager::new(
vendored_plugin_dir,
installed_plugin_dir,
node_bin_path,

View File

@@ -1,66 +0,0 @@
use crate::error::{Error, Result};
use crate::events::PluginContext;
use crate::manager::PluginManager;
use std::path::PathBuf;
use std::sync::Arc;
use yaak_models::models::Plugin;
use yaak_models::query_manager::QueryManager;
use yaak_models::util::UpdateSource;
/// Create a plugin manager and initialize all registered plugins.
///
/// This performs:
/// 1. Plugin runtime startup (`PluginManager::new`)
/// 2. Bundled plugin registration in DB (if missing)
/// 3. Plugin initialization from DB
pub async fn create_and_initialize_manager(
vendored_plugin_dir: PathBuf,
installed_plugin_dir: PathBuf,
node_bin_path: PathBuf,
plugin_runtime_main: PathBuf,
query_manager: &QueryManager,
plugin_context: &PluginContext,
dev_mode: bool,
) -> Result<Arc<PluginManager>> {
let plugin_manager = Arc::new(
PluginManager::new(
vendored_plugin_dir,
installed_plugin_dir,
node_bin_path,
plugin_runtime_main,
dev_mode,
)
.await,
);
let bundled_dirs = plugin_manager.list_bundled_plugin_dirs().await?;
let db = query_manager.connect();
for dir in bundled_dirs {
if db.get_plugin_by_directory(&dir).is_none() {
db.upsert_plugin(
&Plugin {
directory: dir,
enabled: true,
url: None,
..Default::default()
},
&UpdateSource::Background,
)?;
}
}
let plugins = db.list_plugins()?;
drop(db);
let init_errors = plugin_manager.initialize_all_plugins(plugins, plugin_context).await;
if !init_errors.is_empty() {
let joined = init_errors
.into_iter()
.map(|(dir, err)| format!("{dir}: {err}"))
.collect::<Vec<_>>()
.join("; ");
return Err(Error::PluginErr(format!("Failed to initialize plugin(s): {joined}")));
}
Ok(plugin_manager)
}

View File

@@ -7,7 +7,6 @@
//! by yaak-app's plugins_ext module.
pub mod api;
pub mod bootstrap;
mod checksum;
pub mod error;
pub mod events;

View File

@@ -34,7 +34,8 @@ use tokio::sync::mpsc::error::TrySendError;
use tokio::sync::{Mutex, mpsc, oneshot};
use tokio::time::{Instant, timeout};
use yaak_models::models::Plugin;
use yaak_models::util::generate_id;
use yaak_models::query_manager::QueryManager;
use yaak_models::util::{UpdateSource, generate_id};
use yaak_templates::error::Error::RenderError;
use yaak_templates::error::Result as TemplateResult;
@@ -61,14 +62,18 @@ impl PluginManager {
/// * `installed_plugin_dir` - Path to installed plugins directory
/// * `node_bin_path` - Path to the yaaknode binary
/// * `plugin_runtime_main` - Path to the plugin runtime index.cjs
/// * `query_manager` - Query manager for bundled plugin registration and loading
/// * `plugin_context` - Context to use while initializing plugins
/// * `dev_mode` - Whether the app is in dev mode (affects plugin loading)
pub async fn new(
vendored_plugin_dir: PathBuf,
installed_plugin_dir: PathBuf,
node_bin_path: PathBuf,
plugin_runtime_main: PathBuf,
query_manager: &QueryManager,
plugin_context: &PluginContext,
dev_mode: bool,
) -> PluginManager {
) -> Result<PluginManager> {
let (events_tx, mut events_rx) = mpsc::channel(2048);
let (kill_server_tx, kill_server_rx) = tokio::sync::watch::channel(false);
let (killed_tx, killed_rx) = oneshot::channel();
@@ -151,12 +156,40 @@ impl PluginManager {
&kill_server_rx,
killed_tx,
)
.await
.unwrap();
.await?;
info!("Waiting for plugins to initialize");
init_plugins_task.await.unwrap();
init_plugins_task.await.map_err(|e| PluginErr(e.to_string()))?;
plugin_manager
let bundled_dirs = plugin_manager.list_bundled_plugin_dirs().await?;
let db = query_manager.connect();
for dir in bundled_dirs {
if db.get_plugin_by_directory(&dir).is_none() {
db.upsert_plugin(
&Plugin {
directory: dir,
enabled: true,
url: None,
..Default::default()
},
&UpdateSource::Background,
)?;
}
}
let plugins = db.list_plugins()?;
drop(db);
let init_errors = plugin_manager.initialize_all_plugins(plugins, plugin_context).await;
if !init_errors.is_empty() {
let joined = init_errors
.into_iter()
.map(|(dir, err)| format!("{dir}: {err}"))
.collect::<Vec<_>>()
.join("; ");
return Err(PluginErr(format!("Failed to initialize plugin(s): {joined}")));
}
Ok(plugin_manager)
}
/// Get the vendored plugin directory path (resolves dev mode path if applicable)