aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-server/src
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2024-08-21 16:46:01 +0200
committerGitHub <noreply@github.com>2024-08-21 16:46:01 +0200
commit08b6072a6971f99e3958d61515bf77b997cd08b6 (patch)
tree582ad115cf186ec3a4c47ca2e9bfcf3854652ac0 /zellij-server/src
parentdocs(changelog): change themes at runtime (diff)
downloadsl0ppij-08b6072a6971f99e3958d61515bf77b997cd08b6.tar.gz
sl0ppij-08b6072a6971f99e3958d61515bf77b997cd08b6.tar.xz
sl0ppij-08b6072a6971f99e3958d61515bf77b997cd08b6.zip
feat(plugins): API to temporarily bind keys to send a message to a specific plugin id (#3561)
Diffstat (limited to 'zellij-server/src')
-rw-r--r--zellij-server/src/plugins/mod.rs79
-rw-r--r--zellij-server/src/route.rs4
2 files changed, 49 insertions, 34 deletions
diff --git a/zellij-server/src/plugins/mod.rs b/zellij-server/src/plugins/mod.rs
index e1b807ce..62cc8916 100644
--- a/zellij-server/src/plugins/mod.rs
+++ b/zellij-server/src/plugins/mod.rs
@@ -134,6 +134,7 @@ pub enum PluginInstruction {
cwd: Option<PathBuf>,
skip_cache: bool,
cli_client_id: ClientId,
+ plugin_and_client_id: Option<(u32, ClientId)>,
},
CachePluginEvents {
plugin_id: PluginId,
@@ -624,42 +625,52 @@ pub(crate) fn plugin_thread_main(
cwd,
skip_cache,
cli_client_id,
+ plugin_and_client_id,
} => {
let should_float = floating.unwrap_or(true);
let mut pipe_messages = vec![];
- match plugin {
- Some(plugin_url) => {
- // send to specific plugin(s)
- pipe_to_specific_plugins(
- PipeSource::Keybind,
- &plugin_url,
- &configuration,
- &cwd,
- skip_cache,
- should_float,
- &pane_id_to_replace,
- &pane_title,
- Some(cli_client_id),
- &mut pipe_messages,
- &name,
- &payload,
- &args,
- &bus,
- &mut wasm_bridge,
- &plugin_aliases,
- );
- },
- None => {
- // no specific destination, send to all plugins
- pipe_to_all_plugins(
- PipeSource::Keybind,
- &name,
- &payload,
- &args,
- &mut wasm_bridge,
- &mut pipe_messages,
- );
- },
+ if let Some((plugin_id, client_id)) = plugin_and_client_id {
+ let is_private = true;
+ pipe_messages.push((
+ Some(plugin_id),
+ Some(client_id),
+ PipeMessage::new(PipeSource::Keybind, name, &payload, &args, is_private),
+ ));
+ } else {
+ match plugin {
+ Some(plugin_url) => {
+ // send to specific plugin(s)
+ pipe_to_specific_plugins(
+ PipeSource::Keybind,
+ &plugin_url,
+ &configuration,
+ &cwd,
+ skip_cache,
+ should_float,
+ &pane_id_to_replace,
+ &pane_title,
+ Some(cli_client_id),
+ &mut pipe_messages,
+ &name,
+ &payload,
+ &args,
+ &bus,
+ &mut wasm_bridge,
+ &plugin_aliases,
+ );
+ },
+ None => {
+ // no specific destination, send to all plugins
+ pipe_to_all_plugins(
+ PipeSource::Keybind,
+ &name,
+ &payload,
+ &args,
+ &mut wasm_bridge,
+ &mut pipe_messages,
+ );
+ },
+ }
}
wasm_bridge.pipe_messages(pipe_messages, shutdown_send.clone())?;
},
@@ -768,6 +779,8 @@ pub(crate) fn plugin_thread_main(
keybinds,
default_mode,
} => {
+ // TODO: notify plugins that this happened so that they can eg. rebind temporary keys that
+ // were lost
wasm_bridge
.reconfigure(client_id, keybinds, default_mode)
.non_fatal();
diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs
index f27266e0..9da11259 100644
--- a/zellij-server/src/route.rs
+++ b/zellij-server/src/route.rs
@@ -921,12 +921,13 @@ pub(crate) fn route_action(
cwd,
pane_title,
launch_new,
+ plugin_id,
..
} => {
if let Some(name) = name.take() {
let should_open_in_place = in_place.unwrap_or(false);
let pane_id_to_replace = if should_open_in_place { pane_id } else { None };
- if launch_new {
+ if launch_new && plugin_id.is_none() {
// we do this to make sure the plugin is unique (has a unique configuration parameter)
configuration
.get_or_insert_with(BTreeMap::new)
@@ -945,6 +946,7 @@ pub(crate) fn route_action(
pane_title,
skip_cache,
cli_client_id: client_id,
+ plugin_and_client_id: plugin_id.map(|plugin_id| (plugin_id, client_id)),
})
.with_context(err_context)?;
} else {