From c3c790fe7af628ef3a176686fb944e6541fe5d61 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sun, 15 Aug 2021 19:50:45 -0300 Subject: [PATCH 1/4] feat(core): inject src-tauri/Info.plist file on dev, closes #1570 #2338 --- .changes/embed-plist.md | 6 ++++++ core/tauri-codegen/src/context.rs | 21 +++++++++++++++++++++ core/tauri/Cargo.toml | 3 +++ core/tauri/src/lib.rs | 22 ++++++++++++++++++++-- examples/api/src-tauri/Info.plist | 10 ++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 .changes/embed-plist.md create mode 100644 examples/api/src-tauri/Info.plist diff --git a/.changes/embed-plist.md b/.changes/embed-plist.md new file mode 100644 index 000000000000..4939235333b6 --- /dev/null +++ b/.changes/embed-plist.md @@ -0,0 +1,6 @@ +--- +"tauri-codegen": patch +"tauri": patch +--- + +Embed Info.plist file contents on binary on dev. diff --git a/core/tauri-codegen/src/context.rs b/core/tauri-codegen/src/context.rs index 95509709b8fb..30a69ff0269f 100644 --- a/core/tauri-codegen/src/context.rs +++ b/core/tauri-codegen/src/context.rs @@ -144,6 +144,25 @@ pub fn context_codegen(data: ContextData) -> Result Result { pub(crate) config: Config, pub(crate) assets: Arc, pub(crate) default_window_icon: Option>, pub(crate) system_tray_icon: Option, pub(crate) package_info: crate::api::PackageInfo, + #[cfg(target_os = "macos")] + pub(crate) _info_plist: (), +} + +impl fmt::Debug for Context { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Context") + .field("config", &self.config) + .field("default_window_icon", &self.default_window_icon) + .field("system_tray_icon", &self.system_tray_icon) + .field("package_info", &self.package_info) + .finish() + } } impl Context { @@ -224,6 +238,8 @@ impl Context { default_window_icon: Option>, system_tray_icon: Option, package_info: crate::api::PackageInfo, + #[cfg(target_os = "macos")] + info_plist: (), ) -> Self { Self { config, @@ -231,6 +247,8 @@ impl Context { default_window_icon, system_tray_icon, package_info, + #[cfg(target_os = "macos")] + _info_plist: info_plist, } } } diff --git a/examples/api/src-tauri/Info.plist b/examples/api/src-tauri/Info.plist new file mode 100644 index 000000000000..fe253ec7ba00 --- /dev/null +++ b/examples/api/src-tauri/Info.plist @@ -0,0 +1,10 @@ + + + + + NSCameraUsageDescription + Request camera access for WebRTC + NSMicrophoneUsageDescription + Request microphone access for WebRTC + + From 46f8e46bfa244af20516ccba32135ac80f8e3714 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sun, 15 Aug 2021 20:21:22 -0300 Subject: [PATCH 2/4] merge src-tauri/Info.plist on bundler --- .changes/bundler-merge-info-plist.md | 5 +++++ tooling/bundler/src/bundle/macos/app.rs | 25 ++++++++++++++++++++++++- tooling/bundler/src/bundle/settings.rs | 2 ++ tooling/cli.rs/src/interface/rust.rs | 8 ++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 .changes/bundler-merge-info-plist.md diff --git a/.changes/bundler-merge-info-plist.md b/.changes/bundler-merge-info-plist.md new file mode 100644 index 000000000000..545b18e71cb9 --- /dev/null +++ b/.changes/bundler-merge-info-plist.md @@ -0,0 +1,5 @@ +--- +"tauri-bundler": patch +--- + +Merge Tauri-generated Info.plist with the contents of `src-tauri/Info.plist` if it exists. diff --git a/tooling/bundler/src/bundle/macos/app.rs b/tooling/bundler/src/bundle/macos/app.rs index e12963e3c9c7..7c2394729876 100644 --- a/tooling/bundler/src/bundle/macos/app.rs +++ b/tooling/bundler/src/bundle/macos/app.rs @@ -181,7 +181,9 @@ fn create_info_plist( settings: &Settings, ) -> crate::Result<()> { let build_number = chrono::Utc::now().format("%Y%m%d.%H%M%S"); - let file = &mut common::create_file(&bundle_dir.join("Info.plist"))?; + + let bundle_plist_path = bundle_dir.join("Info.plist"); + let file = &mut common::create_file(&bundle_plist_path)?; let use_bootstrapper = settings.macos().use_bootstrapper.unwrap_or_default(); write!( file, @@ -296,6 +298,27 @@ fn create_info_plist( write!(file, "\n\n")?; file.flush()?; + + if let Some(user_plist_path) = &settings.macos().info_plist_path { + let mut cmd = Command::new("/usr/libexec/PlistBuddy"); + cmd.args(&[ + "-c".into(), + format!("Merge {}", user_plist_path.display()), + bundle_plist_path.display().to_string(), + ]); + + common::execute_with_verbosity(&mut cmd, settings).map_err(|_| { + crate::Error::ShellScriptError(format!( + "error running /usr/libexec/PlistBuddy{}", + if settings.is_verbose() { + "" + } else { + ", try running with --verbose to see command output" + } + )) + })?; + } + Ok(()) } diff --git a/tooling/bundler/src/bundle/settings.rs b/tooling/bundler/src/bundle/settings.rs index 24e14cdf65f1..b205ba6d1ac6 100644 --- a/tooling/bundler/src/bundle/settings.rs +++ b/tooling/bundler/src/bundle/settings.rs @@ -170,6 +170,8 @@ pub struct MacOsSettings { pub signing_identity: Option, /// Path to the entitlements.plist file. pub entitlements: Option, + /// Path to the Info.plist file for the bundle. + pub info_plist_path: Option, } /// Settings specific to the WiX implementation. diff --git a/tooling/cli.rs/src/interface/rust.rs b/tooling/cli.rs/src/interface/rust.rs index 74a6a1d2a201..0c92c7016b0a 100644 --- a/tooling/cli.rs/src/interface/rust.rs +++ b/tooling/cli.rs/src/interface/rust.rs @@ -436,6 +436,14 @@ fn tauri_config_to_bundle_settings( exception_domain: config.macos.exception_domain, signing_identity, entitlements: config.macos.entitlements, + info_plist_path: { + let path = tauri_dir().join("Info.plist"); + if path.exists() { + Some(path) + } else { + None + } + } }, windows: WindowsSettings { timestamp_url: config.windows.timestamp_url, From 499dce935641d946d61bedcdc541eebe6a18b1e7 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sun, 15 Aug 2021 20:30:14 -0300 Subject: [PATCH 3/4] fix build on linux/windows --- core/tauri-codegen/src/context.rs | 7 +++---- core/tauri/src/lib.rs | 10 ++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/core/tauri-codegen/src/context.rs b/core/tauri-codegen/src/context.rs index 30a69ff0269f..293dbf18022b 100644 --- a/core/tauri-codegen/src/context.rs +++ b/core/tauri-codegen/src/context.rs @@ -149,9 +149,7 @@ pub fn context_codegen(data: ContextData) -> Result Result Result { pub(crate) default_window_icon: Option>, pub(crate) system_tray_icon: Option, pub(crate) package_info: crate::api::PackageInfo, - #[cfg(target_os = "macos")] pub(crate) _info_plist: (), } @@ -238,7 +238,6 @@ impl Context { default_window_icon: Option>, system_tray_icon: Option, package_info: crate::api::PackageInfo, - #[cfg(target_os = "macos")] info_plist: (), ) -> Self { Self { @@ -247,7 +246,6 @@ impl Context { default_window_icon, system_tray_icon, package_info, - #[cfg(target_os = "macos")] _info_plist: info_plist, } } From fe654b3fea052361af5f76e55e9727f2b8aaf01e Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sun, 15 Aug 2021 20:49:11 -0300 Subject: [PATCH 4/4] fmt --- tooling/cli.rs/src/interface/rust.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/cli.rs/src/interface/rust.rs b/tooling/cli.rs/src/interface/rust.rs index 0c92c7016b0a..91bfcc65ca41 100644 --- a/tooling/cli.rs/src/interface/rust.rs +++ b/tooling/cli.rs/src/interface/rust.rs @@ -443,7 +443,7 @@ fn tauri_config_to_bundle_settings( } else { None } - } + }, }, windows: WindowsSettings { timestamp_url: config.windows.timestamp_url,