11// DEPENDENCY: This module file was created to resolve a missing module error.
2- // The original Spawn.rs was located at Source/Source/SideCar/Spawn.rs in an unusual directory structure.
3- // Consider refactoring the directory structure to avoid duplicate/confusing module locations.
2+ // The original Spawn.rs was located at Source/Source/SideCar/Spawn.rs in an
3+ // unusual directory structure. Consider refactoring the directory structure to
4+ // avoid duplicate/confusing module locations.
5+
6+ use std:: fs;
47
58#[ allow( unused_imports) ]
69use tauri:: { AppHandle , Manager } ;
7- use std:: fs;
810// Note: Mist crate has lib name "mist", so we use lowercase for imports
911use mist:: dns_port;
1012// DEPENDENCY: Add tauri-plugin-shell to Cargo.toml dependencies for Tauri 2.x shell support
1113use tauri_plugin_shell:: ShellExt ;
1214
13- const DNS_OVERRIDE : & str = include_str ! ( "../Resource/dns-override.js" ) ;
15+ const DNS_OVERRIDE : & str = include_str ! ( "../Resource/dns-override.js" ) ;
1416
15- /// Spawns a Node.js sidecar with DNS override configured to use the local Hickory DNS server.
17+ /// Spawns a Node.js sidecar with DNS override configured to use the local
18+ /// Hickory DNS server.
1619///
1720/// This function:
1821/// 1. Creates the app data directory if it doesn't exist
1922/// 2. Writes the DNS override JavaScript file to the app data directory
20- /// 3. Configures the sidecar process with NODE_OPTIONS to require the DNS override script
21- /// 4. Sets the LAND_DNS_SERVER environment variable with the local DNS server address
23+ /// 3. Configures the sidecar process with NODE_OPTIONS to require the DNS
24+ /// override script
25+ /// 4. Sets the LAND_DNS_SERVER environment variable with the local DNS server
26+ /// address
2227/// 5. Spawns the sidecar process
2328///
2429/// # Parameters
2530///
26- /// * `app` - The Tauri app handle, used to access the app data directory and shell
31+ /// * `app` - The Tauri app handle, used to access the app data directory and
32+ /// shell
2733/// * `sidecar_name` - The name of the sidecar executable to spawn
2834///
2935/// # Returns
@@ -40,35 +46,31 @@ const DNS_OVERRIDE: &str = include_str!("../Resource/dns-override.js");
4046/// use SideCar::Spawn::spawn_node_sidecar;
4147///
4248/// #[tauri::command]
43- /// fn launch_sidecar(app: tauri::AppHandle) -> Result<(), String> {
44- /// spawn_node_sidecar(&app, "my-sidecar")
45- /// .map_err(|e| e.to_string())?;
46- /// Ok(())
49+ /// fn launch_sidecar(app:tauri::AppHandle) -> Result<(), String> {
50+ /// spawn_node_sidecar(&app, "my-sidecar").map_err(|e| e.to_string())?;
51+ /// Ok(())
4752/// }
4853/// ```
4954#[ allow( dead_code) ]
50- pub fn spawn_node_sidecar (
51- app : & AppHandle ,
52- sidecar_name : & str ,
53- ) -> anyhow:: Result < ( ) > {
54- // Ensure app data directory exists
55- let data_dir = app. path ( ) . app_data_dir ( ) ?;
56- fs:: create_dir_all ( & data_dir) ?;
55+ pub fn spawn_node_sidecar ( app : & AppHandle , sidecar_name : & str ) -> anyhow:: Result < ( ) > {
56+ // Ensure app data directory exists
57+ let data_dir = app. path ( ) . app_data_dir ( ) ?;
58+ fs:: create_dir_all ( & data_dir) ?;
5759
58- // Write DNS override script to app data directory
59- let override_path = data_dir. join ( "dns-override.js" ) ;
60- fs:: write ( & override_path, DNS_OVERRIDE ) ?;
60+ // Write DNS override script to app data directory
61+ let override_path = data_dir. join ( "dns-override.js" ) ;
62+ fs:: write ( & override_path, DNS_OVERRIDE ) ?;
6163
62- // Get the DNS server port from Mist module
63- let port = dns_port ( ) ;
64- let node_opts = format ! ( "--require {}" , override_path. display( ) ) ;
64+ // Get the DNS server port from Mist module
65+ let port = dns_port ( ) ;
66+ let node_opts = format ! ( "--require {}" , override_path. display( ) ) ;
6567
66- // Spawn the sidecar with DNS configuration
67- app. shell ( )
68- . sidecar ( sidecar_name) ?
69- . env ( "NODE_OPTIONS" , & node_opts)
70- . env ( "LAND_DNS_SERVER" , format ! ( "127.0.0.1:{port}" ) )
71- . spawn ( ) ?;
68+ // Spawn the sidecar with DNS configuration
69+ app. shell ( )
70+ . sidecar ( sidecar_name) ?
71+ . env ( "NODE_OPTIONS" , & node_opts)
72+ . env ( "LAND_DNS_SERVER" , format ! ( "127.0.0.1:{port}" ) )
73+ . spawn ( ) ?;
7274
73- Ok ( ( ) )
75+ Ok ( ( ) )
7476}
0 commit comments