pub struct PluginHandle { /* private fields */ }Expand description
插件服务句柄(插件接口层)。
绑定插件身份(plugin_id)、配置(PluginSdkConfig)与能力集,并持有宿主操作契约
Arc<dyn PluginHost>;所有服务操作委托宿主执行,宿主内部再决定直接处理或
转发平台实现。插件通过 HostApi::register() 获取此句柄。
Implementations§
Source§impl PluginHandle
impl PluginHandle
Sourcepub fn new(
plugin_id: String,
config: PluginSdkConfig,
capabilities: PlatformCapabilities,
host: Arc<dyn PluginHost>,
) -> Self
pub fn new( plugin_id: String, config: PluginSdkConfig, capabilities: PlatformCapabilities, host: Arc<dyn PluginHost>, ) -> Self
绑定插件身份与宿主契约构造句柄。 参数:plugin_id - 插件唯一标识;config - 插件 SDK 配置; capabilities - 平台能力集;host - 宿主操作契约实现。
Sourcepub fn update_config(&self, config: PluginSdkConfig)
pub fn update_config(&self, config: PluginSdkConfig)
更新插件的 SDK 配置,立即生效,影响后续所有服务调用。
Sourcepub fn capabilities(&self) -> &PlatformCapabilities
pub fn capabilities(&self) -> &PlatformCapabilities
查询当前平台支持的能力集合。
Sourcepub async fn get_icon(
&self,
request: IconRequest,
) -> Result<Vec<u8>, HostApiError>
pub async fn get_icon( &self, request: IconRequest, ) -> Result<Vec<u8>, HostApiError>
根据图标请求提取图标数据,行为由注册时的缓存等级决定。
Sourcepub async fn get_icon_or_default(&self, request: IconRequest) -> Vec<u8> ⓘ
pub async fn get_icon_or_default(&self, request: IconRequest) -> Vec<u8> ⓘ
提取图标数据,失败时回退到默认图标(永不返回错误)。
Sourcepub async fn get_icon_and_update_cache(
&self,
request: IconRequest,
) -> Result<Vec<u8>, HostApiError>
pub async fn get_icon_and_update_cache( &self, request: IconRequest, ) -> Result<Vec<u8>, HostApiError>
强制从磁盘提取图标数据并根据缓存等级更新缓存。
Sourcepub async fn override_icon_cache(
&self,
original_request: &IconRequest,
custom_icon_path: &str,
) -> Result<(), HostApiError>
pub async fn override_icon_cache( &self, original_request: &IconRequest, custom_icon_path: &str, ) -> Result<(), HostApiError>
覆盖指定 IconRequest 的缓存图标为自定义图标文件。
Sourcepub async fn shell_open(&self, target: OpenTarget) -> Result<(), HostApiError>
pub async fn shell_open(&self, target: OpenTarget) -> Result<(), HostApiError>
使用系统默认方式打开目标(文件/网址/文件夹)。
Sourcepub async fn shell_open_folder(&self, path: &str) -> Result<(), HostApiError>
pub async fn shell_open_folder(&self, path: &str) -> Result<(), HostApiError>
在文件资源管理器中打开指定路径的父目录并选中该文件。
Sourcepub async fn shell_execute_elevation(
&self,
path: &str,
) -> Result<(), HostApiError>
pub async fn shell_execute_elevation( &self, path: &str, ) -> Result<(), HostApiError>
以管理员权限启动程序。
Sourcepub async fn shell_execute_command(
&self,
command: &str,
) -> Result<(), HostApiError>
pub async fn shell_execute_command( &self, command: &str, ) -> Result<(), HostApiError>
执行命令字符串(后台运行,无窗口)。
Sourcepub async fn activate_window_by_process(
&self,
process_name: &str,
) -> Result<bool, HostApiError>
pub async fn activate_window_by_process( &self, process_name: &str, ) -> Result<bool, HostApiError>
根据进程名(如 “chrome.exe”)激活已存在的窗口。
Sourcepub async fn activate_window_by_title(
&self,
title: &str,
) -> Result<bool, HostApiError>
pub async fn activate_window_by_title( &self, title: &str, ) -> Result<bool, HostApiError>
根据窗口标题的部分内容激活已存在的窗口。
Sourcepub async fn activate_window_by_pid(
&self,
pid: u32,
) -> Result<bool, HostApiError>
pub async fn activate_window_by_pid( &self, pid: u32, ) -> Result<bool, HostApiError>
根据进程 PID 激活已存在的窗口。
Sourcepub fn resolve_path(&self, path: KnownPath) -> Result<String, HostApiError>
pub fn resolve_path(&self, path: KnownPath) -> Result<String, HostApiError>
根据已知路径类型解析实际文件系统路径。
Sourcepub fn set_clipboard_text(&self, text: &str) -> Result<(), HostApiError>
pub fn set_clipboard_text(&self, text: &str) -> Result<(), HostApiError>
将文本写入系统剪贴板。
Sourcepub async fn enumerate_apps(&self) -> Vec<AppInfo>
pub async fn enumerate_apps(&self) -> Vec<AppInfo>
枚举当前平台已安装的应用。
Sourcepub async fn launch_app(
&self,
app_id: &str,
args: Option<&[String]>,
) -> Result<u32, HostApiError>
pub async fn launch_app( &self, app_id: &str, args: Option<&[String]>, ) -> Result<u32, HostApiError>
启动指定应用。
Sourcepub fn get_app_icon_path(&self, name: &str) -> Option<String>
pub fn get_app_icon_path(&self, name: &str) -> Option<String>
根据名称获取内置图标资源的文件系统路径。
Sourcepub fn resolve_lnk_target(&self, lnk_path: &str) -> Option<String>
pub fn resolve_lnk_target(&self, lnk_path: &str) -> Option<String>
解析 .lnk 快捷方式文件的目标路径。
Sourcepub fn parse_localized_names_from_dir(
&self,
dir_path: &Path,
) -> HashMap<String, String>
pub fn parse_localized_names_from_dir( &self, dir_path: &Path, ) -> HashMap<String, String>
解析指定目录下的 desktop.ini 文件,提取 [LocalizedFileNames] 部分。
Sourcepub fn get_theme(&self) -> Result<Theme, HostApiError>
pub fn get_theme(&self) -> Result<Theme, HostApiError>
查询宿主当前实际生效的界面主题(system 模式由宿主解析)。
Sourcepub fn get_system_theme(&self) -> Result<Theme, HostApiError>
pub fn get_system_theme(&self) -> Result<Theme, HostApiError>
查询系统主题(未应用宿主显式 light/dark 配置)。
Sourcepub fn model_list(&self) -> Vec<ModelInfo>
pub fn model_list(&self) -> Vec<ModelInfo>
全网模型清单(聚合缓存,含所有已注册提供方)。
Sourcepub async fn model_chat(
&self,
req: ModelChatRequest,
) -> Result<ModelChatResponse, ModelError>
pub async fn model_chat( &self, req: ModelChatRequest, ) -> Result<ModelChatResponse, ModelError>
按 model_id 调用文本生成。
Sourcepub async fn model_embedding(
&self,
req: ModelEmbeddingRequest,
) -> Result<ModelEmbeddingResponse, ModelError>
pub async fn model_embedding( &self, req: ModelEmbeddingRequest, ) -> Result<ModelEmbeddingResponse, ModelError>
按 model_id 调用文本向量化(task_type 必填)。
Sourcepub async fn model_similarity(
&self,
req: ModelSimilarityRequest,
) -> Result<ModelSimilarityResponse, ModelError>
pub async fn model_similarity( &self, req: ModelSimilarityRequest, ) -> Result<ModelSimilarityResponse, ModelError>
按 model_id 计算查询向量与多个目标向量的相似度。
Sourcepub async fn resolve_parameters(
&self,
template: &str,
user_args: &[String],
snapshot: &ParameterSnapshot,
) -> Result<String, HostApiError>
pub async fn resolve_parameters( &self, template: &str, user_args: &[String], snapshot: &ParameterSnapshot, ) -> Result<String, HostApiError>
解析参数模板。
Sourcepub fn count_user_parameters(&self, template: &str) -> usize
pub fn count_user_parameters(&self, template: &str) -> usize
统计模板中需要用户输入的参数数量。
Sourcepub fn has_system_parameters(&self, template: &str) -> bool
pub fn has_system_parameters(&self, template: &str) -> bool
检查模板是否包含系统参数。
Sourcepub async fn set_timeout(
&self,
delay: Duration,
callback: TimerCallback,
) -> Result<TimerId, HostApiError>
pub async fn set_timeout( &self, delay: Duration, callback: TimerCallback, ) -> Result<TimerId, HostApiError>
创建一个一次性定时器,在指定延迟后触发回调。
Sourcepub async fn set_interval(
&self,
interval: Duration,
callback: TimerCallback,
) -> Result<TimerId, HostApiError>
pub async fn set_interval( &self, interval: Duration, callback: TimerCallback, ) -> Result<TimerId, HostApiError>
创建一个重复定时器,每隔指定间隔触发回调。
Sourcepub async fn cancel_timer(&self, id: TimerId) -> Result<(), HostApiError>
pub async fn cancel_timer(&self, id: TimerId) -> Result<(), HostApiError>
取消指定 ID 的定时器。
Sourcepub async fn cancel_all_timers(&self) -> Result<(), HostApiError>
pub async fn cancel_all_timers(&self) -> Result<(), HostApiError>
取消所有定时器。
Sourcepub async fn resource_upload(
&self,
resource_id: &str,
file_path: &str,
max_size: Option<u64>,
) -> Result<String, HostApiError>
pub async fn resource_upload( &self, resource_id: &str, file_path: &str, max_size: Option<u64>, ) -> Result<String, HostApiError>
上传资源文件到本插件的资源空间。
Sourcepub async fn resource_put(
&self,
resource_id: &str,
data: &[u8],
) -> Result<(), HostApiError>
pub async fn resource_put( &self, resource_id: &str, data: &[u8], ) -> Result<(), HostApiError>
直接写入资源字节数据,无需先创建临时文件或提供本地路径。
Sourcepub async fn resource_get(
&self,
resource_id: &str,
) -> Result<Vec<u8>, HostApiError>
pub async fn resource_get( &self, resource_id: &str, ) -> Result<Vec<u8>, HostApiError>
获取资源文件内容。
Sourcepub async fn resource_delete(
&self,
resource_id: &str,
) -> Result<(), HostApiError>
pub async fn resource_delete( &self, resource_id: &str, ) -> Result<(), HostApiError>
删除资源文件。
Sourcepub async fn resource_list(&self) -> Result<Vec<String>, HostApiError>
pub async fn resource_list(&self) -> Result<Vec<String>, HostApiError>
列出本插件的所有资源。
Sourcepub async fn cache_put(
&self,
domain: &str,
key: &str,
data: &[u8],
) -> Result<(), HostApiError>
pub async fn cache_put( &self, domain: &str, key: &str, data: &[u8], ) -> Result<(), HostApiError>
写入插件本地缓存。 与 resource_* 的区别:缓存存放可再生的本地数据(如模型向量), 不经过 StorageService,仅落在本地缓存目录。
Sourcepub async fn cache_get(
&self,
domain: &str,
key: &str,
) -> Result<Option<Vec<u8>>, HostApiError>
pub async fn cache_get( &self, domain: &str, key: &str, ) -> Result<Option<Vec<u8>>, HostApiError>
读取插件本地缓存;缓存不存在时返回 Ok(None)。
Sourcepub async fn cache_delete(
&self,
domain: &str,
key: &str,
) -> Result<(), HostApiError>
pub async fn cache_delete( &self, domain: &str, key: &str, ) -> Result<(), HostApiError>
删除插件本地缓存条目;缓存不存在时视为成功。
Sourcepub async fn cache_cleanup(
&self,
domain: &str,
max_entries: usize,
) -> Result<(), HostApiError>
pub async fn cache_cleanup( &self, domain: &str, max_entries: usize, ) -> Result<(), HostApiError>
容量控制:缓存域条目超过 max_entries 时按修改时间删除最旧条目。
Sourcepub fn register_hotkey_callback(
&self,
id: &str,
filter: HotkeyEventFilter,
callback: HotkeyCallback,
)
pub fn register_hotkey_callback( &self, id: &str, filter: HotkeyEventFilter, callback: HotkeyCallback, )
注册按键事件回调。ID 自动前缀化为 “{plugin_id}:{id}”。
Sourcepub fn unregister_hotkey_callback(&self, id: &str)
pub fn unregister_hotkey_callback(&self, id: &str)
注销按键事件回调。
Sourcepub fn register_installation_callback(
&self,
id: &str,
callback: InstallationCallback,
)
pub fn register_installation_callback( &self, id: &str, callback: InstallationCallback, )
注册安装事件回调。ID 自动前缀化为 “{plugin_id}:{id}”。
Sourcepub fn unregister_installation_callback(&self, id: &str)
pub fn unregister_installation_callback(&self, id: &str)
注销安装事件回调。
Sourcepub fn register_focus_callback(&self, id: &str, callback: FocusCallback)
pub fn register_focus_callback(&self, id: &str, callback: FocusCallback)
注册焦点事件回调。ID 自动前缀化为 “{plugin_id}:{id}”。
Sourcepub fn unregister_focus_callback(&self, id: &str)
pub fn unregister_focus_callback(&self, id: &str)
注销焦点事件回调。
Auto Trait Implementations§
impl !Freeze for PluginHandle
impl !RefUnwindSafe for PluginHandle
impl !UnwindSafe for PluginHandle
impl Send for PluginHandle
impl Sync for PluginHandle
impl Unpin for PluginHandle
impl UnsafeUnpin for PluginHandle
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
replaced by palette::chromatic_adaptation::AdaptIntoUnclamped
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
replaced by palette::chromatic_adaptation::AdaptIntoUnclamped
Source§impl<T, C> AdaptIntoUnclamped<T> for Cwhere
T: AdaptFromUnclamped<C>,
impl<T, C> AdaptIntoUnclamped<T> for Cwhere
T: AdaptFromUnclamped<C>,
Source§type Scalar = <T as AdaptFromUnclamped<C>>::Scalar
type Scalar = <T as AdaptFromUnclamped<C>>::Scalar
Source§fn adapt_into_unclamped_with<M>(self) -> Twhere
M: LmsToXyz<<C as AdaptIntoUnclamped<T>>::Scalar> + XyzToLms<<C as AdaptIntoUnclamped<T>>::Scalar>,
fn adapt_into_unclamped_with<M>(self) -> Twhere
M: LmsToXyz<<C as AdaptIntoUnclamped<T>>::Scalar> + XyzToLms<<C as AdaptIntoUnclamped<T>>::Scalar>,
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T, C> ComponentsInto<C> for T
impl<T, C> ComponentsInto<C> for T
Source§fn components_into(self) -> C
fn components_into(self) -> C
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more