aboutsummaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorBrooks Rady <b.j.rady@gmail.com>2021-04-14 19:36:11 +0100
committerGitHub <noreply@github.com>2021-04-14 19:36:11 +0100
commit126a4b1d33502b6e371cca4101dbb7a0c7fe28bc (patch)
tree907c865bc81d907077bb0c2ce7bf7d81f4b08c92 /src/common
parentfix(compatibility): bash reverse search (#271) (diff)
parentfix(build): tweak the publishing process (diff)
downloadsl0ppij-126a4b1d33502b6e371cca4101dbb7a0c7fe28bc.tar.gz
sl0ppij-126a4b1d33502b6e371cca4101dbb7a0c7fe28bc.tar.xz
sl0ppij-126a4b1d33502b6e371cca4101dbb7a0c7fe28bc.zip
feat(build): overhaul build system
Diffstat (limited to 'src/common')
-rw-r--r--src/common/install.rs31
-rw-r--r--src/common/mod.rs17
2 files changed, 43 insertions, 5 deletions
diff --git a/src/common/install.rs b/src/common/install.rs
index 8b070848..86fdd269 100644
--- a/src/common/install.rs
+++ b/src/common/install.rs
@@ -1,12 +1,41 @@
+use std::{fs, path::Path};
+
+const VERSION: &str = env!("CARGO_PKG_VERSION");
+
#[macro_export]
macro_rules! asset_map {
($($src:literal => $dst:literal),+ $(,)?) => {
{
let mut assets = std::collections::HashMap::new();
$(
- assets.insert($dst, include_bytes!(concat!("../", $src)).to_vec());
+ assets.insert($dst, include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/", $src)).to_vec());
)+
assets
}
}
}
+
+pub 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);
+ fs::create_dir_all(path.parent().unwrap()).unwrap();
+ if out_of_date || !path.exists() {
+ fs::write(path, bytes).expect("Failed to install default assets!");
+ }
+ }
+}
diff --git a/src/common/mod.rs b/src/common/mod.rs
index 88eb7214..860d12db 100644
--- a/src/common/mod.rs
+++ b/src/common/mod.rs
@@ -33,6 +33,7 @@ use errors::{
ScreenContext,
};
use input::handler::input_loop;
+use install::populate_data_dir;
use os_input_output::OsApi;
use pty_bus::{PtyBus, PtyInstruction};
use screen::{Screen, ScreenInstruction};
@@ -167,12 +168,22 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
opts.debug,
);
+ // Determine and initialize the data directory
+ let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
+ let data_dir = opts
+ .data_dir
+ .unwrap_or_else(|| project_dirs.data_dir().to_path_buf());
+ populate_data_dir(&data_dir);
+
// Don't use default layouts in tests, but do everywhere else
#[cfg(not(test))]
let default_layout = Some(PathBuf::from("default"));
#[cfg(test)]
let default_layout = None;
- let maybe_layout = opts.layout.or(default_layout).map(Layout::new);
+ let maybe_layout = opts
+ .layout
+ .or(default_layout)
+ .map(|p| Layout::new(&p, &data_dir));
#[cfg(not(test))]
std::panic::set_hook({
@@ -443,9 +454,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
err_ctx.add_call(ContextType::Plugin(PluginContext::from(&event)));
match event {
PluginInstruction::Load(pid_tx, path) => {
- let project_dirs =
- ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
- let plugin_dir = project_dirs.data_dir().join("plugins/");
+ let plugin_dir = data_dir.join("plugins/");
let wasm_bytes = fs::read(&path)
.or_else(|_| fs::read(&path.with_extension("wasm")))
.or_else(|_| fs::read(&plugin_dir.join(&path).with_extension("wasm")))