diff --git a/.changes/tauri-utils-windows-version.md b/.changes/tauri-utils-windows-version.md new file mode 100644 index 000000000..ba7972c3b --- /dev/null +++ b/.changes/tauri-utils-windows-version.md @@ -0,0 +1,5 @@ +--- +'tauri-utils': 'minor:breaking' +--- + +Changed `platform::windows_version` to return a `(u32, u32, u32)` instead of `Option<(u32, u32, u32)>` diff --git a/core/tauri-utils/Cargo.toml b/core/tauri-utils/Cargo.toml index 010a183c7..0afb7d66e 100644 --- a/core/tauri-utils/Cargo.toml +++ b/core/tauri-utils/Cargo.toml @@ -43,15 +43,8 @@ log = "0.4.20" [target."cfg(target_os = \"linux\")".dependencies] heck = "0.4" -[target."cfg(windows)".dependencies.windows] -version = "0.51.1" -features = [ - "implement", - "Win32_Foundation", - "Win32_System_Com", - "Win32_System_LibraryLoader", - "Win32_System_SystemInformation" -] +[target."cfg(windows)".dependencies] +windows-version = "0.1" [features] build = [ "proc-macro2", "quote" ] diff --git a/core/tauri-utils/src/platform.rs b/core/tauri-utils/src/platform.rs index 248c5aa66..8a77aff0a 100644 --- a/core/tauri-utils/src/platform.rs +++ b/core/tauri-utils/src/platform.rs @@ -257,85 +257,19 @@ pub fn resource_dir(package_info: &PackageInfo, env: &Env) -> crate::Result bool { - if let Some(v) = windows_version() { - // windows 7 is 6.1 - if v.0 == 6 && v.1 == 1 { - return true; - } - } - false - } - - fn encode_wide(string: impl AsRef) -> Vec { - string.as_ref().encode_wide().chain(once(0)).collect() - } - - /// Helper function to dynamically load function pointer. - /// `library` and `function` must be null-terminated. - pub fn get_function_impl(library: &str, function: &str) -> Option { - let library = encode_wide(library); - assert_eq!(function.chars().last(), Some('\0')); - let function = PCSTR::from_raw(function.as_ptr()); - - // Library names we will use are ASCII so we can use the A version to avoid string conversion. - let module = unsafe { LoadLibraryW(PCWSTR::from_raw(library.as_ptr())) }.unwrap_or_default(); - if module.is_invalid() { - None - } else { - Some(unsafe { GetProcAddress(module, function) }) - } - } - - macro_rules! get_function { - ($lib:expr, $func:ident) => { - get_function_impl(concat!($lib, '\0'), concat!(stringify!($func), '\0')) - .map(|f| unsafe { std::mem::transmute::(f) }) - }; + let v = windows_version(); + v.0 == 6 && v.1 == 1 } /// Returns a tuple of (major, minor, buildnumber) for the Windows version. - pub fn windows_version() -> 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 windows_version() -> (u32, u32, u32) { + let v = windows_version::OsVersion::current(); + (v.major, v.minor, v.build) } } diff --git a/core/tauri/src/vibrancy/windows.rs b/core/tauri/src/vibrancy/windows.rs index e6133b543..b42e12cc0 100644 --- a/core/tauri/src/vibrancy/windows.rs +++ b/core/tauri/src/vibrancy/windows.rs @@ -12,7 +12,7 @@ use std::ffi::c_void; use crate::utils::config::WindowEffectsConfig; use crate::window::{Color, Effect}; use raw_window_handle::HasRawWindowHandle; -use tauri_utils::platform::{get_function_impl, is_windows_7, windows_version}; +use tauri_utils::platform::{is_windows_7, windows_version}; use windows::Win32::Foundation::HWND; pub fn apply_effects(window: impl HasRawWindowHandle, effects: WindowEffectsConfig) {