Skip to content

Commit 27d0183

Browse files
authored
fix(core): clippy warnings, simplify embed_plist usage (tauri-apps#10844)
* fix(core): clippy warnings * fix test * chore: simplify example
1 parent 9c9644d commit 27d0183

File tree

7 files changed

+51
-35
lines changed

7 files changed

+51
-35
lines changed

.changes/embed-plist-no-unit-val.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-codegen": patch:changes
3+
"tauri": patch:changes
4+
---
5+
6+
Changes how the Info.plist is embedded on macOS development to avoid a clippy warning.

crates/tauri-codegen/src/context.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult<TokenStream> {
302302
};
303303

304304
#[cfg(target_os = "macos")]
305-
let info_plist = if target == Target::MacOS && dev && !running_tests {
305+
let maybe_embed_plist_block = if target == Target::MacOS && dev && !running_tests {
306306
let info_plist_path = config_parent.join("Info.plist");
307307
let mut info_plist = if info_plist_path.exists() {
308308
plist::Value::from_file(&info_plist_path)
@@ -333,10 +333,10 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult<TokenStream> {
333333
tauri::embed_plist::embed_info_plist!(#plist);
334334
})
335335
} else {
336-
quote!(())
336+
quote!()
337337
};
338338
#[cfg(not(target_os = "macos"))]
339-
let info_plist = quote!(());
339+
let maybe_embed_plist_block = quote!();
340340

341341
let pattern = match &options.pattern {
342342
PatternKind::Brownfield => quote!(#root::Pattern::Brownfield),
@@ -490,14 +490,15 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult<TokenStream> {
490490
};
491491

492492
let context = quote!({
493+
#maybe_embed_plist_block
494+
493495
#[allow(unused_mut, clippy::let_and_return)]
494496
let mut context = #root::Context::new(
495497
#config,
496498
::std::boxed::Box::new(#assets),
497499
#default_window_icon,
498500
#app_icon,
499501
#package_info,
500-
#info_plist,
501502
#pattern,
502503
#runtime_authority,
503504
#plugin_global_api_script

crates/tauri-utils/src/platform.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44

55
//! Platform helper functions.
66
7-
use std::{
8-
fmt::Display,
9-
path::{Path, PathBuf, MAIN_SEPARATOR},
10-
};
7+
use std::{fmt::Display, path::PathBuf};
118

129
use serde::{Deserialize, Serialize};
1310

1411
use crate::{Env, PackageInfo};
1512

1613
mod starting_binary;
1714

15+
/// URI prefix of a Tauri asset.
16+
///
17+
/// This is referenced in the Tauri Android library,
18+
/// which resolves these assets to a file descriptor.
1819
#[cfg(target_os = "android")]
1920
pub const ANDROID_ASSET_PROTOCOL_URI_PREFIX: &str = "asset://localhost/";
2021

@@ -225,16 +226,16 @@ pub fn target_triple() -> crate::Result<String> {
225226
Ok(format!("{arch}-{os}"))
226227
}
227228

228-
#[cfg(not(test))]
229-
fn is_cargo_output_directory(path: &Path) -> bool {
229+
#[cfg(all(not(test), not(target_os = "android")))]
230+
fn is_cargo_output_directory(path: &std::path::Path) -> bool {
230231
path.join(".cargo-lock").exists()
231232
}
232233

233234
#[cfg(test)]
234235
const CARGO_OUTPUT_DIRECTORIES: &[&str] = &["debug", "release", "custom-profile"];
235236

236237
#[cfg(test)]
237-
fn is_cargo_output_directory(path: &Path) -> bool {
238+
fn is_cargo_output_directory(path: &std::path::Path) -> bool {
238239
let last_component = path
239240
.components()
240241
.last()
@@ -265,21 +266,30 @@ fn is_cargo_output_directory(path: &Path) -> bool {
265266
/// Android uses a special URI prefix that is resolved by the Tauri file system plugin `asset://localhost/`
266267
pub fn resource_dir(package_info: &PackageInfo, env: &Env) -> crate::Result<PathBuf> {
267268
#[cfg(target_os = "android")]
268-
return Ok(PathBuf::from(ANDROID_ASSET_PROTOCOL_URI_PREFIX));
269-
let exe = current_exe()?;
270-
resource_dir_from(exe, package_info, env)
269+
return resource_dir_android(package_info, env);
270+
#[cfg(not(target_os = "android"))]
271+
{
272+
let exe = current_exe()?;
273+
resource_dir_from(exe, package_info, env)
274+
}
275+
}
276+
277+
#[cfg(target_os = "android")]
278+
fn resource_dir_android(_package_info: &PackageInfo, _env: &Env) -> crate::Result<PathBuf> {
279+
Ok(PathBuf::from(ANDROID_ASSET_PROTOCOL_URI_PREFIX))
271280
}
272281

282+
#[cfg(not(target_os = "android"))]
273283
#[allow(unused_variables)]
274-
fn resource_dir_from<P: AsRef<Path>>(
284+
fn resource_dir_from<P: AsRef<std::path::Path>>(
275285
exe: P,
276286
package_info: &PackageInfo,
277287
env: &Env,
278288
) -> crate::Result<PathBuf> {
279289
let exe_dir = exe.as_ref().parent().expect("failed to get exe directory");
280290
let curr_dir = exe_dir.display().to_string();
281291

282-
let parts: Vec<&str> = curr_dir.split(MAIN_SEPARATOR).collect();
292+
let parts: Vec<&str> = curr_dir.split(std::path::MAIN_SEPARATOR).collect();
283293
let len = parts.len();
284294

285295
// Check if running from the Cargo output directory, which means it's an executable in a development machine

crates/tauri/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ pub struct Context<R: Runtime> {
388388
#[cfg(all(desktop, feature = "tray-icon"))]
389389
pub(crate) tray_icon: Option<image::Image<'static>>,
390390
pub(crate) package_info: PackageInfo,
391-
pub(crate) _info_plist: (),
392391
pub(crate) pattern: Pattern,
393392
pub(crate) runtime_authority: RuntimeAuthority,
394393
pub(crate) plugin_global_api_scripts: Option<&'static [&'static str]>,
@@ -502,7 +501,6 @@ impl<R: Runtime> Context<R> {
502501
default_window_icon: Option<image::Image<'static>>,
503502
app_icon: Option<Vec<u8>>,
504503
package_info: PackageInfo,
505-
info_plist: (),
506504
pattern: Pattern,
507505
runtime_authority: RuntimeAuthority,
508506
plugin_global_api_scripts: Option<&'static [&'static str]>,
@@ -517,7 +515,6 @@ impl<R: Runtime> Context<R> {
517515
#[cfg(all(desktop, feature = "tray-icon"))]
518516
tray_icon: None,
519517
package_info,
520-
_info_plist: info_plist,
521518
pattern,
522519
runtime_authority,
523520
plugin_global_api_scripts,

crates/tauri/src/test/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ pub fn mock_context<R: Runtime, A: Assets<R>>(assets: A) -> crate::Context<R> {
131131
description: "Tauri test",
132132
crate_name: "test",
133133
},
134-
_info_plist: (),
135134
pattern: Pattern::Brownfield,
136135
runtime_authority: RuntimeAuthority::new(Default::default(), Resolved::default()),
137136
plugin_global_api_scripts: None,

crates/tauri/src/webview/webview_window.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -505,20 +505,6 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
505505
self
506506
}
507507

508-
/// Whether the window should be transparent. If this is true, writing colors
509-
/// with alpha values different than `1.0` will produce a transparent window.
510-
#[cfg(any(not(target_os = "macos"), feature = "macos-private-api"))]
511-
#[cfg_attr(
512-
docsrs,
513-
doc(cfg(any(not(target_os = "macos"), feature = "macos-private-api")))
514-
)]
515-
#[must_use]
516-
pub fn transparent(mut self, transparent: bool) -> Self {
517-
self.window_builder = self.window_builder.transparent(transparent);
518-
self.webview_builder = self.webview_builder.transparent(transparent);
519-
self
520-
}
521-
522508
/// Whether the window should have borders and bars.
523509
#[must_use]
524510
pub fn decorations(mut self, decorations: bool) -> Self {
@@ -859,6 +845,23 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
859845
self
860846
}
861847

848+
/// Whether the window should be transparent. If this is true, writing colors
849+
/// with alpha values different than `1.0` will produce a transparent window.
850+
#[cfg(any(not(target_os = "macos"), feature = "macos-private-api"))]
851+
#[cfg_attr(
852+
docsrs,
853+
doc(cfg(any(not(target_os = "macos"), feature = "macos-private-api")))
854+
)]
855+
#[must_use]
856+
pub fn transparent(mut self, transparent: bool) -> Self {
857+
#[cfg(desktop)]
858+
{
859+
self.window_builder = self.window_builder.transparent(transparent);
860+
}
861+
self.webview_builder = self.webview_builder.transparent(transparent);
862+
self
863+
}
864+
862865
/// Whether page zooming by hotkeys is enabled
863866
///
864867
/// ## Platform-specific:

examples/file-associations/src-tauri/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn handle_file_associations(app: AppHandle, files: Vec<PathBuf>) {
4949

5050
fn main() {
5151
tauri::Builder::default()
52-
.setup(|app| {
52+
.setup(|#[allow(unused_variables)] app| {
5353
#[cfg(any(windows, target_os = "linux"))]
5454
{
5555
let mut files = Vec::new();

0 commit comments

Comments
 (0)