Skip to content

Commit

Permalink
Fix rustdoc generation of Windows and Mac on docs.rs, fix #503 (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ngo Iok Ui (Wu Yu Wei) authored Feb 27, 2022
1 parent 85fc22c commit 327a019
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

Fix rustdoc generation of Windows and Mac on docs.rs.
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ documentation = "https://docs.rs/wry"
categories = [ "gui" ]

[package.metadata.docs.rs]
features = [ "dox" ]
default-target = "x86_64-unknown-linux-gnu"
default-features = false
features = [ "dox", "file-drop", "protocol" ]
targets = [
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-msvc",
"x86_64-apple-darwin"
]

[features]
default = [ "file-drop", "protocol" ]
default = [ "file-drop", "objc-exception", "protocol" ]
objc-exception = [ "objc/exception" ]
file-drop = [ ]
protocol = [ ]
dox = [ "tao/dox" ]
Expand Down Expand Up @@ -59,7 +60,6 @@ gdk = "0.15"
[target."cfg(target_os = \"windows\")".dependencies]
webview2-com = "0.13.0"
windows_macros = "0.30.0"
sys-info = "0.9"

[target."cfg(target_os = \"windows\")".dependencies.windows]
version = "0.30.0"
Expand All @@ -69,6 +69,7 @@ sys-info = "0.9"
"Win32_Graphics_Gdi",
"Win32_System_Com",
"Win32_System_Com_StructuredStorage",
"Win32_System_SystemInformation",
"Win32_System_Ole",
"Win32_System_SystemServices",
"Win32_UI_Shell",
Expand All @@ -78,5 +79,5 @@ sys-info = "0.9"
[target."cfg(any(target_os = \"ios\", target_os = \"macos\"))".dependencies]
cocoa = "0.24"
core-graphics = "0.22"
objc = { version = "0.2", features = [ "exception" ] }
objc = "0.2"
objc_id = "0.1"
60 changes: 56 additions & 4 deletions src/webview/webview2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ use once_cell::unsync::OnceCell;
use windows::{
core::Interface,
Win32::{
Foundation::{BOOL, E_FAIL, E_POINTER, HWND, POINT, PWSTR, RECT},
Foundation::{BOOL, E_FAIL, E_POINTER, FARPROC, HWND, POINT, PWSTR, RECT},
System::{
Com::{IStream, StructuredStorage::CreateStreamOnHGlobal},
LibraryLoader::{GetProcAddress, LoadLibraryA},
SystemInformation::OSVERSIONINFOW,
WinRT::EventRegistrationToken,
},
UI::WindowsAndMessaging::{
Expand Down Expand Up @@ -591,7 +593,57 @@ pub fn platform_webview_version() -> Result<String> {
}

fn is_windows_7() -> bool {
sys_info::os_release()
.map(|release| release.starts_with("6.1"))
.unwrap_or_default()
if let Some(v) = get_windows_ver() {
// windows 7 is 6.1
if v.0 == 6 && v.1 == 1 {
return true;
}
}
false
}

fn get_function_impl(library: &str, function: &str) -> Option<FARPROC> {
assert_eq!(library.chars().last(), Some('\0'));
assert_eq!(function.chars().last(), Some('\0'));

let module = unsafe { LoadLibraryA(library) };
if module.0 == 0 {
return None;
}
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::<windows::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
}
}

0 comments on commit 327a019

Please sign in to comment.