(app: AppHandle)
| 46 | |
| 47 | #[tracing::instrument(level = "debug", skip(app))] |
| 48 | pub fn get_extension_state(app: AppHandle) -> Result<ExtensionHandler> { |
| 49 | let ext_path = app.path().app_data_dir().unwrap().join("extensions"); |
| 50 | let tmp_dir = app.path().temp_dir().unwrap(); |
| 51 | let cache_dir = app.path().cache_dir().unwrap(); |
| 52 | let (ext_handler, mut ui_request_rx, ui_reply_tx) = |
| 53 | ExtensionHandler::new(ext_path, cache_dir, tmp_dir); |
| 54 | |
| 55 | let app_clone = app.clone(); |
| 56 | async_runtime::spawn(async move { |
| 57 | let app_handle = app.clone(); |
| 58 | let reply_handler = ReplyHandler::new(app_handle); |
| 59 | loop { |
| 60 | tracing::trace!("Waiting for extension UI requests"); |
| 61 | if let Some(resp) = ui_request_rx.recv().await { |
| 62 | if let Some(data) = resp.data { |
| 63 | tracing::debug!("Got main command {:?}", data); |
| 64 | match reply_handler.handle_request(data).await { |
| 65 | Ok(reply) => { |
| 66 | ui_reply_tx |
| 67 | .send(GenericExtensionHostRequest { |
| 68 | channel: resp.channel, |
| 69 | data: Some(reply), |
| 70 | }) |
| 71 | .unwrap(); |
| 72 | } |
| 73 | Err(e) => { |
| 74 | tracing::error!("Failed to handle extension command {:?}", e) |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | }); |
| 81 | async_runtime::spawn(extension_runner_connected(app_clone)); |
| 82 | |
| 83 | Ok(ext_handler) |
| 84 | } |
| 85 | |
| 86 | #[tracing::instrument(level = "debug", skip(app))] |
| 87 | pub fn get_extension_handler(app: &AppHandle) -> State<'_, ExtensionHandler> { |
no test coverage detected