zerolaunch_plugin_api/host/
plugin_host.rs1use std::collections::HashMap;
13use std::path::Path;
14use std::time::Duration;
15
16use async_trait::async_trait;
17
18use crate::host::{CacheLevel, HostApiError, OpenTarget};
19use crate::services::app::AppInfo;
20use crate::services::focus_monitor::FocusCallback;
21use crate::services::hotkey::types::{HotkeyCallback, HotkeyEventFilter};
22use crate::services::installation_monitor::types::InstallationCallback;
23use crate::services::model::{
24 ModelChatRequest, ModelChatResponse, ModelEmbeddingRequest, ModelEmbeddingResponse, ModelError,
25 ModelInfo, ModelSimilarityRequest, ModelSimilarityResponse,
26};
27use crate::services::parameter::types::ParameterSnapshot;
28use crate::services::path::path_resolver::KnownPath;
29use crate::services::theme::Theme;
30use crate::services::timer::types::{TimerCallback, TimerId};
31use crate::services::IconRequest;
32
33#[async_trait]
35pub trait PluginHost: Send + Sync {
36 async fn get_icon(
42 &self,
43 request: &IconRequest,
44 level: CacheLevel,
45 ) -> Result<Vec<u8>, HostApiError>;
46
47 async fn get_icon_or_default(&self, request: &IconRequest, level: CacheLevel) -> Vec<u8>;
49
50 async fn get_icon_and_update_cache(
52 &self,
53 request: &IconRequest,
54 level: CacheLevel,
55 ) -> Result<Vec<u8>, HostApiError>;
56
57 async fn override_icon_cache(
61 &self,
62 original_request: &IconRequest,
63 custom_icon_path: &str,
64 ) -> Result<(), HostApiError>;
65
66 async fn shell_open(&self, target: OpenTarget) -> Result<(), HostApiError>;
70
71 async fn shell_open_folder(&self, path: &str) -> Result<(), HostApiError>;
73
74 async fn shell_execute_elevation(&self, path: &str) -> Result<(), HostApiError>;
76
77 async fn shell_execute_command(&self, command: &str) -> Result<(), HostApiError>;
79
80 async fn activate_window_by_process(&self, process_name: &str) -> Result<bool, HostApiError>;
85
86 async fn activate_window_by_title(&self, title: &str) -> Result<bool, HostApiError>;
88
89 async fn activate_window_by_pid(&self, pid: u32) -> Result<bool, HostApiError>;
91
92 fn resolve_path(&self, path: KnownPath) -> Result<String, HostApiError>;
96
97 fn set_clipboard_text(&self, text: &str) -> Result<(), HostApiError>;
101
102 async fn enumerate_apps(&self) -> Vec<AppInfo>;
106
107 async fn launch_app(&self, app_id: &str, args: Option<&[String]>) -> Result<u32, HostApiError>;
109
110 fn get_app_icon_path(&self, name: &str) -> Option<String>;
114
115 fn resolve_lnk_target(&self, lnk_path: &str) -> Option<String>;
119
120 fn parse_localized_names_from_dir(&self, dir_path: &Path) -> HashMap<String, String>;
122
123 fn get_theme(&self) -> Result<Theme, HostApiError>;
128
129 fn get_system_theme(&self) -> Result<Theme, HostApiError>;
131
132 fn model_list(&self) -> Vec<ModelInfo>;
136
137 async fn model_chat(&self, req: ModelChatRequest) -> Result<ModelChatResponse, ModelError>;
139
140 async fn model_embedding(
142 &self,
143 req: ModelEmbeddingRequest,
144 ) -> Result<ModelEmbeddingResponse, ModelError>;
145
146 async fn model_similarity(
148 &self,
149 req: ModelSimilarityRequest,
150 ) -> Result<ModelSimilarityResponse, ModelError>;
151
152 async fn resolve_parameters(
156 &self,
157 template: &str,
158 user_args: &[String],
159 snapshot: &ParameterSnapshot,
160 ) -> Result<String, HostApiError>;
161
162 fn count_user_parameters(&self, template: &str) -> usize;
164
165 fn has_system_parameters(&self, template: &str) -> bool;
167
168 async fn set_timeout(
172 &self,
173 delay: Duration,
174 callback: TimerCallback,
175 ) -> Result<TimerId, HostApiError>;
176
177 async fn set_interval(
179 &self,
180 interval: Duration,
181 callback: TimerCallback,
182 ) -> Result<TimerId, HostApiError>;
183
184 async fn cancel_timer(&self, id: TimerId) -> Result<(), HostApiError>;
186
187 async fn cancel_all_timers(&self) -> Result<(), HostApiError>;
189
190 async fn resource_upload(
195 &self,
196 plugin_id: &str,
197 resource_id: &str,
198 file_path: &str,
199 max_size: Option<u64>,
200 ) -> Result<String, HostApiError>;
201
202 async fn resource_put(
204 &self,
205 plugin_id: &str,
206 resource_id: &str,
207 data: &[u8],
208 ) -> Result<(), HostApiError>;
209
210 async fn resource_get(
212 &self,
213 plugin_id: &str,
214 resource_id: &str,
215 ) -> Result<Vec<u8>, HostApiError>;
216
217 async fn resource_delete(&self, plugin_id: &str, resource_id: &str)
219 -> Result<(), HostApiError>;
220
221 async fn resource_list(&self, plugin_id: &str) -> Result<Vec<String>, HostApiError>;
223
224 async fn cache_put(
228 &self,
229 plugin_id: &str,
230 domain: &str,
231 key: &str,
232 data: &[u8],
233 ) -> Result<(), HostApiError>;
234
235 async fn cache_get(
237 &self,
238 plugin_id: &str,
239 domain: &str,
240 key: &str,
241 ) -> Result<Option<Vec<u8>>, HostApiError>;
242
243 async fn cache_delete(
245 &self,
246 plugin_id: &str,
247 domain: &str,
248 key: &str,
249 ) -> Result<(), HostApiError>;
250
251 async fn cache_cleanup(
253 &self,
254 plugin_id: &str,
255 domain: &str,
256 max_entries: usize,
257 ) -> Result<(), HostApiError>;
258
259 fn register_hotkey_callback(
263 &self,
264 plugin_id: &str,
265 id: &str,
266 filter: HotkeyEventFilter,
267 callback: HotkeyCallback,
268 );
269
270 fn unregister_hotkey_callback(&self, plugin_id: &str, id: &str);
272
273 fn register_installation_callback(
275 &self,
276 plugin_id: &str,
277 id: &str,
278 callback: InstallationCallback,
279 );
280
281 fn unregister_installation_callback(&self, plugin_id: &str, id: &str);
283
284 fn register_focus_callback(&self, plugin_id: &str, id: &str, callback: FocusCallback);
286
287 fn unregister_focus_callback(&self, plugin_id: &str, id: &str);
289}