From ebb3e83b73a35b29b39cf690af1da91a99ad9ac3 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Sun, 15 Aug 2021 13:16:55 +0200 Subject: [PATCH] feat(library): Add constants for plugin paths --- Cargo.lock | 25 +++++++++++++++++++++++-- Cargo.toml | 7 ++++--- src/codec.rs | 2 +- src/lib.rs | 30 ++++++++++++++++++++++++++++-- 4 files changed, 56 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eeca2fd..680c69f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,9 +22,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.42" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "595d3cfa7a60d4555cb5067b99f07142a08ea778de5cf993f7b75c7d8fabc486" +checksum = "28ae2b3dec75a406790005a200b1bd89785afc02517a00ca99ecfe093ee9e6cf" [[package]] name = "async-channel" @@ -245,6 +245,26 @@ dependencies = [ "cache-padded", ] +[[package]] +name = "const_format" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49aad96768495418a04c9349327f32f2cd7e9bf8ac6b142534466048721c8ff5" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c36c619c422113552db4eb28cddba8faa757e33f758cc3415bd2885977b591" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + [[package]] name = "darling" version = "0.13.0" @@ -762,6 +782,7 @@ name = "pop-launcher" version = "1.0.0" dependencies = [ "blocking", + "const_format", "futures-lite", "futures_codec", "serde", diff --git a/Cargo.toml b/Cargo.toml index 6925833..aeb0dbc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,9 +11,10 @@ resolver = "2" members = ["bin", "plugins", "service"] [dependencies] +blocking = "1" +const_format = "0.2" +futures_codec = "0.4" +futures-lite = "1" serde = { version = "1", features = ["derive"] } serde_json = "1" serde_with = "1" -futures-lite = "1" -futures_codec = "0.4" -blocking = "1" diff --git a/src/codec.rs b/src/codec.rs index 3917ac9..2273f86 100644 --- a/src/codec.rs +++ b/src/codec.rs @@ -1,7 +1,7 @@ +use blocking::Unblock; use futures_codec::{FramedRead, LinesCodec}; use futures_lite::{AsyncRead, Stream, StreamExt}; use serde::Deserialize; -use blocking::Unblock; use std::io; /// stdin with AsyncRead support diff --git a/src/lib.rs b/src/lib.rs index b16d691..7164340 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,8 +2,35 @@ mod codec; pub use self::codec::*; +use const_format::concatcp; use serde::{Deserialize, Serialize}; -use std::{borrow::Cow, path::PathBuf}; +use std::{borrow::Cow, path::{Path, PathBuf}}; + +pub const LOCAL: &str = "~/.local/share/pop-launcher"; +pub const LOCAL_PLUGINS: &str = concatcp!(LOCAL, "/plugins"); + +pub const SYSTEM: &str = "/etc/pop-launcher"; +pub const SYSTEM_PLUGINS: &str = concatcp!(SYSTEM, "/plugins"); + +pub const DISTRIBUTION: &str = "/usr/lib/pop-launcher"; +pub const DISTRIBUTION_PLUGINS: &str = concatcp!(DISTRIBUTION, "/plugins"); + +pub const PLUGIN_PATHS: &[&str] = &[LOCAL_PLUGINS, SYSTEM_PLUGINS, DISTRIBUTION_PLUGINS]; + +pub fn plugin_paths() -> impl Iterator> { + PLUGIN_PATHS.iter() + .map(|path| { + #[allow(deprecated)] + if let Some(path) = path.strip_prefix("~/") { + let path = std::env::home_dir() + .expect("user does not have home dir") + .join(path); + Cow::Owned(path) + } else { + Cow::Borrowed(Path::new(path)) + } + }) +} /// u32 value defining the generation of an indice. pub type Generation = u32; @@ -57,7 +84,6 @@ pub struct PluginSearchResult { pub window: Option<(Generation, Indice)>, } - // Sent to the input pipe of the launcher service, and disseminated to its plugins. #[derive(Debug, Deserialize, Serialize)] pub enum Request {