(&self)
| 37 | } |
| 38 | |
| 39 | pub async fn get_or_init_api(&self) -> Result<TerminalApi, String> { |
| 40 | let mut initialized = self.initialized.lock().await; |
| 41 | let mut api_guard = self.api.lock().await; |
| 42 | |
| 43 | if !*initialized { |
| 44 | let mut config = TerminalConfig::default(); |
| 45 | |
| 46 | // Set scripts directory to app data dir: {config_dir}/bitfun/temp/scripts |
| 47 | let scripts_dir = Self::get_scripts_dir(); |
| 48 | config.shell_integration.scripts_dir = Some(scripts_dir); |
| 49 | |
| 50 | // Prepend BitFun-managed runtime dirs to PATH so Bash/Skill commands can |
| 51 | // run on machines without preinstalled dev tools. |
| 52 | if let Ok(runtime_manager) = RuntimeManager::new() { |
| 53 | let current_path = std::env::var("PATH").ok(); |
| 54 | if let Some(merged_path) = runtime_manager.merged_path_env(current_path.as_deref()) |
| 55 | { |
| 56 | config.env.insert("PATH".to_string(), merged_path.clone()); |
| 57 | #[cfg(windows)] |
| 58 | { |
| 59 | config.env.insert("Path".to_string(), merged_path); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | let api = TerminalApi::new(config).await; |
| 65 | *api_guard = Some(api); |
| 66 | *initialized = true; |
| 67 | } |
| 68 | |
| 69 | TerminalApi::from_singleton().map_err(|e| format!("Terminal API not initialized: {}", e)) |
| 70 | } |
| 71 | |
| 72 | /// Get the scripts directory path for shell integration |
| 73 | /// Uses the same path structure as PathManager |
no test coverage detected