Files
core-cooldown/src-tauri/src/main.rs
T
Your Name 4f4599c4c9 Fix WebView2 detection - use loader API instead of registry
Registry check gave false negatives on systems where WebView2
is installed through Edge rather than EdgeUpdate. Now calls
GetAvailableCoreWebView2BrowserVersionString (statically linked)
which detects all installation methods.
2026-02-07 10:51:49 +02:00

68 lines
2.2 KiB
Rust

// Prevents additional console window on Windows in release
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
#[cfg(windows)]
if !webview2_check::is_webview2_installed() {
webview2_check::show_missing_dialog();
return;
}
core_cooldown_lib::run()
}
#[cfg(windows)]
mod webview2_check {
use std::ptr;
use winapi::um::winuser::{MessageBoxW, MB_OK, MB_ICONWARNING};
use winapi::um::shellapi::ShellExecuteW;
// Statically linked from WebView2LoaderStatic.lib via msvc_compat shims
extern "system" {
fn GetAvailableCoreWebView2BrowserVersionString(
browser_executable_folder: *const u16,
version_info: *mut *mut u16,
) -> i32;
}
extern "system" {
fn CoTaskMemFree(pv: *mut std::ffi::c_void);
}
fn to_wide(s: &str) -> Vec<u16> {
s.encode_utf16().chain(std::iter::once(0)).collect()
}
pub fn is_webview2_installed() -> bool {
unsafe {
let mut version_info: *mut u16 = ptr::null_mut();
let hr = GetAvailableCoreWebView2BrowserVersionString(
ptr::null(),
&mut version_info,
);
let installed = hr == 0 && !version_info.is_null();
if !version_info.is_null() {
CoTaskMemFree(version_info as *mut _);
}
installed
}
}
pub fn show_missing_dialog() {
let title = to_wide("Core Cooldown - WebView2 Required");
let message = to_wide(
"Microsoft WebView2 Runtime is required to run Core Cooldown, \
but it was not found on this system.\n\n\
Click OK to open the download page in your browser.\n\n\
After installing WebView2, restart Core Cooldown."
);
let url = to_wide("https://developer.microsoft.com/en-us/microsoft-edge/webview2/consumer");
let open = to_wide("open");
unsafe {
MessageBoxW(ptr::null_mut(), message.as_ptr(), title.as_ptr(), MB_OK | MB_ICONWARNING);
ShellExecuteW(ptr::null_mut(), open.as_ptr(), url.as_ptr(), ptr::null(), ptr::null(), 1);
}
}
}