#search #gnome #provider #dbus

search-provider

Rust wrapper around the GNOME Shell search provider API

13 releases (8 breaking)

0.10.0 Jul 10, 2024
0.8.1 Feb 22, 2024
0.7.0 Feb 4, 2024
0.6.0 Jul 24, 2023
0.1.0 May 6, 2019

#1107 in GUI

Download history 191/week @ 2024-07-19 136/week @ 2024-07-26 114/week @ 2024-08-02 91/week @ 2024-08-09 105/week @ 2024-08-16 162/week @ 2024-08-23 161/week @ 2024-08-30 139/week @ 2024-09-06 223/week @ 2024-09-13 1135/week @ 2024-09-20 446/week @ 2024-09-27 276/week @ 2024-10-04 242/week @ 2024-10-11 56/week @ 2024-10-18 90/week @ 2024-10-25 33/week @ 2024-11-01

474 downloads per month
Used in 2 crates

GPL-3.0-or-later

19KB
296 lines

search-provider

Rust wrapper around the GNOME Shell search provider API


lib.rs:

The crate aims to provide an easy to use wrapper around the GNOME Shell Search Provider DBus interface.

How to use

use search_provider::{ResultID, ResultMeta, SearchProviderImpl};
use std::collections::HashMap;

#[derive(Debug)]
struct Application {
    results: HashMap<String, String>,
}
impl SearchProviderImpl for Application {
    fn activate_result(&self, identifier: ResultID, terms: &[String], timestamp: u32) {
        let result = self.results.get(&identifier);
        println!(
            "activating result {:#?} identified by {}",
            result, identifier
        );
    }

    fn initial_result_set(&self, terms: &[String]) -> Vec<ResultID> {
        // Here do your search logic
        if terms.contains(&"some_value".to_owned()) {
            vec!["some_key".to_owned()]
        } else {
            vec![]
        }
    }

    fn result_metas(&self, identifiers: &[ResultID]) -> Vec<ResultMeta> {
        self.results
            .iter()
            .map(|(identifier, value)| {
                ResultMeta::builder(identifier.to_owned(), "Some name")
                    .description("Some description of the current identifier")
                    .build()
            })
            .collect::<Vec<_>>()
    }
}
use search_provider::SearchProvider;
use std::collections::HashMap;

async fn main_entry() -> zbus::Result<()> {
    let mut results = HashMap::new();
    results.insert("some_key".to_string(), "some_value".to_string());
    let app = Application { results };
    let provider = SearchProvider::new(
        app,
        "org.gnome.design.IconLibrary.SearchProvider",
        "/org/gnome/design/IconLibrary/SearchProvider",
    )
    .await?;
    Ok(())
}

Dependencies

~6–18MB
~276K SLoC