From aba04fa823d70ff8df9bd22f8e6a25184689c3cb Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 18 Jul 2023 06:20:55 -0700 Subject: [PATCH] feat(build): add API to update the iOS entitlements file (#7448) --- .changes/update-entitlements-api.md | 5 +++++ core/tauri-build/Cargo.toml | 1 + core/tauri-build/src/mobile.rs | 34 +++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 .changes/update-entitlements-api.md diff --git a/.changes/update-entitlements-api.md b/.changes/update-entitlements-api.md new file mode 100644 index 000000000..ccf53a63e --- /dev/null +++ b/.changes/update-entitlements-api.md @@ -0,0 +1,5 @@ +--- +"tauri-build": patch:feat +--- + +Added the `mobile::update_entitlements` function for iOS. diff --git a/core/tauri-build/Cargo.toml b/core/tauri-build/Cargo.toml index e3d514607..cb59fea4c 100644 --- a/core/tauri-build/Cargo.toml +++ b/core/tauri-build/Cargo.toml @@ -32,6 +32,7 @@ semver = "1" [target."cfg(target_os = \"macos\")".dependencies] swift-rs = { version = "1.0.5", features = [ "build" ] } +plist = "1" [features] codegen = [ "tauri-codegen", "quote" ] diff --git a/core/tauri-build/src/mobile.rs b/core/tauri-build/src/mobile.rs index 9b4e0b87e..e10aef33b 100644 --- a/core/tauri-build/src/mobile.rs +++ b/core/tauri-build/src/mobile.rs @@ -146,6 +146,40 @@ fn copy_folder(source: &Path, target: &Path, ignore_paths: &[&str]) -> Result<() Ok(()) } +#[cfg(target_os = "macos")] +fn update_plist_file, F: FnOnce(&mut plist::Dictionary)>( + path: P, + f: F, +) -> Result<()> { + let path = path.as_ref(); + if path.exists() { + let mut plist = plist::Value::from_file(path)?; + if let Some(dict) = plist.as_dictionary_mut() { + f(dict); + plist::to_file_xml(path, &plist)?; + } + } + + Ok(()) +} + +#[cfg(target_os = "macos")] +pub fn update_entitlements(f: F) -> Result<()> { + if let (Some(project_path), Ok(app_name)) = ( + var_os("TAURI_IOS_PROJECT_PATH").map(PathBuf::from), + var("TAURI_IOS_APP_NAME"), + ) { + update_plist_file( + project_path + .join(format!("{app_name}_iOS")) + .join(format!("{app_name}_iOS.entitlements")), + f, + )?; + } + + Ok(()) +} + pub(crate) fn generate_gradle_files(project_dir: PathBuf) -> Result<()> { let gradle_settings_path = project_dir.join("tauri.settings.gradle"); let app_build_gradle_path = project_dir.join("app").join("tauri.build.gradle.kts");