Skip to main content

Mountain/IPC/WindServiceHandlers/NativeHost/
GetEnvironmentPaths.rs

1#![allow(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 Fn(ApplicationHandle:AppHandle) -> Result<Value, String> {
12	let PathResolver = ApplicationHandle.path();
13
14	let AppDataDir = PathResolver.app_data_dir().unwrap_or_default();
15
16	let HomeDir = PathResolver.home_dir().unwrap_or_default();
17
18	let TmpDir = std::env::temp_dir();
19
20	// Logs go under {appDataDir}/logs/{sessionTimestamp}/ - same tree as all
21	// other VS Code data, not Tauri's separate app_log_dir(). VS Code requires
22	// a session-timestamped subdir for log rotation. `DevLog::SessionTimestamp`
23	// is the single source of truth so that `Mountain.dev.log` (written by
24	// DevLog) and VS Code's `window1/output/*.log` files (written into
25	// `logsPath`) share one directory per session.
26	let SessionLogRoot = AppDataDir.join("logs").join(crate::IPC::DevLog::SessionTimestamp::Fn());
27
28	let SessionLogWindowDir = SessionLogRoot.join("window1");
29
30	let _ = std::fs::create_dir_all(&SessionLogWindowDir);
31
32	crate::dev_log!(
33		"config",
34		"getEnvironmentPaths: userDataDir={} logsPath={} homeDir={}",
35		AppDataDir.display(),
36		SessionLogRoot.display(),
37		HomeDir.display()
38	);
39
40	let DevLogEnv = std::env::var("Trace").unwrap_or_default();
41
42	Ok(json!({
43		"userDataDir": AppDataDir.to_string_lossy(),
44		"logsPath": SessionLogRoot.to_string_lossy(),
45		"homeDir": HomeDir.to_string_lossy(),
46		"tmpDir": TmpDir.to_string_lossy(),
47		"devLog": if DevLogEnv.is_empty() { Value::Null } else { json!(DevLogEnv) },
48	}))
49}