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::message::{Destination, Envelope, Message, PlayerCommand, WifiCommand};
|
||||||
|
use crate::core::plugin_ids;
|
||||||
|
|
||||||
/// 命令解析结果
|
/// 命令解析结果
|
||||||
pub struct DispatchResult {
|
pub struct DispatchResult {
|
||||||
@@ -137,7 +138,7 @@ fn ok_video(from: &str, message: Message) -> Result<DispatchResult, String> {
|
|||||||
Ok(DispatchResult {
|
Ok(DispatchResult {
|
||||||
envelope: Envelope {
|
envelope: Envelope {
|
||||||
from: from.to_string(),
|
from: from.to_string(),
|
||||||
to: Destination::Plugin("video".to_string()),
|
to: Destination::Plugin(plugin_ids::VIDEO.to_string()),
|
||||||
message,
|
message,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -147,7 +148,7 @@ fn ok_wifi(from: &str, message: Message) -> Result<DispatchResult, String> {
|
|||||||
Ok(DispatchResult {
|
Ok(DispatchResult {
|
||||||
envelope: Envelope {
|
envelope: Envelope {
|
||||||
from: from.to_string(),
|
from: from.to_string(),
|
||||||
to: Destination::Plugin("wifi".to_string()),
|
to: Destination::Plugin(plugin_ids::WIFI.to_string()),
|
||||||
message,
|
message,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -9,5 +9,15 @@ pub mod plugin_repo;
|
|||||||
pub mod service_manager;
|
pub mod service_manager;
|
||||||
pub mod version_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)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ impl Plugin for HttpPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn dependencies(&self) -> Vec<String> {
|
fn dependencies(&self) -> Vec<String> {
|
||||||
vec!["video".to_string()]
|
vec![crate::core::plugin_ids::VIDEO.to_string()]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init(&mut self, ctx: PluginContext) -> Result<()> {
|
fn init(&mut self, ctx: PluginContext) -> Result<()> {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
use crate::core::{
|
use crate::core::{
|
||||||
message::{Destination, DeviceCommand, Envelope, Message},
|
message::{Destination, DeviceCommand, Envelope, Message},
|
||||||
plugin::*,
|
plugin::*,
|
||||||
|
plugin_ids,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ impl ScreenPlugin {
|
|||||||
if let Some(ctx) = &self.ctx {
|
if let Some(ctx) = &self.ctx {
|
||||||
let envelope = Envelope {
|
let envelope = Envelope {
|
||||||
from: self.id().to_string(),
|
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)),
|
message: Message::DeviceCommand(DeviceCommand::SetSleepInhibit(true)),
|
||||||
};
|
};
|
||||||
let _ = ctx.tx.send(envelope);
|
let _ = ctx.tx.send(envelope);
|
||||||
@@ -36,7 +37,7 @@ impl ScreenPlugin {
|
|||||||
if let Some(ctx) = &self.ctx {
|
if let Some(ctx) = &self.ctx {
|
||||||
let envelope = Envelope {
|
let envelope = Envelope {
|
||||||
from: self.id().to_string(),
|
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)),
|
message: Message::DeviceCommand(DeviceCommand::SetSleepInhibit(false)),
|
||||||
};
|
};
|
||||||
let _ = ctx.tx.send(envelope);
|
let _ = ctx.tx.send(envelope);
|
||||||
@@ -47,7 +48,7 @@ impl ScreenPlugin {
|
|||||||
if let Some(ctx) = &self.ctx {
|
if let Some(ctx) = &self.ctx {
|
||||||
let envelope = Envelope {
|
let envelope = Envelope {
|
||||||
from: self.id().to_string(),
|
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)),
|
message: Message::DeviceCommand(DeviceCommand::SetCursorVisible(!hidden)),
|
||||||
};
|
};
|
||||||
let _ = ctx.tx.send(envelope);
|
let _ = ctx.tx.send(envelope);
|
||||||
@@ -76,7 +77,7 @@ impl Plugin for ScreenPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn dependencies(&self) -> Vec<String> {
|
fn dependencies(&self) -> Vec<String> {
|
||||||
vec!["device".to_string()]
|
vec![plugin_ids::DEVICE.to_string()]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init(&mut self, ctx: PluginContext) -> Result<()> {
|
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::message::{Destination, Envelope, Message, PlayerCommand, PlayerStatusData};
|
||||||
use crate::core::plugin::{Platform, Plugin, PluginContext, PluginInfo};
|
use crate::core::plugin::{Platform, Plugin, PluginContext, PluginInfo};
|
||||||
|
use crate::core::plugin_ids;
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use opencv::highgui;
|
use opencv::highgui;
|
||||||
use processor::VideoProcessor;
|
use processor::VideoProcessor;
|
||||||
@@ -151,7 +152,7 @@ impl Plugin for VideoPlugin {
|
|||||||
if let Some(ctx) = &self.ctx {
|
if let Some(ctx) = &self.ctx {
|
||||||
let _ = ctx.tx.send(Envelope {
|
let _ = ctx.tx.send(Envelope {
|
||||||
from: self.id().to_string(),
|
from: self.id().to_string(),
|
||||||
to: Destination::Plugin("screen".to_string()),
|
to: Destination::Plugin(plugin_ids::SCREEN.to_string()),
|
||||||
message: Message::ScreenLockRequest(true),
|
message: Message::ScreenLockRequest(true),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -162,7 +163,7 @@ impl Plugin for VideoPlugin {
|
|||||||
if let Some(ctx) = &self.ctx {
|
if let Some(ctx) = &self.ctx {
|
||||||
let _ = ctx.tx.send(Envelope {
|
let _ = ctx.tx.send(Envelope {
|
||||||
from: self.id().to_string(),
|
from: self.id().to_string(),
|
||||||
to: Destination::Plugin("screen".to_string()),
|
to: Destination::Plugin(plugin_ids::SCREEN.to_string()),
|
||||||
message: Message::ScreenLockRequest(false),
|
message: Message::ScreenLockRequest(false),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user