mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-10 03:03:37 +02:00
Initialize plugins in PluginManager::new and fix CLI release deps
This commit is contained in:
6
.github/workflows/release-cli-npm.yml
vendored
6
.github/workflows/release-cli-npm.yml
vendored
@@ -27,9 +27,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: lts/*
|
node-version: lts/*
|
||||||
|
|
||||||
|
- name: Install Rust stable
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Install wasm-pack
|
||||||
|
run: npm run bootstrap:install-wasm-pack
|
||||||
|
|
||||||
- name: Build plugin assets
|
- name: Build plugin assets
|
||||||
run: |
|
run: |
|
||||||
npm run build-plugins
|
npm run build-plugins
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ use yaak_crypto::manager::EncryptionManager;
|
|||||||
use yaak_models::blob_manager::BlobManager;
|
use yaak_models::blob_manager::BlobManager;
|
||||||
use yaak_models::db_context::DbContext;
|
use yaak_models::db_context::DbContext;
|
||||||
use yaak_models::query_manager::QueryManager;
|
use yaak_models::query_manager::QueryManager;
|
||||||
use yaak_plugins::bootstrap;
|
|
||||||
use yaak_plugins::events::PluginContext;
|
use yaak_plugins::events::PluginContext;
|
||||||
use yaak_plugins::manager::PluginManager;
|
use yaak_plugins::manager::PluginManager;
|
||||||
|
|
||||||
@@ -52,7 +51,7 @@ impl CliContext {
|
|||||||
.expect("Failed to prepare embedded plugin runtime")
|
.expect("Failed to prepare embedded plugin runtime")
|
||||||
});
|
});
|
||||||
|
|
||||||
match bootstrap::create_and_initialize_manager(
|
match PluginManager::new(
|
||||||
vendored_plugin_dir,
|
vendored_plugin_dir,
|
||||||
installed_plugin_dir,
|
installed_plugin_dir,
|
||||||
node_bin_path,
|
node_bin_path,
|
||||||
@@ -63,7 +62,7 @@ impl CliContext {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(plugin_manager) => Some(plugin_manager),
|
Ok(plugin_manager) => Some(Arc::new(plugin_manager)),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Warning: Failed to initialize plugins: {err}");
|
eprintln!("Warning: Failed to initialize plugins: {err}");
|
||||||
None
|
None
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ use yaak_plugins::api::{
|
|||||||
PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse, check_plugin_updates,
|
PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse, check_plugin_updates,
|
||||||
search_plugins,
|
search_plugins,
|
||||||
};
|
};
|
||||||
use yaak_plugins::bootstrap;
|
|
||||||
use yaak_plugins::events::PluginContext;
|
use yaak_plugins::events::PluginContext;
|
||||||
use yaak_plugins::install::{delete_and_uninstall, download_and_install};
|
use yaak_plugins::install::{delete_and_uninstall, download_and_install};
|
||||||
use yaak_plugins::manager::PluginManager;
|
use yaak_plugins::manager::PluginManager;
|
||||||
@@ -274,7 +273,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
|||||||
// Create plugin manager asynchronously
|
// Create plugin manager asynchronously
|
||||||
let app_handle_clone = app_handle.clone();
|
let app_handle_clone = app_handle.clone();
|
||||||
tauri::async_runtime::block_on(async move {
|
tauri::async_runtime::block_on(async move {
|
||||||
let manager = bootstrap::create_and_initialize_manager(
|
let manager = PluginManager::new(
|
||||||
vendored_plugin_dir,
|
vendored_plugin_dir,
|
||||||
installed_plugin_dir,
|
installed_plugin_dir,
|
||||||
node_bin_path,
|
node_bin_path,
|
||||||
|
|||||||
@@ -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)
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,6 @@
|
|||||||
//! by yaak-app's plugins_ext module.
|
//! by yaak-app's plugins_ext module.
|
||||||
|
|
||||||
pub mod api;
|
pub mod api;
|
||||||
pub mod bootstrap;
|
|
||||||
mod checksum;
|
mod checksum;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod events;
|
pub mod events;
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ use tokio::sync::mpsc::error::TrySendError;
|
|||||||
use tokio::sync::{Mutex, mpsc, oneshot};
|
use tokio::sync::{Mutex, mpsc, oneshot};
|
||||||
use tokio::time::{Instant, timeout};
|
use tokio::time::{Instant, timeout};
|
||||||
use yaak_models::models::Plugin;
|
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::Error::RenderError;
|
||||||
use yaak_templates::error::Result as TemplateResult;
|
use yaak_templates::error::Result as TemplateResult;
|
||||||
|
|
||||||
@@ -61,14 +62,18 @@ impl PluginManager {
|
|||||||
/// * `installed_plugin_dir` - Path to installed plugins directory
|
/// * `installed_plugin_dir` - Path to installed plugins directory
|
||||||
/// * `node_bin_path` - Path to the yaaknode binary
|
/// * `node_bin_path` - Path to the yaaknode binary
|
||||||
/// * `plugin_runtime_main` - Path to the plugin runtime index.cjs
|
/// * `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)
|
/// * `dev_mode` - Whether the app is in dev mode (affects plugin loading)
|
||||||
pub async fn new(
|
pub async fn new(
|
||||||
vendored_plugin_dir: PathBuf,
|
vendored_plugin_dir: PathBuf,
|
||||||
installed_plugin_dir: PathBuf,
|
installed_plugin_dir: PathBuf,
|
||||||
node_bin_path: PathBuf,
|
node_bin_path: PathBuf,
|
||||||
plugin_runtime_main: PathBuf,
|
plugin_runtime_main: PathBuf,
|
||||||
|
query_manager: &QueryManager,
|
||||||
|
plugin_context: &PluginContext,
|
||||||
dev_mode: bool,
|
dev_mode: bool,
|
||||||
) -> PluginManager {
|
) -> Result<PluginManager> {
|
||||||
let (events_tx, mut events_rx) = mpsc::channel(2048);
|
let (events_tx, mut events_rx) = mpsc::channel(2048);
|
||||||
let (kill_server_tx, kill_server_rx) = tokio::sync::watch::channel(false);
|
let (kill_server_tx, kill_server_rx) = tokio::sync::watch::channel(false);
|
||||||
let (killed_tx, killed_rx) = oneshot::channel();
|
let (killed_tx, killed_rx) = oneshot::channel();
|
||||||
@@ -151,12 +156,40 @@ impl PluginManager {
|
|||||||
&kill_server_rx,
|
&kill_server_rx,
|
||||||
killed_tx,
|
killed_tx,
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
info!("Waiting for plugins to initialize");
|
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)
|
/// Get the vendored plugin directory path (resolves dev mode path if applicable)
|
||||||
|
|||||||
Reference in New Issue
Block a user