diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2023-05-01 03:06:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-01 03:06:10 +0200 |
commit | d00c49812af54121867eb1835f9d25e44d16c109 (patch) | |
tree | a7eccc74159588fd5b3ca97867a75b0a594dc6a3 /src-tauri/src/main.rs | |
parent | 06754cc2f63468a6a1945357918428fd9707cd91 (diff) | |
download | FlightCore-d00c49812af54121867eb1835f9d25e44d16c109.tar.gz FlightCore-d00c49812af54121867eb1835f9d25e44d16c109.zip |
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)
Diffstat (limited to 'src-tauri/src/main.rs')
-rw-r--r-- | src-tauri/src/main.rs | 44 |
1 files changed, 42 insertions, 2 deletions
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::<Vec<_>>(); + let message = "FlightCore requires WebView2 to run.\n\nClick OK to open installation instructions.".encode_utf16().chain(Some(0)).collect::<Vec<_>>(); + 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] |