Skip to content

Commit

Permalink
feat: migrate manual implementation to the light windows-version cr…
Browse files Browse the repository at this point in the history
…ate (#847)
  • Loading branch information
amrbashir authored Nov 17, 2023
1 parent 7486f70 commit 69317ca
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ parking_lot = "0.12"
unicode-segmentation = "1.10"
image = { version = "0.24", default-features = false }
windows-implement = "0.52"
windows-version = "0.1"

[target."cfg(target_os = \"windows\")".dependencies.windows]
version = "0.52"
Expand Down
26 changes: 4 additions & 22 deletions src/platform_impl/windows/dark_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use windows::{
core::{s, w, PCSTR, PCWSTR, PSTR},
Win32::{
Foundation::{BOOL, HANDLE, HMODULE, HWND},
System::{LibraryLoader::*, SystemInformation::OSVERSIONINFOW},
System::LibraryLoader::*,
UI::{Accessibility::*, Controls::SetWindowTheme, WindowsAndMessaging::*},
},
};
Expand All @@ -23,27 +23,9 @@ static HUXTHEME: Lazy<HMODULE> =
Lazy::new(|| unsafe { LoadLibraryA(s!("uxtheme.dll")).unwrap_or_default() });

static WIN10_BUILD_VERSION: Lazy<Option<u32>> = Lazy::new(|| {
type RtlGetVersion = unsafe extern "system" fn(*mut OSVERSIONINFOW) -> i32;

let handle = get_function!("ntdll.dll", RtlGetVersion);

let mut vi = OSVERSIONINFOW {
dwOSVersionInfoSize: 0,
dwMajorVersion: 0,
dwMinorVersion: 0,
dwBuildNumber: 0,
dwPlatformId: 0,
szCSDVersion: [0; 128],
};

if let Some(rtl_get_version) = handle {
let status = unsafe { (rtl_get_version)(&mut vi as _) };

if status >= 0 && vi.dwMajorVersion == 10 && vi.dwMinorVersion == 0 {
Some(vi.dwBuildNumber)
} else {
None
}
let version = windows_version::OsVersion::current();
if version.major == 10 && version.minor == 0 {
Some(version.build)
} else {
None
}
Expand Down

0 comments on commit 69317ca

Please sign in to comment.