MCPcopy Create free account
hub / github.com/GCWing/BitFun / get_or_init_api

Method get_or_init_api

src/apps/desktop/src/api/terminal_api.rs:39–70  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

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

Callers 15

terminal_get_shellsFunction · 0.80
terminal_createFunction · 0.80
terminal_getFunction · 0.80
terminal_listFunction · 0.80
terminal_closeFunction · 0.80
terminal_writeFunction · 0.80
terminal_resizeFunction · 0.80
terminal_signalFunction · 0.80
terminal_ackFunction · 0.80
terminal_executeFunction · 0.80
terminal_send_commandFunction · 0.80

Calls 4

okMethod · 0.45
merged_path_envMethod · 0.45
insertMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected