Skip to main content

PlistEdit

Function PlistEdit 

Source
pub fn PlistEdit(
    File: &Path,
    EnvVars: &BTreeMap<String, String>,
) -> Result<bool, Error>
Expand description

Injects or replaces the LSEnvironment dictionary in a macOS Info.plist.

Tauri uses the Info.plist in the project directory as a template during bundling. When the bundled .app is launched by LaunchServices (double-click in Finder, open, or Spotlight), any keys under LSEnvironment are injected into the process environment before the executable starts. This is the mechanism that makes the dev-control variables (Trace, Record, etc.) available without requiring a wrapper script.

§Parameters

  • File - Path to the Info.plist template file
  • EnvVars - Map of environment variable names to their values. These become key-value pairs in the LSEnvironment dictionary.

§Returns

Returns a Result<bool> indicating:

  • Ok(true) - The file was modified and saved
  • Ok(false) - No changes were needed (LSEnvironment already matches)
  • Err(BuildError) - An error occurred during modification

§Errors

  • BuildError::Io - If the file cannot be read or written
  • BuildError::Plist - If the plist cannot be parsed or serialized

§Behavior

  • Parses the plist into an in-memory tree.
  • Inserts or replaces the LSEnvironment dictionary with the given env vars.
  • Serialises back to XML with tab indentation.
  • Only writes the file if the content changed.

§Example

use crate::Maintain::Source::Build::PlistEdit;
let mut env = std::collections::BTreeMap::new();
env.insert("Trace".to_string(), "all".to_string());
env.insert("Record".to_string(), "1".to_string());
let modified = PlistEdit(&path, &env)?;