aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-server/src/plugins/plugin_loader.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_loader.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_loader.rs')
-rw-r--r--zellij-server/src/plugins/plugin_loader.rs43
1 files changed, 38 insertions, 5 deletions
diff --git a/zellij-server/src/plugins/plugin_loader.rs b/zellij-server/src/plugins/plugin_loader.rs
index 91eb6c93..4d77bd9e 100644
--- a/zellij-server/src/plugins/plugin_loader.rs
+++ b/zellij-server/src/plugins/plugin_loader.rs
@@ -1,6 +1,5 @@
-use crate::plugins::plugin_map::{
- PluginEnv, PluginMap, RunningPlugin, RunningWorker, Subscriptions,
-};
+use crate::plugins::plugin_map::{PluginEnv, PluginMap, RunningPlugin, Subscriptions};
+use crate::plugins::plugin_worker::{plugin_worker, RunningWorker};
use crate::plugins::zellij_exports::{wasi_read_string, zellij_exports};
use crate::plugins::PluginId;
use highway::{HighwayHash, PortableHash};
@@ -164,6 +163,8 @@ pub struct PluginLoader<'a> {
plugin_own_data_dir: PathBuf,
size: Size,
wasm_blob_on_hd: Option<(Vec<u8>, PathBuf)>,
+ path_to_default_shell: PathBuf,
+ zellij_cwd: PathBuf,
}
impl<'a> PluginLoader<'a> {
@@ -176,6 +177,8 @@ impl<'a> PluginLoader<'a> {
plugin_map: Arc<Mutex<PluginMap>>,
connected_clients: Arc<Mutex<Vec<ClientId>>>,
loading_indication: &mut LoadingIndication,
+ path_to_default_shell: PathBuf,
+ zellij_cwd: PathBuf,
) -> Result<()> {
let err_context = || format!("failed to reload plugin {plugin_id} from memory");
let mut connected_clients: Vec<ClientId> =
@@ -194,6 +197,8 @@ impl<'a> PluginLoader<'a> {
first_client_id,
&store,
&plugin_dir,
+ path_to_default_shell,
+ zellij_cwd,
)?;
plugin_loader
.load_module_from_memory()
@@ -227,6 +232,8 @@ impl<'a> PluginLoader<'a> {
size: Size,
connected_clients: Arc<Mutex<Vec<ClientId>>>,
loading_indication: &mut LoadingIndication,
+ path_to_default_shell: PathBuf,
+ zellij_cwd: PathBuf,
) -> Result<()> {
let err_context = || format!("failed to start plugin {plugin_id} for client {client_id}");
let mut plugin_loader = PluginLoader::new(
@@ -240,6 +247,8 @@ impl<'a> PluginLoader<'a> {
&plugin_dir,
tab_index,
size,
+ path_to_default_shell,
+ zellij_cwd,
)?;
plugin_loader
.load_module_from_memory()
@@ -273,6 +282,8 @@ impl<'a> PluginLoader<'a> {
plugin_map: Arc<Mutex<PluginMap>>,
connected_clients: Arc<Mutex<Vec<ClientId>>>,
loading_indication: &mut LoadingIndication,
+ path_to_default_shell: PathBuf,
+ zellij_cwd: PathBuf,
) -> Result<()> {
let mut new_plugins = HashSet::new();
for plugin_id in plugin_map.lock().unwrap().plugin_ids() {
@@ -288,6 +299,8 @@ impl<'a> PluginLoader<'a> {
existing_client_id,
&store,
&plugin_dir,
+ path_to_default_shell.clone(),
+ zellij_cwd.clone(),
)?;
plugin_loader
.load_module_from_memory()
@@ -314,6 +327,8 @@ impl<'a> PluginLoader<'a> {
plugin_map: Arc<Mutex<PluginMap>>,
connected_clients: Arc<Mutex<Vec<ClientId>>>,
loading_indication: &mut LoadingIndication,
+ path_to_default_shell: PathBuf,
+ zellij_cwd: PathBuf,
) -> Result<()> {
let err_context = || format!("failed to reload plugin id {plugin_id}");
@@ -333,6 +348,8 @@ impl<'a> PluginLoader<'a> {
first_client_id,
&store,
&plugin_dir,
+ path_to_default_shell,
+ zellij_cwd,
)?;
plugin_loader
.compile_module()
@@ -363,6 +380,8 @@ impl<'a> PluginLoader<'a> {
plugin_dir: &'a PathBuf,
tab_index: usize,
size: Size,
+ path_to_default_shell: PathBuf,
+ zellij_cwd: PathBuf,
) -> Result<Self> {
let plugin_own_data_dir = ZELLIJ_SESSION_CACHE_DIR
.join(Url::from(&plugin.location).to_string())
@@ -383,6 +402,8 @@ impl<'a> PluginLoader<'a> {
plugin_own_data_dir,
size,
wasm_blob_on_hd: None,
+ path_to_default_shell,
+ zellij_cwd,
})
}
pub fn new_from_existing_plugin_attributes(
@@ -394,6 +415,8 @@ impl<'a> PluginLoader<'a> {
client_id: ClientId,
store: &Store,
plugin_dir: &'a PathBuf,
+ path_to_default_shell: PathBuf,
+ zellij_cwd: PathBuf,
) -> Result<Self> {
let err_context = || "Failed to find existing plugin";
let (running_plugin, _subscriptions, _workers) = {
@@ -421,6 +444,8 @@ impl<'a> PluginLoader<'a> {
plugin_dir,
tab_index,
size,
+ path_to_default_shell,
+ zellij_cwd,
)
}
pub fn new_from_different_client_id(
@@ -432,6 +457,8 @@ impl<'a> PluginLoader<'a> {
client_id: ClientId,
store: &Store,
plugin_dir: &'a PathBuf,
+ path_to_default_shell: PathBuf,
+ zellij_cwd: PathBuf,
) -> Result<Self> {
let err_context = || "Failed to find existing plugin";
let running_plugin = {
@@ -460,6 +487,8 @@ impl<'a> PluginLoader<'a> {
plugin_dir,
tab_index,
size,
+ path_to_default_shell,
+ zellij_cwd,
)
}
pub fn load_module_from_memory(&mut self) -> Result<Module> {
@@ -625,7 +654,8 @@ impl<'a> PluginLoader<'a> {
let worker =
RunningWorker::new(instance, &function_name, plugin_config, plugin_env);
- workers.insert(function_name.into(), Arc::new(Mutex::new(worker)));
+ let worker_sender = plugin_worker(worker);
+ workers.insert(function_name.into(), worker_sender);
}
}
start_function.call(&[]).with_context(err_context)?;
@@ -689,6 +719,8 @@ impl<'a> PluginLoader<'a> {
*client_id,
&self.store,
&self.plugin_dir,
+ self.path_to_default_shell.clone(),
+ self.zellij_cwd.clone(),
)?;
plugin_loader_for_client
.load_module_from_memory()
@@ -746,7 +778,7 @@ impl<'a> PluginLoader<'a> {
};
let mut wasi_env = WasiState::new("Zellij")
.env("CLICOLOR_FORCE", "1")
- .map_dir("/host", ".")
+ .map_dir("/host", self.zellij_cwd.clone())
.and_then(|wasi| wasi.map_dir("/data", &self.plugin_own_data_dir))
.and_then(|wasi| wasi.map_dir("/tmp", ZELLIJ_TMP_DIR.as_path()))
.and_then(|wasi| {
@@ -771,6 +803,7 @@ impl<'a> PluginLoader<'a> {
wasi_env,
plugin_own_data_dir: self.plugin_own_data_dir.clone(),
tab_index: self.tab_index,
+ path_to_default_shell: self.path_to_default_shell.clone(),
};
let subscriptions = Arc::new(Mutex::new(HashSet::new()));