Skip to main content

zerolaunch_plugin_api/services/shell/
shell_executor.rs

1use super::types::CommandRunMode;
2use crate::host::error::HostApiError;
3use crate::host::open_target::OpenTarget;
4use async_trait::async_trait;
5
6/// Shell 执行器 trait,定义平台原语。
7/// 平台实现者实现各原语方法,PluginHandle 通过注入的 ShellExecutor 委托调用。
8#[async_trait]
9pub trait ShellExecutor: Send + Sync {
10    /// 使用系统默认方式打开目标(文件/网址/文件夹)。
11    /// 参数:target - 打开目标枚举。
12    /// 返回:成功返回 Ok(()),失败返回 HostApiError。
13    async fn shell_open(&self, target: &OpenTarget) -> Result<(), HostApiError>;
14
15    /// 在文件资源管理器中打开指定路径的父目录并选中该文件。
16    /// 参数:path - 要打开所在位置的文件路径。
17    /// 返回:成功返回 Ok(()),失败返回 HostApiError。
18    async fn shell_open_folder(&self, path: &str) -> Result<(), HostApiError>;
19
20    /// 以管理员权限启动程序。
21    /// 参数:path - 要以管理员身份运行的程序路径。
22    /// 返回:成功返回 Ok(()),失败返回 HostApiError。
23    async fn shell_execute_elevation(&self, path: &str) -> Result<(), HostApiError>;
24
25    /// 执行命令字符串。
26    /// 参数:command - 要执行的命令字符串;mode - 执行方式(后台静默 / 可见控制台窗口)。
27    /// 返回:成功返回 Ok(()),失败返回 HostApiError。
28    async fn shell_execute_command(
29        &self,
30        command: &str,
31        mode: CommandRunMode,
32    ) -> Result<(), HostApiError>;
33}