mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-01-31 00:35:19 +01:00
fix(core): clippy warnings, simplify embed_plist usage (#10844)
* fix(core): clippy warnings * fix test * chore: simplify example
This commit is contained in:
committed by
GitHub
parent
9c9644d155
commit
27d0183431
6
.changes/embed-plist-no-unit-val.md
Normal file
6
.changes/embed-plist-no-unit-val.md
Normal file
@@ -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.
|
||||
@@ -302,7 +302,7 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult<TokenStream> {
|
||||
};
|
||||
|
||||
#[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<TokenStream> {
|
||||
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<TokenStream> {
|
||||
};
|
||||
|
||||
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<TokenStream> {
|
||||
#default_window_icon,
|
||||
#app_icon,
|
||||
#package_info,
|
||||
#info_plist,
|
||||
#pattern,
|
||||
#runtime_authority,
|
||||
#plugin_global_api_script
|
||||
|
||||
@@ -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<String> {
|
||||
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<PathBuf> {
|
||||
#[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<PathBuf> {
|
||||
Ok(PathBuf::from(ANDROID_ASSET_PROTOCOL_URI_PREFIX))
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
#[allow(unused_variables)]
|
||||
fn resource_dir_from<P: AsRef<Path>>(
|
||||
fn resource_dir_from<P: AsRef<std::path::Path>>(
|
||||
exe: P,
|
||||
package_info: &PackageInfo,
|
||||
env: &Env,
|
||||
@@ -279,7 +289,7 @@ fn resource_dir_from<P: AsRef<Path>>(
|
||||
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
|
||||
|
||||
@@ -388,7 +388,6 @@ pub struct Context<R: Runtime> {
|
||||
#[cfg(all(desktop, feature = "tray-icon"))]
|
||||
pub(crate) tray_icon: Option<image::Image<'static>>,
|
||||
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<R: Runtime> Context<R> {
|
||||
default_window_icon: Option<image::Image<'static>>,
|
||||
app_icon: Option<Vec<u8>>,
|
||||
package_info: PackageInfo,
|
||||
info_plist: (),
|
||||
pattern: Pattern,
|
||||
runtime_authority: RuntimeAuthority,
|
||||
plugin_global_api_scripts: Option<&'static [&'static str]>,
|
||||
@@ -517,7 +515,6 @@ impl<R: Runtime> Context<R> {
|
||||
#[cfg(all(desktop, feature = "tray-icon"))]
|
||||
tray_icon: None,
|
||||
package_info,
|
||||
_info_plist: info_plist,
|
||||
pattern,
|
||||
runtime_authority,
|
||||
plugin_global_api_scripts,
|
||||
|
||||
@@ -131,7 +131,6 @@ pub fn mock_context<R: Runtime, A: Assets<R>>(assets: A) -> crate::Context<R> {
|
||||
description: "Tauri test",
|
||||
crate_name: "test",
|
||||
},
|
||||
_info_plist: (),
|
||||
pattern: Pattern::Brownfield,
|
||||
runtime_authority: RuntimeAuthority::new(Default::default(), Resolved::default()),
|
||||
plugin_global_api_scripts: None,
|
||||
|
||||
@@ -505,20 +505,6 @@ impl<'a, R: Runtime, M: Manager<R>> 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<R>> 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:
|
||||
|
||||
@@ -49,7 +49,7 @@ fn handle_file_associations(app: AppHandle, files: Vec<PathBuf>) {
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.setup(|app| {
|
||||
.setup(|#[allow(unused_variables)] app| {
|
||||
#[cfg(any(windows, target_os = "linux"))]
|
||||
{
|
||||
let mut files = Vec::new();
|
||||
|
||||
Reference in New Issue
Block a user