Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rustdoc generation of Windows and Mac on docs.rs, fix #503 #507

Merged
merged 8 commits into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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 +68,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 +78,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"
wusyong marked this conversation as resolved.
Show resolved Hide resolved
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
}
}