#plugin #anyrun #plugin-api

anyrun-plugin

The crate for building plugins for Anyrun

1 unstable release

0.1.0 Aug 21, 2023

#59 in #plugin-api

Download history 25/week @ 2024-07-29 15/week @ 2024-08-05 21/week @ 2024-08-12 14/week @ 2024-08-19 60/week @ 2024-08-26 33/week @ 2024-09-02 34/week @ 2024-09-09 28/week @ 2024-09-16 58/week @ 2024-09-23 38/week @ 2024-09-30 10/week @ 2024-10-07 32/week @ 2024-10-14 14/week @ 2024-10-21 24/week @ 2024-10-28 27/week @ 2024-11-04 4/week @ 2024-11-11

71 downloads per month

GPL-3.0 license

14KB

anyrun-plugin

The main easy to use crate for creating Anyrun plugins.

Usage

The plugin API is intentionally very simple to use. This is all you need for a plugin:

Cargo.toml:

#[package] omitted
[lib]
crate-type = ["cdylib"] # Required to build a dynamic library that can be loaded by anyrun

[dependencies]
anyrun-plugin = { git = "https://github.com/Kirottu/anyrun" }
abi_stable = "0.11.1"
# Any other dependencies you may have

lib.rs:

use abi_stable::std_types::{RString, RVec, ROption};
use anyrun_plugin::*;

#[init]
fn init(config_dir: RString) {
  // Your initialization code. This is run in another thread.
  // The return type is the data you want to share between functions
}

#[info]
fn info() -> PluginInfo {
  PluginInfo {
    name: "Demo".into(),
    icon: "help-about".into(), // Icon from the icon theme
  }
}

#[get_matches]
fn get_matches(input: RString) -> RVec<Match> {
  // The logic to get matches from the input text in the `input` argument.
  // The `data` is a mutable reference to the shared data type later specified.
  vec![Match {
    title: "Test match".into(),
    icon: ROption::RSome("help-about".into()),
    use_pango: false,
    description: ROption::RSome("Test match for the plugin API demo".into()),
    id: ROption::RNone, // The ID can be used for identifying the match later, is not required
  }].into()
}

#[handler]
fn handler(selection: Match) -> HandleResult {
  // Handle the selected match and return how anyrun should proceed
  HandleResult::Close
}

Dependencies

~4–9.5MB
~97K SLoC