From 4aef826a8024d220c2ebfec8f1603ade60b0a985 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sun, 22 Feb 2026 15:06:55 -0800 Subject: [PATCH] Initialize plugins in PluginManager::new and fix CLI release deps --- .github/workflows/release-cli-npm.yml | 6 +++ crates-cli/yaak-cli/src/context.rs | 5 +- crates-tauri/yaak-app/src/plugins_ext.rs | 3 +- crates/yaak-plugins/src/bootstrap.rs | 66 ------------------------ crates/yaak-plugins/src/lib.rs | 1 - crates/yaak-plugins/src/manager.rs | 45 +++++++++++++--- 6 files changed, 48 insertions(+), 78 deletions(-) delete mode 100644 crates/yaak-plugins/src/bootstrap.rs diff --git a/.github/workflows/release-cli-npm.yml b/.github/workflows/release-cli-npm.yml index 8246faf2..69b23f47 100644 --- a/.github/workflows/release-cli-npm.yml +++ b/.github/workflows/release-cli-npm.yml @@ -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 diff --git a/crates-cli/yaak-cli/src/context.rs b/crates-cli/yaak-cli/src/context.rs index 59b065a6..af3753f4 100644 --- a/crates-cli/yaak-cli/src/context.rs +++ b/crates-cli/yaak-cli/src/context.rs @@ -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 diff --git a/crates-tauri/yaak-app/src/plugins_ext.rs b/crates-tauri/yaak-app/src/plugins_ext.rs index 89172474..ced6bca8 100644 --- a/crates-tauri/yaak-app/src/plugins_ext.rs +++ b/crates-tauri/yaak-app/src/plugins_ext.rs @@ -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() -> TauriPlugin { // 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, diff --git a/crates/yaak-plugins/src/bootstrap.rs b/crates/yaak-plugins/src/bootstrap.rs deleted file mode 100644 index 797735d7..00000000 --- a/crates/yaak-plugins/src/bootstrap.rs +++ /dev/null @@ -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> { - 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::>() - .join("; "); - return Err(Error::PluginErr(format!("Failed to initialize plugin(s): {joined}"))); - } - - Ok(plugin_manager) -} diff --git a/crates/yaak-plugins/src/lib.rs b/crates/yaak-plugins/src/lib.rs index b82414d1..510756d0 100644 --- a/crates/yaak-plugins/src/lib.rs +++ b/crates/yaak-plugins/src/lib.rs @@ -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; diff --git a/crates/yaak-plugins/src/manager.rs b/crates/yaak-plugins/src/manager.rs index 66c854d6..d7b30a08 100644 --- a/crates/yaak-plugins/src/manager.rs +++ b/crates/yaak-plugins/src/manager.rs @@ -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 { 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::>() + .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)