Skip to content

Commit 537ab1b

Browse files
authored
feat(core): inject src-tauri/Info.plist file on dev and merge on bundle, closes #1570 #2338 (#2444)
1 parent 957e863 commit 537ab1b

9 files changed

Lines changed: 96 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-bundler": patch
3+
---
4+
5+
Merge Tauri-generated Info.plist with the contents of `src-tauri/Info.plist` if it exists.

.changes/embed-plist.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-codegen": patch
3+
"tauri": patch
4+
---
5+
6+
Embed Info.plist file contents on binary on dev.

core/tauri-codegen/src/context.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,33 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
144144
quote!(None)
145145
};
146146

147+
#[cfg(target_os = "macos")]
148+
let info_plist = {
149+
if dev {
150+
let info_plist_path = config_parent.join("Info.plist");
151+
if info_plist_path.exists() {
152+
let info_plist_path = info_plist_path.display().to_string();
153+
quote!({
154+
tauri::embed_plist::embed_info_plist!(#info_plist_path);
155+
})
156+
} else {
157+
quote!(())
158+
}
159+
} else {
160+
quote!(())
161+
}
162+
};
163+
#[cfg(not(target_os = "macos"))]
164+
let info_plist = quote!(());
165+
147166
// double braces are purposeful to force the code into a block expression
148167
Ok(quote!(#root::Context::new(
149168
#config,
150169
::std::sync::Arc::new(#assets),
151170
#default_window_icon,
152171
#system_tray_icon,
153172
#package_info,
173+
#info_plist,
154174
)))
155175
}
156176

core/tauri/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ futures-lite = "1.12"
7676
gtk = { version = "0.14", features = [ "v3_20" ] }
7777
glib = "0.14"
7878

79+
[target."cfg(target_os = \"macos\")".dependencies]
80+
embed_plist = "1.2"
81+
7982
[build-dependencies]
8083
cfg_aliases = "0.1.1"
8184

core/tauri/src/lib.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#![warn(missing_docs, rust_2018_idioms)]
2020
#![cfg_attr(doc_cfg, feature(doc_cfg))]
2121

22+
#[cfg(target_os = "macos")]
23+
#[doc(hidden)]
24+
pub use embed_plist;
2225
/// The Tauri error enum.
2326
pub use error::Error;
2427
pub use tauri_macros::{command, generate_handler};
@@ -60,7 +63,7 @@ use crate::{
6063
runtime::window::PendingWindow,
6164
};
6265
use serde::Serialize;
63-
use std::{collections::HashMap, sync::Arc};
66+
use std::{collections::HashMap, fmt, sync::Arc};
6467

6568
// Export types likely to be used by the application.
6669
pub use runtime::menu::CustomMenuItem;
@@ -146,13 +149,24 @@ macro_rules! tauri_build_context {
146149
/// # Stability
147150
/// This is the output of the `tauri::generate_context!` macro, and is not considered part of the stable API.
148151
/// Unless you know what you are doing and are prepared for this type to have breaking changes, do not create it yourself.
149-
#[derive(Debug)]
150152
pub struct Context<A: Assets> {
151153
pub(crate) config: Config,
152154
pub(crate) assets: Arc<A>,
153155
pub(crate) default_window_icon: Option<Vec<u8>>,
154156
pub(crate) system_tray_icon: Option<Icon>,
155157
pub(crate) package_info: crate::api::PackageInfo,
158+
pub(crate) _info_plist: (),
159+
}
160+
161+
impl<A: Assets> fmt::Debug for Context<A> {
162+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
163+
f.debug_struct("Context")
164+
.field("config", &self.config)
165+
.field("default_window_icon", &self.default_window_icon)
166+
.field("system_tray_icon", &self.system_tray_icon)
167+
.field("package_info", &self.package_info)
168+
.finish()
169+
}
156170
}
157171

158172
impl<A: Assets> Context<A> {
@@ -224,13 +238,15 @@ impl<A: Assets> Context<A> {
224238
default_window_icon: Option<Vec<u8>>,
225239
system_tray_icon: Option<Icon>,
226240
package_info: crate::api::PackageInfo,
241+
info_plist: (),
227242
) -> Self {
228243
Self {
229244
config,
230245
assets,
231246
default_window_icon,
232247
system_tray_icon,
233248
package_info,
249+
_info_plist: info_plist,
234250
}
235251
}
236252
}

examples/api/src-tauri/Info.plist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>NSCameraUsageDescription</key>
6+
<string>Request camera access for WebRTC</string>
7+
<key>NSMicrophoneUsageDescription</key>
8+
<string>Request microphone access for WebRTC</string>
9+
</dict>
10+
</plist>

tooling/bundler/src/bundle/macos/app.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ fn create_info_plist(
181181
settings: &Settings,
182182
) -> crate::Result<()> {
183183
let build_number = chrono::Utc::now().format("%Y%m%d.%H%M%S");
184-
let file = &mut common::create_file(&bundle_dir.join("Info.plist"))?;
184+
185+
let bundle_plist_path = bundle_dir.join("Info.plist");
186+
let file = &mut common::create_file(&bundle_plist_path)?;
185187
let use_bootstrapper = settings.macos().use_bootstrapper.unwrap_or_default();
186188
write!(
187189
file,
@@ -296,6 +298,27 @@ fn create_info_plist(
296298

297299
write!(file, "</dict>\n</plist>\n")?;
298300
file.flush()?;
301+
302+
if let Some(user_plist_path) = &settings.macos().info_plist_path {
303+
let mut cmd = Command::new("/usr/libexec/PlistBuddy");
304+
cmd.args(&[
305+
"-c".into(),
306+
format!("Merge {}", user_plist_path.display()),
307+
bundle_plist_path.display().to_string(),
308+
]);
309+
310+
common::execute_with_verbosity(&mut cmd, settings).map_err(|_| {
311+
crate::Error::ShellScriptError(format!(
312+
"error running /usr/libexec/PlistBuddy{}",
313+
if settings.is_verbose() {
314+
""
315+
} else {
316+
", try running with --verbose to see command output"
317+
}
318+
))
319+
})?;
320+
}
321+
299322
Ok(())
300323
}
301324

tooling/bundler/src/bundle/settings.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ pub struct MacOsSettings {
170170
pub signing_identity: Option<String>,
171171
/// Path to the entitlements.plist file.
172172
pub entitlements: Option<String>,
173+
/// Path to the Info.plist file for the bundle.
174+
pub info_plist_path: Option<PathBuf>,
173175
}
174176

175177
/// Settings specific to the WiX implementation.

tooling/cli.rs/src/interface/rust.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,14 @@ fn tauri_config_to_bundle_settings(
436436
exception_domain: config.macos.exception_domain,
437437
signing_identity,
438438
entitlements: config.macos.entitlements,
439+
info_plist_path: {
440+
let path = tauri_dir().join("Info.plist");
441+
if path.exists() {
442+
Some(path)
443+
} else {
444+
None
445+
}
446+
},
439447
},
440448
windows: WindowsSettings {
441449
timestamp_url: config.windows.timestamp_url,

0 commit comments

Comments
 (0)