From 41fdd906ddd89ae62787fbba48362792e50fce2b Mon Sep 17 00:00:00 2001 From: keiko233 Date: Tue, 19 Mar 2024 21:36:28 +0800 Subject: [PATCH] fix: slinet start get_window err https://github.com/LibNyanpasu/clash-nyanpasu/issues/639 --- backend/tauri/src/main.rs | 20 -------------------- backend/tauri/src/utils/resolve.rs | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/backend/tauri/src/main.rs b/backend/tauri/src/main.rs index 14c281f572..5a0ddc87d3 100644 --- a/backend/tauri/src/main.rs +++ b/backend/tauri/src/main.rs @@ -18,11 +18,6 @@ use crate::{ use anyhow::Context; use tauri::{api, Manager, SystemTray}; -#[cfg(target_os = "windows")] -use webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2Settings6; -#[cfg(target_os = "windows")] -use windows::core::Interface; - rust_i18n::i18n!("../../locales"); #[cfg(feature = "deadlock-detection")] @@ -135,21 +130,6 @@ fn main() -> std::io::Result<()> { handle.emit_all("scheme-request-received", request).unwrap(); } )); - let window = app.get_window("main").unwrap(); - #[cfg(target_os = "windows")] - window - .with_webview(|webview| unsafe { - let settings = webview - .controller() - .CoreWebView2() - .unwrap() - .Settings() - .unwrap(); - let settings: ICoreWebView2Settings6 = - settings.cast::().unwrap(); - settings.SetIsSwipeNavigationEnabled(false).unwrap(); - }) - .unwrap(); Ok(()) }) .on_system_tray_event(core::tray::Tray::on_system_tray_event) diff --git a/backend/tauri/src/utils/resolve.rs b/backend/tauri/src/utils/resolve.rs index 08cd2417e9..f2cd79f4b5 100644 --- a/backend/tauri/src/utils/resolve.rs +++ b/backend/tauri/src/utils/resolve.rs @@ -17,6 +17,11 @@ use serde_yaml::Mapping; use std::net::TcpListener; use tauri::{api::process::Command, App, AppHandle, Manager, PhysicalPosition, PhysicalSize}; +#[cfg(target_os = "windows")] +use webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2Settings6; +#[cfg(target_os = "windows")] +use windows::core::Interface; + pub fn find_unused_port() -> Result { match TcpListener::bind("127.0.0.1:0") { Ok(listener) => { @@ -263,6 +268,23 @@ pub fn create_window(app_handle: &AppHandle) { #[cfg(target_os = "linux")] crate::log_err!(builder.decorations(true).transparent(false).build()); + + #[cfg(target_os = "windows")] + app_handle + .get_window("main") + .unwrap() + .with_webview(|webview| unsafe { + let settings = webview + .controller() + .CoreWebView2() + .unwrap() + .Settings() + .unwrap(); + let settings: ICoreWebView2Settings6 = + settings.cast::().unwrap(); + settings.SetIsSwipeNavigationEnabled(false).unwrap(); + }) + .unwrap(); } /// close main window