#plugin #anyrun #plugin-api

anyrun-plugin

The crate for building plugins for Anyrun

1 unstable release

0.1.0 Aug 21, 2023

#31 in #plugin-api

Download history 2/week @ 2024-01-13 2/week @ 2024-02-10 27/week @ 2024-02-17 23/week @ 2024-02-24 25/week @ 2024-03-02 29/week @ 2024-03-09 21/week @ 2024-03-16 26/week @ 2024-03-23 40/week @ 2024-03-30 23/week @ 2024-04-06 23/week @ 2024-04-13 26/week @ 2024-04-20 14/week @ 2024-04-27

92 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–10MB
~97K SLoC