diff --git a/.changes/merge-ios-plist.md b/.changes/merge-ios-plist.md new file mode 100644 index 000000000000..87cf86f3a789 --- /dev/null +++ b/.changes/merge-ios-plist.md @@ -0,0 +1,6 @@ +--- +"tauri-cli": patch:feat +"@tauri-apps/cli": patch:feat +--- + +Merge `src-tauri/Info.plist` and `src-tauri/Info.ios.plist` with the iOS project plist file. diff --git a/examples/api/src-tauri/Cargo.lock b/examples/api/src-tauri/Cargo.lock index e373e3597910..dbdf9dee0750 100644 --- a/examples/api/src-tauri/Cargo.lock +++ b/examples/api/src-tauri/Cargo.lock @@ -482,9 +482,9 @@ dependencies = [ [[package]] name = "cargo_toml" -version = "0.16.3" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3f9629bc6c4388ea699781dc988c2b99766d7679b151c81990b4fa1208fafd3" +checksum = "6ca592ad99e6a0fd4b95153406138b997cc26ccd3cd0aecdfd4fbdbf1519bd77" dependencies = [ "serde", "toml 0.8.2", diff --git a/tooling/cli/Cargo.lock b/tooling/cli/Cargo.lock index fbfc953a994e..a4879c609782 100644 --- a/tooling/cli/Cargo.lock +++ b/tooling/cli/Cargo.lock @@ -4099,6 +4099,7 @@ dependencies = [ "once_cell", "os_info", "os_pipe", + "plist", "regex", "resvg", "semver", diff --git a/tooling/cli/Cargo.toml b/tooling/cli/Cargo.toml index ceb4a0d14328..4a3369146a1b 100644 --- a/tooling/cli/Cargo.toml +++ b/tooling/cli/Cargo.toml @@ -102,6 +102,9 @@ cc = "1" [target."cfg(unix)".dependencies] libc = "0.2" +[target."cfg(target_os = \"macos\")".dependencies] +plist = "1" + [features] default = [ "rustls" ] native-tls = [ diff --git a/tooling/cli/src/mobile/ios/build.rs b/tooling/cli/src/mobile/ios/build.rs index 76c3d03be181..675fa5107e00 100644 --- a/tooling/cli/src/mobile/ios/build.rs +++ b/tooling/cli/src/mobile/ios/build.rs @@ -4,7 +4,7 @@ use super::{ configure_cargo, detect_target_ok, ensure_init, env, get_app, get_config, inject_assets, - log_finished, open_and_wait, MobileTarget, + log_finished, merge_plist, open_and_wait, MobileTarget, }; use crate::{ build::Options as BuildOptions, @@ -94,11 +94,23 @@ pub fn command(mut options: Options, noise_level: NoiseLevel) -> Result<()> { }; let tauri_path = tauri_dir(); - set_current_dir(tauri_path).with_context(|| "failed to change current working directory")?; + set_current_dir(&tauri_path).with_context(|| "failed to change current working directory")?; ensure_init(config.project_dir(), MobileTarget::Ios)?; inject_assets(&config)?; + let info_plist_path = config + .project_dir() + .join(config.scheme()) + .join("Info.plist"); + merge_plist( + &[ + tauri_path.join("Info.plist"), + tauri_path.join("Info.ios.plist"), + ], + &info_plist_path, + )?; + let mut env = env()?; configure_cargo(&app, None)?; diff --git a/tooling/cli/src/mobile/ios/dev.rs b/tooling/cli/src/mobile/ios/dev.rs index 230bb339a5bc..7664a0e203ff 100644 --- a/tooling/cli/src/mobile/ios/dev.rs +++ b/tooling/cli/src/mobile/ios/dev.rs @@ -4,7 +4,7 @@ use super::{ configure_cargo, device_prompt, ensure_init, env, get_app, get_config, inject_assets, - open_and_wait, setup_dev_config, MobileTarget, APPLE_DEVELOPMENT_TEAM_ENV_VAR_NAME, + merge_plist, open_and_wait, setup_dev_config, MobileTarget, APPLE_DEVELOPMENT_TEAM_ENV_VAR_NAME, }; use crate::{ dev::Options as DevOptions, @@ -145,10 +145,23 @@ fn run_command(mut options: Options, noise_level: NoiseLevel) -> Result<()> { }; let tauri_path = tauri_dir(); - set_current_dir(tauri_path).with_context(|| "failed to change current working directory")?; + set_current_dir(&tauri_path).with_context(|| "failed to change current working directory")?; ensure_init(config.project_dir(), MobileTarget::Ios)?; inject_assets(&config)?; + + let info_plist_path = config + .project_dir() + .join(config.scheme()) + .join("Info.plist"); + merge_plist( + &[ + tauri_path.join("Info.plist"), + tauri_path.join("Info.ios.plist"), + ], + &info_plist_path, + )?; + run_dev(options, tauri_config, &app, &config, noise_level) } diff --git a/tooling/cli/src/mobile/ios/mod.rs b/tooling/cli/src/mobile/ios/mod.rs index 05039a53d2f8..ffbc77731820 100644 --- a/tooling/cli/src/mobile/ios/mod.rs +++ b/tooling/cli/src/mobile/ios/mod.rs @@ -29,7 +29,14 @@ use super::{ }; use crate::{helpers::config::Config as TauriConfig, Result}; -use std::{env::set_var, fs::create_dir_all, process::exit, thread::sleep, time::Duration}; +use std::{ + env::set_var, + fs::create_dir_all, + path::{Path, PathBuf}, + process::exit, + thread::sleep, + time::Duration, +}; mod build; mod dev; @@ -261,3 +268,30 @@ fn inject_assets(config: &AppleConfig) -> Result<()> { create_dir_all(asset_dir)?; Ok(()) } + +fn merge_plist(src: &[PathBuf], dest: &Path) -> Result<()> { + let mut dest_plist = None; + + for src_path in src { + if let Ok(src_plist) = plist::Value::from_file(src_path) { + if dest_plist.is_none() { + dest_plist.replace(plist::Value::from_file(dest)?); + } + + let plist = dest_plist.as_mut().expect("Info.plist not loaded"); + if let Some(plist) = plist.as_dictionary_mut() { + if let Some(dict) = src_plist.into_dictionary() { + for (key, value) in dict { + plist.insert(key, value); + } + } + } + } + } + + if let Some(dest_plist) = dest_plist { + dest_plist.to_file_xml(dest)?; + } + + Ok(()) +}