feat(plugin): Search in root folder for plugins and layout files
This commit is contained in:
parent
decc38232b
commit
c32b837df7
3 changed files with 13 additions and 2 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
|
use crate::utils::consts::MOSAIC_ROOT_LAYOUT_DIR;
|
||||||
use directories_next::ProjectDirs;
|
use directories_next::ProjectDirs;
|
||||||
use serde::{Deserialize, Serialize};
|
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;
|
use crate::panes::PositionAndSize;
|
||||||
|
|
||||||
|
|
@ -182,9 +184,11 @@ impl Layout {
|
||||||
pub fn new(layout_path: PathBuf) -> Self {
|
pub fn new(layout_path: PathBuf) -> Self {
|
||||||
let project_dirs = ProjectDirs::from("org", "Mosaic Contributors", "Mosaic").unwrap();
|
let project_dirs = ProjectDirs::from("org", "Mosaic Contributors", "Mosaic").unwrap();
|
||||||
let layout_dir = project_dirs.data_dir().join("layouts/");
|
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)
|
let mut layout_file = File::open(&layout_path)
|
||||||
.or_else(|_| File::open(&layout_path.with_extension("yaml")))
|
.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(&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()));
|
.unwrap_or_else(|_| panic!("cannot find layout {}", &layout_path.display()));
|
||||||
|
|
||||||
let mut layout = String::new();
|
let mut layout = String::new();
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ mod wasm_vm;
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::os::unix::net::UnixStream;
|
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::sync::mpsc::{channel, sync_channel, Receiver, SendError, Sender, SyncSender};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::{cell::RefCell, sync::mpsc::TrySendError};
|
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::os_input_output::{get_os_input, OsApi};
|
||||||
use crate::pty_bus::{PtyBus, PtyInstruction, VteEvent};
|
use crate::pty_bus::{PtyBus, PtyInstruction, VteEvent};
|
||||||
use crate::screen::{Screen, ScreenInstruction};
|
use crate::screen::{Screen, ScreenInstruction};
|
||||||
|
use crate::utils::consts::MOSAIC_ROOT_PLUGIN_DIR;
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
consts::{MOSAIC_IPC_PIPE, MOSAIC_TMP_DIR, MOSAIC_TMP_LOG_DIR},
|
consts::{MOSAIC_IPC_PIPE, MOSAIC_TMP_DIR, MOSAIC_TMP_LOG_DIR},
|
||||||
logging::*,
|
logging::*,
|
||||||
|
|
@ -452,9 +453,13 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
|
||||||
let project_dirs =
|
let project_dirs =
|
||||||
ProjectDirs::from("org", "Mosaic Contributors", "Mosaic").unwrap();
|
ProjectDirs::from("org", "Mosaic Contributors", "Mosaic").unwrap();
|
||||||
let plugin_dir = project_dirs.data_dir().join("plugins/");
|
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)
|
let wasm_bytes = fs::read(&path)
|
||||||
.or_else(|_| fs::read(&path.with_extension("wasm")))
|
.or_else(|_| fs::read(&path.with_extension("wasm")))
|
||||||
.or_else(|_| fs::read(&plugin_dir.join(&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()));
|
.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
|
// FIXME: Cache this compiled module on disk. I could use `(de)serialize_to_file()` for that
|
||||||
|
|
|
||||||
|
|
@ -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_DIR: &str = "/tmp/mosaic/mosaic-log";
|
||||||
pub const MOSAIC_TMP_LOG_FILE: &str = "/tmp/mosaic/mosaic-log/log.txt";
|
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_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";
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue