Fixed bugs in Plugin settings pane

This commit is contained in:
Gregory Schier
2025-07-20 08:28:00 -07:00
parent 861b41b5ae
commit 86f23990eb
7 changed files with 146 additions and 105 deletions

View File

@@ -1,10 +1,10 @@
use crate::error::Error::MigrationError;
use crate::error::Result;
use include_dir::{include_dir, Dir, DirEntry};
use log::{debug, info};
use include_dir::{Dir, DirEntry, include_dir};
use log::info;
use r2d2::Pool;
use r2d2_sqlite::SqliteConnectionManager;
use rusqlite::{params, OptionalExtension, TransactionBehavior};
use rusqlite::{OptionalExtension, TransactionBehavior, params};
use sha2::{Digest, Sha384};
static MIGRATIONS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/migrations");
@@ -40,12 +40,18 @@ pub(crate) fn migrate_db(pool: &Pool<SqliteConnectionManager>) -> Result<()> {
// Run each migration in a transaction
let mut num_migrations = 0;
let mut ran_migrations = 0;
for entry in entries {
num_migrations += 1;
let mut conn = pool.get()?;
let mut tx = conn.transaction_with_behavior(TransactionBehavior::Immediate)?;
match run_migration(entry, &mut tx) {
Ok(_) => tx.commit()?,
Ok(ran) => {
if ran {
ran_migrations += 1;
}
tx.commit()?
}
Err(e) => {
let msg = format!(
"{} failed with {}",
@@ -58,7 +64,11 @@ pub(crate) fn migrate_db(pool: &Pool<SqliteConnectionManager>) -> Result<()> {
};
}
info!("Finished running {} migrations", num_migrations);
if ran_migrations == 0 {
info!("No migrations to run out of {}", num_migrations);
} else {
info!("Ran {}/{} migrations", ran_migrations, num_migrations);
}
Ok(())
}
@@ -76,9 +86,7 @@ fn run_migration(migration_path: &DirEntry, tx: &mut rusqlite::Transaction) -> R
.optional()?;
if row.is_some() {
debug!("Skipping migration {description}");
// Migration was already run
return Ok(false);
return Ok(false); // Migration was already run
}
let sql =

View File

@@ -43,8 +43,10 @@ pub async fn download_plugin_archive<R: Runtime>(
};
let resp = yaak_api_client(app_handle)?.get(url.clone()).send().await?;
if !resp.status().is_success() {
warn!("Failed to download plugin: {name} {version}");
return Err(ApiErr(format!("{} response to {}", resp.status(), url.to_string())));
}
info!("Downloaded plugin: {url}");
Ok(resp)
}

View File

@@ -13,7 +13,10 @@ use yaak_models::models::Plugin;
use yaak_models::query_manager::QueryManagerExt;
use yaak_models::util::UpdateSource;
pub async fn delete_and_uninstall<R: Runtime>(window: &WebviewWindow<R>, plugin_id: &str) -> Result<Plugin> {
pub async fn delete_and_uninstall<R: Runtime>(
window: &WebviewWindow<R>,
plugin_id: &str,
) -> Result<Plugin> {
let plugin_manager = window.state::<PluginManager>();
let plugin = window.db().delete_plugin_by_id(plugin_id, &UpdateSource::from_window(&window))?;
plugin_manager.uninstall(&PluginWindowContext::new(&window), plugin.directory.as_str()).await?;
@@ -25,6 +28,7 @@ pub async fn download_and_install<R: Runtime>(
name: &str,
version: Option<String>,
) -> Result<PluginVersion> {
info!("Installing plugin {} {}", name, version.clone().unwrap_or_default());
let plugin_manager = window.state::<PluginManager>();
let plugin_version = get_plugin(window.app_handle(), name, version).await?;
let resp = download_plugin_archive(window.app_handle(), &plugin_version).await?;

View File

@@ -209,6 +209,7 @@ impl PluginManager {
dir: &str,
) -> Result<()> {
info!("Adding plugin by dir {dir}");
let maybe_tx = self.ws_service.app_to_plugin_events_tx.lock().await;
let tx = match &*maybe_tx {
None => return Err(ClientNotInitializedErr),
@@ -233,6 +234,12 @@ impl PluginManager {
)
.await??;
let mut plugins = self.plugins.lock().await;
// Remove the existing plugin (if exists) before adding this one
plugins.retain(|p| p.dir != dir);
plugins.push(plugin_handle.clone());
// Add the new plugin
self.plugins.lock().await.push(plugin_handle.clone());