From 47852e53cb6f637003ed6bdb178fe76cb90dff24 Mon Sep 17 00:00:00 2001 From: Paul Delafosse Date: Wed, 11 May 2022 14:09:27 +0200 Subject: [PATCH] feat: add a toolkit crate for both client and pop-launcher-bin --- Cargo.lock | 12 ++++++++++-- Cargo.toml | 2 +- bin/Cargo.toml | 3 +-- bin/src/main.rs | 4 ++-- plugins/src/web/config.rs | 8 ++++---- plugins/src/web/mod.rs | 3 +-- service/src/lib.rs | 2 ++ service/src/plugins/config.rs | 6 +++--- service/src/plugins/mod.rs | 4 +++- src/lib.rs | 14 +++++++------- toolkit/Cargo.toml | 12 ++++++++++++ toolkit/src/lib.rs | 10 ++++++++++ 12 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 toolkit/Cargo.toml create mode 100644 toolkit/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index d122abb..4d6e0b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1075,8 +1075,7 @@ version = "1.2.1" dependencies = [ "dirs 4.0.0", "mimalloc", - "pop-launcher-plugins", - "pop-launcher-service", + "pop-launcher-toolkit", "tokio", "tracing", "tracing-subscriber", @@ -1143,6 +1142,15 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "pop-launcher-toolkit" +version = "0.1.0" +dependencies = [ + "pop-launcher", + "pop-launcher-plugins", + "pop-launcher-service", +] + [[package]] name = "ppv-lite86" version = "0.2.16" diff --git a/Cargo.toml b/Cargo.toml index 8138859..556ffdf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/pop-os/launcher" edition = "2018" [workspace] -members = ["bin", "plugins", "service"] +members = ["bin", "plugins", "service", "toolkit"] [dependencies] const_format = "0.2.22" diff --git a/bin/Cargo.toml b/bin/Cargo.toml index ddcb481..1fcd391 100644 --- a/bin/Cargo.toml +++ b/bin/Cargo.toml @@ -8,8 +8,7 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -pop-launcher-plugins = { path = "../plugins" } -pop-launcher-service = { path = "../service" } +pop-launcher-toolkit = { path = "../toolkit" } tracing = "0.1.32" tracing-subscriber = { version = "0.3.9", default-features = false, features = ["std", "fmt", "env-filter"] } dirs = "4.0.0" diff --git a/bin/src/main.rs b/bin/src/main.rs index ea200ee..20076ce 100644 --- a/bin/src/main.rs +++ b/bin/src/main.rs @@ -1,8 +1,8 @@ // Copyright 2021 System76 // SPDX-License-Identifier: MPL-2.0 -use pop_launcher_plugins as plugins; -use pop_launcher_service as service; +use pop_launcher_toolkit::plugins; +use pop_launcher_toolkit::service; use mimalloc::MiMalloc; diff --git a/plugins/src/web/config.rs b/plugins/src/web/config.rs index 33ae287..19b5b70 100644 --- a/plugins/src/web/config.rs +++ b/plugins/src/web/config.rs @@ -5,7 +5,7 @@ use serde::Deserialize; use slab::Slab; use std::collections::HashMap; -#[derive(Default)] +#[derive(Default, Clone)] pub struct Config { matches: HashMap, queries: Slab>, @@ -29,18 +29,18 @@ impl Config { } } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Clone)] pub struct RawConfig { pub rules: Vec, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Clone)] pub struct Rule { pub matches: Vec, pub queries: Vec, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Clone)] pub struct Definition { pub name: String, pub query: String, diff --git a/plugins/src/web/mod.rs b/plugins/src/web/mod.rs index 2461615..8ca427b 100644 --- a/plugins/src/web/mod.rs +++ b/plugins/src/web/mod.rs @@ -12,11 +12,10 @@ use url::Url; use pop_launcher::*; -use self::config::{Config, Definition}; +pub use config::{Config, Definition, load}; use regex::Regex; mod config; - pub async fn main() { let mut app = App::default(); diff --git a/service/src/lib.rs b/service/src/lib.rs index 2207e8c..6d7d6f9 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -5,6 +5,8 @@ mod client; mod plugins; pub use client::*; +pub use plugins::config; +pub use plugins::external::load; use crate::plugins::*; use flume::{Receiver, Sender}; diff --git a/service/src/plugins/config.rs b/service/src/plugins/config.rs index c9e31dc..a6c048d 100644 --- a/service/src/plugins/config.rs +++ b/service/src/plugins/config.rs @@ -8,7 +8,7 @@ use std::{ path::{Path, PathBuf}, }; -#[derive(Debug, Default, Deserialize)] +#[derive(Debug, Default, Deserialize, Clone)] pub struct PluginConfig { pub name: Cow<'static, str>, pub description: Cow<'static, str>, @@ -32,7 +32,7 @@ pub struct PluginConfig { pub history: bool, } -#[derive(Debug, Default, Deserialize)] +#[derive(Debug, Default, Deserialize, Clone)] pub struct PluginBinary { path: Cow<'static, str>, @@ -41,7 +41,7 @@ pub struct PluginBinary { args: Vec>, } -#[derive(Debug, Default, Deserialize)] +#[derive(Debug, Default, Deserialize, Clone)] pub struct PluginQuery { #[serde( default, diff --git a/service/src/plugins/mod.rs b/service/src/plugins/mod.rs index 0d08a79..656c189 100644 --- a/service/src/plugins/mod.rs +++ b/service/src/plugins/mod.rs @@ -1,10 +1,12 @@ // Copyright 2021 System76 // SPDX-License-Identifier: MPL-2.0 -mod config; pub(crate) mod external; +pub mod config; pub mod help; +pub use external::load; + pub use self::config::{PluginBinary, PluginConfig, PluginPriority, PluginQuery}; pub use self::external::ExternalPlugin; pub use self::help::HelpPlugin; diff --git a/src/lib.rs b/src/lib.rs index 9776d03..169562f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,13 +44,13 @@ pub type Generation = u32; /// u32 value defining the indice of a slot. pub type Indice = u32; -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Clone)] pub struct ContextOption { pub id: Indice, pub name: String, } -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Clone)] pub enum GpuPreference { Default, NonDefault, @@ -65,7 +65,7 @@ pub enum IconSource { } /// Sent from a plugin to the launcher service. -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Clone)] pub enum PluginResponse { /// Append a new search item to the launcher. Append(PluginSearchResult), @@ -92,7 +92,7 @@ pub enum PluginResponse { } /// Search information from a plugin to be sorted and filtered by the launcher service. -#[derive(Debug, Default, Deserialize, Serialize)] +#[derive(Debug, Default, Deserialize, Serialize, Clone)] pub struct PluginSearchResult { /// Numeric identifier tracked by the plugin. pub id: Indice, @@ -111,7 +111,7 @@ pub struct PluginSearchResult { } // Sent to the input pipe of the launcher service, and disseminated to its plugins. -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Clone)] pub enum Request { /// Activate on the selected item. Activate(Indice), @@ -132,7 +132,7 @@ pub enum Request { } /// Sent from the launcher service to a frontend. -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Clone)] pub enum Response { // An operation was performed and the frontend may choose to exit its process. Close, @@ -153,7 +153,7 @@ pub enum Response { } /// Serialized response to launcher frontend about a search result. -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct SearchResult { /// Numeric identifier tracked by the plugin. pub id: Indice, diff --git a/toolkit/Cargo.toml b/toolkit/Cargo.toml new file mode 100644 index 0000000..f0fdbf0 --- /dev/null +++ b/toolkit/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "pop-launcher-toolkit" +version = "0.1.0" +edition = "2021" +description = "A wrapper around pop-launcher, pop-launcher-service and pop-launcher-plugins types for writing plugins and frontends for pop-launcher." + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +pop-launcher-plugins = { path = "../plugins"} +pop-launcher-service = { path = "../service"} +pop-launcher = { path = "../" } \ No newline at end of file diff --git a/toolkit/src/lib.rs b/toolkit/src/lib.rs new file mode 100644 index 0000000..cd7aee5 --- /dev/null +++ b/toolkit/src/lib.rs @@ -0,0 +1,10 @@ +// Copyright 2021 System76 +// SPDX-License-Identifier: MPL-2.0 + +pub use pop_launcher_service::{ + self as service, + load::from_path as load_plugin_from_path, + load::from_paths as load_plugins_from_paths +}; +pub use pop_launcher_plugins as plugins; +pub use pop_launcher as launcher;