Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/NativeHost/
GetEnvironmentPaths.rs

1//! Wire method: `nativeHost:getEnvironmentPaths`.
2//! Returns paths used by VS Code's `ResolveConfiguration` to locate user-data,
3//! logs, home, and temp directories. The session-timestamped logs subdirectory
4//! is created on first call so VS Code can write output files immediately.
5
6use serde_json::{Value, json};
7use tauri::{AppHandle, Manager};
8
9pub async fn Fn(ApplicationHandle:AppHandle) -> Result<Value, String> {
10	let PathResolver = ApplicationHandle.path();
11
12	// Propagate path resolver failures rather than returning empty PathBuf.
13	// An empty AppDataDir produces paths like URI.joinPath("", "extensions")
14	// which crash VS Code's boot - same class as the dataFolderName bug.
15	let AppDataDir = PathResolver
16		.app_data_dir()
17		.map_err(|E| format!("nativeHost:getEnvironmentPaths app_data_dir failed: {}", E))?;
18
19	let HomeDir = PathResolver
20		.home_dir()
21		.map_err(|E| format!("nativeHost:getEnvironmentPaths home_dir failed: {}", E))?;
22
23	let TmpDir = std::env::temp_dir();
24
25	// Logs go under {appDataDir}/logs/{sessionTimestamp}/ - same tree as all
26	// other VS Code data, not Tauri's separate app_log_dir(). VS Code requires
27	// a session-timestamped subdir for log rotation. `DevLog::SessionTimestamp`
28	// is the single source of truth so that `Mountain.dev.log` (written by
29	// DevLog) and VS Code's `window1/output/*.log` files (written into
30	// `logsPath`) share one directory per session.
31	let SessionLogRoot = AppDataDir.join("logs").join(crate::IPC::DevLog::SessionTimestamp::Fn());
32
33	let SessionLogWindowDir = SessionLogRoot.join("window1");
34
35	let _ = std::fs::create_dir_all(&SessionLogWindowDir);
36
37	crate::dev_log!(
38		"config",
39		"getEnvironmentPaths: userDataDir={} logsPath={} homeDir={}",
40		AppDataDir.display(),
41		SessionLogRoot.display(),
42		HomeDir.display()
43	);
44
45	let DevLogEnv = std::env::var("Trace").unwrap_or_default();
46
47	Ok(json!({
48		"userDataDir": AppDataDir.to_string_lossy(),
49		"logsPath": SessionLogRoot.to_string_lossy(),
50		"homeDir": HomeDir.to_string_lossy(),
51		"tmpDir": TmpDir.to_string_lossy(),
52		"devLog": if DevLogEnv.is_empty() { Value::Null } else { json!(DevLogEnv) },
53	}))
54}