Skip to content

Commit ed7c9a4

Browse files
authored
feat(core): add config for Info.plist extensions, closes #13667 (#14108)
* feat(core): add config for Info.plist extensions, closes #13667 * add missing tag * do not lie :)
1 parent abf7e88 commit ed7c9a4

File tree

16 files changed

+182
-62
lines changed

16 files changed

+182
-62
lines changed

.changes/info-plist-config.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"tauri-utils": minor:feat
3+
"tauri-cli": minor:feat
4+
"@tauri-apps/cli": minor:feat
5+
---
6+
7+
Added `bundle > macOS > infoPlist` and `bundle > iOS > infoPlist` configurations to allow defining custom Info.plist extensions.
8+

.changes/refactor-info-plist.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-bundler": minor:breaking
3+
---
4+
5+
Changed `MacOsSettings::info_plist_path` to `MacOsSettings::info_plist`.

crates/tauri-build/src/codegen/context.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ impl CodegenContext {
120120
if info_plist_path.exists() {
121121
println!("cargo:rerun-if-changed={}", info_plist_path.display());
122122
}
123+
124+
if let Some(plist_path) = &config.bundle.macos.info_plist {
125+
let info_plist_path = config_parent.join(plist_path);
126+
if info_plist_path.exists() {
127+
println!("cargo:rerun-if-changed={}", info_plist_path.display());
128+
}
129+
}
123130
}
124131

125132
let code = context_codegen(ContextData {

crates/tauri-bundler/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ url = "2"
4444
uuid = { version = "1", features = ["v4", "v5"] }
4545
regex = "1"
4646
goblin = "0.9"
47+
plist = "1"
4748

4849
[target."cfg(target_os = \"windows\")".dependencies]
4950
bitness = "0.4"
@@ -57,7 +58,6 @@ features = ["Win32_System_SystemInformation", "Win32_System_Diagnostics_Debug"]
5758
[target."cfg(target_os = \"macos\")".dependencies]
5859
icns = { package = "tauri-icns", version = "0.1" }
5960
time = { version = "0.3", features = ["formatting"] }
60-
plist = "1"
6161
tauri-macos-sign = { version = "2.2.0", path = "../tauri-macos-sign" }
6262

6363
[target."cfg(target_os = \"linux\")".dependencies]

crates/tauri-bundler/src/bundle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ pub use self::{
4545
category::AppCategory,
4646
settings::{
4747
AppImageSettings, BundleBinary, BundleSettings, CustomSignCommandSettings, DebianSettings,
48-
DmgSettings, IosSettings, MacOsSettings, PackageSettings, PackageType, Position, RpmSettings,
49-
Settings, SettingsBuilder, Size, UpdaterSettings,
48+
DmgSettings, IosSettings, MacOsSettings, PackageSettings, PackageType, PlistKind, Position,
49+
RpmSettings, Settings, SettingsBuilder, Size, UpdaterSettings,
5050
},
5151
};
5252
pub use settings::{NsisSettings, WindowsSettings, WixLanguage, WixLanguageConfig, WixSettings};

crates/tauri-bundler/src/bundle/macos/app.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use super::{
2727
sign::{notarize, notarize_auth, notarize_without_stapling, sign, SignTarget},
2828
};
2929
use crate::{
30+
bundle::settings::PlistKind,
3031
error::{Context, ErrorExt, NotarizeAuthError},
3132
utils::{fs_utils, CommandExt},
3233
Error::GenericError,
@@ -361,8 +362,11 @@ fn create_info_plist(
361362
plist.insert("NSAppTransportSecurity".into(), security.into());
362363
}
363364

364-
if let Some(user_plist_path) = &settings.macos().info_plist_path {
365-
let user_plist = plist::Value::from_file(user_plist_path)?;
365+
if let Some(user_plist) = &settings.macos().info_plist {
366+
let user_plist = match user_plist {
367+
PlistKind::Path(path) => plist::Value::from_file(path)?,
368+
PlistKind::Plist(value) => value.clone(),
369+
};
366370
if let Some(dict) = user_plist.into_dictionary() {
367371
for (key, value) in dict {
368372
plist.insert(key, value);

crates/tauri-bundler/src/bundle/settings.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,17 @@ pub struct MacOsSettings {
362362
pub provider_short_name: Option<String>,
363363
/// Path to the entitlements.plist file.
364364
pub entitlements: Option<String>,
365-
/// Path to the Info.plist file for the bundle.
366-
pub info_plist_path: Option<PathBuf>,
365+
/// Path to the Info.plist file or raw plist value to merge with the bundle Info.plist.
366+
pub info_plist: Option<PlistKind>,
367+
}
368+
369+
/// Plist format.
370+
#[derive(Debug, Clone)]
371+
pub enum PlistKind {
372+
/// Path to a .plist file.
373+
Path(PathBuf),
374+
/// Raw plist value.
375+
Plist(plist::Value),
367376
}
368377

369378
/// Configuration for a target language for the WiX build.

crates/tauri-cli/config.schema.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3572,6 +3572,13 @@
35723572
"null"
35733573
]
35743574
},
3575+
"infoPlist": {
3576+
"description": "Path to a Info.plist file to merge with the default Info.plist.\n\n Note that Tauri also looks for a `Info.plist` file in the same directory as the Tauri configuration file.",
3577+
"type": [
3578+
"string",
3579+
"null"
3580+
]
3581+
},
35753582
"dmg": {
35763583
"description": "DMG-specific settings.",
35773584
"default": {
@@ -3743,6 +3750,13 @@
37433750
"description": "A version string indicating the minimum iOS version that the bundled application supports. Defaults to `13.0`.\n\n Maps to the IPHONEOS_DEPLOYMENT_TARGET value.",
37443751
"default": "14.0",
37453752
"type": "string"
3753+
},
3754+
"infoPlist": {
3755+
"description": "Path to a Info.plist file to merge with the default Info.plist.\n\n Note that Tauri also looks for a `Info.plist` and `Info.ios.plist` file in the same directory as the Tauri configuration file.",
3756+
"type": [
3757+
"string",
3758+
"null"
3759+
]
37463760
}
37473761
},
37483762
"additionalProperties": false

crates/tauri-cli/src/helpers/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pub mod http;
1313
pub mod npm;
1414
#[cfg(target_os = "macos")]
1515
pub mod pbxproj;
16+
#[cfg(target_os = "macos")]
17+
pub mod plist;
1618
pub mod plugins;
1719
pub mod prompts;
1820
pub mod template;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
use std::path::PathBuf;
6+
7+
use crate::error::Context;
8+
9+
pub enum PlistKind {
10+
Path(PathBuf),
11+
Plist(plist::Value),
12+
}
13+
14+
impl From<PathBuf> for PlistKind {
15+
fn from(p: PathBuf) -> Self {
16+
Self::Path(p)
17+
}
18+
}
19+
impl From<plist::Value> for PlistKind {
20+
fn from(p: plist::Value) -> Self {
21+
Self::Plist(p)
22+
}
23+
}
24+
25+
pub fn merge_plist(src: Vec<PlistKind>) -> crate::Result<plist::Value> {
26+
let mut merged_plist = plist::Dictionary::new();
27+
28+
for plist_kind in src {
29+
let src_plist = match plist_kind {
30+
PlistKind::Path(p) => plist::Value::from_file(&p)
31+
.with_context(|| format!("failed to parse plist from {}", p.display()))?,
32+
PlistKind::Plist(v) => v,
33+
};
34+
if let Some(dict) = src_plist.into_dictionary() {
35+
for (key, value) in dict {
36+
merged_plist.insert(key, value);
37+
}
38+
}
39+
}
40+
41+
Ok(plist::Value::Dictionary(merged_plist))
42+
}

0 commit comments

Comments
 (0)