CrossPoint.registerPlugin((container, api) => {
api.registerAction('save-url', async (args) => {
if (!args.url) throw new Error('url required'); // -> state "error", result {error: "url required"}
const name = (args.name || 'download') + '.epub';
const res = await api.fetchToSd(args.url, '/Books/Inbox/' + name);
return { path: '/Books/Inbox/' + name, bytes: res.bytes }; // -> state "done", result {...}
});
});
- fn(args) may be async. Its return value becomes result (undefined/null -> {}).
- Throwing -> state error with {error: message}.
- Returning something JSON.stringify can't handle (BigInt, circular) -> error.
- An unknown action name -> error {error: "unknown action: x"}.
- Register actions inside the render function. They exist only once your plugin has rendered on that page.
- Which pages load your plugin depends on mount (see chapter 3). /plugins-run loads every plugin regardless of mount.