Expand description
Write Mochi plugin backends in Rust.
A plugin backend is a program mochid starts and talks to over a socket.
This crate does the talking: ModuleCtx has the same calls as a
builtin module’s context in mochid, so a plugin can show activities on
the island, bubbles, answer mochi ipc actions and publish state for
its views, like any builtin.
use mochi_sdk::{ActivitySpec, ModuleCtx, ModuleEvent, json};
fn main() -> std::process::ExitCode {
mochi_sdk::run(hello)
}
async fn hello(mut ctx: ModuleCtx) -> Result<(), mochi_sdk::Error> {
while let Some(event) = ctx.next_event().await {
if let ModuleEvent::Command(command) = event {
// `mochi ipc hello say`, declared in mochi-plugin.toml.
let spec = ActivitySpec::new("Hello").payload(json!({ "text": "Hi" }));
ctx.present(spec);
command.reply(Ok(()));
}
}
Ok(())
}The backend runs until mochid closes the connection: then
ModuleCtx::next_event returns None, and the plugin should return.
Re-exports§
pub use mochi_protocol as protocol;
Macros§
- json
- Construct a
serde_json::Valuefrom a JSON literal.
Structs§
- Activity
Id - Identifies one activity for its whole life, across the daemon and the UI.
- Activity
Spec - Everything a module says about an activity it wants to show.
- Args
- Parsed arguments, looked up by name.
- Bubble
Id - Identifies one bubble for its whole life, across the daemon and the UI.
- Bubble
Spec - Everything a module says about a bubble it wants to show.
- Compositor
State - The compositor’s state, as
ModuleCtx::compositorgives builtins. - Contribution
- One thing a module offers another.
- Module
Command - An action to run, with arguments already checked against the manifest. Dropping it without an answer tells the caller it failed.
- Module
Ctx - The plugin’s connection to mochid. Every call is one message, and none waits for mochid unless it returns a future.
- Output
Info - A monitor.
- Priority
- Higher values win. The named levels leave room for anything in between.
- Window
Info - A window on a visible workspace.
- Workspace
Info - A workspace.
Enums§
- Area
- One of the five places along the edge, from left to right. The island sits in one of them too.
- ArgValue
- One parsed argument, of the kind its action declares.
- Call
Error - Why calling another module’s action failed.
- EndReason
- Why an activity ended.
- Module
Event - What mochid tells the plugin.
- Same
Priority - What a new activity does when the shown one has the same priority.
- Value
- Represents any valid JSON value.
Constants§
- API
- The protocol version both sides announce in
hello.
Functions§
- run
- Connects to mochid, runs
pluginuntil it returns, and turns its result into an exit code. Runs on a single-threaded tokio runtime; to pick another, useModuleCtx::connectfrom your own.
Type Aliases§
- Error
- Any error a plugin returns:
?turns most errors into it, and"text".into()makes one from a message.