picoframe_core/lib.rs
1//! Core types and the base frame plugin for picoframe Tauri apps.
2//!
3//! Every picoframe plugin command returns a [`CliResult`] — a small, uniform
4//! envelope the frontend's typed `defineCommand` bindings unwrap. This mirrors
5//! the engineer-assist `CliResult` pattern but trimmed to the essentials.
6
7use serde::Serialize;
8use serde_json::Value;
9use tauri::{
10 plugin::{Builder, TauriPlugin},
11 Runtime,
12};
13
14/// Uniform result envelope returned by picoframe plugin commands.
15#[derive(Debug, Clone, Serialize)]
16pub struct CliResult {
17 pub success: bool,
18 #[serde(skip_serializing_if = "Option::is_none")]
19 pub data: Option<Value>,
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub error: Option<String>,
22}
23
24impl CliResult {
25 /// A successful result carrying a JSON payload.
26 pub fn ok(data: Value) -> Self {
27 Self { success: true, data: Some(data), error: None }
28 }
29
30 /// A failed result carrying an error message.
31 pub fn err(message: impl Into<String>) -> Self {
32 Self { success: false, data: None, error: Some(message.into()) }
33 }
34}
35
36/// The base frame plugin. Registered first in every picoframe app's builder.
37///
38/// It currently registers no commands — window/theme commands land in Phase 1.
39/// It exists now so the generated `main.rs` template can call
40/// `.plugin(picoframe_core::init())` as a stable anchor above the plugin markers.
41pub fn init<R: Runtime>() -> TauriPlugin<R> {
42 Builder::new("picoframe").build()
43}