aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-server/src/plugins/plugin_map.rs
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2023-06-07 12:43:35 +0200
committerGitHub <noreply@github.com>2023-06-07 12:43:35 +0200
commitc11d75f9157873fc99fe0d40933de8ec5fbb4f6b (patch)
treefc55dc7f9132395585613dd9cce94c98c8c76600 /zellij-server/src/plugins/plugin_map.rs
parentdocs(changelog): fix cwd of newtab action (diff)
downloadsl0ppij-c11d75f9157873fc99fe0d40933de8ec5fbb4f6b.tar.gz
sl0ppij-c11d75f9157873fc99fe0d40933de8ec5fbb4f6b.tar.xz
sl0ppij-c11d75f9157873fc99fe0d40933de8ec5fbb4f6b.zip
feat(wasm-plugin-system): major overhaul and some goodies (#2510)
* strider resiliency * worker channel prototype * finalized ui * show hide plugin * fs events to plugins * tests for events and new screen instructions * various refactoringz * report plugin errors instead of crashing zellij * fix plugin loading with workers * refactor: move watch filesystem * some fixes and refactoring * refactor(panes): combine pane insertion logic * refactor(screen): launch or focus * refactor(pty): consolidate default shell fetching * refactor: various cleanups * initial refactoring * more initial refactoring * refactor(strider): search * style(fmt): rustfmt * style(pty): cleanup * style(clippy): ok clippy * style(fmt): rustfmt
Diffstat (limited to 'zellij-server/src/plugins/plugin_map.rs')
-rw-r--r--zellij-server/src/plugins/plugin_map.rs70
1 files changed, 10 insertions, 60 deletions
diff --git a/zellij-server/src/plugins/plugin_map.rs b/zellij-server/src/plugins/plugin_map.rs
index 0c3df931..040c9f9f 100644
--- a/zellij-server/src/plugins/plugin_map.rs
+++ b/zellij-server/src/plugins/plugin_map.rs
@@ -1,5 +1,4 @@
-use crate::plugins::plugin_loader::{PluginLoader, VersionMismatchError};
-use crate::plugins::zellij_exports::wasi_write_object;
+use crate::plugins::plugin_worker::MessageToWorker;
use crate::plugins::PluginId;
use std::{
collections::{HashMap, HashSet},
@@ -11,10 +10,10 @@ use wasmer_wasi::WasiEnv;
use crate::{thread_bus::ThreadSenders, ClientId};
+use zellij_utils::async_channel::Sender;
use zellij_utils::errors::prelude::*;
use zellij_utils::{
- consts::VERSION, data::EventType, input::layout::RunPluginLocation,
- input::plugins::PluginConfig,
+ data::EventType, input::layout::RunPluginLocation, input::plugins::PluginConfig,
};
// the idea here is to provide atomicity when adding/removing plugins from the map (eg. when a new
@@ -29,7 +28,7 @@ pub struct PluginMap {
(
Arc<Mutex<RunningPlugin>>,
Arc<Mutex<Subscriptions>>,
- HashMap<String, Arc<Mutex<RunningWorker>>>,
+ HashMap<String, Sender<MessageToWorker>>,
),
>,
}
@@ -41,7 +40,7 @@ impl PluginMap {
) -> Vec<(
Arc<Mutex<RunningPlugin>>,
Arc<Mutex<Subscriptions>>,
- HashMap<String, Arc<Mutex<RunningWorker>>>,
+ HashMap<String, Sender<MessageToWorker>>,
)> {
let mut removed = vec![];
let ids_in_plugin_map: Vec<(PluginId, ClientId)> =
@@ -62,7 +61,7 @@ impl PluginMap {
) -> Option<(
Arc<Mutex<RunningPlugin>>,
Arc<Mutex<Subscriptions>>,
- HashMap<String, Arc<Mutex<RunningWorker>>>,
+ HashMap<String, Sender<MessageToWorker>>,
)> {
self.plugin_assets.remove(&(plugin_id, client_id))
}
@@ -132,12 +131,12 @@ impl PluginMap {
.and_then(|(_, (running_plugin, _, _))| Some(running_plugin.clone())),
}
}
- pub fn clone_worker(
+ pub fn worker_sender(
&self,
plugin_id: PluginId,
client_id: ClientId,
worker_name: &str,
- ) -> Option<Arc<Mutex<RunningWorker>>> {
+ ) -> Option<Sender<MessageToWorker>> {
self.plugin_assets
.iter()
.find(|((p_id, c_id), _)| p_id == &plugin_id && c_id == &client_id)
@@ -174,7 +173,7 @@ impl PluginMap {
client_id: ClientId,
running_plugin: Arc<Mutex<RunningPlugin>>,
subscriptions: Arc<Mutex<Subscriptions>>,
- running_workers: HashMap<String, Arc<Mutex<RunningWorker>>>,
+ running_workers: HashMap<String, Sender<MessageToWorker>>,
) {
self.plugin_assets.insert(
(plugin_id, client_id),
@@ -195,6 +194,7 @@ pub struct PluginEnv {
pub client_id: ClientId,
#[allow(dead_code)]
pub plugin_own_data_dir: PathBuf,
+ pub path_to_default_shell: PathBuf,
}
impl PluginEnv {
@@ -256,53 +256,3 @@ impl RunningPlugin {
}
}
}
-
-pub struct RunningWorker {
- pub instance: Instance,
- pub name: String,
- pub plugin_config: PluginConfig,
- pub plugin_env: PluginEnv,
-}
-
-impl RunningWorker {
- pub fn new(
- instance: Instance,
- name: &str,
- plugin_config: PluginConfig,
- plugin_env: PluginEnv,
- ) -> Self {
- RunningWorker {
- instance,
- name: name.into(),
- plugin_config,
- plugin_env,
- }
- }
- pub fn send_message(&self, message: String, payload: String) -> Result<()> {
- let err_context = || format!("Failed to send message to worker");
-
- let work_function = self
- .instance
- .exports
- .get_function(&self.name)
- .with_context(err_context)?;
- wasi_write_object(&self.plugin_env.wasi_env, &(message, payload))
- .with_context(err_context)?;
- work_function.call(&[]).or_else::<anyError, _>(|e| {
- match e.downcast::<serde_json::Error>() {
- Ok(_) => panic!(
- "{}",
- anyError::new(VersionMismatchError::new(
- VERSION,
- "Unavailable",
- &self.plugin_config.path,
- self.plugin_config.is_builtin(),
- ))
- ),
- Err(e) => Err(e).with_context(err_context),
- }
- })?;
-
- Ok(())
- }
-}