diff options
| author | Kunal Mohan <kunalmohan99@gmail.com> | 2021-05-27 15:30:14 +0530 |
|---|---|---|
| committer | Kunal Mohan <kunalmohan99@gmail.com> | 2021-05-27 15:30:14 +0530 |
| commit | cb3072066dc482cbadfbd77c64b7e61a1b24b9c6 (patch) | |
| tree | 4d16baf85a519670ca8647b0b11abb1c54fc0bad /src | |
| parent | chore(build): update makefile (diff) | |
| download | sl0ppij-cb3072066dc482cbadfbd77c64b7e61a1b24b9c6.tar.gz sl0ppij-cb3072066dc482cbadfbd77c64b7e61a1b24b9c6.tar.xz sl0ppij-cb3072066dc482cbadfbd77c64b7e61a1b24b9c6.zip | |
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.rs | 42 | ||||
| -rw-r--r-- | src/main.rs | 10 |
2 files changed, 51 insertions, 1 deletions
diff --git a/src/install.rs b/src/install.rs new file mode 100644 index 00000000..e9f58a8b --- /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 67b83398..efb99156 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, |
