Skip to main content

PluginHandle

Struct PluginHandle 

Source
pub struct PluginHandle { /* private fields */ }
Expand description

插件服务句柄,绑定插件身份与配置。 跨平台 struct,通过 Arc 等平台 trait 注入平台代码。 插件通过 HostApi::register() 获取此句柄,后续所有服务调用通过句柄完成。 句柄自动应用注册时的插件配置(如缓存等级),插件无需在每次调用时传递配置。

Implementations§

Source§

impl PluginHandle

Source

pub fn new( plugin_id: String, config: PluginSdkConfig, capabilities: PlatformCapabilities, theme_provider: Arc<dyn ThemeProvider>, theme_mode: Arc<RwLock<String>>, icon_extractor: Arc<dyn IconExtractor>, icon_cache: Arc<IconCacheService>, shell_executor: Arc<dyn ShellExecutor>, window_manager: Arc<dyn WindowManager>, path_resolver: Arc<dyn PathResolver>, app_enumerator: Arc<dyn AppEnumerator>, app_launcher: Arc<dyn AppLauncher>, lnk_resolver: Arc<dyn LnkResolver>, resource_loader: Arc<dyn ResourceLoader>, parameter_resolver: Arc<dyn ParameterResolver>, timer_manager: Arc<dyn TimerManager>, app_resource: Arc<AppResourceService>, storage: Arc<RwLock<Arc<dyn StorageService>>>, hotkey_manager: Arc<dyn HotkeyManager>, installation_monitor: Arc<dyn InstallationMonitor>, focus_monitor: Arc<dyn FocusMonitor>, clipboard_manager: Arc<dyn ClipboardManager>, model_service: Arc<dyn ModelService>, ) -> Self

Creates a new PluginHandle with all the service references injected.

Source

pub fn plugin_id(&self) -> &str

返回当前插件 ID(宿主模型缓存等按插件隔离目录需要)。

Source

pub async fn get_icon( &self, request: IconRequest, ) -> Result<Vec<u8>, HostApiError>

根据图标请求提取图标数据,行为由注册时的缓存等级决定。 参数:request - 图标请求(路径/网址/扩展名)。 返回:WebP 格式的图标字节数据(回退路径可能为 PNG),失败返回 HostApiError。

Source

pub async fn get_icon_or_default(&self, request: IconRequest) -> Vec<u8> ⓘ

提取图标数据,失败时回退到默认图标。 与 get_icon 不同,此方法永不返回错误,提取失败时返回默认图标数据。

Source

pub async fn get_icon_and_update_cache( &self, request: IconRequest, ) -> Result<Vec<u8>, HostApiError>

强制从磁盘提取图标数据并根据缓存等级更新缓存。 与 get_icon 不同,此方法跳过缓存读取,直接提取并更新缓存。 参数:request - 图标请求(路径/网址/扩展名)。 返回:WebP 格式的图标字节数据(回退路径可能为 PNG),失败返回 HostApiError。

Source

pub async fn override_icon_cache( &self, original_request: &IconRequest, custom_icon_path: &str, ) -> Result<(), HostApiError>

覆盖指定 IconRequest 的缓存图标为自定义图标文件。 参数:original_request - 需要覆盖图标的原始 IconRequest custom_icon_path - 用户选择的自定义图标文件路径 返回:成功返回 Ok(()), 失败返回 HostApiError

Source

pub async fn shell_open(&self, target: OpenTarget) -> Result<(), HostApiError>

使用系统默认方式打开目标(文件/网址/文件夹)。 参数:target - 打开目标。 返回:成功返回 Ok(()),失败返回 HostApiError。

Source

pub async fn shell_open_folder(&self, path: &str) -> Result<(), HostApiError>

在文件资源管理器中打开指定路径的父目录并选中该文件。 参数:path - 要打开所在位置的文件路径。 返回:成功返回 Ok(()),失败返回 HostApiError。

Source

pub async fn shell_execute_elevation( &self, path: &str, ) -> Result<(), HostApiError>

以管理员权限启动程序。 参数:path - 要以管理员身份运行的程序路径。 返回:成功返回 Ok(()),失败返回 HostApiError。

Source

pub async fn shell_execute_command( &self, command: &str, ) -> Result<(), HostApiError>

执行命令字符串(后台运行,无窗口)。 参数:command - 要执行的命令字符串。 返回:成功返回 Ok(()),失败返回 HostApiError。

Source

pub async fn activate_window_by_process( &self, process_name: &str, ) -> Result<bool, HostApiError>

根据进程名(如 “chrome.exe”)激活已存在的窗口。 参数:process_name - 进程名(含扩展名)。 返回:成功激活返回 Ok(true),未找到窗口返回 Ok(false),失败返回 HostApiError。

Source

pub async fn activate_window_by_title( &self, title: &str, ) -> Result<bool, HostApiError>

根据窗口标题的部分内容激活已存在的窗口。 参数:title - 窗口标题的部分匹配文本。 返回:成功激活返回 Ok(true),未找到窗口返回 Ok(false),失败返回 HostApiError。

Source

pub async fn activate_window_by_pid( &self, pid: u32, ) -> Result<bool, HostApiError>

根据进程 PID 激活已存在的窗口。 参数:pid - 进程标识符。 返回:成功激活返回 Ok(true),未找到窗口返回 Ok(false),失败返回 HostApiError。

Source

pub fn resolve_path(&self, path: KnownPath) -> Result<String, HostApiError>

根据已知路径类型解析实际文件系统路径。 参数:path - 已知路径类型枚举。 返回:解析后的路径字符串,失败返回 HostApiError。

Source

pub fn set_clipboard_text(&self, text: &str) -> Result<(), HostApiError>

将文本写入系统剪贴板。 参数:text - 要写入的文本内容。 返回:成功返回 Ok(()),失败返回 HostApiError。

Source

pub async fn enumerate_apps(&self) -> Vec<AppInfo>

枚举当前平台已安装的应用。 参数:无。 返回:应用信息列表。

Source

pub async fn launch_app( &self, app_id: &str, args: Option<&[String]>, ) -> Result<u32, HostApiError>

启动指定应用。 参数:app_id - 应用唯一标识;args - 启动参数(可选)。 返回:成功返回 Ok(pid),失败返回 HostApiError。

Source

pub fn get_app_icon_path(&self, name: &str) -> Option<String>

根据名称获取内置图标资源的文件系统路径。 参数:name - 图标名称(如 “tray_icon”, “web_pages” 等)。 返回:图标路径,未注册则返回 None。

Source

pub fn resolve_lnk_target(&self, lnk_path: &str) -> Option<String>

解析 .lnk 快捷方式文件的目标路径。 参数:lnk_path - .lnk 文件的路径。 返回:解析成功返回目标路径,失败返回 None。

Source

pub fn parse_localized_names_from_dir( &self, dir_path: &Path, ) -> HashMap<String, String>

解析指定目录下的 desktop.ini 文件,提取 [LocalizedFileNames] 部分。 参数:dir_path - 要解析的目录路径。 返回:从原始文件名到本地化名称的映射。

Source

pub fn update_config(&self, config: PluginSdkConfig)

更新插件的 SDK 配置。 参数:config - 新的插件 SDK 配置。 返回:无。 特性:立即生效,影响后续所有服务调用。

Source

pub fn capabilities(&self) -> &PlatformCapabilities

查询当前平台支持的能力集合。 参数:无。 返回:平台能力的不可变引用。

Source

pub fn get_theme(&self) -> Result<Theme, HostApiError>

查询宿主当前实际生效的界面主题。 显式 light/dark 配置直接返回;system 模式委托平台读取系统主题。

Source

pub fn get_system_theme(&self) -> Result<Theme, HostApiError>

查询系统主题(未应用宿主显式 light/dark 配置),供前端 system 模式跟随。

Source

pub fn model_list(&self) -> Vec<ModelInfo>

全网模型清单(聚合缓存,含所有已注册提供方)。

Source

pub async fn model_chat( &self, req: ModelChatRequest, ) -> Result<ModelChatResponse, ModelError>

按 model_id 调用文本生成。

Source

pub async fn model_embedding( &self, req: ModelEmbeddingRequest, ) -> Result<ModelEmbeddingResponse, ModelError>

按 model_id 调用文本向量化(task_type 必填,宿主对缺失/未知值返回 InvalidRequest)。

Source

pub async fn model_similarity( &self, req: ModelSimilarityRequest, ) -> Result<ModelSimilarityResponse, ModelError>

按 model_id 计算查询向量与多个目标向量的相似度。

Source

pub async fn resolve_parameters( &self, template: &str, user_args: &[String], snapshot: &ParameterSnapshot, ) -> Result<String, HostApiError>

解析参数模板

参数:

  • template: 包含占位符的模板字符串
  • user_args: 用户输入的参数列表
  • snapshot: 系统参数快照(不透明句柄)

返回:填充后的完整字符串

Source

pub fn count_user_parameters(&self, template: &str) -> usize

统计模板中需要用户输入的参数数量

参数:template - 模板字符串 返回:位置参数的数量

Source

pub fn has_system_parameters(&self, template: &str) -> bool

检查模板是否包含系统参数

参数:template - 模板字符串 返回:是否包含系统参数

Source

pub async fn set_timeout( &self, delay: Duration, callback: TimerCallback, ) -> Result<TimerId, HostApiError>

创建一个一次性定时器,在指定延迟后触发回调。

参数:

  • delay: 触发延迟时长
  • callback: 触发时调用的回调函数

返回:TimerId,可用于取消定时器。

Source

pub async fn set_interval( &self, interval: Duration, callback: TimerCallback, ) -> Result<TimerId, HostApiError>

创建一个重复定时器,每隔指定间隔触发回调。

参数:

  • interval: 触发间隔时长
  • callback: 每次触发时调用的回调函数

返回:TimerId,可用于取消定时器。

Source

pub async fn cancel_timer(&self, id: TimerId) -> Result<(), HostApiError>

取消指定 ID 的定时器。

参数:id - 要取消的定时器 ID。

Source

pub async fn cancel_all_timers(&self) -> Result<(), HostApiError>

取消所有定时器。

Source

pub async fn resource_upload( &self, resource_id: &str, file_path: &str, max_size: Option<u64>, ) -> Result<String, HostApiError>

上传资源文件到本插件的资源空间。

Source

pub async fn resource_put( &self, resource_id: &str, data: &[u8], ) -> Result<(), HostApiError>

直接写入资源字节数据,无需先创建临时文件或提供本地路径。 参数:resource_id - 资源标识符;data - 资源字节内容。 返回:成功返回 Ok(()),失败返回 HostApiError。

Source

pub async fn resource_get( &self, resource_id: &str, ) -> Result<Vec<u8>, HostApiError>

获取资源文件内容。

Source

pub async fn resource_delete( &self, resource_id: &str, ) -> Result<(), HostApiError>

删除资源文件。

Source

pub async fn resource_list(&self) -> Result<Vec<String>, HostApiError>

列出本插件的所有资源。

Source

pub async fn cache_put( &self, domain: &str, key: &str, data: &[u8], ) -> Result<(), HostApiError>

写入插件本地缓存。 参数:domain - 缓存域(按用途隔离,如 “model-embedding”);key - 缓存键;data - 缓存字节内容。 返回:成功返回 Ok(())。 与 resource_* 的区别:缓存存放可再生的本地数据(如模型向量), 不经过 StorageService,WebDAV 同步模式不会上传远端; 路径为 <app_data>/plugin-cache/<plugin_id>//。

Source

pub async fn cache_get( &self, domain: &str, key: &str, ) -> Result<Option<Vec<u8>>, HostApiError>

读取插件本地缓存;缓存不存在时返回 Ok(None)。

Source

pub async fn cache_delete( &self, domain: &str, key: &str, ) -> Result<(), HostApiError>

删除插件本地缓存条目;缓存不存在时视为成功。

Source

pub async fn cache_cleanup( &self, domain: &str, max_entries: usize, ) -> Result<(), HostApiError>

容量控制:缓存域条目超过 max_entries 时按修改时间删除最旧条目。 目录结构 <cache_root>/<plugin_id>//<sha前2>/.bin(两级分片)。 参数:domain - 缓存域;max_entries - 条目数上限。 返回:成功返回 Ok(())(目录不存在视为无需清理)。

Source

pub fn register_hotkey_callback( &self, id: &str, filter: HotkeyEventFilter, callback: HotkeyCallback, )

注册按键事件回调。 参数:id - 回调标识(自动前缀化为 “{plugin_id}:{id}”);filter - 事件过滤器;callback - 回调函数。

Source

pub fn unregister_hotkey_callback(&self, id: &str)

注销按键事件回调。 参数:id - 回调标识(自动前缀化为 “{plugin_id}:{id}”)。

Source

pub fn register_installation_callback( &self, id: &str, callback: InstallationCallback, )

注册安装事件回调。 参数:id - 回调标识(自动前缀化为 “{plugin_id}:{id}”);callback - 回调函数。

Source

pub fn unregister_installation_callback(&self, id: &str)

注销安装事件回调。 参数:id - 回调标识(自动前缀化为 “{plugin_id}:{id}”)。

Source

pub fn register_focus_callback(&self, id: &str, callback: FocusCallback)

注册焦点事件回调。 参数:id - 回调标识(自动前缀化为 “{plugin_id}:{id}”);callback - 回调函数。

Source

pub fn unregister_focus_callback(&self, id: &str)

注销焦点事件回调。 参数:id - 回调标识(自动前缀化为 “{plugin_id}:{id}”)。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where 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) -> D
where M: TransformMatrix<T>,

Convert the source color to the destination color using the specified method.
Source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default.
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, C> ArraysFrom<C> for T
where C: IntoArrays<T>,

Source§

fn arrays_from(colors: C) -> T

Cast a collection of colors into a collection of arrays.
Source§

impl<T, C> ArraysInto<C> for T
where C: FromArrays<T>,

Source§

fn arrays_into(self) -> C

Cast this collection of arrays into a collection of colors.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for U
where T: FromCam16Unclamped<WpParam, U>,

Source§

type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T, C> ComponentsFrom<C> for T
where C: IntoComponents<T>,

Source§

fn components_from(colors: C) -> T

Cast a collection of colors into a collection of color components.
Source§

impl<T, C> ComponentsInto<C> for T

Source§

fn components_into(self) -> C

Cast this collection of color components into a collection of colors. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromAngle<T> for T

Source§

fn from_angle(angle: T) -> T

Performs a conversion from angle.
Source§

impl<T, U> FromStimulus<U> for T
where U: IntoStimulus<T>,

Source§

fn from_stimulus(other: U) -> T

Converts other into Self, while performing the appropriate scaling, rounding and clamping.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> IntoAngle<U> for T
where U: FromAngle<T>,

Source§

fn into_angle(self) -> U

Performs a conversion into T.
Source§

impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for U
where T: Cam16FromUnclamped<WpParam, U>,

Source§

type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<T, U> IntoColor<U> for T
where U: FromColor<T>,

Source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
Source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

Source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoStimulus<T> for T

Source§

fn into_stimulus(self) -> T

Converts self into T, while performing the appropriate scaling, rounding and clamping.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, C> TryComponentsInto<C> for T
where C: TryFromComponents<T>,

Source§

type Error = <C as TryFromComponents<T>>::Error

The error for when try_into_colors fails to cast.
Source§

fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>

Try to cast this collection of color components into a collection of colors. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

Source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
Source§

impl<C, U> UintsFrom<C> for U
where C: IntoUints<U>,

Source§

fn uints_from(colors: C) -> U

Cast a collection of colors into a collection of unsigned integers.
Source§

impl<C, U> UintsInto<C> for U
where C: FromUints<U>,

Source§

fn uints_into(self) -> C

Cast this collection of unsigned integers into a collection of colors.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more