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
This commit is contained in:
Tony
2025-08-09 08:19:03 +08:00
committed by GitHub
parent 390cb9c36a
commit c134a769ea
6 changed files with 46 additions and 66 deletions

View File

@@ -2563,7 +2563,9 @@ impl<T: UserEvent> RuntimeHandle<T> for WryHandle<T> {
send_user_message(&self.context, Message::Task(Box::new(f)))
}
fn display_handle(&self) -> std::result::Result<DisplayHandle, raw_window_handle::HandleError> {
fn display_handle(
&self,
) -> std::result::Result<DisplayHandle<'_>, raw_window_handle::HandleError> {
self.context.main_thread.window_target.display_handle()
}

View File

@@ -297,7 +297,9 @@ pub trait RuntimeHandle<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'st
fn run_on_main_thread<F: FnOnce() + Send + 'static>(&self, f: F) -> Result<()>;
/// Get a handle to the display controller of the windowing system.
fn display_handle(&self) -> std::result::Result<DisplayHandle, raw_window_handle::HandleError>;
fn display_handle(
&self,
) -> std::result::Result<DisplayHandle<'_>, raw_window_handle::HandleError>;
/// Returns the primary monitor of the system.
///

View File

@@ -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<str> for WebviewLabel {
fn as_ref(&self) -> &str {
&self.0
}
}
impl<'de> Deserialize<'de> for WebviewLabel {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
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<R: Runtime>(
webview: Webview<R>,

View File

@@ -55,6 +55,7 @@ pub struct Channel<TSend = InvokeResponseBody> {
const _: () = {
#[derive(specta::Type)]
#[specta(remote = super::Channel, rename = "TAURI_CHANNEL")]
#[allow(dead_code)]
struct Channel<TSend>(std::marker::PhantomData<TSend>);
};

View File

@@ -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

View File

@@ -1351,48 +1351,46 @@ impl<R: Runtime> Webview<R> {
```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 <https://docs.rs/webkit2gtk/2.0.0/webkit2gtk/struct.WebView.html>
// and <https://docs.rs/webkit2gtk/2.0.0/webkit2gtk/trait.WebViewExt.html>
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 <https://docs.rs/webkit2gtk/2.0.0/webkit2gtk/struct.WebView.html>
// and <https://docs.rs/webkit2gtk/2.0.0/webkit2gtk/trait.WebViewExt.html>
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(())
});
```
"####
)]