diff --git a/src/core/dispatch.rs b/src/core/dispatch.rs index 5d5823c..b37a43b 100644 --- a/src/core/dispatch.rs +++ b/src/core/dispatch.rs @@ -1,4 +1,5 @@ use crate::core::message::{Destination, Envelope, Message, PlayerCommand, WifiCommand}; +use crate::core::plugin_ids; /// 命令解析结果 pub struct DispatchResult { @@ -137,7 +138,7 @@ fn ok_video(from: &str, message: Message) -> Result { Ok(DispatchResult { envelope: Envelope { from: from.to_string(), - to: Destination::Plugin("video".to_string()), + to: Destination::Plugin(plugin_ids::VIDEO.to_string()), message, }, }) @@ -147,7 +148,7 @@ fn ok_wifi(from: &str, message: Message) -> Result { Ok(DispatchResult { envelope: Envelope { from: from.to_string(), - to: Destination::Plugin("wifi".to_string()), + to: Destination::Plugin(plugin_ids::WIFI.to_string()), message, }, }) diff --git a/src/core/mod.rs b/src/core/mod.rs index a949977..698ac7d 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -9,5 +9,15 @@ pub mod plugin_repo; pub mod service_manager; pub mod version_manager; +/// 内置插件 ID 常量 +pub mod plugin_ids { + pub const VIDEO: &str = "video"; + pub const HTTP: &str = "http"; + pub const WIFI: &str = "wifi"; + pub const BLE: &str = "ble"; + pub const DEVICE: &str = "device"; + pub const SCREEN: &str = "screen"; +} + #[cfg(test)] mod tests; diff --git a/src/plugins/http/mod.rs b/src/plugins/http/mod.rs index 374bee7..9aabf80 100644 --- a/src/plugins/http/mod.rs +++ b/src/plugins/http/mod.rs @@ -244,7 +244,7 @@ impl Plugin for HttpPlugin { } fn dependencies(&self) -> Vec { - vec!["video".to_string()] + vec![crate::core::plugin_ids::VIDEO.to_string()] } fn init(&mut self, ctx: PluginContext) -> Result<()> { diff --git a/src/plugins/screen/mod.rs b/src/plugins/screen/mod.rs index 3b9a14d..8a7d9e6 100644 --- a/src/plugins/screen/mod.rs +++ b/src/plugins/screen/mod.rs @@ -9,6 +9,7 @@ use crate::core::{ message::{Destination, DeviceCommand, Envelope, Message}, plugin::*, + plugin_ids, }; use anyhow::Result; @@ -25,7 +26,7 @@ impl ScreenPlugin { if let Some(ctx) = &self.ctx { let envelope = Envelope { from: self.id().to_string(), - to: Destination::Plugin("device".to_string()), + to: Destination::Plugin(plugin_ids::DEVICE.to_string()), message: Message::DeviceCommand(DeviceCommand::SetSleepInhibit(true)), }; let _ = ctx.tx.send(envelope); @@ -36,7 +37,7 @@ impl ScreenPlugin { if let Some(ctx) = &self.ctx { let envelope = Envelope { from: self.id().to_string(), - to: Destination::Plugin("device".to_string()), + to: Destination::Plugin(plugin_ids::DEVICE.to_string()), message: Message::DeviceCommand(DeviceCommand::SetSleepInhibit(false)), }; let _ = ctx.tx.send(envelope); @@ -47,7 +48,7 @@ impl ScreenPlugin { if let Some(ctx) = &self.ctx { let envelope = Envelope { from: self.id().to_string(), - to: Destination::Plugin("device".to_string()), + to: Destination::Plugin(plugin_ids::DEVICE.to_string()), message: Message::DeviceCommand(DeviceCommand::SetCursorVisible(!hidden)), }; let _ = ctx.tx.send(envelope); @@ -76,7 +77,7 @@ impl Plugin for ScreenPlugin { } fn dependencies(&self) -> Vec { - vec!["device".to_string()] + vec![plugin_ids::DEVICE.to_string()] } fn init(&mut self, ctx: PluginContext) -> Result<()> { diff --git a/src/plugins/video/mod.rs b/src/plugins/video/mod.rs index 6e4e906..9c6f032 100644 --- a/src/plugins/video/mod.rs +++ b/src/plugins/video/mod.rs @@ -7,6 +7,7 @@ pub mod state_machine; use crate::core::message::{Destination, Envelope, Message, PlayerCommand, PlayerStatusData}; use crate::core::plugin::{Platform, Plugin, PluginContext, PluginInfo}; +use crate::core::plugin_ids; use anyhow::{anyhow, Context, Result}; use opencv::highgui; use processor::VideoProcessor; @@ -151,7 +152,7 @@ impl Plugin for VideoPlugin { if let Some(ctx) = &self.ctx { let _ = ctx.tx.send(Envelope { from: self.id().to_string(), - to: Destination::Plugin("screen".to_string()), + to: Destination::Plugin(plugin_ids::SCREEN.to_string()), message: Message::ScreenLockRequest(true), }); } @@ -162,7 +163,7 @@ impl Plugin for VideoPlugin { if let Some(ctx) = &self.ctx { let _ = ctx.tx.send(Envelope { from: self.id().to_string(), - to: Destination::Plugin("screen".to_string()), + to: Destination::Plugin(plugin_ids::SCREEN.to_string()), message: Message::ScreenLockRequest(false), }); }