diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index d8d859a..1b017fb 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -528,6 +528,7 @@ dependencies = [ "which 4.2.5", "window-shadows", "window-vibrancy", + "windows-sys", "winreg", ] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index efbb726..0d51821 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -40,6 +40,7 @@ port_scanner = "0.1.5" [target.'cfg(windows)'.dependencies] runas = "0.2.1" deelevate = "0.2.0" +windows-sys = "0.36" winreg = { version = "0.10", features = ["transactions"] } [features] diff --git a/src-tauri/src/utils/mod.rs b/src-tauri/src/utils/mod.rs index 2ff1709..f1af3a3 100644 --- a/src-tauri/src/utils/mod.rs +++ b/src-tauri/src/utils/mod.rs @@ -6,3 +6,4 @@ pub mod resolve; pub mod server; pub mod sysopt; pub mod tmpl; +mod winhelp; diff --git a/src-tauri/src/utils/resolve.rs b/src-tauri/src/utils/resolve.rs index ccbf639..cf5e617 100644 --- a/src-tauri/src/utils/resolve.rs +++ b/src-tauri/src/utils/resolve.rs @@ -35,12 +35,18 @@ fn resolve_window(app: &App) { #[cfg(target_os = "windows")] { + use crate::utils::winhelp; use window_shadows::set_shadow; use window_vibrancy::apply_blur; let _ = window.set_decorations(false); let _ = set_shadow(&window, true); - let _ = apply_blur(&window, None); + + // todo + // win11 disable this feature temporarily due to lag + if !winhelp::is_win11() { + let _ = apply_blur(&window, None); + } } #[cfg(target_os = "macos")] diff --git a/src-tauri/src/utils/winhelp.rs b/src-tauri/src/utils/winhelp.rs new file mode 100644 index 0000000..8abd7b5 --- /dev/null +++ b/src-tauri/src/utils/winhelp.rs @@ -0,0 +1,69 @@ +#![cfg(target_os = "windows")] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +//! +//! From https://github.com/tauri-apps/window-vibrancy/blob/dev/src/windows.rs +//! + +use windows_sys::Win32::{ + Foundation::*, + System::{LibraryLoader::*, SystemInformation::*}, +}; + +fn get_function_impl(library: &str, function: &str) -> Option { + assert_eq!(library.chars().last(), Some('\0')); + assert_eq!(function.chars().last(), Some('\0')); + + let module = unsafe { LoadLibraryA(library.as_ptr()) }; + if module == 0 { + return None; + } + Some(unsafe { GetProcAddress(module, function.as_ptr()) }) +} + +macro_rules! get_function { + ($lib:expr, $func:ident) => { + get_function_impl(concat!($lib, '\0'), concat!(stringify!($func), '\0')).map(|f| unsafe { + std::mem::transmute::<::windows_sys::Win32::Foundation::FARPROC, $func>(f) + }) + }; +} + +/// Returns a tuple of (major, minor, buildnumber) +fn get_windows_ver() -> Option<(u32, u32, u32)> { + type RtlGetVersion = unsafe extern "system" fn(*mut OSVERSIONINFOW) -> i32; + let handle = get_function!("ntdll.dll", RtlGetVersion); + if let Some(rtl_get_version) = handle { + unsafe { + let mut vi = OSVERSIONINFOW { + dwOSVersionInfoSize: 0, + dwMajorVersion: 0, + dwMinorVersion: 0, + dwBuildNumber: 0, + dwPlatformId: 0, + szCSDVersion: [0; 128], + }; + + let status = (rtl_get_version)(&mut vi as _); + + if status >= 0 { + Some((vi.dwMajorVersion, vi.dwMinorVersion, vi.dwBuildNumber)) + } else { + None + } + } + } else { + None + } +} + +pub fn is_win11() -> bool { + let v = get_windows_ver().unwrap_or_default(); + v.2 >= 22000 +} + +#[test] +fn test_version() { + dbg!(get_windows_ver().unwrap_or_default()); +}