refactor: introduce plugin_ids constants, replace hardcoded plugin ID strings
This commit is contained in:
@@ -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<DispatchResult, String> {
|
||||
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<DispatchResult, String> {
|
||||
Ok(DispatchResult {
|
||||
envelope: Envelope {
|
||||
from: from.to_string(),
|
||||
to: Destination::Plugin("wifi".to_string()),
|
||||
to: Destination::Plugin(plugin_ids::WIFI.to_string()),
|
||||
message,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -244,7 +244,7 @@ impl Plugin for HttpPlugin {
|
||||
}
|
||||
|
||||
fn dependencies(&self) -> Vec<String> {
|
||||
vec!["video".to_string()]
|
||||
vec![crate::core::plugin_ids::VIDEO.to_string()]
|
||||
}
|
||||
|
||||
fn init(&mut self, ctx: PluginContext) -> Result<()> {
|
||||
|
||||
@@ -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<String> {
|
||||
vec!["device".to_string()]
|
||||
vec![plugin_ids::DEVICE.to_string()]
|
||||
}
|
||||
|
||||
fn init(&mut self, ctx: PluginContext) -> Result<()> {
|
||||
|
||||
@@ -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),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user