Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): merge user-defined plist with the iOS plist file #8200

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/merge-ios-plist.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions examples/api/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tooling/cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tooling/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
16 changes: 14 additions & 2 deletions tooling/cli/src/mobile/ios/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)?;

Expand Down
17 changes: 15 additions & 2 deletions tooling/cli/src/mobile/ios/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}

Expand Down
36 changes: 35 additions & 1 deletion tooling/cli/src/mobile/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(())
}