mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-23 18:01:08 +01:00
Fixed bugs in Plugin settings pane
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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?;
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user