* default layouts won't be installed by anymore, instead they will be directly loaded * `layout-dir` is now a subdirectory of the `config-dir` by default, instead of the `data-dir` POSSIBLE BREAKING CHANGE: In case of having custom layouts in the previous `layout-dir` one can switch either the layouts to the new dir, or set the `layout-dir` to be the current `layout-dir` * it is possible to change the location of the `layout-dir`: - `zellij options --layout-dir [LAYOUR_DIR]` - `layout_dir: [LAYOUT_DIR]`
38 lines
1.3 KiB
Rust
38 lines
1.3 KiB
Rust
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/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!");
|
|
}
|
|
}
|
|
}
|