pop-launcher/src/lib.rs

125 lines
3.8 KiB
Rust
Raw Normal View History

2021-08-10 01:04:20 +02:00
mod codec;
pub use self::codec::*;
use serde::{Deserialize, Serialize};
use std::{borrow::Cow, path::PathBuf};
/// u32 value defining the generation of an indice.
2021-08-10 01:04:20 +02:00
pub type Generation = u32;
/// u32 value defining the indice of a slot.
pub type Indice = u32;
2021-08-10 01:04:20 +02:00
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum IconSource {
// Locate by name or path.
2021-08-10 01:04:20 +02:00
Name(Cow<'static, str>),
// Icon is a mime type.
2021-08-10 01:04:20 +02:00
Mime(Cow<'static, str>),
// Window Entity ID.
2021-08-10 01:04:20 +02:00
Window((Generation, Indice)),
}
/// Sent from a plugin to the launcher service.
2021-08-10 01:04:20 +02:00
#[derive(Debug, Deserialize, Serialize)]
pub enum PluginResponse {
/// Append a new search item to the launcher.
Append(PluginSearchResult),
/// Clear all results in the launcher list.
2021-08-10 01:04:20 +02:00
Clear,
/// Close the launcher.
2021-08-10 01:04:20 +02:00
Close,
// Notifies that a .desktop entry should be launched by the frontend.
2021-08-10 01:04:20 +02:00
DesktopEntry(PathBuf),
/// Update the text in the launcher.
2021-08-10 01:04:20 +02:00
Fill(String),
/// Indicoates that a plugin is finished with its queries.
2021-08-10 01:04:20 +02:00
Finished,
}
/// Search information from a plugin to be sorted and filtered by the launcher service.
2021-08-10 01:04:20 +02:00
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct PluginSearchResult {
/// Numeric identifier tracked by the plugin.
2021-08-10 01:04:20 +02:00
pub id: Indice,
/// The name / title.
2021-08-10 01:04:20 +02:00
pub name: String,
/// The description / subtitle.
2021-08-10 01:04:20 +02:00
pub description: String,
/// Extra words to match when sorting and filtering.
2021-08-10 01:04:20 +02:00
pub keywords: Option<Vec<String>>,
/// Icon to display in the frontend.
2021-08-10 01:04:20 +02:00
pub icon: Option<IconSource>,
/// Command that is executed by this result, used for sorting and filtering.
2021-08-10 01:04:20 +02:00
pub exec: Option<String>,
/// Designates that this search item refers to a window.
2021-08-10 01:04:20 +02:00
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 {
/// Activate on the selected item.
Activate(Indice),
/// Perform a tab completion from the selected item.
Complete(Indice),
/// Request to end the service.
Exit,
/// Requests to cancel any active searches.
Interrupt,
/// Request to close the selected item.
Quit(Indice),
/// Perform a search in our database.
Search(String),
}
/// Sent from the launcher service to a frontend.
#[derive(Debug, Deserialize, Serialize)]
pub enum Response {
// An operation was performed and the frontend may choose to exit its process.
Close,
// Notifies that a .desktop entry should be launched by the frontend.
DesktopEntry(PathBuf),
// The frontend should clear its search results and display a new list.
Update(Vec<SearchResult>),
// An item was selected that resulted in a need to autofill the launcher.
Fill(String),
}
2021-08-10 01:04:20 +02:00
/// Serialized response to launcher frontend about a search result.
#[derive(Debug, Serialize, Deserialize)]
pub struct SearchResult {
/// Numeric identifier tracked by the plugin.
2021-08-10 01:04:20 +02:00
pub id: Indice,
/// The name / title.
2021-08-10 01:04:20 +02:00
pub name: String,
/// The description / subtitle.
2021-08-10 01:04:20 +02:00
pub description: String,
2021-08-10 01:04:20 +02:00
#[serde(
default,
skip_serializing_if = "Option::is_none",
with = "::serde_with::rust::unwrap_or_skip"
)]
/// Icon to display in the frontend for this item
2021-08-10 01:04:20 +02:00
pub icon: Option<IconSource>,
2021-08-10 01:04:20 +02:00
#[serde(
default,
skip_serializing_if = "Option::is_none",
with = "::serde_with::rust::unwrap_or_skip"
)]
/// Icon to display in the frontend for this plugin
2021-08-10 01:04:20 +02:00
pub category_icon: Option<IconSource>,
2021-08-10 01:04:20 +02:00
#[serde(
default,
skip_serializing_if = "Option::is_none",
with = "::serde_with::rust::unwrap_or_skip"
)]
/// Designates that this search item refers to a window.
2021-08-10 01:04:20 +02:00
pub window: Option<(Generation, Indice)>,
}