Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/NativeHost/
GetEnvironmentPaths.rs

1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3//! Wire method: `nativeHost:getEnvironmentPaths`.
4//! Returns paths used by VS Code's `ResolveConfiguration` to locate user-data,
5//! logs, home, and temp directories. The session-timestamped logs subdirectory
6//! is created on first call so VS Code can write output files immediately.
7
8use serde_json::{Value, json};
9use tauri::{AppHandle, Manager};
10
11pub async fn NativeGetEnvironmentPaths(ApplicationHandle:AppHandle) -> Result<Value, String> {
12	let PathResolver = ApplicationHandle.path();
13	let AppDataDir = PathResolver.app_data_dir().unwrap_or_default();
14	let HomeDir = PathResolver.home_dir().unwrap_or_default();
15	let TmpDir = std::env::temp_dir();
16
17	// Logs go under {appDataDir}/logs/{sessionTimestamp}/ - same tree as all
18	// other VS Code data, not Tauri's separate app_log_dir(). VS Code requires
19	// a session-timestamped subdir for log rotation. `DevLog::SessionTimestamp`
20	// is the single source of truth so that `Mountain.dev.log` (written by
21	// DevLog) and VS Code's `window1/output/*.log` files (written into
22	// `logsPath`) share one directory per session.
23	let SessionLogRoot = AppDataDir.join("logs").join(crate::IPC::DevLog::SessionTimestamp::Fn());
24	let SessionLogWindowDir = SessionLogRoot.join("window1");
25	let _ = std::fs::create_dir_all(&SessionLogWindowDir);
26
27	crate::dev_log!(
28		"config",
29		"getEnvironmentPaths: userDataDir={} logsPath={} homeDir={}",
30		AppDataDir.display(),
31		SessionLogRoot.display(),
32		HomeDir.display()
33	);
34	let DevLogEnv = std::env::var("Trace").unwrap_or_default();
35	Ok(json!({
36		"userDataDir": AppDataDir.to_string_lossy(),
37		"logsPath": SessionLogRoot.to_string_lossy(),
38		"homeDir": HomeDir.to_string_lossy(),
39		"tmpDir": TmpDir.to_string_lossy(),
40		"devLog": if DevLogEnv.is_empty() { Value::Null } else { json!(DevLogEnv) },
41	}))
42}