Crates.io | anyrun-plugin |
lib.rs | anyrun-plugin |
version | 0.1.0 |
source | src |
created_at | 2023-08-21 15:51:00.74137 |
updated_at | 2023-08-21 15:51:00.74137 |
description | The crate for building plugins for Anyrun |
homepage | https://github.com/anyrun-org/plugin |
repository | https://github.com/anyrun-org/plugin |
max_upload_size | |
id | 950095 |
size | 38,523 |
The main easy to use crate for creating Anyrun plugins.
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
}