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

@@ -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());