use crate::api::{ PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse, check_plugin_updates, search_plugins, }; use crate::error::Result; use crate::install::{delete_and_uninstall, download_and_install}; use tauri::{AppHandle, Manager, Runtime, WebviewWindow, command}; use yaak_models::models::Plugin; #[command] pub(crate) async fn search( app_handle: AppHandle, query: &str, ) -> Result { search_plugins(&app_handle, query).await } #[command] pub(crate) async fn install( window: WebviewWindow, name: &str, version: Option, ) -> Result<()> { download_and_install(&window, name, version).await?; Ok(()) } #[command] pub(crate) async fn uninstall( plugin_id: &str, window: WebviewWindow, ) -> Result { delete_and_uninstall(&window, plugin_id).await } #[command] pub(crate) async fn updates(app_handle: AppHandle) -> Result { check_plugin_updates(&app_handle).await } #[command] pub(crate) async fn update_all( window: WebviewWindow, ) -> Result> { use log::info; // Get list of available updates (already filtered to only registry plugins) let updates = check_plugin_updates(&window.app_handle()).await?; if updates.plugins.is_empty() { return Ok(Vec::new()); } let mut updated = Vec::new(); for update in updates.plugins { info!("Updating plugin: {} to version {}", update.name, update.version); match download_and_install(&window, &update.name, Some(update.version.clone())).await { Ok(_) => { info!("Successfully updated plugin: {}", update.name); updated.push(update.clone()); } Err(e) => { log::error!("Failed to update plugin {}: {:?}", update.name, e); } } } Ok(updated) }