From d00c49812af54121867eb1835f9d25e44d16c109 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Mon, 1 May 2023 03:06:10 +0200 Subject: feat: Show error message if WebView2 not installed (#285) * feat: Show error message if WebView2 not installed on Windows * fix: Add missing dependency * fix: Do not import lib on OS where not needed Don't need to import Windows lib on Linux * feat: Link to troubleshooting page directly * chore: Update comments * docs: Show error message in troubleshooting guide Show the "WebView2 not installed" error message in the troubleshooting guide * fix: Resolve clippy error * fix: Resolve clippy error (again) --- docs/TROUBLESHOOTING.md | 8 +++- .../flightcore-webview2-windows-error-message.png | Bin 0 -> 4631 bytes src-tauri/Cargo.lock | 1 + src-tauri/Cargo.toml | 2 + src-tauri/src/main.rs | 44 ++++++++++++++++++++- 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 docs/assets/flightcore-webview2-windows-error-message.png diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md index aed174e0..d36b1e1f 100644 --- a/docs/TROUBLESHOOTING.md +++ b/docs/TROUBLESHOOTING.md @@ -4,7 +4,13 @@ Got an issue with FlightCore? Hopefully one of the steps below will help you res ## FlightCore won't launch -If you are on Windows on FlightCore won't start, make sure you have WebView2 installed. You can grab the latest version from the Microsoft website: \ +If you are on Windows and FlightCore won't start but instead shows an error message like this + +![webview2 error message windows](assets/flightcore-webview2-windows-error-message.png) + +that means that WebView2 is not installed. WebView2 is an embedded browser framework used by FlightCore to display its GUI. + +To install it, you can grab the latest version from the Microsoft website: \ https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section ![webview2 download screenshot](assets/webview2-download-screenshot.png) diff --git a/docs/assets/flightcore-webview2-windows-error-message.png b/docs/assets/flightcore-webview2-windows-error-message.png new file mode 100644 index 00000000..bbe4422f Binary files /dev/null and b/docs/assets/flightcore-webview2-windows-error-message.png differ diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 5c0285da..960039ad 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -112,6 +112,7 @@ dependencies = [ "tauri-plugin-store", "tokio", "ts-rs", + "winapi", "zip", "zip-extract", ] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 0f68a560..0f65d665 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -64,6 +64,8 @@ log = "0.4.17" zip-extract = "0.1.2" # open urls open = "3.2.0" +# Windows API stuff +winapi = "0.3.9" [features] # by default Tauri runs in production mode diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 3aa17459..2e4b3370 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -9,6 +9,11 @@ use std::{ time::Duration, }; +#[cfg(target_os = "windows")] +use std::ptr::null_mut; +#[cfg(target_os = "windows")] +use winapi::um::winuser::{MessageBoxW, MB_ICONERROR, MB_OK, MB_USERICON}; + use app::{ constants::{APP_USER_AGENT, MASTER_SERVER_URL, REFRESH_DELAY, SERVER_BROWSER_ENDPOINT}, *, @@ -66,7 +71,7 @@ fn main() { }, )); - tauri::Builder::default() + match tauri::Builder::default() .plugin(tauri_plugin_store::Builder::default().build()) .setup(|app| { let app_handle = app.app_handle(); @@ -148,7 +153,42 @@ fn main() { close_application, ]) .run(tauri::generate_context!()) - .expect("error while running tauri application"); + { + Ok(()) => (), + Err(err) => { + // Failed to launch system native web view + + // Log error on Linux + #[cfg(not(target_os = "windows"))] + { + log::error!("{err}"); + } + + // On Windows we can show an error window using Windows API to show how to install WebView2 + #[cfg(target_os = "windows")] + { + log::error!("WebView2 not installed: {err}"); + // Display a message box to the user with a button to open the installation instructions + let title = "WebView2 not found" + .encode_utf16() + .chain(Some(0)) + .collect::>(); + let message = "FlightCore requires WebView2 to run.\n\nClick OK to open installation instructions.".encode_utf16().chain(Some(0)).collect::>(); + unsafe { + let result = MessageBoxW( + null_mut(), + message.as_ptr(), + title.as_ptr(), + MB_OK | MB_ICONERROR | MB_USERICON, + ); + if result == 1 { + // Open the installation instructions URL in the user's default web browser + open::that("https://github.com/R2NorthstarTools/FlightCore/blob/main/docs/TROUBLESHOOTING.md#flightcore-wont-launch").unwrap(); + } + } + } + } + }; } #[tauri::command] -- cgit v1.2.3