use crate::plugins::plugin_map::{
PluginEnv, PluginMap, RunningPlugin, RunningWorker, Subscriptions,
};
use crate::plugins::zellij_exports::{wasi_read_string, zellij_exports};
use crate::plugins::PluginId;
use highway::{HighwayHash, PortableHash};
use log::info;
use semver::Version;
use std::{
collections::{HashMap, HashSet},
fmt, fs,
path::PathBuf,
sync::{Arc, Mutex},
};
use url::Url;
use wasmer::{ChainableNamedResolver, Instance, Module, Store};
use wasmer_wasi::{Pipe, WasiState};
use crate::{
logging_pipe::LoggingPipe, screen::ScreenInstruction, thread_bus::ThreadSenders,
ui::loading_indication::LoadingIndication, ClientId,
};
use zellij_utils::{
consts::{VERSION, ZELLIJ_CACHE_DIR, ZELLIJ_SESSION_CACHE_DIR, ZELLIJ_TMP_DIR},
errors::prelude::*,
input::plugins::PluginConfig,
pane_size::Size,
};
macro_rules! display_loading_stage {
($loading_stage:ident, $loading_indication:expr, $senders:expr, $plugin_id:expr) => {{
$loading_indication.$loading_stage();
drop(
$senders.send_to_screen(ScreenInstruction::UpdatePluginLoadingStage(
$plugin_id,
$loading_indication.clone(),
)),
);
}};
}
/// Custom error for plugin version mismatch.
///
/// This is thrown when, during starting a plugin, it is detected that the plugin version doesn't
/// match the zellij version. This is treated as a fatal error and leads to instantaneous
/// termination.
#[derive(Debug)]
pub struct VersionMismatchError {
zellij_version: String,
plugin_version: String,
plugin_path: PathBuf,
// true for builtin plugins
builtin: bool,
}
impl std::error::Error for VersionMismatchError {}
impl VersionMismatchError {
pub fn new(
zellij_version: &str,
plugin_version: &str,
plugin_path: &PathBuf,
builtin: bool,
) -> Self {
VersionMismatchError {
zellij_version: zellij_version.to_owned(),
plugin_version: plugin_version.to_owned(),
plugin_path: plugin_path.to_owned(),
builtin,
}
}
}
impl fmt::Display for VersionMismatchError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let first_line = if self.builtin {
"It seems your version of zellij was built with outdated core plugins."
} else {
"If you're seeing this error a plugin version doesn't match the current
zellij version."
};
write!(
f,
"{}
Detected versions:
- Plugin version: {}
- Zellij version: {}
- Offending plugin: {}
If you're a user:
Please contact the distributor of your zellij version and report this error
to them.
If you're a developer:
Please run zellij with updated plugins. The easiest way to achieve this
is to build zellij with `cargo xtask install`. Also refer to the docs:
https://github.com/zellij-org/zellij/blob/main/CONTRIBUTING.md#building
",
first_line,
self.plugin_version.trim_end(),
self.zellij_version.trim_end(),
self.plugin_path.display()
)
}
}
// Returns `Ok` if the plugin version matches the zellij version.
// Returns an `Err` otherwise.
fn assert_plugin_version(instance: &Instance, plugin_env: &PluginEnv) -> Result<()> {
let err_context = || {
format!(
"failed to determine plugin version for plugin {}",
plugin_env.plugin.path.display()
)
};
let plugin_version_func = match instance.exports.get_function("plugin_version") {
Ok(val) =>