From c134a769eabb63d94866c773d99444203ef452d9 Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Sat, 9 Aug 2025 08:19:03 +0800 Subject: [PATCH] chore: fix some warnings on new rust version (#13965) * chore: fix some warnings on new rust version * No main * allow dead code on specta Channel --- crates/tauri-runtime-wry/src/lib.rs | 4 +- crates/tauri-runtime/src/lib.rs | 4 +- crates/tauri/src/event/plugin.rs | 26 ---------- crates/tauri/src/ipc/channel.rs | 1 + crates/tauri/src/pattern.rs | 3 ++ crates/tauri/src/webview/mod.rs | 74 ++++++++++++++--------------- 6 files changed, 46 insertions(+), 66 deletions(-) diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index af7ddf5e7..2041102e0 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -2563,7 +2563,9 @@ impl RuntimeHandle for WryHandle { send_user_message(&self.context, Message::Task(Box::new(f))) } - fn display_handle(&self) -> std::result::Result { + fn display_handle( + &self, + ) -> std::result::Result, raw_window_handle::HandleError> { self.context.main_thread.window_target.display_handle() } diff --git a/crates/tauri-runtime/src/lib.rs b/crates/tauri-runtime/src/lib.rs index a6da26160..b3403c091 100644 --- a/crates/tauri-runtime/src/lib.rs +++ b/crates/tauri-runtime/src/lib.rs @@ -297,7 +297,9 @@ pub trait RuntimeHandle: Debug + Clone + Send + Sync + Sized + 'st fn run_on_main_thread(&self, f: F) -> Result<()>; /// Get a handle to the display controller of the windowing system. - fn display_handle(&self) -> std::result::Result; + fn display_handle( + &self, + ) -> std::result::Result, raw_window_handle::HandleError>; /// Returns the primary monitor of the system. /// diff --git a/crates/tauri/src/event/plugin.rs b/crates/tauri/src/event/plugin.rs index 008cd6800..fcdcddd66 100644 --- a/crates/tauri/src/event/plugin.rs +++ b/crates/tauri/src/event/plugin.rs @@ -1,10 +1,8 @@ // Copyright 2019-2024 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -use serde::{Deserialize, Deserializer}; use serde_json::Value as JsonValue; use serialize_to_javascript::{default_template, DefaultTemplate, Template}; -use tauri_runtime::window::is_label_valid; use crate::plugin::{Builder, TauriPlugin}; use crate::{command, ipc::CallbackFn, EventId, Result, Runtime}; @@ -13,30 +11,6 @@ use crate::{AppHandle, Emitter, Manager, Webview}; use super::EventName; use super::EventTarget; -pub struct WebviewLabel(String); - -impl AsRef for WebviewLabel { - fn as_ref(&self) -> &str { - &self.0 - } -} - -impl<'de> Deserialize<'de> for WebviewLabel { - fn deserialize(deserializer: D) -> std::result::Result - where - D: Deserializer<'de>, - { - let event_id = String::deserialize(deserializer)?; - if is_label_valid(&event_id) { - Ok(WebviewLabel(event_id)) - } else { - Err(serde::de::Error::custom( - "Webview label must include only alphanumeric characters, `-`, `/`, `:` and `_`.", - )) - } - } -} - #[command(root = "crate")] async fn listen( webview: Webview, diff --git a/crates/tauri/src/ipc/channel.rs b/crates/tauri/src/ipc/channel.rs index 558225979..c33caf2a2 100644 --- a/crates/tauri/src/ipc/channel.rs +++ b/crates/tauri/src/ipc/channel.rs @@ -55,6 +55,7 @@ pub struct Channel { const _: () = { #[derive(specta::Type)] #[specta(remote = super::Channel, rename = "TAURI_CHANNEL")] + #[allow(dead_code)] struct Channel(std::marker::PhantomData); }; diff --git a/crates/tauri/src/pattern.rs b/crates/tauri/src/pattern.rs index 20b18e759..5048e86e0 100644 --- a/crates/tauri/src/pattern.rs +++ b/crates/tauri/src/pattern.rs @@ -9,6 +9,7 @@ use serde::Serialize; use serialize_to_javascript::{default_template, Template}; /// The domain of the isolation iframe source. +#[cfg(feature = "isolation")] pub const ISOLATION_IFRAME_SRC_DOMAIN: &str = "localhost"; /// An application pattern. @@ -62,6 +63,7 @@ impl From<&Pattern> for PatternObject { } /// Where the JavaScript is injected to +#[cfg(feature = "isolation")] #[derive(Debug, Serialize)] #[serde(rename_all = "lowercase")] pub(crate) enum IsolationSide { @@ -72,6 +74,7 @@ pub(crate) enum IsolationSide { Secure, } +#[cfg(feature = "isolation")] impl Default for IsolationSide { fn default() -> Self { Self::Original diff --git a/crates/tauri/src/webview/mod.rs b/crates/tauri/src/webview/mod.rs index a8e29d7ce..4f7a17a0e 100644 --- a/crates/tauri/src/webview/mod.rs +++ b/crates/tauri/src/webview/mod.rs @@ -1351,48 +1351,46 @@ impl Webview { ```rust,no_run use tauri::Manager; -fn main() { - tauri::Builder::default() - .setup(|app| { - let main_webview = app.get_webview("main").unwrap(); - main_webview.with_webview(|webview| { - #[cfg(target_os = "linux")] - { - // see - // and - use webkit2gtk::WebViewExt; - webview.inner().set_zoom_level(4.); - } +tauri::Builder::default() + .setup(|app| { + let main_webview = app.get_webview("main").unwrap(); + main_webview.with_webview(|webview| { + #[cfg(target_os = "linux")] + { + // see + // and + use webkit2gtk::WebViewExt; + webview.inner().set_zoom_level(4.); + } - #[cfg(windows)] - unsafe { - // see https://docs.rs/webview2-com/0.19.1/webview2_com/Microsoft/Web/WebView2/Win32/struct.ICoreWebView2Controller.html - webview.controller().SetZoomFactor(4.).unwrap(); - } + #[cfg(windows)] + unsafe { + // see https://docs.rs/webview2-com/0.19.1/webview2_com/Microsoft/Web/WebView2/Win32/struct.ICoreWebView2Controller.html + webview.controller().SetZoomFactor(4.).unwrap(); + } - #[cfg(target_os = "macos")] - unsafe { - let view: &objc2_web_kit::WKWebView = &*webview.inner().cast(); - let controller: &objc2_web_kit::WKUserContentController = &*webview.controller().cast(); - let window: &objc2_app_kit::NSWindow = &*webview.ns_window().cast(); + #[cfg(target_os = "macos")] + unsafe { + let view: &objc2_web_kit::WKWebView = &*webview.inner().cast(); + let controller: &objc2_web_kit::WKUserContentController = &*webview.controller().cast(); + let window: &objc2_app_kit::NSWindow = &*webview.ns_window().cast(); - view.setPageZoom(4.); - controller.removeAllUserScripts(); - let bg_color = objc2_app_kit::NSColor::colorWithDeviceRed_green_blue_alpha(0.5, 0.2, 0.4, 1.); - window.setBackgroundColor(Some(&bg_color)); - } + view.setPageZoom(4.); + controller.removeAllUserScripts(); + let bg_color = objc2_app_kit::NSColor::colorWithDeviceRed_green_blue_alpha(0.5, 0.2, 0.4, 1.); + window.setBackgroundColor(Some(&bg_color)); + } - #[cfg(target_os = "android")] - { - use jni::objects::JValue; - webview.jni_handle().exec(|env, _, webview| { - env.call_method(webview, "zoomBy", "(F)V", &[JValue::Float(4.)]).unwrap(); - }) - } - }); - Ok(()) - }); -} + #[cfg(target_os = "android")] + { + use jni::objects::JValue; + webview.jni_handle().exec(|env, _, webview| { + env.call_method(webview, "zoomBy", "(F)V", &[JValue::Float(4.)]).unwrap(); + }) + } + }); + Ok(()) +}); ``` "#### )]