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