diff --git a/.changes/embed-plist-no-unit-val.md b/.changes/embed-plist-no-unit-val.md new file mode 100644 index 000000000..b054d7342 --- /dev/null +++ b/.changes/embed-plist-no-unit-val.md @@ -0,0 +1,6 @@ +--- +"tauri-codegen": patch:changes +"tauri": patch:changes +--- + +Changes how the Info.plist is embedded on macOS development to avoid a clippy warning. diff --git a/crates/tauri-codegen/src/context.rs b/crates/tauri-codegen/src/context.rs index ecbbc1360..849af6dd2 100644 --- a/crates/tauri-codegen/src/context.rs +++ b/crates/tauri-codegen/src/context.rs @@ -302,7 +302,7 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult { }; #[cfg(target_os = "macos")] - let info_plist = if target == Target::MacOS && dev && !running_tests { + let maybe_embed_plist_block = if target == Target::MacOS && dev && !running_tests { let info_plist_path = config_parent.join("Info.plist"); let mut info_plist = if info_plist_path.exists() { plist::Value::from_file(&info_plist_path) @@ -333,10 +333,10 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult { tauri::embed_plist::embed_info_plist!(#plist); }) } else { - quote!(()) + quote!() }; #[cfg(not(target_os = "macos"))] - let info_plist = quote!(()); + let maybe_embed_plist_block = quote!(); let pattern = match &options.pattern { PatternKind::Brownfield => quote!(#root::Pattern::Brownfield), @@ -490,6 +490,8 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult { }; let context = quote!({ + #maybe_embed_plist_block + #[allow(unused_mut, clippy::let_and_return)] let mut context = #root::Context::new( #config, @@ -497,7 +499,6 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult { #default_window_icon, #app_icon, #package_info, - #info_plist, #pattern, #runtime_authority, #plugin_global_api_script diff --git a/crates/tauri-utils/src/platform.rs b/crates/tauri-utils/src/platform.rs index 81df60b9c..fcf47a970 100644 --- a/crates/tauri-utils/src/platform.rs +++ b/crates/tauri-utils/src/platform.rs @@ -4,10 +4,7 @@ //! Platform helper functions. -use std::{ - fmt::Display, - path::{Path, PathBuf, MAIN_SEPARATOR}, -}; +use std::{fmt::Display, path::PathBuf}; use serde::{Deserialize, Serialize}; @@ -15,6 +12,10 @@ use crate::{Env, PackageInfo}; mod starting_binary; +/// URI prefix of a Tauri asset. +/// +/// This is referenced in the Tauri Android library, +/// which resolves these assets to a file descriptor. #[cfg(target_os = "android")] pub const ANDROID_ASSET_PROTOCOL_URI_PREFIX: &str = "asset://localhost/"; @@ -225,8 +226,8 @@ pub fn target_triple() -> crate::Result { Ok(format!("{arch}-{os}")) } -#[cfg(not(test))] -fn is_cargo_output_directory(path: &Path) -> bool { +#[cfg(all(not(test), not(target_os = "android")))] +fn is_cargo_output_directory(path: &std::path::Path) -> bool { path.join(".cargo-lock").exists() } @@ -234,7 +235,7 @@ fn is_cargo_output_directory(path: &Path) -> bool { const CARGO_OUTPUT_DIRECTORIES: &[&str] = &["debug", "release", "custom-profile"]; #[cfg(test)] -fn is_cargo_output_directory(path: &Path) -> bool { +fn is_cargo_output_directory(path: &std::path::Path) -> bool { let last_component = path .components() .last() @@ -265,13 +266,22 @@ fn is_cargo_output_directory(path: &Path) -> bool { /// Android uses a special URI prefix that is resolved by the Tauri file system plugin `asset://localhost/` pub fn resource_dir(package_info: &PackageInfo, env: &Env) -> crate::Result { #[cfg(target_os = "android")] - return Ok(PathBuf::from(ANDROID_ASSET_PROTOCOL_URI_PREFIX)); - let exe = current_exe()?; - resource_dir_from(exe, package_info, env) + return resource_dir_android(package_info, env); + #[cfg(not(target_os = "android"))] + { + let exe = current_exe()?; + resource_dir_from(exe, package_info, env) + } } +#[cfg(target_os = "android")] +fn resource_dir_android(_package_info: &PackageInfo, _env: &Env) -> crate::Result { + Ok(PathBuf::from(ANDROID_ASSET_PROTOCOL_URI_PREFIX)) +} + +#[cfg(not(target_os = "android"))] #[allow(unused_variables)] -fn resource_dir_from>( +fn resource_dir_from>( exe: P, package_info: &PackageInfo, env: &Env, @@ -279,7 +289,7 @@ fn resource_dir_from>( let exe_dir = exe.as_ref().parent().expect("failed to get exe directory"); let curr_dir = exe_dir.display().to_string(); - let parts: Vec<&str> = curr_dir.split(MAIN_SEPARATOR).collect(); + let parts: Vec<&str> = curr_dir.split(std::path::MAIN_SEPARATOR).collect(); let len = parts.len(); // Check if running from the Cargo output directory, which means it's an executable in a development machine diff --git a/crates/tauri/src/lib.rs b/crates/tauri/src/lib.rs index 28ec93daf..237776357 100644 --- a/crates/tauri/src/lib.rs +++ b/crates/tauri/src/lib.rs @@ -388,7 +388,6 @@ pub struct Context { #[cfg(all(desktop, feature = "tray-icon"))] pub(crate) tray_icon: Option>, pub(crate) package_info: PackageInfo, - pub(crate) _info_plist: (), pub(crate) pattern: Pattern, pub(crate) runtime_authority: RuntimeAuthority, pub(crate) plugin_global_api_scripts: Option<&'static [&'static str]>, @@ -502,7 +501,6 @@ impl Context { default_window_icon: Option>, app_icon: Option>, package_info: PackageInfo, - info_plist: (), pattern: Pattern, runtime_authority: RuntimeAuthority, plugin_global_api_scripts: Option<&'static [&'static str]>, @@ -517,7 +515,6 @@ impl Context { #[cfg(all(desktop, feature = "tray-icon"))] tray_icon: None, package_info, - _info_plist: info_plist, pattern, runtime_authority, plugin_global_api_scripts, diff --git a/crates/tauri/src/test/mod.rs b/crates/tauri/src/test/mod.rs index 6987cf867..8bfddf09e 100644 --- a/crates/tauri/src/test/mod.rs +++ b/crates/tauri/src/test/mod.rs @@ -131,7 +131,6 @@ pub fn mock_context>(assets: A) -> crate::Context { description: "Tauri test", crate_name: "test", }, - _info_plist: (), pattern: Pattern::Brownfield, runtime_authority: RuntimeAuthority::new(Default::default(), Resolved::default()), plugin_global_api_scripts: None, diff --git a/crates/tauri/src/webview/webview_window.rs b/crates/tauri/src/webview/webview_window.rs index ba0f8ce7a..5bb427408 100644 --- a/crates/tauri/src/webview/webview_window.rs +++ b/crates/tauri/src/webview/webview_window.rs @@ -505,20 +505,6 @@ impl<'a, R: Runtime, M: Manager> WebviewWindowBuilder<'a, R, M> { self } - /// Whether the window should be transparent. If this is true, writing colors - /// with alpha values different than `1.0` will produce a transparent window. - #[cfg(any(not(target_os = "macos"), feature = "macos-private-api"))] - #[cfg_attr( - docsrs, - doc(cfg(any(not(target_os = "macos"), feature = "macos-private-api"))) - )] - #[must_use] - pub fn transparent(mut self, transparent: bool) -> Self { - self.window_builder = self.window_builder.transparent(transparent); - self.webview_builder = self.webview_builder.transparent(transparent); - self - } - /// Whether the window should have borders and bars. #[must_use] pub fn decorations(mut self, decorations: bool) -> Self { @@ -859,6 +845,23 @@ impl<'a, R: Runtime, M: Manager> WebviewWindowBuilder<'a, R, M> { self } + /// Whether the window should be transparent. If this is true, writing colors + /// with alpha values different than `1.0` will produce a transparent window. + #[cfg(any(not(target_os = "macos"), feature = "macos-private-api"))] + #[cfg_attr( + docsrs, + doc(cfg(any(not(target_os = "macos"), feature = "macos-private-api"))) + )] + #[must_use] + pub fn transparent(mut self, transparent: bool) -> Self { + #[cfg(desktop)] + { + self.window_builder = self.window_builder.transparent(transparent); + } + self.webview_builder = self.webview_builder.transparent(transparent); + self + } + /// Whether page zooming by hotkeys is enabled /// /// ## Platform-specific: diff --git a/examples/file-associations/src-tauri/src/main.rs b/examples/file-associations/src-tauri/src/main.rs index 1eab17103..397e36eda 100644 --- a/examples/file-associations/src-tauri/src/main.rs +++ b/examples/file-associations/src-tauri/src/main.rs @@ -49,7 +49,7 @@ fn handle_file_associations(app: AppHandle, files: Vec) { fn main() { tauri::Builder::default() - .setup(|app| { + .setup(|#[allow(unused_variables)] app| { #[cfg(any(windows, target_os = "linux"))] { let mut files = Vec::new();