mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-07-08 22:05:16 +02:00
Restructure add plugin
This commit is contained in:
@@ -1282,7 +1282,7 @@ async fn cmd_install_plugin<R: Runtime>(
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
plugin_manager
|
plugin_manager
|
||||||
.add_plugin_by_dir(&PluginContext::new(&window), &plugin.directory, plugin.enabled)
|
.add_plugin(&PluginContext::new(&window), &plugin.directory, plugin.enabled)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(plugin)
|
Ok(plugin)
|
||||||
|
|||||||
@@ -55,9 +55,7 @@ pub async fn download_and_install<R: Runtime>(
|
|||||||
zip_extract::extract(Cursor::new(&bytes), &plugin_dir, true)?;
|
zip_extract::extract(Cursor::new(&bytes), &plugin_dir, true)?;
|
||||||
info!("Extracted plugin {} to {}", plugin_version.id, plugin_dir_str);
|
info!("Extracted plugin {} to {}", plugin_version.id, plugin_dir_str);
|
||||||
|
|
||||||
plugin_manager.add_plugin_by_dir(&PluginContext::new(&window), &plugin_dir_str, true).await?;
|
let plugin = window.db().upsert_plugin(
|
||||||
|
|
||||||
window.db().upsert_plugin(
|
|
||||||
&Plugin {
|
&Plugin {
|
||||||
id: plugin_version.id.clone(),
|
id: plugin_version.id.clone(),
|
||||||
checked_at: Some(Utc::now().naive_utc()),
|
checked_at: Some(Utc::now().naive_utc()),
|
||||||
@@ -69,6 +67,8 @@ pub async fn download_and_install<R: Runtime>(
|
|||||||
&UpdateSource::Background,
|
&UpdateSource::Background,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
plugin_manager.add_plugin(&PluginContext::new(&window), &plugin).await?;
|
||||||
|
|
||||||
info!("Installed plugin {} to {}", plugin_version.id, plugin_dir_str);
|
info!("Installed plugin {} to {}", plugin_version.id, plugin_dir_str);
|
||||||
|
|
||||||
Ok(plugin_version)
|
Ok(plugin_version)
|
||||||
|
|||||||
@@ -227,32 +227,27 @@ impl PluginManager {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn add_plugin_by_dir(
|
pub async fn add_plugin(&self, plugin_context: &PluginContext, plugin: &Plugin) -> Result<()> {
|
||||||
&self,
|
info!("Adding plugin by dir {}", plugin.directory);
|
||||||
plugin_context: &PluginContext,
|
|
||||||
dir: &str,
|
|
||||||
enabled: bool,
|
|
||||||
) -> Result<()> {
|
|
||||||
info!("Adding plugin by dir {dir}");
|
|
||||||
|
|
||||||
let maybe_tx = self.ws_service.app_to_plugin_events_tx.lock().await;
|
let maybe_tx = self.ws_service.app_to_plugin_events_tx.lock().await;
|
||||||
let tx = match &*maybe_tx {
|
let tx = match &*maybe_tx {
|
||||||
None => return Err(ClientNotInitializedErr),
|
None => return Err(ClientNotInitializedErr),
|
||||||
Some(tx) => tx,
|
Some(tx) => tx,
|
||||||
};
|
};
|
||||||
let plugin_handle = PluginHandle::new(dir, enabled, tx.clone())?;
|
let plugin_handle = PluginHandle::new(&plugin.directory, plugin.enabled, tx.clone())?;
|
||||||
let dir_path = Path::new(dir);
|
let dir_path = Path::new(&plugin.directory);
|
||||||
let is_vendored = dir_path.starts_with(self.vendored_plugin_dir.as_path());
|
let is_vendored = dir_path.starts_with(self.vendored_plugin_dir.as_path());
|
||||||
let is_installed = dir_path.starts_with(self.installed_plugin_dir.as_path());
|
let is_installed = dir_path.starts_with(self.installed_plugin_dir.as_path());
|
||||||
|
|
||||||
// Boot the plugin if it's enabled
|
// Boot the plugin if it's enabled
|
||||||
if enabled {
|
if plugin.enabled {
|
||||||
let event = self
|
let event = self
|
||||||
.send_to_plugin_and_wait(
|
.send_to_plugin_and_wait(
|
||||||
plugin_context,
|
plugin_context,
|
||||||
&plugin_handle,
|
&plugin_handle,
|
||||||
&InternalEventPayload::BootRequest(BootRequest {
|
&InternalEventPayload::BootRequest(BootRequest {
|
||||||
dir: dir.to_string(),
|
dir: plugin.directory.clone(),
|
||||||
watch: !is_vendored && !is_installed,
|
watch: !is_vendored && !is_installed,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@@ -264,7 +259,7 @@ impl PluginManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut plugin_handles = self.plugin_handles.lock().await;
|
let mut plugin_handles = self.plugin_handles.lock().await;
|
||||||
plugin_handles.retain(|p| p.dir != dir);
|
plugin_handles.retain(|p| p.dir != plugin.directory);
|
||||||
plugin_handles.push(plugin_handle.clone());
|
plugin_handles.push(plugin_handle.clone());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -285,9 +280,7 @@ impl PluginManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Err(e) =
|
if let Err(e) = self.add_plugin(plugin_context, &plugin).await {
|
||||||
self.add_plugin_by_dir(plugin_context, &plugin.directory, plugin.enabled).await
|
|
||||||
{
|
|
||||||
warn!("Failed to add plugin {} {e:?}", plugin.directory);
|
warn!("Failed to add plugin {} {e:?}", plugin.directory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user