Install assets on first run

This commit is contained in:
Brooks J Rady 2021-02-16 17:23:16 +00:00
parent c74e2ef273
commit 5a3caba55f
6 changed files with 33 additions and 17 deletions

Binary file not shown.

Binary file not shown.

View File

@ -134,20 +134,4 @@ fn main() {
clap_app.gen_completions(BIN_NAME, Shell::Bash, &out_dir);
clap_app.gen_completions(BIN_NAME, Shell::Zsh, &out_dir);
clap_app.gen_completions(BIN_NAME, Shell::Fish, &out_dir);
// Install Default Plugins and Layouts
let assets = vec![
"plugins/status-bar.wasm",
"plugins/strider.wasm",
"layouts/default.yaml",
"layouts/strider.yaml",
];
let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
let data_dir = project_dirs.data_dir();
fs::create_dir_all(data_dir.join("plugins")).unwrap();
fs::create_dir_all(data_dir.join("layouts")).unwrap();
for asset in assets {
fs::copy(Path::new("assets/").join(asset), data_dir.join(asset))
.expect("Failed to copy asset files");
}
}

12
src/common/install.rs Normal file
View File

@ -0,0 +1,12 @@
#[macro_export]
macro_rules! asset_map {
($($path:literal),+) => {
{
let mut assets = std::collections::HashMap::new();
$(
assets.insert($path, include_bytes!(concat!("../assets/", $path)).to_vec());
)+
assets
}
}
}

View File

@ -2,6 +2,7 @@ pub mod command_is_executing;
pub mod errors;
pub mod input;
pub mod ipc;
pub mod install;
pub mod os_input_output;
pub mod pty_bus;
pub mod screen;

View File

@ -11,8 +11,9 @@ use common::{
command_is_executing, errors, os_input_output, pty_bus, screen, start, utils, wasm_vm,
ApiCommand,
};
use directories_next::ProjectDirs;
use std::io::Write;
use std::{fs, io::Write};
use std::os::unix::net::UnixStream;
use structopt::StructOpt;
@ -27,6 +28,24 @@ use crate::utils::{
};
pub fn main() {
// First run installation of default plugins & layouts
let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
let data_dir = project_dirs.data_dir();
let assets = asset_map!{
"plugins/status-bar.wasm",
"plugins/strider.wasm",
"layouts/default.yaml",
"layouts/strider.yaml"
};
for (path, bytes) in assets {
let path = data_dir.join(path);
fs::create_dir_all(path.parent().unwrap()).unwrap();
if !path.exists() {
fs::write(path, bytes).expect("Failed to install default assets!");
}
}
let opts = CliArgs::from_args();
if let Some(split_dir) = opts.split {
match split_dir {