summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKunal Mohan <kunalmohan99@gmail.com>2021-05-27 15:30:14 +0530
committerKunal Mohan <kunalmohan99@gmail.com>2021-05-27 15:30:14 +0530
commitcb3072066dc482cbadfbd77c64b7e61a1b24b9c6 (patch)
tree4d16baf85a519670ca8647b0b11abb1c54fc0bad /src
parent1e5c688ed99fe7f96e5e690fba70d80782a53d3d (diff)
hotfix(publish): Move install module and asset_map to main zellij package. publish should hopefully work now.
Diffstat (limited to 'src')
-rw-r--r--src/install.rs42
-rw-r--r--src/main.rs10
2 files changed, 51 insertions, 1 deletions
diff --git a/src/install.rs b/src/install.rs
new file mode 100644
index 000000000..e9f58a8b9
--- /dev/null
+++ b/src/install.rs
@@ -0,0 +1,42 @@
+use std::fs;
+use std::path::Path;
+use zellij_utils::{consts::VERSION, shared::set_permissions};
+
+macro_rules! asset_map {
+ ($($src:literal => $dst:literal),+ $(,)?) => {
+ {
+ let mut assets = std::collections::HashMap::new();
+ $(
+ assets.insert($dst, include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/", $src)).to_vec());
+ )+
+ assets
+ }
+ }
+}
+
+pub(crate) fn populate_data_dir(data_dir: &Path) {
+ // First run installation of default plugins & layouts
+ let mut assets = asset_map! {
+ "assets/layouts/default.yaml" => "layouts/default.yaml",
+ "assets/layouts/strider.yaml" => "layouts/strider.yaml",
+ };
+ assets.extend(asset_map! {
+ "assets/plugins/status-bar.wasm" => "plugins/status-bar.wasm",
+ "assets/plugins/tab-bar.wasm" => "plugins/tab-bar.wasm",
+ "assets/plugins/strider.wasm" => "plugins/strider.wasm",
+ });
+ assets.insert("VERSION", VERSION.as_bytes().to_vec());
+
+ let last_version = fs::read_to_string(data_dir.join("VERSION")).unwrap_or_default();
+ let out_of_date = VERSION != last_version;
+
+ for (path, bytes) in assets {
+ let path = data_dir.join(path);
+ let parent_path = path.parent().unwrap();
+ fs::create_dir_all(parent_path).unwrap();
+ set_permissions(parent_path).unwrap();
+ if out_of_date || !path.exists() {
+ fs::write(path, bytes).expect("Failed to install default assets!");
+ }
+ }
+}
diff --git a/src/main.rs b/src/main.rs
index 67b833988..efb991567 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,7 +1,9 @@
+mod install;
mod sessions;
#[cfg(test)]
mod tests;
+use crate::install::populate_data_dir;
use sessions::{assert_session, assert_session_ne, list_sessions};
use std::convert::TryFrom;
use std::process;
@@ -12,7 +14,7 @@ use zellij_utils::{
consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR},
input::config::Config,
logging::*,
- setup::Setup,
+ setup::{get_default_data_dir, Setup},
structopt::StructOpt,
};
@@ -69,6 +71,12 @@ pub fn main() {
.clone()
.unwrap_or_else(|| names::Generator::default().next().unwrap());
assert_session_ne(&session_name);
+ // Determine and initialize the data directory
+ let data_dir = opts.data_dir.clone().unwrap_or_else(get_default_data_dir);
+
+ #[cfg(not(disable_automatic_asset_installation))]
+ populate_data_dir(&data_dir);
+
start_client(
Box::new(os_input),
opts,