From c32b837df772cbfb53ccd3b5434aefcbe7aaaf0b Mon Sep 17 00:00:00 2001 From: Henil Dedania Date: Thu, 21 Jan 2021 12:04:29 +0530 Subject: [PATCH] feat(plugin): Search in root folder for plugins and layout files --- src/layout.rs | 6 +++++- src/main.rs | 7 ++++++- src/utils/consts.rs | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/layout.rs b/src/layout.rs index 2935d42d..d09e7618 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -1,6 +1,8 @@ +use crate::utils::consts::MOSAIC_ROOT_LAYOUT_DIR; use directories_next::ProjectDirs; use serde::{Deserialize, Serialize}; -use std::{fs::File, io::prelude::*, path::PathBuf}; +use std::path::{Path, PathBuf}; +use std::{fs::File, io::prelude::*}; use crate::panes::PositionAndSize; @@ -182,9 +184,11 @@ impl Layout { pub fn new(layout_path: PathBuf) -> Self { let project_dirs = ProjectDirs::from("org", "Mosaic Contributors", "Mosaic").unwrap(); let layout_dir = project_dirs.data_dir().join("layouts/"); + let root_layout_dir = Path::new(MOSAIC_ROOT_LAYOUT_DIR); let mut layout_file = File::open(&layout_path) .or_else(|_| File::open(&layout_path.with_extension("yaml"))) .or_else(|_| File::open(&layout_dir.join(&layout_path).with_extension("yaml"))) + .or_else(|_| File::open(root_layout_dir.join(&layout_path).with_extension("yaml"))) .unwrap_or_else(|_| panic!("cannot find layout {}", &layout_path.display())); let mut layout = String::new(); diff --git a/src/main.rs b/src/main.rs index a913de16..dd6f91af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ mod wasm_vm; use std::io::Write; use std::os::unix::net::UnixStream; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::sync::mpsc::{channel, sync_channel, Receiver, SendError, Sender, SyncSender}; use std::thread; use std::{cell::RefCell, sync::mpsc::TrySendError}; @@ -44,6 +44,7 @@ use crate::layout::Layout; use crate::os_input_output::{get_os_input, OsApi}; use crate::pty_bus::{PtyBus, PtyInstruction, VteEvent}; use crate::screen::{Screen, ScreenInstruction}; +use crate::utils::consts::MOSAIC_ROOT_PLUGIN_DIR; use crate::utils::{ consts::{MOSAIC_IPC_PIPE, MOSAIC_TMP_DIR, MOSAIC_TMP_LOG_DIR}, logging::*, @@ -452,9 +453,13 @@ pub fn start(mut os_input: Box, opts: CliArgs) { let project_dirs = ProjectDirs::from("org", "Mosaic Contributors", "Mosaic").unwrap(); let plugin_dir = project_dirs.data_dir().join("plugins/"); + let root_plugin_dir = Path::new(MOSAIC_ROOT_PLUGIN_DIR); 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"))) + .or_else(|_| { + fs::read(&root_plugin_dir.join(&path).with_extension("wasm")) + }) .unwrap_or_else(|_| panic!("cannot find plugin {}", &path.display())); // FIXME: Cache this compiled module on disk. I could use `(de)serialize_to_file()` for that diff --git a/src/utils/consts.rs b/src/utils/consts.rs index 5aa6aab4..7a0c9ddf 100644 --- a/src/utils/consts.rs +++ b/src/utils/consts.rs @@ -2,3 +2,5 @@ pub const MOSAIC_TMP_DIR: &str = "/tmp/mosaic"; pub const MOSAIC_TMP_LOG_DIR: &str = "/tmp/mosaic/mosaic-log"; pub const MOSAIC_TMP_LOG_FILE: &str = "/tmp/mosaic/mosaic-log/log.txt"; pub const MOSAIC_IPC_PIPE: &str = "/tmp/mosaic/ipc"; +pub const MOSAIC_ROOT_PLUGIN_DIR: &str = "/usr/share/mosaic/plugins"; +pub const MOSAIC_ROOT_LAYOUT_DIR: &str = "/usr/share/mosaic/layouts";