Skip to content

Commit 25e5f91

Browse files
authored
feat(cli): merge user-defined plist with the iOS plist file (#8200)
1 parent adc3cc2 commit 25e5f91

File tree

6 files changed

+74
-5
lines changed

6 files changed

+74
-5
lines changed

.changes/merge-ios-plist.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:feat
3+
"@tauri-apps/cli": patch:feat
4+
---
5+
6+
Merge `src-tauri/Info.plist` and `src-tauri/Info.ios.plist` with the iOS project plist file.

tooling/cli/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/cli/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ cc = "1"
102102
[target."cfg(unix)".dependencies]
103103
libc = "0.2"
104104

105+
[target."cfg(target_os = \"macos\")".dependencies]
106+
plist = "1"
107+
105108
[features]
106109
default = [ "rustls" ]
107110
native-tls = [

tooling/cli/src/mobile/ios/build.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use super::{
66
configure_cargo, detect_target_ok, ensure_init, env, get_app, get_config, inject_assets,
7-
log_finished, open_and_wait, MobileTarget,
7+
log_finished, merge_plist, open_and_wait, MobileTarget,
88
};
99
use crate::{
1010
build::Options as BuildOptions,
@@ -94,11 +94,23 @@ pub fn command(mut options: Options, noise_level: NoiseLevel) -> Result<()> {
9494
};
9595

9696
let tauri_path = tauri_dir();
97-
set_current_dir(tauri_path).with_context(|| "failed to change current working directory")?;
97+
set_current_dir(&tauri_path).with_context(|| "failed to change current working directory")?;
9898

9999
ensure_init(config.project_dir(), MobileTarget::Ios)?;
100100
inject_assets(&config)?;
101101

102+
let info_plist_path = config
103+
.project_dir()
104+
.join(config.scheme())
105+
.join("Info.plist");
106+
merge_plist(
107+
&[
108+
tauri_path.join("Info.plist"),
109+
tauri_path.join("Info.ios.plist"),
110+
],
111+
&info_plist_path,
112+
)?;
113+
102114
let mut env = env()?;
103115
configure_cargo(&app, None)?;
104116

tooling/cli/src/mobile/ios/dev.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use super::{
66
configure_cargo, device_prompt, ensure_init, env, get_app, get_config, inject_assets,
7-
open_and_wait, setup_dev_config, MobileTarget, APPLE_DEVELOPMENT_TEAM_ENV_VAR_NAME,
7+
merge_plist, open_and_wait, setup_dev_config, MobileTarget, APPLE_DEVELOPMENT_TEAM_ENV_VAR_NAME,
88
};
99
use crate::{
1010
dev::Options as DevOptions,
@@ -145,10 +145,23 @@ fn run_command(mut options: Options, noise_level: NoiseLevel) -> Result<()> {
145145
};
146146

147147
let tauri_path = tauri_dir();
148-
set_current_dir(tauri_path).with_context(|| "failed to change current working directory")?;
148+
set_current_dir(&tauri_path).with_context(|| "failed to change current working directory")?;
149149

150150
ensure_init(config.project_dir(), MobileTarget::Ios)?;
151151
inject_assets(&config)?;
152+
153+
let info_plist_path = config
154+
.project_dir()
155+
.join(config.scheme())
156+
.join("Info.plist");
157+
merge_plist(
158+
&[
159+
tauri_path.join("Info.plist"),
160+
tauri_path.join("Info.ios.plist"),
161+
],
162+
&info_plist_path,
163+
)?;
164+
152165
run_dev(options, tauri_config, &app, &config, noise_level)
153166
}
154167

tooling/cli/src/mobile/ios/mod.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ use super::{
2929
};
3030
use crate::{helpers::config::Config as TauriConfig, Result};
3131

32-
use std::{env::set_var, fs::create_dir_all, process::exit, thread::sleep, time::Duration};
32+
use std::{
33+
env::set_var,
34+
fs::create_dir_all,
35+
path::{Path, PathBuf},
36+
process::exit,
37+
thread::sleep,
38+
time::Duration,
39+
};
3340

3441
mod build;
3542
mod dev;
@@ -261,3 +268,30 @@ fn inject_assets(config: &AppleConfig) -> Result<()> {
261268
create_dir_all(asset_dir)?;
262269
Ok(())
263270
}
271+
272+
fn merge_plist(src: &[PathBuf], dest: &Path) -> Result<()> {
273+
let mut dest_plist = None;
274+
275+
for src_path in src {
276+
if let Ok(src_plist) = plist::Value::from_file(src_path) {
277+
if dest_plist.is_none() {
278+
dest_plist.replace(plist::Value::from_file(dest)?);
279+
}
280+
281+
let plist = dest_plist.as_mut().expect("Info.plist not loaded");
282+
if let Some(plist) = plist.as_dictionary_mut() {
283+
if let Some(dict) = src_plist.into_dictionary() {
284+
for (key, value) in dict {
285+
plist.insert(key, value);
286+
}
287+
}
288+
}
289+
}
290+
}
291+
292+
if let Some(dest_plist) = dest_plist {
293+
dest_plist.to_file_xml(dest)?;
294+
}
295+
296+
Ok(())
297+
}

0 commit comments

Comments
 (0)