Skip to content

Commit

Permalink
feat(build): add API to update the iOS entitlements file (#7448)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Jul 18, 2023
1 parent aa94f71 commit aba04fa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/update-entitlements-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-build": patch:feat
---

Added the `mobile::update_entitlements` function for iOS.
1 change: 1 addition & 0 deletions core/tauri-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
34 changes: 34 additions & 0 deletions core/tauri-build/src/mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,40 @@ fn copy_folder(source: &Path, target: &Path, ignore_paths: &[&str]) -> Result<()
Ok(())
}

#[cfg(target_os = "macos")]
fn update_plist_file<P: AsRef<Path>, 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: FnOnce(&mut plist::Dictionary)>(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");
Expand Down

0 comments on commit aba04fa

Please sign in to comment.