zerolaunch_plugin_host/
info.rs1use serde::Serialize;
8use zerolaunch_plugin_api::plugin::{PluginKind, PluginMetadata, PluginMode};
9
10use crate::manager::PluginRuntimeState;
11
12#[derive(Debug, Clone, Serialize)]
14pub struct PluginInfo {
15 #[serde(rename = "pluginId")]
17 pub plugin_id: String,
18 #[serde(rename = "name")]
19 pub name: String,
20 #[serde(rename = "version")]
21 pub version: String,
22 #[serde(rename = "description")]
23 pub description: String,
24 #[serde(rename = "author")]
25 pub author: String,
26 #[serde(rename = "state")]
28 pub state: PluginRuntimeState,
29 #[serde(rename = "enabled")]
31 pub enabled: bool,
32 #[serde(rename = "kind", default)]
34 pub kind: PluginKind,
35 #[serde(rename = "priority")]
36 pub priority: u32,
37 #[serde(rename = "canUninstall")]
39 pub can_uninstall: bool,
40 #[serde(rename = "canReload")]
42 pub can_reload: bool,
43 #[serde(rename = "canViewLogs")]
45 pub can_view_logs: bool,
46 #[serde(rename = "canToggle")]
48 pub can_toggle: bool,
49 #[serde(rename = "hotkey", default)]
51 pub hotkey: Option<String>,
52 #[serde(rename = "icon", default)]
54 pub icon: Option<String>,
55 #[serde(rename = "mode", default)]
57 pub mode: PluginMode,
58}
59
60impl PluginInfo {
61 pub fn from_metadata(meta: &PluginMetadata, state: PluginRuntimeState, enabled: bool) -> Self {
66 let third_party = meta.kind == PluginKind::ThirdParty;
67 let can_toggle = !(third_party && matches!(state, PluginRuntimeState::Error));
68 Self {
69 plugin_id: meta.id.clone(),
70 name: meta.name.clone(),
71 version: meta.version.clone(),
72 description: meta.description.clone(),
73 author: meta.author.clone(),
74 state,
75 enabled,
76 kind: meta.kind,
77 priority: meta.priority,
78 can_uninstall: third_party,
79 can_reload: third_party,
80 can_view_logs: third_party,
81 can_toggle,
82 hotkey: meta.hotkey.clone(),
83 icon: meta.icon.clone(),
84 mode: meta.mode,
85 }
86 }
87}