Skip to content

Commit 4aef826

Browse files
committed
Initialize plugins in PluginManager::new and fix CLI release deps
1 parent 50c7992 commit 4aef826

File tree

6 files changed

+48
-78
lines changed

6 files changed

+48
-78
lines changed

.github/workflows/release-cli-npm.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ jobs:
2727
with:
2828
node-version: lts/*
2929

30+
- name: Install Rust stable
31+
uses: dtolnay/rust-toolchain@stable
32+
3033
- name: Install dependencies
3134
run: npm ci
3235

36+
- name: Install wasm-pack
37+
run: npm run bootstrap:install-wasm-pack
38+
3339
- name: Build plugin assets
3440
run: |
3541
npm run build-plugins

crates-cli/yaak-cli/src/context.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use yaak_crypto::manager::EncryptionManager;
88
use yaak_models::blob_manager::BlobManager;
99
use yaak_models::db_context::DbContext;
1010
use yaak_models::query_manager::QueryManager;
11-
use yaak_plugins::bootstrap;
1211
use yaak_plugins::events::PluginContext;
1312
use yaak_plugins::manager::PluginManager;
1413

@@ -52,7 +51,7 @@ impl CliContext {
5251
.expect("Failed to prepare embedded plugin runtime")
5352
});
5453

55-
match bootstrap::create_and_initialize_manager(
54+
match PluginManager::new(
5655
vendored_plugin_dir,
5756
installed_plugin_dir,
5857
node_bin_path,
@@ -63,7 +62,7 @@ impl CliContext {
6362
)
6463
.await
6564
{
66-
Ok(plugin_manager) => Some(plugin_manager),
65+
Ok(plugin_manager) => Some(Arc::new(plugin_manager)),
6766
Err(err) => {
6867
eprintln!("Warning: Failed to initialize plugins: {err}");
6968
None

crates-tauri/yaak-app/src/plugins_ext.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use yaak_plugins::api::{
2727
PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse, check_plugin_updates,
2828
search_plugins,
2929
};
30-
use yaak_plugins::bootstrap;
3130
use yaak_plugins::events::PluginContext;
3231
use yaak_plugins::install::{delete_and_uninstall, download_and_install};
3332
use yaak_plugins::manager::PluginManager;
@@ -274,7 +273,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
274273
// Create plugin manager asynchronously
275274
let app_handle_clone = app_handle.clone();
276275
tauri::async_runtime::block_on(async move {
277-
let manager = bootstrap::create_and_initialize_manager(
276+
let manager = PluginManager::new(
278277
vendored_plugin_dir,
279278
installed_plugin_dir,
280279
node_bin_path,

crates/yaak-plugins/src/bootstrap.rs

Lines changed: 0 additions & 66 deletions
This file was deleted.

crates/yaak-plugins/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//! by yaak-app's plugins_ext module.
88
99
pub mod api;
10-
pub mod bootstrap;
1110
mod checksum;
1211
pub mod error;
1312
pub mod events;

crates/yaak-plugins/src/manager.rs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ use tokio::sync::mpsc::error::TrySendError;
3434
use tokio::sync::{Mutex, mpsc, oneshot};
3535
use tokio::time::{Instant, timeout};
3636
use yaak_models::models::Plugin;
37-
use yaak_models::util::generate_id;
37+
use yaak_models::query_manager::QueryManager;
38+
use yaak_models::util::{UpdateSource, generate_id};
3839
use yaak_templates::error::Error::RenderError;
3940
use yaak_templates::error::Result as TemplateResult;
4041

@@ -61,14 +62,18 @@ impl PluginManager {
6162
/// * `installed_plugin_dir` - Path to installed plugins directory
6263
/// * `node_bin_path` - Path to the yaaknode binary
6364
/// * `plugin_runtime_main` - Path to the plugin runtime index.cjs
65+
/// * `query_manager` - Query manager for bundled plugin registration and loading
66+
/// * `plugin_context` - Context to use while initializing plugins
6467
/// * `dev_mode` - Whether the app is in dev mode (affects plugin loading)
6568
pub async fn new(
6669
vendored_plugin_dir: PathBuf,
6770
installed_plugin_dir: PathBuf,
6871
node_bin_path: PathBuf,
6972
plugin_runtime_main: PathBuf,
73+
query_manager: &QueryManager,
74+
plugin_context: &PluginContext,
7075
dev_mode: bool,
71-
) -> PluginManager {
76+
) -> Result<PluginManager> {
7277
let (events_tx, mut events_rx) = mpsc::channel(2048);
7378
let (kill_server_tx, kill_server_rx) = tokio::sync::watch::channel(false);
7479
let (killed_tx, killed_rx) = oneshot::channel();
@@ -151,12 +156,40 @@ impl PluginManager {
151156
&kill_server_rx,
152157
killed_tx,
153158
)
154-
.await
155-
.unwrap();
159+
.await?;
156160
info!("Waiting for plugins to initialize");
157-
init_plugins_task.await.unwrap();
161+
init_plugins_task.await.map_err(|e| PluginErr(e.to_string()))?;
162+
163+
let bundled_dirs = plugin_manager.list_bundled_plugin_dirs().await?;
164+
let db = query_manager.connect();
165+
for dir in bundled_dirs {
166+
if db.get_plugin_by_directory(&dir).is_none() {
167+
db.upsert_plugin(
168+
&Plugin {
169+
directory: dir,
170+
enabled: true,
171+
url: None,
172+
..Default::default()
173+
},
174+
&UpdateSource::Background,
175+
)?;
176+
}
177+
}
178+
179+
let plugins = db.list_plugins()?;
180+
drop(db);
181+
182+
let init_errors = plugin_manager.initialize_all_plugins(plugins, plugin_context).await;
183+
if !init_errors.is_empty() {
184+
let joined = init_errors
185+
.into_iter()
186+
.map(|(dir, err)| format!("{dir}: {err}"))
187+
.collect::<Vec<_>>()
188+
.join("; ");
189+
return Err(PluginErr(format!("Failed to initialize plugin(s): {joined}")));
190+
}
158191

159-
plugin_manager
192+
Ok(plugin_manager)
160193
}
161194

162195
/// Get the vendored plugin directory path (resolves dev mode path if applicable)

0 commit comments

Comments
 (0)