From 555f9af37a70ac929bd996b49dc3f8879b0d5191 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Mon, 11 Jan 2021 23:00:19 +0000 Subject: [PATCH] Install default layouts and plugins at build-time --- Cargo.lock | 49 ++++++++++++++++-- Cargo.toml | 2 + assets/layouts/default.yaml | 8 +++ .../layouts/strider.yaml | 0 .../plugins/status-bar.wasm | Bin strider.wasm => assets/plugins/strider.wasm | Bin build.rs | 23 +++++++- 7 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 assets/layouts/default.yaml rename src/tests/fixtures/layouts/panes-with-plugins.yaml => assets/layouts/strider.yaml (100%) rename status-bar.wasm => assets/plugins/status-bar.wasm (100%) rename strider.wasm => assets/plugins/strider.wasm (100%) diff --git a/Cargo.lock b/Cargo.lock index a8656836..f869fa22 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -407,6 +407,27 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" +[[package]] +name = "directories-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc" +dependencies = [ + "cfg-if 1.0.0", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "dtoa" version = "0.4.6" @@ -882,6 +903,7 @@ dependencies = [ "async-std", "backtrace", "bincode", + "directories-next", "futures", "insta", "libc", @@ -1142,13 +1164,32 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +[[package]] +name = "redox_syscall" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05ec8ca9416c5ea37062b502703cd7fcb207736bc294f6e0cf367ac6fc234570" +dependencies = [ + "bitflags", +] + [[package]] name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" dependencies = [ - "redox_syscall", + "redox_syscall 0.1.57", +] + +[[package]] +name = "redox_users" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" +dependencies = [ + "getrandom 0.2.0", + "redox_syscall 0.2.4", ] [[package]] @@ -1356,7 +1397,7 @@ checksum = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918" dependencies = [ "cfg-if 0.1.10", "libc", - "redox_syscall", + "redox_syscall 0.1.57", "winapi", ] @@ -1437,7 +1478,7 @@ dependencies = [ "cfg-if 0.1.10", "libc", "rand", - "redox_syscall", + "redox_syscall 0.1.57", "remove_dir_all", "winapi", ] @@ -1459,7 +1500,7 @@ source = "git+https://gitlab.com/TheLostLambda/termion.git#70159e07c59c02dc681db dependencies = [ "libc", "numtoa", - "redox_syscall", + "redox_syscall 0.1.57", "redox_termios", "serde", ] diff --git a/Cargo.toml b/Cargo.toml index f1964cb4..ef2c47ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2018" [dependencies] backtrace = "0.3.55" bincode = "1.3.1" +directories-next = "2.0" futures = "0.3.5" libc = "0.2" nix = "0.17.0" @@ -34,6 +35,7 @@ features = ["unstable"] insta = "0.16.1" [build-dependencies] +directories-next = "2.0" structopt = "0.3" [profile.release] diff --git a/assets/layouts/default.yaml b/assets/layouts/default.yaml new file mode 100644 index 00000000..8c87e635 --- /dev/null +++ b/assets/layouts/default.yaml @@ -0,0 +1,8 @@ +--- +direction: Horizontal +parts: + - direction: Vertical + - direction: Vertical + split_size: + Fixed: 1 + plugin: status-bar.wasm \ No newline at end of file diff --git a/src/tests/fixtures/layouts/panes-with-plugins.yaml b/assets/layouts/strider.yaml similarity index 100% rename from src/tests/fixtures/layouts/panes-with-plugins.yaml rename to assets/layouts/strider.yaml diff --git a/status-bar.wasm b/assets/plugins/status-bar.wasm similarity index 100% rename from status-bar.wasm rename to assets/plugins/status-bar.wasm diff --git a/strider.wasm b/assets/plugins/strider.wasm similarity index 100% rename from strider.wasm rename to assets/plugins/strider.wasm diff --git a/build.rs b/build.rs index f0f92e61..c405d27e 100644 --- a/build.rs +++ b/build.rs @@ -1,4 +1,5 @@ -use std::fs; +use directories_next::ProjectDirs; +use std::{fs, path::Path}; use structopt::clap::Shell; include!("src/cli.rs"); @@ -6,8 +7,9 @@ include!("src/cli.rs"); const BIN_NAME: &str = "mosaic"; fn main() { + // Generate Shell Completions let mut clap_app = CliArgs::clap(); - println!("cargo:rerun-if-changed=src/app.rs"); + println!("cargo:rerun-if-changed=src/cli.rs"); let mut out_dir = std::env::var_os("CARGO_MANIFEST_DIR").unwrap(); out_dir.push("/assets/completions"); @@ -19,4 +21,21 @@ 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", "Mosaic Contributors", "Mosaic").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 { + println!("cargo:rerun-if-changed=assets/{}", asset); + fs::copy(Path::new("assets/").join(asset), data_dir.join(asset)) + .expect("Failed to copy asset files"); + } }